Find the intersection between two geographical data points

前端 未结 1 1965
旧巷少年郎
旧巷少年郎 2021-01-07 07:33

I have two pairs of lat/lon (expressed in decimal degrees) along with their radius (expressed in meters). What I am trying to achieve is to find if an intersect between thes

1条回答
  •  悲哀的现实
    2021-01-07 07:38

    Shapely only uses the Cartesian coordinate system, so in order to make sense of metric distances, you would need to either:

    1. project the coordinates into a local projection system that uses distance units in metres, such as a UTM zone.
    2. buffer a point from (0,0), and use a dynamic azimuthal equidistant projection centered on the lat/lon point to project to geographic coords.

    Here's how to do #2, using shapely.ops.transform and pyproj

    import pyproj
    from shapely.geometry import Point
    from shapely.ops import transform
    from functools import partial
    
    WGS84 = pyproj.Proj(init='epsg:4326')
    
    def latlonbuffer(lat, lon, radius_m):
        proj4str = '+proj=aeqd +lat_0=%s +lon_0=%s +x_0=0 +y_0=0' % (lat, lon)
        AEQD = pyproj.Proj(proj4str)
        project = partial(pyproj.transform, AEQD, WGS84)
        return transform(project, Point(0, 0).buffer(radius_m))
    
    A = latlonbuffer(48.180759, 11.518950, 19.0)
    B = latlonbuffer(47.180759, 10.518950, 10.0)
    print(A.intersects(B))  # False
    

    Your two buffered points don't intersect. But these do:

    A = latlonbuffer(48.180759, 11.518950, 100000.0)
    B = latlonbuffer(47.180759, 10.518950, 100000.0)
    print(A.intersects(B))  # True
    

    As shown by plotting the lon/lat coords (which distorts the circles):

    img

    0 讨论(0)
提交回复
热议问题