marceloprates / prettymaps

A small set of Python functions to draw pretty maps from OpenStreetMap data. Based on osmnx, matplotlib and shapely libraries.
GNU Affero General Public License v3.0
11.04k stars 516 forks source link

Fix geometry-perimeter intersection Supersedes #48 #54

Closed G21-Goose closed 2 years ago

G21-Goose commented 2 years ago

I've fixed some of the merge errors in my previous PR #48 and I'm using a different branch so I opened a new PR and shut the old one. The following is the text from my last PR.


Some geometry was removed, even through it was partially in the perimeter such as in issue #46 where not all the river was visible because the last bit partially went out of the perimeter. This seemed to happen when a perimeter was provided and not a point or radius.

If geometries = geometries.intersection(perimeter) is changed to geometries = geometries.intersection(perimeter).buffer(0) it seems to have behaviour that would be expected.

Before change image

After change image

Also the buffer on the perimeter in get_geometries() and get_streets() was being performed on the longitude and latitude in degrees, not meters. It now projects it, buffers it in meters, then turns it back into degrees for the ox.geometries_from_polygon()/ox.graph_from_polygon().

The get_streets() function would have streets going over the perimeter when only used with a perimeter. This was because the intersection code wasn't running when only a perimeter was used, and the perimeter was still a GeoDataFrame because the line perimeter = unary_union(ox.project_gdf(perimeter).geometry) was missing.


There was also an issue with some roads disappearing like in the case of #53 . This is because highway is sometimes a list e.g.

['residential', 'footway']

Because this does not equal residential or footway it was being excluded when the highways are being assigned a width. It has been changed to check if the highway being widened is in any of the values, so 'residential' is in ['residential','footway']