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

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

Merged
merged 1 commit into from
Feb 22, 2024

Conversation

peterrrock2
Copy link
Collaborator

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.

…ns function

This is a quick fix for mggg#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.
Copy link
Collaborator

@jnclelland jnclelland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

@peterrrock2 peterrrock2 merged commit 7c45373 into mggg:dev/bugfix Feb 22, 2024
8 checks passed
@peterrrock2
Copy link
Collaborator Author

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

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.

2 participants