Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: Add geodesic_area method for accurate area calculations #3525

Closed
wants to merge 2 commits into from

Conversation

popogis24
Copy link

@popogis24 popogis24 commented Mar 8, 2025

ENH: Add geodesic_area method for accurate area calculations

This PR adds a new geodesic_area() method to GeoPandasBase that calculates areas using the WGS84 ellipsoid, providing more accurate results for geographic coordinates (latitude/longitude) compared to the standard .area property.

Key features:

  • Calculates geodesic area using the WGS84 ellipsoid via geographiclib
  • Supports different units (m², km², ha)
  • Handles polygons with holes and multipolygons
  • Issues warning when used with non-geographic CRS
  • Includes comprehensive test coverage
  • Adds detailed documentation with examples
    This is particularly useful when working with geographic data where accurate area calculations are important, such as:

Land use/cover analysis
Conservation and environmental studies
Urban planning
Agricultural applications
Changes made:

Added geodesic_area() method to GeoPandasBase
Added comprehensive test suite in test_geom_methods.py
Updated documentation in:
GeoSeries reference
Geometric manipulations user guide
Added geographiclib as a dependency

Example usage:

import geopandas as gpd
from shapely.geometry import Polygon

# Create a polygon with geographic coordinates
poly = Polygon([(-48.5, -27.5), (-48.4, -27.5), 
                (-48.4, -27.4), (-48.5, -27.4)])
gs = gpd.GeoSeries([poly], crs="EPSG:4326")

# Calculate area in different units
area_m2 = gs.geodesic_area()  # square meters
area_km2 = gs.geodesic_area('km2')  # square kilometers
area_ha = gs.geodesic_area('ha')  # hectares

This commit adds a new geodesic_area() method to GeoPandasBase that:
- Calculates areas using WGS84 ellipsoid for geographic coordinates
- Supports different units (m², km², ha)
- Handles polygons with holes and multipolygons
- Includes comprehensive test coverage
- Add geodesic_area to GeoSeries reference
- Add usage examples and explanation in geometric manipulations guide
- Include comparison with standard area property
- Show examples with different units and geographic locations
@popogis24
Copy link
Author

btw tests failed bc we must add geographiclib to requirements

@martinfleis
Copy link
Member

Hi @popogis24,

thanks for the PR! The typical workflow for contributions is to start with an issue where we agree on what should be done and how before writing code but we're too late for that :). We have discussed this PR during the last dev call yesterday night and agreed that there is a scope to include geodesic measurements (area, perimeter, length) but probably in a bit different way.

First of all, we would prefer using pyproj for the computation, rather that depending directly on geographiclib. We already depend on pyproj and can directly use the ellipsoid from the CRS.

Second, we would eventually want to use it directly within .area. In the final stage, it should be used automatically for any geographic CRS (aiming at geopandas 2.0). There should be a geopandas.options toggle to turn it on and off, defaulting to True. In the intermediate step, this option should be False and the warning we raise right now should be updated to point to the new options as a transition period.

Would that make sense in your eyes?

@popogis24
Copy link
Author

popogis24 commented Mar 28, 2025

Hi @martinfleis,

Thanks for the feedback! That makes perfect sense. I understand the preference for using pyproj instead of geographiclib and integrating geodesic calculations directly into .area with an option to toggle it.

To align better with the development roadmap, I can create an issue so we can further discuss the methodology and implementation details before proceeding. Let me know if that sounds good to you!

BTW, I’m really looking forward to this update with geodesic calculations—I have a project that directly depends on it.

Thanks again!

@martinfleis
Copy link
Member

To align better with the development roadmap, I can create an issue so we can further discuss the methodology and implementation details before proceeding. Let me know if that sounds good to you!

Yes please! That is always a preferred way.

@popogis24 popogis24 closed this by deleting the head repository Apr 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants