Python module for storing and querying geographical coordinates

前端 未结 7 627
忘了有多久
忘了有多久 2020-12-28 17:20

Is there a Python module where I can create objects with a geographical location coordinate (latitude and longitude), and query all the objects for ones which are within a 5

7条回答
  •  情歌与酒
    2020-12-28 18:19

    The usual approach in GIS is to create a buffer around the point of interest and query the intersection. As @RyanDalton suggests, if you plan to do a lot of geolocation stuff, use Shapely, the GIS API for Python. It is good to know about Shapely even if you still want a spatial index (see below). Here is how to create buffers in Shapely:

    distance = 3
    center = Point(1, 1)
    pts = [Point(1.1, 1.2),Point(1.2,1.2)]
    center_buf = a.buffer(distance)
    #filters the points list according to whether they are contained in the list
    contained = filter(center_buf.contains,pts)
    

    You can index your points yourself (let's say by longitude for example) if you don't have many. Otherwise you can also use the Rtree package, check the link called Using Rtree as a cheapo spatial database!

提交回复
热议问题