Skip to content

WeoGeo API: Python Examples, Part 1

January 7, 2010
tags:
by DanDye

The Developer Documentation for WeoGeo’s API provides examples using curl:

curl example in WeoGeo Developer Documentation (wiki.weogeo.com)

curl example in WeoGeo Developer Documentation (wiki.weogeo.com)

However, after fielding some questions from Developers, I’m thinking some Python (and C#?) examples might be useful too.  So here is the first installment.

This is a bare-bones example of the List Datasets API, which returns a list of Datasets within the (optional) defined parameters.  Possible parameters include a Minimum Bounding Rectangle (MBR), date range, ratings, and/or Tags.

[python]
import urllib

usern = [your WeoGeo username]
passw = [your WeoGeo password]
library = [the * part of your Library's domain name *.weogeo.com]

# List Datasets (GET) curl example:
# curl -H ‘Content-Type: application/xml’ http://#{hostname}/datasets.weo?page=1&east=0&north=90&south=0&west=-180&scale=5

# Optional parameters:
params = urllib.urlencode(
{
‘page’: 1,
‘per_page’: ’15′,
‘north’: ’90.0′,
‘south’: ‘-90.0′,
‘east’: ’180.0′,
‘west’: ‘-180.0′,
‘date_from’: ’1990-01-01′,
‘date_to’: ’2010-01-01′,
‘data_type’: ‘RASTER’,
‘min_provider_rating’: ’0′,
‘min_dataset_rating’: ’0′,
‘tags’: ‘test’
}
)

# construct the URI for the API with parameters:
url = "https://%s:%s@%s.weogeo.com/datasets.weo?%s" % (usern,passw,library,params)

# call the URI
f = urllib.urlopen(url)

# print results to the CLI
print f.read()
[/python]

For extra credit, try changing the extension from “.weo” to [".kml",".json",".rss"].

Next time, I’ll show the same WeoGeo API call in Python but use httplib instead of urllib.  Although, urllib is simpler, httplib handles authentication better and enables the more sophisticated requests that will be required for later API examples.


3 Comments
  1. March 6, 2010 6:29 pm

    Cool Thanks for this post. I am a newbie at python and this got me straight.

Trackbacks

  1. WeoGeo API: Python Examples, Part 2 « Dwell Time with Dan Dye
  2. Browsing WeoGeo Market Using the ESRI Silverlight API « GeoMusings

Comments are closed.