Skip to content

Sample Code and Tutorials

housemate edited this page Nov 29, 2013 · 15 revisions

Services

Web Services

There are a number of services that provide a simple HTTP interface for querying of geographic data. These include the Web Map Service, the Web Feature Service and the Web Coverage Service.

Visit the Geo Query Builder to simplify the process of building queries to retrieve the data you need from a WMS/WFS server. Or take a look at the some sample queries below.

WMS

The Web Map Service can be used for requesting map images and tiles from geospatial databases. Multiple layers can be requested at once or requested as transparent images to layer with other images.For example an image depicting the Australian state boundaries.

Examples
A Simple Request - State Boundaries of Australia

http://geospace.research.nicta.com.au:8080/admin_bnds/ows?service=WMS&request=GetMap&bbox=96.816941408,-43.740509603,159.109219008,-9.142175977&layers=admin_bnds_abs:STE_2011_AUST&width=360&height=200&format=image/png

JSON object representing the parameters:

{
    "service": "WMS",
    "request": "GetMap",
    "bbox": "96.816941408,-43.740509603,159.109219008,-9.142175977",
    "layers": "admin_bnds_abs:STE_2011_AUST",
    "width": 360,
    "height": 200,
    "format": "image/png"
}

Note that all of the above parameters are required in order to retrieve an image.

The bounding box (bbox) is defined as the coordinates for west, south, east, north.

A Multi-Layer Request - Mines and Railways

http://geospace.research.nicta.com.au:8080/geotopo_250k/ows?service=WMS&request=GetMap&bbox=113.361663818359,-43.4303932189941,153.504867553711,-11.8729591369629&layers=Transport:railways,Infrastructure:mineareas&width=254&height=200&format=image/png

JSON object representing the parameters:

{
    "service": "WMS",
    "request": "GetMap",
    "bbox": "113.361663818359,-43.4303932189941,153.504867553711,-11.8729591369629",
    "layers": "Infrastructure:mineareas,Transport:railways",
    "width": 254,
    "height": 200,
    "format": "image/png"
}

Multiple layers can be specified simply by adding commas between multiple layer names.

WFS

The Web Feature Service can be used to retrieve data sets from geospatial databases. It can return geometry as a series of points and polygons with the properties of that geometry. For example, Australian states geometry with the state names and population as properties.

A Simple Request - State Boundaries

http://geospace.research.nicta.com.au:8080/admin_bnds/ows?service=WFS&request=GetFeature&typeName=admin_bnds_abs:STE_2011_AUST&outputFormat=json&maxFeatures=50

{
    "service": "WFS",
    "request": "GetFeature",
    "typeName": "admin_bnds_abs:STE_2011_AUST",
    "bbox": "-43.740509603,96.816941408,-9.142175977,159.109219008", // Optional
    "maxFeatures": 50, // Optional, but beware of large amounts of data
    "outputFormat": "json"
}

Note that all of the above parameters (except maxFeatures and bbox) are required in order to retrieve a feature set.

The bounding box (bbox) is defined as the coordinates for south, west, north, east.

WCS

Getting the capabilities of a WFS or WMS server

If you want to know the services, requests and format types that a web service provides there's a standard for querying for this information. This involves setting the request parameter to getCapabilities.

Examples

WMS Capabilities

http://geospace.research.nicta.com.au:8080/admin_bnds/ows?service=WMS&request=GetCapabilities

{
    "service": "WMS",
    "request": "GetCapabilities"
}
WFS Capabilities

http://geospace.research.nicta.com.au:8080/admin_bnds/ows?service=WFS&request=GetCapabilities

{
    "service": "WFS",
    "request": "GetCapabilities"
}

Programming Languages/Environments

Javascript

D3

D3 is a helpful library for many types of visualization. Particularly for geographic visualization as it includes a built in geo module for dealing with GeoJSON and geographical projections.

Here are some useful samples and tutorials on how to use D3 for geospatial data:

Leaflet

Leaflet is a modern open-source JavaScript library for mobile-friendly interactive maps.

Leaflet has its own series of tutorials on creating interactive maps.

There is a mobile example using Leaflet with Cordova that demonstrates visualising a WMS layer from a geoserver. There is also a live demo that runs in a browser.

C++

Some relevant C++ libraries:

Python

Some Python tools that might be useful for manipulating geospatial data:

See the Git repository for some examples of using Basemap to plot pointcloud, shapefile and rastered data in python.

Matlab