Check if a geopoint with latitude and longitude is

2019-01-12 18:52发布

How can I check if a geopoint is within the area of a given shapefile?

I managed to load a shapefile in python, but can't get any further.

7条回答
Bombasti
2楼-- · 2019-01-12 19:42

Here is a simple solution based on pyshp and shapely.

Let's assume that your shapefile only contains one polygon (but you can easily adapt for multiple polygons):

import shapefile
from shapely.geometry import shape, Point

# read your shapefile
r = shapefile.Reader("your_shapefile.shp")

# get the shapes
shapes = r.shapes()

# build a shapely polygon from your shape
polygon = shape(shapes[0])    

def check(lon, lat):
    # build a shapely point from your geopoint
    point = Point(lon, lat)

    # the contains function does exactly what you want
    return polygon.contains(point)
查看更多
登录 后发表回答