TransWikia.com

Problem with intersection between two Geopandas Dataframes

Geographic Information Systems Asked by RRSC NGP on August 12, 2020

I have 2 shape files one “country.shp” (containing the tiles geometry covering the whole country) & other “district.shp”(containing one particular district). Now I want to get the tiles information getting intersected with the district polygon (similar to search by location in ArcGIS) and the final intersected geodataframe should contain the attributes of “country.shp” (containing only intersected rows from “country.shp”). Up till now I have used the following code but it is working fine only for some district shape files (projections are same for both the shapefiles). Can someone help me what is wrong with the following code or suggest some other alternatives?


import geopandas as gpd

f1 = "/home/geo/country.shp"
f2 = "/home/geo/district.shp"
data1 = gpd.read_file(f1)
data2 = gpd.read_file(f2)

import shapely.speedups
shapely.speedups.enable()

pip_mask = data1.within(data2.loc[0, 'geometry']) 

pip_data= data1.loc[pip_mask]

One Answer

Try using the squeeze method in order to extract the Shapely geometry:

pip_mask = data1.within(data2.loc[0, 'geometry'].squeeze())

Answered by ramiroaznar on August 12, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP