PYTHON POINT-IN-POLYGON WITH SHAPELY

PYTHON POINT-IN-POLYGON WITH SHAPELY

1. creating a polygon
First, you need to create a polygon. If you already have an ordered list of coordinate points that define a closed ring, you can create a Polygon directly, like so:

from shapely.geometry import Polygon
poly = Polygon(((0, 0), (0, 1), (1, 1), (1, 0)))

2. point-in-polygon
Now that you have a polygon, determining whether a point is inside it is very easy. There’s 2 ways to do it.

point.within(polygon)
polygon.contains(point)

3. overlapping polygons
In addition to point-in-polygon, you can also determine whether shapely geometries overlap each other. poly.within(poly) and poly.contains(poly) can be used to determine if one polygon is completely within another polygon. For partial overlaps, you can use the intersects method, or call intersection to get the overlapping area as a polygon.


strong@foreverstrong:~$ python
Python 2.7.12 (default, Dec  4 2017, 14:50:18) 
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from shapely.geometry import Polygon
>>> poly1 = Polygon([(0,1,1),(1,-1,1),(-1,-1,1)])
>>> poly2 = Polygon([(0,1,0),(1,-1,0),(-1,-1,0)])
>>> poly1.intersects(poly2)
True
>>> 
>>> poly1.equals(poly2)
True
>>> 
>>> exit()
strong@foreverstrong:~$ 

A third z coordinate value may be used when constructing instances, but has no effect on geometric analysis. All operations are performed in the x-y plane.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值