mvexel / overpass-api-python-wrapper

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

First crack at geoJSON output #17

Closed mharnold closed 9 years ago

mharnold commented 9 years ago

TODO: retrieve missing nodes referenced in ways to get their coords.

mvexel commented 9 years ago

I'd like another set of eyes on this. @mharnold, @itiboi, @johnjohndoe ? Comments?

johnjohndoe commented 9 years ago

I won't have time to review until next week.

mharnold commented 9 years ago

My eyes have already been all over it. ;) I am concerned that the merge is getting more difficult as other changes are added but I guess what I did is pretty localized.

Cheers, Michael spiderOSM.org

On Wed, Nov 19, 2014 at 9:03 AM, Tobias Preuss notifications@github.com wrote:

I won't have time to review until next week.

— Reply to this email directly or view it on GitHub https://github.com/mvexel/overpass-api-python-wrapper/pull/17#issuecomment-63674583 .

mvexel commented 9 years ago

@mharnold can you rebase and then I am ready to pull this in.

mvexel commented 9 years ago

actually I have time to rebase now if that's OK with you?

mharnold commented 9 years ago

It's fine with me but not sure what exactly is involved! This is my first time cloning/modifying and then issuing a pull request on github.

Cheers, Michael spiderOSM.org

On Mon, Nov 24, 2014 at 9:54 AM, Martijn van Exel notifications@github.com wrote:

actually I have time to rebase now if that's OK with you?

— Reply to this email directly or view it on GitHub https://github.com/mvexel/overpass-api-python-wrapper/pull/17#issuecomment-64234250 .

mharnold commented 9 years ago

Please explain 'rebase.' If you can do it from your end without my intervention that is cool with me.

Cheers, Michael spiderOSM.org

On Mon, Nov 24, 2014 at 9:57 AM, Michael Arnold mha.hiker@gmail.com wrote:

It's fine with me but not sure what exactly is involved! This is my first time cloning/modifying and then issuing a pull request on github.

Cheers, Michael spiderOSM.org

On Mon, Nov 24, 2014 at 9:54 AM, Martijn van Exel < notifications@github.com> wrote:

actually I have time to rebase now if that's OK with you?

— Reply to this email directly or view it on GitHub https://github.com/mvexel/overpass-api-python-wrapper/pull/17#issuecomment-64234250 .

mvexel commented 9 years ago

Rebasing is basically re-applying your changes on top of the updated head. It's pretty straightforward if there are no conflicts :)

One question though, simply passing out body geom does not seem to magically create actual GeoJSON output, it just adds lon/lat dicts to the output - we'd still need to process the output into proper GeoJSON, or am I missing something here?

On Mon Nov 24 2014 at 10:57:09 AM mharnold notifications@github.com wrote:

It's fine with me but not sure what exactly is involved! This is my first time cloning/modifying and then issuing a pull request on github.

Cheers, Michael spiderOSM.org

On Mon, Nov 24, 2014 at 9:54 AM, Martijn van Exel < notifications@github.com> wrote:

actually I have time to rebase now if that's OK with you?

— Reply to this email directly or view it on GitHub < https://github.com/mvexel/overpass-api-python-wrapper/pull/17#issuecomment-64234250>

.

— Reply to this email directly or view it on GitHub https://github.com/mvexel/overpass-api-python-wrapper/pull/17#issuecomment-64234665 .

mharnold commented 9 years ago

I do that processing in API._asGeoJSON() Someone had created this method as a stub, and I filled it out.

def _asGeoJSON(self, elements):

print 'DEB _asGeoJson elements:', 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":
            points = []
            for coords in elem["geometry"]:
                points.append((coords["lon"], coords["lat"]))
            geometry = geojson.LineString(points)
        else:
            continue

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

    return geojson.FeatureCollection(features)
mvexel commented 9 years ago

Me and Mondays, just not a great combo... I apologize @mharnold ..

I'll test for myself, rebase and merge today. Thanks for all the work.

For me, this will be a major step in accomplishing a bridge between Overpass and MapRoulette. I will use this for creating a 'No-Name-Ways' challenge for Brazil (based on a query like this: http://overpass-turbo.eu/?Q=%5Bout%3Ajson%5D%3B%0Away(-22.9%2C-43.6%2C-22.8%2C-43.5)%0A%20%20%5Bhighway~%22.%22%5D%0A%20%20%5Bname!~%22.%22%5D%3B%0A(._%3B%3E%3B)%3B%0Aout%3B&C=-22.85234;-43.54874;12 )

mharnold commented 9 years ago

No problem. :) Very cool that this has immediate application, thanks for sharing that.

BTW If you uncomment the two lines before the assert in TestAPI.test_geojson() you can look at the results for a tiny query in the Berkeley Marina. This is how I debugged.