gboeing / osmnx

OSMnx is a Python package to easily download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap.
https://osmnx.readthedocs.io
MIT License
4.89k stars 827 forks source link

Optimize _remove_polygon_holes and _create_gdf for performance #1205

Closed wrignj08 closed 3 months ago

wrignj08 commented 3 months ago

This pull request addresses issue #1200 by optimizing the _remove_polygon_holes function to improve performance when dealing with complex geometries. Additionally, it enhances the efficiency of the _create_gdf function.

Changes proposed in this pull request:

  1. Optimized _remove_polygon_holes function to use shapely.prepared geometries and perform a single difference operation per outer polygon.
  2. Updated _create_gdf function to improve performance and avoid PerformanceWarnings.
  3. Added prepare import from shapely.

The functionality remains the same, just faster on complex polygons. ox.features.features_from_point((46.18, 74.42), tags={"natural": "water"}, dist=50000)

The CHANGELOG.md has been updated to reflect these changes.

The changes have been tested and all tests pass with the exception of mypy failed on osmnx/plot.py:856, but this was an existing issue and not related to the changes in this PR. As such, --no-verify was used to bypass the GitHub precommit hooks.

codecov[bot] commented 3 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 98.30%. Comparing base (29addce) to head (2b10aac).

Additional details and impacted files ```diff @@ Coverage Diff @@ ## tests #1205 +/- ## ========================================== - Coverage 98.31% 98.30% -0.01% ========================================== Files 24 24 Lines 2367 2366 -1 ========================================== - Hits 2327 2326 -1 Misses 40 40 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.