如何创建以距离、投影和点给出的边界框来选择以坐标给出的点?

问题描述 投票:0回答:1

给定一个点

(lat, lng)
和一个投影
crs
创建 由
miles
给出的边界框方块用于选择行 在 geopandas
GeoDataFrame
中组成几何体 其他点。

似乎

pyproject
应该这样做,但我只能找到例子 从一种投影转换为另一种投影。我想要原始坐标 投影到当前投影。在这种情况下,英里会很好。

import pandas as pd
import geopandas as gpd
import shapely as shp
#import pyproject ?

def rowsWithinDistanceByPoint(gdf, lat, lng, miles=10, crs='epsg:4269')

    # we do not know to use miles yet so ...
    tenmilesish = 1/6.0 #lame
    circle = shp.geometry.Point(lng, lat).buffer(tenmileish)
    # we really want converted coords
    #(xmin, ymin, xmax, ymax) = magicFunction(miles, crs)
    # but this sort of gets us there if were not next to the poles
    xmin, ymin, xmax, ymax = circle.bounds

    return gdf.cx[xmin:xmax, ymin:ymax]

因此这应该返回距离该点 10 英里以内的行。

python geopandas shapely pyproj
1个回答
0
投票

经过几个小时的搜索,我发现这是相关的:

获取给定当前点、距离和方位的纬度/经度

我不敢相信这个问题花了半天时间才解决! 红色听证会认为投影很重要。当将其放入 geopandas 数据框中时,就会处理这一点。


import geopy
#from geopy.distance import VincentyDistance #changed names !!!!!
from geopy.distance import geodesic

def magicFunction(lat, lng, miles):
    # sw, ne
    bearings = [225, 45]
    origin = geopy.Point(lat, lng)
    l = []

    for bearing in bearings:
        destination = geodesic(miles=miles).destination(origin, bearing)
        coords = destination.longitude, destination.latitude
        l.extend(coords)
    # xmin, ymin, xmax, ymax
    return l

使用这些坐标制作

shapely.box
,然后将其插入我现有的代码中:

蓝色框是这段代码,红色椭圆是我在问题中使用的代码。

© www.soinside.com 2019 - 2024. All rights reserved.