- Python Geospatial Analysis Cookbook
- Michael Diener
- 320字
- 2021-07-30 10:13:23
Listing projection(s) from a WMS server
The Web Mapping Service (WMS), which can be found at provide data in several coordinate systems and you can then specify which one you would like. However, you can't reproject or transform the WMS into some other system that the service provider does not provide, which means that you can only use the coordinate system that is provided. The following is an example of a WMS getCapabilities
request (http://gis.ktn.gv.at/arcgis/services/INSPIRE/INSPIRE/MapServer/WmsServer?service=wms&version=1.3.0&request=getcapabilities), showing a list of the five available coordinate systems from a WMS service:

Getting ready
The WMS service URL that we will use is http://ogc.bgs.ac.uk/cgi-bin/BGS_1GE_Geology/wms?service=WMS&version=1.3.0&request=GetCapabilities. This is from the British Geological Survey, titled OneGeology Europe geology.
Tip
For a list of WMS servers that are available worldwide, refer to Skylab Mobile Systems at http://www.skylab-mobilesystems.com/en/wms_serverlist.html. Also, take a look at http://geopole.org/.
We will use a library called OWSLib. This library is a great package for working with OGC web services such as WMS, as follows:
Pip install owslib
How to do it...
Let's go through these steps to retrieve the projections that a WMS server provides and print the available EPSG codes to screen:
- Create a new Python file named
ch02_03_show_wms_srs.py
in your/ch02/code/working/
directory, and add the following code:#!/usr/bin/env python # -*- coding: utf-8 -*- from owslib.wms import WebMapService url = "http://ogc.bgs.ac.uk/cgi-bin/BGS_1GE_Geology/wms" get_wms_url = WebMapService(url) crs_list = get_wms_url.contents['GBR_Kilmarnock_BGS_50K_CompressibleGround'].crsOptions print crs_list
- Now, run the
ch02_03_show_wms_srs.py
script and you should see the following screen output:$ python ch02_03_show_wms_srs.py ['EPSG:3857', 'EPSG:3034', 'EPSG:4326', 'EPSG:3031', 'EPSG:27700', 'EPSG:900913', 'EPSG:3413', 'CRS:84', 'EPSG:4258']
How it works...
Determining information on the WMS projection involves using the OWSLib library. This is quite a powerful way to get all kinds of OGC web service information from your client. The code simply takes in the WMS URL to retrieve the WMS information. The content of the response is called, and we are able to access the crsOptions
attribute to list out all the available EPSG codes.
- C及C++程序設(shè)計(jì)(第4版)
- Learn TypeScript 3 by Building Web Applications
- 深度實(shí)踐OpenStack:基于Python的OpenStack組件開發(fā)
- Learn to Create WordPress Themes by Building 5 Projects
- 算法零基礎(chǔ)一本通(Python版)
- Learning ArcGIS Pro 2
- 基于免疫進(jìn)化的算法及應(yīng)用研究
- Mastering Drupal 8 Views
- Asynchronous Android Programming(Second Edition)
- Visual Studio 2015高級(jí)編程(第6版)
- INSTANT Apache ServiceMix How-to
- Secret Recipes of the Python Ninja
- Visual Basic語(yǔ)言程序設(shè)計(jì)基礎(chǔ)(第3版)
- Java高手是怎樣煉成的:原理、方法與實(shí)踐
- Android高級(jí)開發(fā)實(shí)戰(zhàn):UI、NDK與安全