Shapely - Python Package - Spatial Analysis Methods

Shapely - Python Package - Spatial Analysis Methods

As well as boolean attributes and methods, Shapely provides analysis methods that return new geometric objects.
1. object.difference(other)
Returns a representation of the points making up this geometric object that do not make up the other object.

>>> a = Point(1, 1).buffer(1.5)
>>> b = Point(2, 1).buffer(1.5)
>>> a.difference(b)


Note
The buffer() method is used to produce approximately circular polygons in the examples of this section; it will be explained in detail later in this manual.

Shapely - Python Package - Spatial Analysis Methods_第1张图片
Figure 1. Differences between two approximately circular polygons.

Note
Shapely can not represent the difference between an object and a lower dimensional object (such as the difference between a polygon and a line or point) as a single object, and in these cases the difference method returns a copy of the object named self.

2. object.intersection(other)
Returns a representation of the intersection of this object with the other geometric object.

>>> a = Point(1, 1).buffer(1.5)
>>> b = Point(2, 1).buffer(1.5)
>>> a.intersection(b)


3. object.symmetric_difference(other)
Returns a representation of the points in this object not in the other geometric object, and the points in the other not in this geometric object.

>>> a = Point(1, 1).buffer(1.5)
>>> b = Point(2, 1).buffer(1.5)
>>> a.symmetric_difference(b)


Shapely - Python Package - Spatial Analysis Methods_第2张图片

4. object.union(other)
Returns a representation of the union of points from this object and the other geometric object.
The type of object returned depends on the relationship between the operands. The union of polygons (for example) will be a polygon or a multi-polygon depending on whether they intersect or not.

>>> a = Point(1, 1).buffer(1.5)
>>> b = Point(2, 1).buffer(1.5)
>>> a.union(b)


The semantics of these operations vary with type of geometric object. For example, compare the boundary of the union of polygons to the union of their boundaries.

>>> a.union(b).boundary

>>> a.boundary.union(b.boundary)


Shapely - Python Package - Spatial Analysis Methods_第3张图片
5. object.intersects(other)
Returns True if the boundary and interior of the object intersect in any way with those of the other.


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
>>> p1 = Polygon([(0,0),(1,1),(1,0)])
>>> p2 = Polygon([(0,1),(1,0),(1,1)])
>>> print(p1.intersects(p2))
True
>>> 
>>> exit()
strong@foreverstrong:~$ 





你可能感兴趣的:(Python)