Skip to content

Graph.from_geodataframe() fails without crs #417

@RKBuck1

Description

@RKBuck1

I'm working with some toy data that doesn't have a crs and getting the following error from Graph.geodataframe():

AttributeError                            Traceback (most recent call last)
[<ipython-input-12-0266b8024caa>](https://localhost:8080/#) in <cell line: 1>()
----> 1 graph = Graph.from_geodataframe(zones, reproject = False)

[/usr/local/lib/python3.10/dist-packages/gerrychain/graph/graph.py](https://localhost:8080/#) in from_geodataframe(cls, dataframe, adjacency, cols_to_add, reproject, ignore_errors)
    181 
    182         graph.add_data(df, columns=cols_to_add)
--> 183         graph.graph["crs"] = df.crs.to_json()
    184         return graph
    185 

AttributeError: 'NoneType' object has no attribute 'to_json' 

I can work around it by setting the crs to a pseudo Plate Carrée projection, but it seems like it might make more sense to issue a warning here instead if the GeoDataFrame doesn't already have a crs assigned

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions