Skip to main content
added 15 characters in body
Source Link
Bera
  • 77.8k
  • 14
  • 78
  • 188

You can inner join themthe dataframes, then select the rows whichthat are not in the join.

Find the features in df that are not intersecting df2:

import geopandas as gpd

df = gpd.read_file(r"C:/GIS/data/Bakgrundskartor/Topografi_250/data/mark_sverige.gpkg", layer="sankmark")
df["tempid"] = range(0, df.shape[0]) #Create an id column

df2 = gpd.read_file(r"C:/GIS/data/Bakgrundskartor/Topografi_250/data/naturvard_sverige.gpkg", layer="skyddadnatur")

joined = gpd.sjoin(left_df=df, right_df=df2, how="inner", predicate="intersects") #Find the intersecting polygons

nonintersecting = df.loc[~df["tempid"].isin(joined["tempid"])] #Select the ids in df, that are not in the spatial join output

enter image description here

You can join them, then select the rows which are not in the join.

Find the features in df that are not intersecting df2:

import geopandas as gpd

df = gpd.read_file(r"C:/GIS/data/Bakgrundskartor/Topografi_250/data/mark_sverige.gpkg", layer="sankmark")
df["tempid"] = range(0, df.shape[0]) #Create an id column

df2 = gpd.read_file(r"C:/GIS/data/Bakgrundskartor/Topografi_250/data/naturvard_sverige.gpkg", layer="skyddadnatur")

joined = gpd.sjoin(left_df=df, right_df=df2, how="inner", predicate="intersects") #Find the intersecting polygons

nonintersecting = df.loc[~df["tempid"].isin(joined["tempid"])] #Select the ids in df, that are not in the spatial join output

enter image description here

You can inner join the dataframes, then select the rows that are not in the join.

Find the features in df that are not intersecting df2:

import geopandas as gpd

df = gpd.read_file(r"C:/GIS/data/Bakgrundskartor/Topografi_250/data/mark_sverige.gpkg", layer="sankmark")
df["tempid"] = range(0, df.shape[0]) #Create an id column

df2 = gpd.read_file(r"C:/GIS/data/Bakgrundskartor/Topografi_250/data/naturvard_sverige.gpkg", layer="skyddadnatur")

joined = gpd.sjoin(left_df=df, right_df=df2, how="inner", predicate="intersects") #Find the intersecting polygons

nonintersecting = df.loc[~df["tempid"].isin(joined["tempid"])] #Select the ids in df, that are not in the spatial join output

enter image description here

Source Link
Bera
  • 77.8k
  • 14
  • 78
  • 188

You can join them, then select the rows which are not in the join.

Find the features in df that are not intersecting df2:

import geopandas as gpd

df = gpd.read_file(r"C:/GIS/data/Bakgrundskartor/Topografi_250/data/mark_sverige.gpkg", layer="sankmark")
df["tempid"] = range(0, df.shape[0]) #Create an id column

df2 = gpd.read_file(r"C:/GIS/data/Bakgrundskartor/Topografi_250/data/naturvard_sverige.gpkg", layer="skyddadnatur")

joined = gpd.sjoin(left_df=df, right_df=df2, how="inner", predicate="intersects") #Find the intersecting polygons

nonintersecting = df.loc[~df["tempid"].isin(joined["tempid"])] #Select the ids in df, that are not in the spatial join output

enter image description here