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")
csv.csv
andsquares.shp
files)? There might be some oddities with your inputs, too.