0

I am attempting to overlay and find the intersection between two geodataframes but the result is an empty geodataframe when there should be several intersections. The two geodataframes should be in the same projection. Here are the two individually plotted geodataframes: gdf1 gdf2

Here is the code that I've tried:

import geopandas as gpd
import pandas as pd
import fiona
import os

#read shapefile
shapefile = gpd.read_file("./Superfund_Shape/Superfund_Shape.shp")

#read coordinate and elements data
hmsdata = pd.read_csv('./Heavy Metal Sheet-Final.csv')
hmsdf = pd.DataFrame(hmsdata)
elements = hmsdf.iloc[: , 3:12].copy()
coord = hmsdf.iloc[: , [12,13]].copy()

#convert coordinates dataframe to geodataframe
coords_gdf = gpd.GeoDataFrame(coord, geometry=gpd.points_from_xy(hmsdf.Coordinate2, hmsdf.Coordinate1))

#set the initial geodataframe crs
coords_gdf.crs = "EPSG:26954"

#convert coordinates to a Colorado specific projection
shapefile = shapefile.to_crs("EPSG:26954")

#buffer for 3 miles in meters (I think the buffer uses the CRS measurement for calculation
#the CRS for EPSG:26954 is in meters so it wants meters for the buffer function

buffer = coords_gdf.buffer(4828.03)
buffer = gpd.GeoDataFrame(gpd.GeoSeries(buffer))
buffer = buffer.rename(columns={0: 'geometry'})
buffer = buffer.set_geometry('geometry')

buffer.plot()
shapefile.plot()
#Superfund sites that fall within one of the beehive buffers?
intersection = gpd.overlay(buffer, shapefile, how='intersection')

and as I mentioned the 'intersection' geodataframe is empty: empty gdf

I know I'm probably missing something super simple, what am I doing wrong?

  • From the coordinates in your 2 plots, the geometries are far away from each other. That means no intersection can occur. If one of them is in correct CRS, say, the shapelile data, the other must be in wrong CRS and need to re-examine for correction. – swatchai Dec 03 '22 at 01:30
  • So if I understand correctly it's not enough to simply set them to the same CRS? – mrmcbreakfast Dec 03 '22 at 02:05
  • Yes. Along the series of coordinate (assignment and) conversion, each must be correct. – swatchai Dec 03 '22 at 03:45

0 Answers0