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: CRS from GeoDataFrame not passed on to individual geometry objects #3277

Open
codeananda opened this issue May 7, 2024 · 3 comments
Open
Labels
enhancement needs discussion Requires further discussion

Comments

@codeananda
Copy link

  • [✅ ] I have checked that this issue has not already been reported.

  • [✅ ] I have confirmed this bug exists on the latest version of geopandas.

  • [❌] (optional) I have confirmed this bug exists on the main branch of geopandas.


Code Sample, a copy-pastable example

import geopandas as gpd
import shapely
from shapely import get_srid
from shapely.geometry import Point

# Create a test GeoDataFrame
data = {'name': ['A', 'B', 'C'],
        'geometry': [Point(0, 0), Point(1, 1), Point(2, 2)]}
gdf = gpd.GeoDataFrame(data, crs='EPSG:4326')

# Check the CRS of the GeoDataFrame
print("GeoDataFrame CRS:", gdf.crs)

# Check the CRS of individual geometries
for idx, row in gdf.iterrows():
    geom = row.geometry
    print(
        f"Geometry {idx} CRS: "
        f"\n{get_srid(geom)=}"
        f"\n{get_srid(shapely.wkt.loads(geom.wkt))=}"
        f"\n{get_srid(shapely.from_wkb(geom.wkb))=}\n"
        
    )

Output

GeoDataFrame CRS: EPSG:4326
Geometry 0 CRS: 
get_srid(geom)=0
get_srid(shapely.wkt.loads(geom.wkt))=0
get_srid(shapely.from_wkb(geom.wkb))=0

Geometry 1 CRS: 
get_srid(geom)=0
get_srid(shapely.wkt.loads(geom.wkt))=0
get_srid(shapely.from_wkb(geom.wkb))=0

Geometry 2 CRS: 
get_srid(geom)=0
get_srid(shapely.wkt.loads(geom.wkt))=0
get_srid(shapely.from_wkb(geom.wkb))=0

Problem description

The GDF has the correct CRS but the individual geometry objects themselves do not.

Expected Output

This seems odd. I would expect each geom object to have the same CRS as the gdf.

Output of geopandas.show_versions()

SYSTEM INFO

python : 3.10.6 (tags/v3.10.6:9c7b4bd, Aug 1 2022, 21:53:49) [MSC v.1932 64 bit (AMD64)]
executable : C:\Users\User\AppData\Local\pypoetry\Cache\virtualenvs\big-bertha-O8kHtzvf-py3.10\Scripts\python.exe
machine : Windows-10-10.0.22631-SP0

GEOS, GDAL, PROJ INFO

GEOS : 3.11.3
GEOS lib : None
GDAL : 3.6.4
GDAL data dir: C:\Users\User\AppData\Local\pypoetry\Cache\virtualenvs\big-bertha-O8kHtzvf-py3.10\lib\site-packages\fiona\gdal_data
PROJ : 9.3.0
PROJ data dir: C:\Users\User\AppData\Local\pypoetry\Cache\virtualenvs\big-bertha-O8kHtzvf-py3.10\lib\site-packages\pyproj\proj_dir\share\proj

PYTHON DEPENDENCIES

geopandas : 0.14.4
numpy : 1.26.4
pandas : 2.1.3
pyproj : 3.6.1
shapely : 2.0.4
fiona : 1.9.6
geoalchemy2: None
geopy : None
matplotlib : 3.8.4
mapclassify: 2.6.1
pygeos : None
pyogrio : 0.7.2
psycopg2 : None
pyarrow : None
rtree : 1.2.0

@martinfleis
Copy link
Member

The CRS information is not stored on the geometry level but for the whole GeometryArray. GeoPandas has never passed CRS information as SRID onto geometries. Given you can work with custom projections defined as pyproj.CRS which cannot be expressed as SRID integer, we would often run into trouble trying to do that. Not mentioning the likely performance issue.

If you want to set SRIDs, you can do that using shapely.set_srid. But the fact that the geometries do not have SRID at the moment is not a bug but an expected behaviour.

@martinfleis martinfleis added needs discussion Requires further discussion and removed bug needs triage labels May 7, 2024
@martinfleis martinfleis changed the title BUG: CRS from GeoDataFrame not passed on to individual geometry objects ENH: CRS from GeoDataFrame not passed on to individual geometry objects May 7, 2024
@jorisvandenbossche
Copy link
Member

We might want to better document this

@codeananda
Copy link
Author

codeananda commented May 13, 2024

@martinfleis understood, I get the performance considerations.

We might want to better document this

@jorisvandenbossche I agree, this isn't obvious

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement needs discussion Requires further discussion
Projects
None yet
Development

No branches or pull requests

3 participants