geoMusings

geospatial technologies and practices

Getting Started With a Python Wrapper for the WeoGeo API

| Comments

One of my goals for 2011 was to sharpen my Python skills. As if on cue, WeoGeo puts out a Python wrapper for their RESTful API. It can be found here. The good news is that I now have a familiar problem set to sink my teeth into. The bad news (for me) is that it’s so easy to use it’s probably not going to do much for my Python skills.

The wrapper addresses the full WeoGeo API (Datasets, Jobs, Events, etc.) so it exposes pretty much everything you can through through the WeoGeo SaaS. For example, here is a very simple browse operation:

1
2
3
4
5
6
7
8
9
import WeoGeoAPI

#do a simple browse of WeoGeo Market
session = WeoGeoAPI.weoSession('market.weogeo.com', '', '')
session.connectToMarket()
#send some parameters to look for vector data sets covering Washington, DC.
datasets = session.getDatasets('JSON', '&data_type=VECTOR&per_page=2&page=1&north=39.043&south=38.767&west=-77.2&east=-77.906')
#prints the raw JSON response
print datasets

The output, cleaned up with JSONLint is at the end of this post. The WeoGeo JSON output for a dataset is large so I used the ‘per_page” parameter to limit the response to two datasets.

Since I started playing with the wrapper, WeoGeo has posted a test script which shows how to use it. I’ll start playing with creating jobs next. A word of caution about jobs: I highly recommend creating your own individual WeoGeo library (free) and loading a couple of datasets to play with. Most of the datasets on WeoGeo Market are for sale commercially so that’s probably not the best place to test an API.

In all, the wrapper seems pretty straightforward. I’m looking forward to working with it in more detail.

The JSON response to the browse executed above:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
{
    'per_page': 2,
    'total_entries': 34,
    'current_page': 1,
    'total_pages': 17,
    'items': [
        {
            'rating': 0.0,
            'projection': 'geo',
            'provider_margin': 1995.0,
            'uncompressed_misc_files_size': 7683891,
            'spatial_resolution': 0,
            'children_count': 0,
            'datum': 'WGS84',
            'library': {
                'name': 'Pitney Bowes - Business Insight',
                'id': 112
            },
            'kml_file_size': 0,
            'hosted': True,
            'market': 'Complete',
            'center_lat': 38.8051135,
            'layers': [
                'all'
            ],
            'east': -74.986282,
            'votes': 0,
            'content_license': {
                'url': 'http: //licenses.weogeo.com/licenses/8/original.PDF?1273263090',
                'name': 'PBBI Software and Data End User License v. April 2008'
            },
            'data_type': 'VECTOR',
            'royalty_model': 'CREDITED',
            'west': -79.487651,
            'scales': '6;7;8;9;10;11;12',
            'provider_discount_expires_at': None,
            'boundaries': {
                'geo': {
                    'proj4': '+proj=latlong +datum=wgs84',
                    'north': '39.723622',
                    'west': '-79.487651',
                    'datum': 'WGS84',
                    'projection_datum': 'geo-wgs84',
                    'east': '-74.986282',
                    'south': '37.886605'
                },
                'tiles': {
                    'number_of_lines': '316',
                    'number_of_samples': '316',
                    'datum': 'WGS84',
                    'line_pixel_size': '-830.510836842',
                    'sample_pixel_size': '1585.72818023',
                    'proj4': '+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +no_defs',
                    'projection_datum': 'spherical_mercator',
                    'west': '-8848524.83367',
                    'north': '4825860.68838',
                    'east': '-8347434.72872',
                    'south': '4563419.26394'
                },
                'native': {
                    'number_of_lines': '316',
                    'number_of_samples': '316',
                    'datum': 'WGS84',
                    'line_pixel_size': '-830.510836842',
                    'sample_pixel_size': '1585.72818023',
                    'proj4': '+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +no_defs',
                    'projection_datum': 'spherical_mercator',
                    'west': '-8848524.83367',
                    'north': '4825860.68838',
                    'east': '-8347434.72872',
                    'south': '4563419.26394'
                },
                'data': {
                    'proj4': '',
                    'datum': 'WGS84',
                    'projection_datum': 'geo-WGS84'
                },
                'baseimage': {
                    'number_of_lines': 0,
                    'number_of_samples': 0,
                    'west': '-8848524.833673440000000',
                    'line_pixel_size': 0,
                    'sample_pixel_size': 0,
                    'proj4': 'spherical_mercator',
                    'projection_datum': 'spherical_mercator',
                    'north': '4945185.028635530000000',
                    'east': '-8347434.728720820000000',
                    'south': '4444094.923682910000000'
                }
            },
            'tile_layer_type': 'xyz',
            'provider_discount_rate': 100,
            'provider_discount_expire_option': True,
            'x_conv': 1,
            'parents_count': 0,
            'status': 'Approved',
            'north': 39.723622,
            'description': '<b>StreetPro USA</b><br>\nVersion 2009.12<br><br> \nStreetPro offers users a premier street-level data product featuring accuracy and street display quality unparalleled in the industry. It reflects real world geographic conditions with the most current street data available.<br />With StreetPro,
            perform the most comprehensive,
            efficient and effective street-based analysis possible.<br /><br />StreetPro U.S.: <br /> * Provides the most complete,
            current and comprehensive streets on the market.<br /> * Integrates easily with Pitney Bowes Business Insight software.<br /> * Includes exclusive tools for use with Pitney Bowes Business Insight software.<br /> * Ships with display templates to get up and running quickly and easily with great looking maps.<br /><br />Created from Tele Atlas streets,
            this highly accurate street data is gathered from over 35,
            000 sources including E911 agencies,
            the U.S. Postal Service,
            city planning commissions,
            state departments of transportation and other local government sources. ',
            'spatial_resolution_in_meters': 0.0,
            'provider_min_margin': 477.67,
            'from_appliance?': False,
            'center_long': -77.2369665,
            'user': {
                'username': 'pbbidata',
                'rating': 5.0,
                'votes': 1
            },
            'data_created_on': '2009/12/15',
            'provider_max_discount': 304.32,
            'permalink': 'pbbidata_streetpro_maryland',
            'uploaded_at': '2010/05/06 15: 42: 51 -0400',
            'name': u'StreetPro\xae Maryland',
            'price_type': 'VARIABLE',
            'tile_file_format': 'png',
            'number_of_layers': 1,
            'file_format': 'mapinfo_tab',
            'token': '64ac8785-eab9-4856-b04b-1f33d872f511',
            'uncompressed_data_files_size': 127090387,
            'y_conv': 1,
            'max_price': 1995.0,
            'south': 37.886605
        },
        {
            'rating': 0.0,
            'projection': 'geo',
            'provider_margin': 1995.0,
            'uncompressed_misc_files_size': 7683891,
            'spatial_resolution': 0,
            'children_count': 0,
            'datum': 'WGS84',
            'library': {
                'name': 'Pitney Bowes - Business Insight',
                'id': 112
            },
            'kml_file_size': 0,
            'hosted': True,
            'market': 'Complete',
            'center_lat': 38.003375,
            'layers': [
                'all'
            ],
            'east': -75.166435,
            'votes': 0,
            'content_license': {
                'url': 'http: //licenses.weogeo.com/licenses/8/original.PDF?1273263090',
                'name': 'PBBI Software and Data End User License v. April 2008'
            },
            'data_type': 'VECTOR',
            'royalty_model': 'CREDITED',
            'west': -83.675415,
            'scales': '5;6;7;8;9;10;11;12',
            'provider_discount_expires_at': None,
            'boundaries': {
                'geo': {
                    'proj4': '+proj=latlong +datum=wgs84',
                    'north': '39.466012',
                    'west': '-83.675415',
                    'datum': 'WGS84',
                    'projection_datum': 'geo-wgs84',
                    'east': '-75.166435',
                    'south': '36.540738'
                },
                'tiles': {
                    'number_of_lines': '316',
                    'number_of_samples': '316',
                    'datum': 'WGS84',
                    'line_pixel_size': '-1308.10717344',
                    'sample_pixel_size': '2997.51683788',
                    'proj4': '+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +no_defs',
                    'projection_datum': 'spherical_mercator',
                    'west': '-9314704.58972',
                    'north': '4788645.33132',
                    'east': '-8367489.26895',
                    'south': '4375283.46452'
                },
                'native': {
                    'number_of_lines': '316',
                    'number_of_samples': '316',
                    'datum': 'WGS84',
                    'line_pixel_size': '-1308.10717344',
                    'sample_pixel_size': '2997.51683788',
                    'proj4': '+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +no_defs',
                    'projection_datum': 'spherical_mercator',
                    'west': '-9314704.58972',
                    'north': '4788645.33132',
                    'east': '-8367489.26895',
                    'south': '4375283.46452'
                },
                'data': {
                    'proj4': '',
                    'datum': 'WGS84',
                    'projection_datum': 'geo-WGS84'
                },
                'baseimage': {
                    'number_of_lines': 0,
                    'number_of_samples': 0,
                    'west': '-9314704.589715850000000',
                    'line_pixel_size': 0,
                    'sample_pixel_size': 0,
                    'proj4': 'spherical_mercator',
                    'projection_datum': 'spherical_mercator',
                    'north': '5055572.058304870000000',
                    'east': '-8367489.268945700000000',
                    'south': '4108356.737534730000000'
                }
            },
            'tile_layer_type': 'xyz',
            'provider_discount_rate': 100,
            'provider_discount_expire_option': True,
            'x_conv': 1,
            'parents_count': 0,
            'status': 'Approved',
            'north': 39.466012,
            'description': '<b>StreetPro USA</b><br>\nVersion 2009.12<br><br> \nStreetPro offers users a premier street-level data product featuring accuracy and street display quality unparalleled in the industry. It reflects real world geographic conditions with the most current street data available.<br />With StreetPro,
            perform the most comprehensive,
            efficient and effective street-based analysis possible.<br /><br />StreetPro U.S.: <br /> * Provides the most complete,
            current and comprehensive streets on the market.<br /> * Integrates easily with Pitney Bowes Business Insight software.<br /> * Includes exclusive tools for use with Pitney Bowes Business Insight software.<br /> * Ships with display templates to get up and running quickly and easily with great looking maps.<br /><br />Created from Tele Atlas streets,
            this highly accurate street data is gathered from over 35,
            000 sources including E911 agencies,
            the U.S. Postal Service,
            city planning commissions,
            state departments of transportation and other local government sources. ',
            'spatial_resolution_in_meters': 0.0,
            'provider_min_margin': 477.71,
            'from_appliance?': False,
            'center_long': -79.420925,
            'user': {
                'username': 'pbbidata',
                'rating': 5.0,
                'votes': 1
            },
            'data_created_on': '2009/12/15',
            'provider_max_discount': 304.37,
            'permalink': 'pbbidata_streetpro_virginia',
            'uploaded_at': '2010/05/06 14: 35: 58 -0400',
            'name': u'StreetPro\xae Virginia',
            'price_type': 'VARIABLE',
            'tile_file_format': 'png',
            'number_of_layers': 1,
            'file_format': 'mapinfo_tab',
            'token': '06ce3537-deb2-cc51-a081-2360eff828f7',
            'uncompressed_data_files_size': 234980712,
            'y_conv': 1,
            'max_price': 1995.0,
            'south': 36.540738
        }
    ]
}

Comments