Geometry relationships
Every geometry has methods for querying spatial relationships with another geometry, similar to libraries such as Shapely:
if linea.crosses(otra_linea):
print("se cruzan")
if punto.within(parcela):
print("el punto está dentro de la parcela")
Important: these relationships use shared vertices and nodes, rather than geometrically calculated intersections. For example, two lines “touch” (
touches) only if they share a vertex; crossing without a shared vertex is insufficient.
An undefined relationship for the given type combination raises
TypeError. See the full table in Reference: Geometry.
Examples
Detect points lying on no line:
sueltos = [p for p in puntos if all(p.disjoint(l) for l in lineas)]
Check whether a line ends inside a parcel:
if linea.terminates_within(parcela):
print("la línea acaba dentro de la parcela")
Find adjacent parcels:
for a in parcelas:
for b in parcelas:
if a is not b and a.adjacent(b):
print("parcelas vecinas")
Get the vertices where two lines cross:
vertices = linea.cross_vertices(otra_linea)
if vertices:
print("se cruzan en", len(vertices), "puntos")
primer_corte = linea[vertices[0]]
See also
- Reference: Geometry: all relationships and supported type combinations.