Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 两个地理坐标系之间的交点_Python_Python 3.x_Pandas_Geopandas - Fatal编程技术网

Python 两个地理坐标系之间的交点

Python 两个地理坐标系之间的交点,python,python-3.x,pandas,geopandas,Python,Python 3.x,Pandas,Geopandas,我正在Geopanda库上做一些工作,我有一个包含多边形的形状文件和excel表格上的数据,我将其转换为点。我想将两个数据帧相交并将其导出到一个文件中。我也在两个投影上使用(WGS84),以便比较它们。 应该至少有一些点与多边形相交。 我的intersect GeoSeries没有给我任何适合多边形的点,但我不明白为什么 我检查了shapefile的单位是否真的是公里,而不是别的什么。我对GeoPlot并不精通,所以我不能真正确定GeopataFrame是什么样子 f = pd.read_exc

我正在Geopanda库上做一些工作,我有一个包含多边形的形状文件和excel表格上的数据,我将其转换为点。我想将两个数据帧相交并将其导出到一个文件中。我也在两个投影上使用(WGS84),以便比较它们。 应该至少有一些点与多边形相交。 我的intersect GeoSeries没有给我任何适合多边形的点,但我不明白为什么

我检查了shapefile的单位是否真的是公里,而不是别的什么。我对GeoPlot并不精通,所以我不能真正确定GeopataFrame是什么样子

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

所需文件: 有两件事:

创建点时,您需要交换
geobrete
geoLaenge

geometry=[拉链中xy的点(xy)(df.geoLaenge,df.geobrete)]

这是因为shapely遵循x,y逻辑,而不是lat,lon

至于检查交叉口,您可以执行以下操作:

gdf['inside'] = gdf['geometry'].apply(lambda shp: shp.intersects(gdfBuffer.dissolve('LAND').iloc[0]['geometry']))
它检测形状文件中的六个桩号:

gdf['inside'].sum()
输出:

6
因此,除了其他一些小的修复外,我们还得到:

import geopandas as gpd
from shapely.geometry import Point

df = pd.read_excel(r'C:\Users\peilj\meteo_sites.xlsx')

geometry = [Point(xy) for xy in zip(df.geoLaenge, df.geoBreite)]
crs = {'init': 'epsg:4326'}
gdf = gpd.GeoDataFrame(df, crs=crs, geometry=geometry)

gdfBuffer = gpd.read_file(filename = r'C:\Users\peilj\lkr_vallanUTM.shp')
gdfBuffer['goemetry'] = gdfBuffer['geometry'].buffer(100)

gdfBuffer = gdfBuffer.to_crs(crs)

gdf['inside'] = gdf['geometry'].apply(lambda shp: shp.intersects(gdfBuffer.dissolve('LAND').iloc[0]['geometry']))
两件事:

创建点时,您需要交换
geobrete
geoLaenge

geometry=[拉链中xy的点(xy)(df.geoLaenge,df.geobrete)]

这是因为shapely遵循x,y逻辑,而不是lat,lon

至于检查交叉口,您可以执行以下操作:

gdf['inside'] = gdf['geometry'].apply(lambda shp: shp.intersects(gdfBuffer.dissolve('LAND').iloc[0]['geometry']))
它检测形状文件中的六个桩号:

gdf['inside'].sum()
输出:

6
因此,除了其他一些小的修复外,我们还得到:

import geopandas as gpd
from shapely.geometry import Point

df = pd.read_excel(r'C:\Users\peilj\meteo_sites.xlsx')

geometry = [Point(xy) for xy in zip(df.geoLaenge, df.geoBreite)]
crs = {'init': 'epsg:4326'}
gdf = gpd.GeoDataFrame(df, crs=crs, geometry=geometry)

gdfBuffer = gpd.read_file(filename = r'C:\Users\peilj\lkr_vallanUTM.shp')
gdfBuffer['goemetry'] = gdfBuffer['geometry'].buffer(100)

gdfBuffer = gdfBuffer.to_crs(crs)

gdf['inside'] = gdf['geometry'].apply(lambda shp: shp.intersects(gdfBuffer.dissolve('LAND').iloc[0]['geometry']))