0

I have an issue when performing a spatial join, I have a polygon of 2x2Km squares (no overlapping between polygons) and a CSV which I converted to a geodataframe and assigned the same CRS as that for the polygon's shapefile. I had to change the CRS from ArcGIS to a new one "EPSG:4204" (it was originally EPSG:32638 and no matter if I changed it along with the CSV CRS, the sjoin returned empty gdf).

After performing a project to CRS EPSG:4202 using ArcGIS, the result of the sjoin on GeoPandas was ok, except for points nearby the boundary lines (it's not on the borderline but actually few meters within it when I checked manually), for some reason it maps the point to the polygon next to the borderline.

The code I used:

The GeoPandas version I have is 0.9.0

import pandas as pd
import geopandas as gpd
from geopandas import geodataframe
df = pd.read_csv("csv.csv")
squares = gpd.read_file("squares.shp")
gdf_points = gpd.GeoDataFrame(df, geometry=gpd.points_from_xy(df.longitude, df.latitude), crs =squares.crs)
sjoined = gpd.sjoin(gdf_points, squares, how="left", op="within")
Lilium
1,0651 gold badge8 silver badges17 bronze badges
asked Jan 10, 2022 at 21:21
3
  • This shouldn't happen. Unless there's an issue with the data, it is a bug in GeoPandas (or elsewhere). Can you report it to github.com/geopandas/geopandas/issues together with some data excerpt? Commented Jan 10, 2022 at 23:00
  • Also, can you share your input data as well (the csv.csv and squares.shp files)? There might be some oddities with your inputs, too. Commented Jan 12, 2022 at 17:53
  • thanks guys, I really wanted to upload some data but unfortunetly it's work related and I'm not allowed to post samples online. Appearntly the issue resolved when I used EPSG:4326 as a crs for both the points and polygons. Not really sure why this happened and how correct is it to use crs 4326 but visually there was no difference from the original EPSG. Commented Jan 13, 2022 at 0:27

1 Answer 1

1

For some reason when I projected the polygon to EPSG:4326 using ArcGIS (didn't try to do this step using python) then converted the CSV to GeoDataFrame on python with the same CRS (4326) using the same code I used in above in my question, it worked! I have no explaination for such a behavior as I'm new to GIS and CRS in particular:).

answered Jan 13, 2022 at 0:25

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.