Select to view content in your preferred language

# Clipping Polyline from Polygon - Geometry

648
4
03-24-2023 07:12 AM
New Contributor III

Hi, I am trying to find the length of polyline in a polygon however clip only accepts envelop (rectangle). what can I do to get the total length of the polyline within a polygon. Thanks in advance.

for track_f in track_fset.features:
track_polyline = Polyline(track_f.geometry)
clipped_track_polyline = track_polyline.clip(Polygon(bounding_geom))
print(type(clipped_track_polyline))

1 Solution

Accepted Solutions
MVP Frequent Contributor

ah glad it may work, I've no experience of doing it however. The documentation also seems a bit arcane.

I'm assuming it's returning a set of points where they intersect?

the doc here suggest a 'dimension' parameter https://developers.arcgis.com/python/guide/part3-spatial-operations-on-geometries/

so perhaps:

``yourGeometry.intersect(yourOtherGeom, dimension=2)``

#### a4. intersect() V.S. overlaps()

The intersect() constructs a geometry that is the geometric intersection of the two input geometries. Different dimension values can be used to create different shape types. The intersection of two geometries of the same shape type is a geometry containing only the regions of overlap between the original geometries, and its arguments include:

• second_geometry: required arcgis.geometry.Geometry.
• A second geometry dimension: required Integer. The topological dimension (shape type) of the resulting geometry, which can be:
• 1: A zero-dimensional geometry (point or multipoint).
• 2: A one-dimensional geometry (polyline).
• 4: A two-dimensional geometry (polygon).

4 Replies
MVP Frequent Contributor

try intersect()

New Contributor III

wow, thanks @DavidPike . I simply assumed intersect returns True or False :D. I tested with intersect and it is returning a multipoint. Any advise on how to convert that to a polyline?

MVP Frequent Contributor

ah glad it may work, I've no experience of doing it however. The documentation also seems a bit arcane.

I'm assuming it's returning a set of points where they intersect?

the doc here suggest a 'dimension' parameter https://developers.arcgis.com/python/guide/part3-spatial-operations-on-geometries/

so perhaps:

``yourGeometry.intersect(yourOtherGeom, dimension=2)``

#### a4. intersect() V.S. overlaps()

The intersect() constructs a geometry that is the geometric intersection of the two input geometries. Different dimension values can be used to create different shape types. The intersection of two geometries of the same shape type is a geometry containing only the regions of overlap between the original geometries, and its arguments include:

• second_geometry: required arcgis.geometry.Geometry.
• A second geometry dimension: required Integer. The topological dimension (shape type) of the resulting geometry, which can be:
• 1: A zero-dimensional geometry (point or multipoint).
• 2: A one-dimensional geometry (polyline).
• 4: A two-dimensional geometry (polygon).

New Contributor III

thank you 🙂 that worked. I should really learn to read the documentation.