Find the intersection between two geographical data points

让人想犯罪 __ 提交于 2019-12-04 18:44:46

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):

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!