Skip to content

Commit

Permalink
merging pep8 changes
Browse files Browse the repository at this point in the history
  • Loading branch information
mvexel committed Nov 25, 2014
1 parent f99f3fc commit e471d3b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
27 changes: 17 additions & 10 deletions overpass/api.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import sys
import requests
import json
from shapely.geometry import Point
import geojson


class API(object):
"""A simple Python wrapper for the OpenStreetMap Overpass API"""
Expand Down Expand Up @@ -69,10 +70,15 @@ def _ConstructQLQuery(self, userquery, asGeoJSON=False):
if not raw_query.endswith(";"):
raw_query += ";"

complete_query = self._QUERY_TEMPLATE.format(
if asGeoJSON:
template = self._GEOJSON_QUERY_TEMPLATE
else:
template = self._QUERY_TEMPLATE

complete_query = template.format(
responseformat=self.responseformat,
query=raw_query
)
query=raw_query)

if self.debug:
print(complete_query)
return complete_query
Expand Down Expand Up @@ -116,9 +122,9 @@ def _asGeoJSON(self, elements):
features = []
for elem in elements:
elem_type = elem["type"]
if elem["type"] == "node":
geometry=geojson.Point((elem["lon"], elem["lat"]))
elif elem["type"] == "way":
if elem_type == "node":
geometry = geojson.Point((elem["lon"], elem["lat"]))
elif elem_type == "way":
points = []
for coords in elem["geometry"]:
points.append((coords["lon"], coords["lat"]))
Expand All @@ -127,13 +133,14 @@ def _asGeoJSON(self, elements):
continue

feature = geojson.Feature(
id=elem["id"],
geometry=geometry,
properties=elem.get("tags"))
id=elem["id"],
geometry=geometry,
properties=elem.get("tags"))
features.append(feature)

return geojson.FeatureCollection(features)


class OverpassException(Exception):
def __init__(self, status_code, message):
self.status_code = status_code
Expand Down
9 changes: 4 additions & 5 deletions test_api.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import geojson
import overpass


Expand All @@ -7,16 +6,16 @@ class TestAPI(object):
def test_initialize_api(self):
api = overpass.API()
assert isinstance(api, overpass.API)
assert api.debug == False
assert api.debug is False

def test_geojson(self):
api = overpass.API()
#osm_elements = api.Get(overpass.MapQuery(37.86517,-122.31851,37.86687,-122.31635))
#print 'DEB osm_elements:', geojson.dumps(osm_elements,sort_keys=True,indent=2)
osm_geo = api.Get(overpass.MapQuery(37.86517,-122.31851,37.86687,-122.31635), asGeoJSON=True)
osm_geo = api.Get(overpass.MapQuery(37.86517, -122.31851, 37.86687, -122.31635), asGeoJSON=True)
#with open('test.geojson','w') as f:
# geojson.dump(osm_geo,f,indent=2,sort_keys=True)
assert len(osm_geo['features'])>1
assert len(osm_geo['features']) > 1

def run_tests(self):
self.test_initialize_api()
Expand All @@ -25,4 +24,4 @@ def run_tests(self):
if __name__ == '__main__':
tapi = TestAPI()
tapi.run_tests()
print "overpass PASS"
print("overpass PASS")

0 comments on commit e471d3b

Please sign in to comment.