A geometry prepared for efficient comparison to a set of other geometries. Examples -------- >>> from shapely.prepared import prep >>> from shapely.geometry import Point, Polygon >>> triangle = Polygon([(0.0, 0.0), (1.0, 1.0), (1.0, -1.0)]) >>> p = prep(triangle) >>> p.i
| 6 | |
| 7 | |
| 8 | class PreparedGeometry: |
| 9 | """A geometry prepared for efficient comparison to a set of other geometries. |
| 10 | |
| 11 | Examples |
| 12 | -------- |
| 13 | >>> from shapely.prepared import prep |
| 14 | >>> from shapely.geometry import Point, Polygon |
| 15 | >>> triangle = Polygon([(0.0, 0.0), (1.0, 1.0), (1.0, -1.0)]) |
| 16 | >>> p = prep(triangle) |
| 17 | >>> p.intersects(Point(0.5, 0.5)) |
| 18 | True |
| 19 | |
| 20 | """ |
| 21 | |
| 22 | def __init__(self, context): |
| 23 | """Prepare a geometry for efficient comparison to other geometries.""" |
| 24 | if isinstance(context, PreparedGeometry): |
| 25 | self.context = context.context |
| 26 | else: |
| 27 | shapely.prepare(context) |
| 28 | self.context = context |
| 29 | self.prepared = True |
| 30 | |
| 31 | def contains(self, other): |
| 32 | """Return True if the geometry contains the other, else False.""" |
| 33 | return self.context.contains(other) |
| 34 | |
| 35 | def contains_properly(self, other): |
| 36 | """Return True if the geometry properly contains the other, else False.""" |
| 37 | return self.context.contains_properly(other) |
| 38 | |
| 39 | def covers(self, other): |
| 40 | """Return True if the geometry covers the other, else False.""" |
| 41 | return self.context.covers(other) |
| 42 | |
| 43 | def crosses(self, other): |
| 44 | """Return True if the geometries cross, else False.""" |
| 45 | return self.context.crosses(other) |
| 46 | |
| 47 | def disjoint(self, other): |
| 48 | """Return True if geometries are disjoint, else False.""" |
| 49 | return self.context.disjoint(other) |
| 50 | |
| 51 | def intersects(self, other): |
| 52 | """Return True if geometries intersect, else False.""" |
| 53 | return self.context.intersects(other) |
| 54 | |
| 55 | def overlaps(self, other): |
| 56 | """Return True if geometries overlap, else False.""" |
| 57 | return self.context.overlaps(other) |
| 58 | |
| 59 | def touches(self, other): |
| 60 | """Return True if geometries touch, else False.""" |
| 61 | return self.context.touches(other) |
| 62 | |
| 63 | def within(self, other): |
| 64 | """Return True if geometry is within the other, else False.""" |
| 65 | return self.context.within(other) |
no outgoing calls
searching dependent graphs…