mggg / maup

The geospatial toolkit for redistricting data.
https://maup.readthedocs.io/en/latest/
MIT License
65 stars 23 forks source link

Fix issue in from_records not tracking crs correctly in intersections function #96

Closed peterrrock2 closed 7 months ago

peterrrock2 commented 7 months ago

This is a quick fix for #95. The main issue is that the from_records function is inherited from the pandas library, and it does not track so when it creates a GeoDataFrame from a list of records, it does not assign the column labeled "geometry" as a geometry column, and, with the new change to pandas 2, it looks like this ends up throwing the following error:

ValueError: Assigning CRS to a GeoDataFrame without a geometry column is not supported. Use GeoDataFrame.set_geometry to set the active geometry column.`

If we use the constructor for the GeoDataFrame object intead, then geopandas correctly handles the geometry column, and we can assign the crs to the GeoDataFrame object directly.

peterrrock2 commented 7 months ago

Looks good to me - I assume that you've checked that Line 44 in intersections.py results in a geometry with the correct CRS and so Line 46 is unnecessary?

Correct. Since we set the crs in the declaration of the GeoDataFrame object in

df = GeoDataFrame(
    records,
    columns=["source", "target", "geometry"], 
    crs=sources.crs
)

Everything that is derived from that object will inherit the crs