地理数据框以选择某些ID并在指定距离内找到几何形状
我创建了一个测试形状文件,其中包含EPSG:2157中的15个点功能,并导出了Geojson。每个点都被分配了一个ID-例如1、2、3等。它们看起来像:
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {
"id": "1"
},
"geometry": {
"type": "Point",
"coordinates": [
-5.905044078826904,
54.609987802465916
]
}
},
{
"type": "Feature",
"properties": {
"id": "11"
},
"geometry": {
"type": "Point",
"coordinates": [
-5.902683734893799,
54.60972062159888
]
}
}
]
}
etc
我现在想使用python来本质上:
- 指定感兴趣点的ID
- 添加搜索距离,以仪表
- 打印iD指定距离内的点及其距离感兴趣点的总距离,
我尝试了geopandas
到目前为止,以使我按照 https://gis.stac.stackexchange.com/questions/questions/349637/given - 列表lat-lat-long-how-how-to-find-all-points-within-radius of-a-give ,
import geopandas as gpd
import pandas as pd
input_file = 'C:/test/points.geojson'
df = gpd.read_file(input_file)
df['lon'] = df['geometry'].x
df['lat'] = df['geometry'].y
gdf = gpd.GeoDataFrame(
df,
geometry=gpd.points_from_xy(
df["lon"],
df["lat"],
),
crs={"init":"EPSG:2157"},
)
print(gdf)
gdf_proj = gdf.to_crs({"init": "EPSG:3857"})
x = gdf_proj.buffer(10)
neighbours = gdf_proj["geometry"].intersection(x)
# print all the nearby points
print(gdf_proj[~neighbours.is_empty])
但这只是在打印我的原始geopandas dataframe,其中所有15个ID和经度/经度/纬度,
我需要一种从数据框架中指定所需的ID的方法,在其上设置了10米缓冲区,以及从该点剩下的14点ID和该点的距离中的任何一个打印中。
我该如何做这样的事情?
I have created a test shapefile containing 15 point features in EPSG:2157 and exported it geojson. Each point has been assigned an ID - e.g. 1, 2 ,3 , etc. They look like so:
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {
"id": "1"
},
"geometry": {
"type": "Point",
"coordinates": [
-5.905044078826904,
54.609987802465916
]
}
},
{
"type": "Feature",
"properties": {
"id": "11"
},
"geometry": {
"type": "Point",
"coordinates": [
-5.902683734893799,
54.60972062159888
]
}
}
]
}
etc
I now want to use Python to essentially:
- Specify the ID of the point of interest
- Add a search distance in metres
- Print the ID's of the points within the specified distance and their total distance from the point of interest
I have tried geopandas
so far to get me going as per https://gis.stackexchange.com/questions/349637/given-list-of-points-lat-long-how-to-find-all-points-within-radius-of-a-give
import geopandas as gpd
import pandas as pd
input_file = 'C:/test/points.geojson'
df = gpd.read_file(input_file)
df['lon'] = df['geometry'].x
df['lat'] = df['geometry'].y
gdf = gpd.GeoDataFrame(
df,
geometry=gpd.points_from_xy(
df["lon"],
df["lat"],
),
crs={"init":"EPSG:2157"},
)
print(gdf)
gdf_proj = gdf.to_crs({"init": "EPSG:3857"})
x = gdf_proj.buffer(10)
neighbours = gdf_proj["geometry"].intersection(x)
# print all the nearby points
print(gdf_proj[~neighbours.is_empty])
But this is just printing my original geopandas dataframe with all 15 IDs and longitude/latitudes,
I need a way of specifying which ID I want from the dataframe, set the 10 metre buffer on it and from that print whichever of the remaining 14 points ID and distance from that point.
How do I go about such a thing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该方法首先计算从选定点,然后过滤到搜索距离的距离:
输出:
This approach first calculates the distance from the selected point and then filters to the search distance:
Output: