arcgis.geometry module

The arcgis.geometry module defines useful geometry types for working with geographic information and GIS functionality. It provides functions which use geometric types as input and output as well as functions for easily converting geometries between different representations.

Several functions accept geometries represented as dictionaries and the geometry objects in this module behave like them as well as support the ‘.’ (dot) notation providing attribute access.

Example:

pt = Point({"x" : -118.15, "y" : 33.80, "spatialReference" : {"wkid" : 4326}})
print (pt.is_valid)
print (pt.type) # POINT
print (pt)
print (pt.x, pt.y)

Example Polyline:

line = {
  "paths" : [[[-97.06138,32.837],[-97.06133,32.836],[-97.06124,32.834],[-97.06127,32.832]],
             [[-97.06326,32.759],[-97.06298,32.755]]],
  "spatialReference" : {"wkid" : 4326}
}
polyline = Polyline(line)
print(polyline)
print(polyline.is_valid)

Example of invalid geometry:

line = {
  "paths" : [[[-97.06138],[-97.06133,32.836],[-97.06124,32.834],[-97.06127,32.832]],
             [[-97.06326,32.759],[-97.06298,32.755]]],
  "spatialReference" : {"wkid" : 4326}
}
polyline = Polyline(line)
print(polyline)
print(polyline.is_valid) # False

The same pattern can be used repeated for Polygon, MultiPoint and SpatialReference.

You can create a Geometry even when you don’t know the exact type. The Geometry constructor is able to figure out the geometry type and returns the correct type as the example below demonstrates:

geom = Geometry({
  "rings" : [[[-97.06138,32.837],[-97.06133,32.836],[-97.06124,32.834],[-97.06127,32.832],
              [-97.06138,32.837]],[[-97.06326,32.759],[-97.06298,32.755],[-97.06153,32.749],
              [-97.06326,32.759]]],
  "spatialReference" : {"wkid" : 4326}
})
print (geom.type) # Polygon
print (isinstance(geom, Polygon) # True

Point

class arcgis.geometry.Point(iterable=None, **kwargs)

A point contains x and y fields along with a spatialReference field. A point can also contain m and z fields. A point is empty when its x field is present and has the value null or the string “NaN”. An empty point has no location in space.

property type

MultiPoint

class arcgis.geometry.MultiPoint(iterable=None, **kwargs)

A multipoint contains an array of points, along with a spatialReference field. A multipoint can also have boolean-valued hasZ and hasM fields. These fields control the interpretation of elements of the points array. Omitting an hasZ or hasM field is equivalent to setting it to false. Each element of the points array is itself an array of two, three, or four numbers. It will have two elements for 2D points, two or three elements for 2D points with Ms, three elements for 3D points, and three or four elements for 3D points with Ms. In all cases, the x coordinate is at index 0 of a point’s array, and the y coordinate is at index 1. For 2D points with Ms, the m coordinate, if present, is at index 2. For 3D points, the Z coordinate is required and is at index 2. For 3D points with Ms, the Z coordinate is at index 2, and the M coordinate, if present, is at index 3. An empty multipoint has a points field with no elements. Empty points are ignored.

property type

Polyline

class arcgis.geometry.Polyline(iterable=None, **kwargs)

A polyline contains an array of paths or curvePaths and a spatialReference. For polylines with curvePaths, see the sections on JSON curve object and Polyline with curve. Each path is represented as an array of points, and each point in the path is represented as an array of numbers. A polyline can also have boolean-valued hasM and hasZ fields. See the description of multipoints for details on how the point arrays are interpreted. An empty polyline is represented with an empty array for the paths field. Nulls and/or NaNs embedded in an otherwise defined coordinate stream for polylines/polygons is a syntax error.

property type

Polygon

class arcgis.geometry.Polygon(iterable=None, **kwargs)

A polygon contains an array of rings or curveRings and a spatialReference. For polygons with curveRings, see the sections on JSON curve object and Polygon with curve. Each ring is represented as an array of points. The first point of each ring is always the same as the last point. Each point in the ring is represented as an array of numbers. A polygon can also have boolean-valued hasM and hasZ fields.

An empty polygon is represented with an empty array for the rings field. Nulls and/or NaNs embedded in an otherwise defined coordinate stream for polylines/polygons is a syntax error. Polygons should be topologically simple. Exterior rings are oriented clockwise, while holes are oriented counter-clockwise. Rings can touch at a vertex or self-touch at a vertex, but there should be no other intersections. Polygons returned by services are topologically simple. When drawing a polygon, use the even-odd fill rule. The even-odd fill rule will guarantee that the polygon will draw correctly even if the ring orientation is not as described above.

property type

Envelope

class arcgis.geometry.Envelope(iterable=None, **kwargs)

An envelope is a rectangle defined by a range of values for each coordinate and attribute. It also has a spatialReference field. The fields for the z and m ranges are optional. An empty envelope has no in space and is defined by the presence of an xmin field a null value or a “NaN” string.

property type

SpatialReference

class arcgis.geometry.SpatialReference(iterable=None, **kwargs)

A spatial reference can be defined using a well-known ID (wkid) or well-known text (wkt). The default tolerance and resolution values for the associated coordinate system are used. The xy and z tolerance values are 1 mm or the equivalent in the unit of the coordinate system. If the coordinate system uses feet, the tolerance is 0.00328083333 ft. The resolution values are 10x smaller or 1/10 the tolerance values. Thus, 0.0001 m or 0.0003280833333 ft. For geographic coordinate systems using degrees, the equivalent of a mm at the equator is used. The well-known ID (WKID) for a given spatial reference can occasionally change. For example, the WGS 1984 Web Mercator (Auxiliary Sphere) projection was originally assigned WKID 102100, but was later changed to 3857. To ensure backward compatibility with older spatial data servers, the JSON wkid property will always be the value that was originally assigned to an SR when it was created. An additional property, latestWkid, identifies the current WKID value (as of a given software release) associated with the same spatial reference. A spatial reference can optionally include a definition for a vertical coordinate system (VCS), which is used to interpret the z-values of a geometry. A VCS defines units of measure, the location of z = 0, and whether the positive vertical direction is up or down. When a vertical coordinate system is specified with a WKID, the same caveat as mentioned above applies. There are two VCS WKID properties: vcsWkid and latestVcsWkid. A VCS WKT can also be embedded in the string value of the wkt property. In other words, the WKT syntax can be used to define an SR with both horizontal and vertical components in one string. If either part of an SR is custom, the entire SR will be serialized with only the wkt property. Starting at 10.3, Image Service supports image coordinate systems.

property as_arcpy

returns the class as an arcpy SpatialReference object

property type

Geometry

class arcgis.geometry.Geometry(iterable=None, **kwargs)

The base class for all geometries.

You can create a Geometry even when you don’t know the exact type. The Geometry constructor is able to figure out the geometry type and returns the correct type as the example below demonstrates:

geom = Geometry({
  "rings" : [[[-97.06138,32.837],[-97.06133,32.836],[-97.06124,32.834],[-97.06127,32.832],
              [-97.06138,32.837]],[[-97.06326,32.759],[-97.06298,32.755],[-97.06153,32.749],
              [-97.06326,32.759]]],
  "spatialReference" : {"wkid" : 4326}
})
print (geom.type) # POLYGON
print (isinstance(geom, Polygon) # True
property JSON
property WKB
property WKT
angle_distance_to(second_geometry, method='GEODESIC')

Returns a tuple of angle and distance to another point using a measurement type.

Paramters:
second_geometry
  • a second geometry

method
  • PLANAR measurements reflect the projection of geographic

data onto the 2D surface (in other words, they will not take into account the curvature of the earth). GEODESIC, GREAT_ELLIPTIC, LOXODROME, and PRESERVE_SHAPE measurement types may be chosen as an alternative, if desired.

property area
property as_arcpy
boundary()

Constructs the boundary of the geometry.

buffer(distance)

Constructs a polygon at a specified distance from the geometry.

Parameters:
distance
  • length in current projection. Only polygon accept

negative values.

property centroid
clip(envelope)

Constructs the intersection of the geometry and the specified extent.

Parameters:
envelope
  • arcpy.Extent object

contains(second_geometry, relation=None)

Indicates if the base geometry contains the comparison geometry.

Paramters:
second_geometry
  • a second geometry

Returns:

Boolean

convex_hull()

Constructs the geometry that is the minimal bounding polygon such that all outer angles are convex.

crosses(second_geometry)

Indicates if the two geometries intersect in a geometry of a lesser shape type.

Paramters:
second_geometry
  • a second geometry

cut(cutter)

Splits this geometry into a part left of the cutting polyline, and a part right of it.

Parameters:
cutter
  • The cutting polyline geometry.

densify(method, distance, deviation)

Creates a new geometry with added vertices

Parameters:
method
  • The type of densification, DISTANCE, ANGLE, or GEODESIC

distance
  • The maximum distance between vertices. The actual

distance between vertices will usually be less than the maximum distance as new vertices will be evenly distributed along the original segment. If using a type of DISTANCE or ANGLE, the distance is measured in the units of the geometry’s spatial reference. If using a type of GEODESIC, the distance is measured in meters.

deviation
  • Densify uses straight lines to approximate curves.

You use deviation to control the accuracy of this approximation. The deviation is the maximum distance between the new segment and the original curve. The smaller its value, the more segments will be required to approximate the curve.

difference(second_geometry)

Constructs the geometry that is composed only of the region unique to the base geometry but not part of the other geometry. The following illustration shows the results when the red polygon is the source geometry.

Paramters:
second_geometry
  • a second geometry

disjoint(second_geometry)

Indicates if the base and comparison geometries share no points in common.

Paramters:
second_geometry
  • a second geometry

distance_to(second_geometry)

Returns the minimum distance between two geometries. If the geometries intersect, the minimum distance is 0. Both geometries must have the same projection.

Paramters:
second_geometry
  • a second geometry

equals(second_geometry)

Indicates if the base and comparison geometries are of the same shape type and define the same set of points in the plane. This is a 2D comparison only; M and Z values are ignored. Paramters:

second_geometry
  • a second geometry

property extent
property first_point
generalize(max_offset)

Creates a new simplified geometry using a specified maximum offset tolerance.

Parameters:
max_offset
  • The maximum offset tolerance.

property geoextent

Returns the current feature’s extent

property geometry_type
get_area(method, units=None)

Returns the area of the feature using a measurement type.

Parameters:
method
  • PLANAR measurements reflect the projection of

geographic data onto the 2D surface (in other words, they will not take into account the curvature of the earth). GEODESIC, GREAT_ELLIPTIC, LOXODROME, and PRESERVE_SHAPE measurement types may be chosen as an alternative, if desired.

units
  • Areal unit of measure keywords: ACRES | ARES | HECTARES

SQUARECENTIMETERS | SQUAREDECIMETERS | SQUAREINCHES | SQUAREFEET
SQUAREKILOMETERS | SQUAREMETERS | SQUAREMILES |

SQUAREMILLIMETERS | SQUAREYARDS

get_length(method, units)

Returns the length of the feature using a measurement type.

Parameters:
method
  • PLANAR measurements reflect the projection of

geographic data onto the 2D surface (in other words, they will not take into account the curvature of the earth). GEODESIC, GREAT_ELLIPTIC, LOXODROME, and PRESERVE_SHAPE measurement types may be chosen as an alternative, if desired.

units
  • Linear unit of measure keywords: CENTIMETERS |

DECIMETERS | FEET | INCHES | KILOMETERS | METERS | MILES | MILLIMETERS | NAUTICALMILES | YARDS

get_part(index=None)

Returns an array of point objects for a particular part of geometry or an array containing a number of arrays, one for each part.

Parameters:
index
  • The index position of the geometry.

property hull_rectangle
intersect(second_geometry, dimension)

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.

Paramters:
second_geometry
  • a second geometry

dimension
  • The topological dimension (shape type) of the

resulting geometry.

1 -A zero-dimensional geometry (point or multipoint). 2 -A one-dimensional geometry (polyline). 4 -A two-dimensional geometry (polygon).

property is_multipart
property label_point
property last_point
property length
property length3D
measure_on_line(second_geometry, as_percentage=False)

Returns a measure from the start point of this line to the in_point.

Paramters:
second_geometry
  • a second geometry

as_percentage
  • If False, the measure will be returned as a

distance; if True, the measure will be returned as a percentage.

overlaps(second_geometry)

Indicates if the intersection of the two geometries has the same shape type as one of the input geometries and is not equivalent to either of the input geometries.

Paramters:
second_geometry
  • a second geometry

property part_count
property point_count
point_from_angle_and_distance(angle, distance, method='GEODESCIC')

Returns a point at a given angle and distance in degrees and meters using the specified measurement type.

Parameters:
angle
  • The angle in degrees to the returned point.

distance
  • The distance in meters to the returned point.

method
  • PLANAR measurements reflect the projection of geographic

data onto the 2D surface (in other words, they will not take into account the curvature of the earth). GEODESIC, GREAT_ELLIPTIC, LOXODROME, and PRESERVE_SHAPE measurement types may be chosen as an alternative, if desired.

position_along_line(value, use_percentage=False)

Returns a point on a line at a specified distance from the beginning of the line.

Parameters:
value
  • The distance along the line.

use_percentage
  • The distance may be specified as a fixed unit

of measure or a ratio of the length of the line. If True, value is used as a percentage; if False, value is used as a distance. For percentages, the value should be expressed as a double from 0.0 (0%) to 1.0 (100%).

project_as(spatial_reference, transformation_name=None)

Projects a geometry and optionally applies a geotransformation.

Parameter:
spatial_reference
  • The new spatial reference. This can be a

SpatialReference object or the coordinate system name.

transformation_name
  • The geotransformation name.

query_point_and_distance(second_geometry, use_percentage=False)

Finds the point on the polyline nearest to the in_point and the distance between those points. Also returns information about the side of the line the in_point is on as well as the distance along the line where the nearest point occurs.

Paramters:
second_geometry
  • a second geometry

as_percentage
  • if False, the measure will be returned as

distance, True, measure will be a percentage

rotate(theta, inplace=False)

rotates a shape by some degree theta

scale(x_scale=1, y_scale=1, inplace=False)

scales in either the x,y or both directions

segment_along_line(start_measure, end_measure, use_percentage=False)

Returns a Polyline between start and end measures. Similar to Polyline.positionAlongLine but will return a polyline segment between two points on the polyline instead of a single point.

Parameters:
start_measure
  • The starting distance from the beginning of the

line.

end_measure
  • The ending distance from the beginning of the

line.

use_percentage
  • The start and end measures may be specified as

fixed units or as a ratio. If True, start_measure and end_measure are used as a percentage; if False, start_measure and end_measure are used as a distance. For percentages, the measures should be expressed as a double from 0.0 (0 percent) to 1.0 (100 percent).

skew(x_angle=0, y_angle=0, inplace=False)
snap_to_line(second_geometry)

Returns a new point based on in_point snapped to this geometry.

Paramters:
second_geometry
  • a second geometry

property spatial_reference
symmetric_difference(second_geometry)

Returns a new point based on in_point snapped to this geometry.

Paramters:
second_geometry
  • a second geometry

touches(second_geometry)

Indicates if the boundaries of the geometries intersect.

Paramters:
second_geometry
  • a second geometry

translate(x_offset=0, y_offset=0, inplace=False)

moves a geometry in a given x and y distance

property true_centroid
union(second_geometry)

Constructs the geometry that is the set-theoretic union of the input geometries.

Paramters:
second_geometry
  • a second geometry

within(second_geometry, relation=None)

Indicates if the base geometry is within the comparison geometry. Paramters:

second_geometry
  • a second geometry

relation
  • The spatial relationship type.

BOUNDARY - Relationship has no restrictions for interiors or boundaries. CLEMENTINI - Interiors of geometries must intersect. Specifying CLEMENTINI is equivalent to specifying None. This is the default. PROPER - Boundaries of geometries must not intersect.

areas_and_lengths

auto_complete

buffer

convex_hull

cut

density

difference

distance

find_transformation

from_geo_coordinate_string

generalize

intersect

label_points

lengths

offset

project

relation

reshape

to_geo_coordinate_string

trim_extend

union