mvexel / overpass-api-python-wrapper

Python bindings for the OpenStreetMap Overpass API
Apache License 2.0
368 stars 90 forks source link

[help wanted] Trying to pull roads in a region #100

Closed seangrogan closed 5 years ago

seangrogan commented 6 years ago

Hello all;

I think I have two problems here, the first is that when pulling the GeoJOSN file, i am not getting the data I expect. The second, when I try to change the format to 'xml' or 'csv', (to try to debug) i get an error (which seems similar to Issue 96. For the former, I feel like I'm missing something when it comes to interpreting the GEO JOSN file.

What I am specifically trying to do is pull all the roads (and points/ways that pertain to roads) in a search area. I'm leaning on overpass because my area pulls a few too many points for the standard API.

I first call the mapquery as

response = api.get(overpass.MapQuery(west=min_lon, south=min_lat, east=max_lon, north=max_lat))

and then I go through the response with

    desired_features = ['highway']
    desired_subfeatures = ['motorway', 'trunk', 'primary', 'secondary', 'tertiary', 'unclassified', 'residential', 'service']
    for i in response.features:
        features = i['properties']
        for j in features:
            if j in desired_features:
                if i['properties'][j] in desired_subfeatures:
                      # add it to my list.  

however, nothing is pulled containing the desired_subfeatures, and when ignoring the if i['properties'][j] in desired_subfeatures: command, it appears only intersections and junctions are pulled. I don't think I can use wayQuery because it requires a specific name of a way to be pulled.

If it helps, the coordinates I'm trying to pull are:

max_lat = {float} 35.47
max_lon = {float} -97.28
min_lat = {float} 35.19
min_lon = {float} -97.75

Just south of Oklahoma City, Oklahoma.

mvexel commented 5 years ago

Does the API return the data you expect? I think this may be more a generic Python issue than something specific to this project.

I would do something like

for feature in response.features:
    if set(desired_keys) & set(feature.properties.keys()) and \
            set(desired_subfeatures) & set(feature.properties.values()):
        print(feature.properties)

Or perhaps I am misunderstanding your issue..?

mvexel commented 5 years ago

Closing this but feel free to re-open if you feel your issue was not addressed