我正在Geopanda库上做一些工作,我有一个形状文件,里面有多边形和excel表上的数据,我把它转换成点。我想让两个数据帧相交并将其导出到一个文件中。我也在两个投影(WGS84)上使用,这样我可以比较它们。 至少应该有一些点与多边形相交。 我的intersect GeoSeries没有给我任何适合多边形的点,但我不明白为什么。。。在
我检查了shapefile的单位是否真的是公里,而不是其他什么。我对GeoPlot不太精通,所以我不能确定GeoDataFrame是什么样子。在
f = pd.read_excel(io = 'C:\\Users\\peilj\\meteo_sites.xlsx')
#Converting panda dataframe into a GeoDataFrame with CRS projection
geometry = [Point(xy) for xy in zip(df.geoBreite, df.geoLaenge)]
df = df.drop(['geoBreite', 'geoLaenge'], axis=1)
crs = "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs"
gdf = GeoDataFrame(df, crs=crs, geometry=geometry)
#Reading shapefile and creating buffer
gdfBuffer = geopandas.read_file(filename = 'C:\\Users\\peilj\\lkr_vallanUTM.shp')
gdfBuffer = gdfBuffer.buffer(100) #When the unit is kilometer
#Converting positions long/lat into shapely object
gdfBuffer = gdfBuffer.to_crs("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs")
#Intersection coordonates from polygon Buffer and points of stations
gdf['intersection'] = gdf.geometry.intersects(gdfBuffer)
#Problem: DOES NOT FIND ANY POINTS INSIDE STATIONS !!!!!!!
#Giving CRS projection to the intersect GeoDataframe
gdf_final = gdf.to_crs("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs")
gdf_final['intersection'] = gdf_final['intersection'].astype(int) #Shapefile does not accept bool
#Exporting to a file
gdf_final.to_file(driver='ESRI Shapefile', filename=r'C:\\GIS\\dwd_stationen.shp
需要的文件: https://drive.google.com/open?id=11x55aNxPOdJVKDzRWLqrI3S_ExwbqCE9
有两件事:
创建指向以下对象的点时,需要交换}:
geoBreite
和{geometry = [Point(xy) for xy in zip(df.geoLaenge, df.geoBreite)]
这是因为shapely遵循x,y逻辑,而不是lat,lon。在
检查交叉口时,可按以下步骤进行:
它检测形状文件内的六个桩号:
^{pr2}$输出:
因此,除了一些其他的小问题外,我们还得到了:
相关问题 更多 >
编程相关推荐