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 as well as the geometry objects in this module. Prior to the 2.4.4. release, geometry objects in this module behave like dictionaries in supporting the bracket notation for retrieving information. After 2.4.4, only the ‘.’ (dot) notation is supported for providing attribute access.
Note
Prior to 2.4.4, it is recommended (and in some cases necessary) to have either ArcPy
or Shapely downloaded in your environment in order to use most Geometry
methods and properties. At the 2.4.4 release with the introduction of the Rust
arcgis.geometry package,
many geometry properties and methods can be used without downloading any other packages. Those that
still require specific libraries such as ArcPy or Shapely are noted.
Note
While Geometry objects can be initialized
directly using dictionaries, they can also be accessed using the
query() method of
FeatureLayer objects.
from arcgis.gis import GIS
from arcgis.geometry import Point
gis = GIS("home")
warren_county_item = gis.content.search(
query="Warren_County_Towns",
item_type="Feature Layer"
)[0]
warren_county_layer = warren_county_item.layers[0]
warren_fs = warren_county_layer.query()
town_1 = warren_fs.features[0]
town_geom_dict = town_1.geometry
town_geom = Point(town_geom_dict)
print(town_geom)
'{"x" : -118.15, "y" : 33.80, "spatialReference" : {"wkid" : 4326}}'
# Examples: Initializing geometry objects directly
# Example: Point geometry
from arcgis.geometry import Point
pt = Point(
{
"x" : -118.15,
"y" : 33.80,
"spatialReference" : {"wkid" : 4326}
}
)
print (pt.is_valid)
True
print (pt.type)
'POINT'
print (pt)
'{"x" : -118.15, "y" : 33.80, "spatialReference" : {"wkid" : 4326}}'
print (pt.x, pt.y)
(-118.15,33.80)
# Example: Polyline geometry
from arcgis.geometry import 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)
'{"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}}'
print(polyline.is_valid)
True
# Example INVALID Geometry
from arcgis.geometry import Polyline
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)
'''{"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}}'''
print(polyline.is_valid)
False
The same pattern can be repeated for Polygon,
MultiPoint and SpatialReference
objects.
You can create a Geometry even when you don’t know the
exact type. The Geometry initializer (constructor) can infer the specific
geometry type and return the correct type as the example below demonstrates:
Example Unknown Geometry Type
from arcgis.geometry import Geometry
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)
Represents x and y pairs along with spatial reference information, and optionally may contain m (measure) and z (elevation/height) information. Objects are seen as empty when its x values is present and has the value null (None). An empty point has no location in space.
Parameter
Description
iterable
A dictionary with x, y, and spatialReference keys denoting a coordinate pair and the coordinate system in which it is represented.
# Example:Initialize directly
from arcgis.gis import GIS from arcgis.geometry import Point p = Point({ "x": -118.15, "y": 33.80, "spatialReference": {"wkid": 4326} } ) print(p)
{'spatialReference': {'wkid': 4326}, 'x': -118.15, 'y': 33.8}Example: Get a point from a feature layer
from arcgis.gis import GIS from arcgis.geometry import Point flyr_item = gis.content.get("feature_layer_id") flyr_obj = flyr_item.layers[0] feature_set = flyr_obj.query(where="1=1", out_fields="*", return_geometry=True) feature = feature_set.features[0] pt_geom = Point(feature.geometry) print(pt_geom)
{'spatialReference': {'wkid': 4326}, 'x': -118.15, 'y': 33.8}Note
When in a Jupyter Lab notebook, evaluating a variable assigned to a geometry object will render an inline SVG graphic representation of the object.
- coordinates()
Retrieves the coordinates of the
Point.# Example:
from arcgis.gis import GIS gis = GIS("home") point_item = gis.content.search( query="search terms", item_type="Feature Layer" )[0] point_layer = point_item.layers[0] point_fset = point_layer.query(as_df=True) point = point_fset.loc[0].SHAPE coords = point.coordinates() coords
array([-9770036.71378282, 5144407.10980244])
- Returns:
An
numpy.ndarraycontaining the coordinate values.
- svg(scale_factor: float = 1, fill_color: str | None = None)
Returns a string representation of a SVG (Scalable Vector Graphic) circle element for the geometry. SVG defines vector-based graphics in XML format.
Note
Python API geometries are natively integrated with Jupyter, so if you evaluate a geometry object as the final line of a notebook cell, the environment automatically renders it as an inline SVG graphic.
Parameter
Description
scale_factor
An optional float. Multiplication factor for the SVG circle diameter. Default is 1.
fill_color
An optional string. Hex string for fill color. Default is to use “#66cc99” if geometry is valid, and “#ff3333” if invalid.
- Returns:
A Python
stringcontaining an SVG circle element.
MultiPoint
- class arcgis.geometry.MultiPoint(iterable=None, **kwargs)
Contains an array of coordinate values representing point geometries all considered to be one geometry object. The coordinate values may represent a coordinate location on the earth’s surface, and may also have z and/or m values as well. These objects can be initialized directly with the API. They are also returned by the
boundary()method ofPolylineobjects.Note
Omitting an hasZ or hasM field is equivalent to setting it to false.
Each element of the 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.
Note
An empty multipoint has a points field with no elements. Empty points are ignored.
Example: initializing an object directly
from arcgis.geometry import MultiPoint mpt_object = MultiPoint( { "points": [ [-113.993797, 46.871941], [-113.994875, 46.872725], [-113.994913, 46.874384] ], "spatialReference": {"wkid":4326} } ) type(mpt_object)
arcgis.geometry._types.MultiPoint
Example: Getting object from the boundary method
from arcgis.geometry import Polyline pline_object = Polyline( { "paths": [ [ [-71.406579, 41.814606], [-71.406451, 41.816916], [-71.408032, 41.819112], [-71.408196, 41.824133], [-71.408778, 41.825416], [-71.410061, 41.826372], [-71.412334, 41.826746], [-71.414987, 41.825792] ] ], "spatialReference": {"wkid":4326} } ) mpt_from_boundary = pline_object.boundary() type(mpt_from_boundary)
arcgis.geometry._types.MultiPoint
- coordinates()
Retrieves the coordinates of the
MultiPointas an np.array#Usage Example coords = multiPoint.coordinates() coords [ [x1,y1,m1,z1], [x2,y2,m2,z2],...]
- Returns:
An np.array containing coordinate values for each point
- svg(scale_factor: float = 1.0, fill_color: str | None = None)
Returns a group of SVG (Scalable Vector Graphic) circle element for the
MultiPointgeometry.Keys
Description
scale_factor
An optional float. Multiplication factor for the SVG circle diameter. Default is 1.
fill_color
An optional string. Hex string for fill color. Default is to use “#66cc99” if geometry is valid, and “#ff3333” if invalid.
- Returns:
A group of SVG circle elements
Polyline
- class arcgis.geometry.Polyline(iterable=None, **kwargs)
Represents a shape defined by one or more paths, in which a path is a series of connected segments, including spatial reference information. For objects with curve paths, see the Polyline with curves <https://developers.arcgis.com/rest/services-reference/enterprise/geometry-objects/#polyline-with-curves> documentation on how they are represented within JSON objects (which are equivalent to dictionaries in the Python API). Each path is represented as a Python
listof x, y coordinates.An empty object is represented with an empty array for the paths field. Nulls (
NoneType) and/or NaNs embedded in an otherwise defined coordinate stream forPolylineobjects results in a syntax error.Example: Initialize a Polyline object from a dictionary
from arcgis.gis import GIS from arcgis.geometry import Polyline gis = GIS("home") polyline_dict = { "paths": [ [ [19450302.04, -4426980.61], [19450400.85, -4427066.68] ], ], "spatialReference": {"wkid": 102100, "latestWkid": 3857} } polyline = Polyline(polyline_dict)
Example: Get a polyline from a Feature Layer
from arcgis.gis import GIS gis = GIS("home") flyr_item = gis.content.search("City Streets")[0] streets_flyr = flyr_item.layers[0] streets_df = streets_flyr.query( where="Street_name='Main St'", as_df=True ) streets_df.index
RangeIndex(start=0, stop=1, step=1)
street_geom = streets_df.loc[0].SHAPE type(street_geom)
arcgis.geometry._types.Polyline
- coordinates()
Retrieves the coordinate pairs of the segment.
#Usage Example coords = polyLine.coordinates() coords [ [x1,y1,m1,z1], [x2,y2,m2,z2],...]
- Returns:
A Python
ndarraycontaining the coordinate values.
- property has_z: bool
Indicates whether the
Polylineobject has Z values stored as part of the coordinate.- Returns:
A boolean indicating yes (True), or no (False)
- svg(scale_factor: float = 1, stroke_color: str | None = None)
Retrieves a Python
stringrepresenting the SVG (Scalable Vector Graphic) polyline element for geometry object.Keys
Description
scale_factor
An optional float. Multiplication factor for the SVG stroke-width. Default is 1.
stroke_color
An optional string. Hex string for fill color. Default is to use “#66cc99” if geometry is valid, and “#ff3333” if invalid.
- Returns:
The Python
stringrepresenting the SVG polyline element for the geometry.
Polygon
- class arcgis.geometry.Polygon(iterable=None, **kwargs)
Represents a closed shape defined by a connected sequence of x,*y* coordinate pairs as an
arrayof rings or curveRings and spatial reference information. For Polygons with curve rings, see the Rest API documentation, Polygon with curves.Each ring is represented as a
listof x, y pairs. The first point of each ring is always the same as the last point. Each point in the ring is represented as a list offloatsdesignating the x, y values.An empty
Polygonis represented with an empty array. Null (NoneType) and/or NaNs embedded in an otherwise defined coordinate stream forPolylineorPolygonobjects 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.
Example: Creating a Polygon from a dictionary
from arcgis.gis import GIS from arcgis.geometry import Polygon gis = GIS(profile="your_organization_profile") city_geom = Polygon({ "rings" = [ [ [-10248446.4454076, 4208686.7214691], [-10248468.7296279, 4207067.31537853], [-10248503.1104404, 4205076.77674108], [-10248293.6967532, 4209046.2809732], [-10248298.7042736, 4208682.89441194], [-10248446.4454076, 4208686.7214691] ] ], "spatialReference": {"wkid": 102100, "latestWkid": 3857} } )
# Example: Get a Polygon object from a feature layer
from arcgis.gis import GIS gis = GIS(profile="your_organization_profile") flyr_item = gis.content.search( query="City Parks", item_type="Feature Layer" )[0] parks_flyr = flyr_item.layers[0] parks_df = parks_flyr.query( where="park_name='Main City Park'", return_geometry=True, as_df=True ) park_geom = parks_df.loc[0].SHAPE print(type(park_geom))
<class 'arcgis.geometry._types.Polygon'>
- coordinates()
Retrieves the object’s coordinates as an
arraycontaining the coordinate pairs.# Code example
from arcgis.gis import GIS gis = GIS(profile="your_organization_profile") county_item = gis.content.get("your_county_item_id") county_layer = county_item.layers[0] county_df = county_layer.query( where="County_Name = 'Davis'", as_df=True ) davis_polygon = county_df.iloc[0].SHAPE coords = davis_polygon.coordinates() coords
array([[[-10287797.1731894, 4271577.21456354], [-10287803.295528, 4271064.49712967], [-10287802.6743368, 4271036.97232046], ... [-10289769.8298089, 4271597.42812342], [-10289009.4574741, 4271586.87526337], [-10287797.1731894, 4271577.21456354]]], dtype=object)- Returns:
A
arraycontaining coordinate values.
- svg(scale_factor: float = 1, fill_color: str | None = None)
Retrieves a string representation of a SVG (Scalable Vector Graphic) polygon element. SVG defines vector-based graphics in XML format.
Keys
Description
scale_factor
An optional float. Multiplication factor for the SVG stroke-width. Default is 1.
fill_color
An optional string. Hex string for fill color. Default is to use “#66cc99” if geometry is valid, and “#ff3333” if invalid.
- Returns:
A Python
stringrepresentation of an SVG polygon element
Envelope
- class arcgis.geometry.Envelope(iterable=None, **kwargs)
Represents a rectangle described by the lower-left and upper-right corners, of a shape that covers the extent of a feature or layer. It also contains spatial reference information.
Objects of this class are not intended to be created directly, but instead are returned by the
envelopeproperty of any Geometry object.Note
Pointobjects return themselves.Example: Get the envelope for a Polygon object
from arcgis.gis import GIS gis = GIS("home") parks_item = gis.content.get("your_item_id_here") parks_layer = parks_item.layers[0] city_park_dict = parks_layer.query(where="name='City Park'").features[0].geometry city_park_geom = Polygon(city_park_dict) city_park_envelope = city_park_geom.envelope print(city_park_envelope)
{'xmin': 19450302.04, 'ymin': -4427066.68, 'xmax': 19450400.85, 'ymax': -4426980.61, 'spatialReference': SpatialReference({'wkid': 102100, 'latestWkid': 3857})}- coordinates()
Retrieves an array of coordinates representing the corners (lower-left and upper-right) of the envelope object.
Example: Print the coordinates of an envelope object.
from arcgis.gis import GIS feature_layer_item = gis.content.get("item_id") feature_layer = feature_layer_item.layers[0] feature_df = feature_layer.query( where="OBJECTID=10", as_df=True ) feature10_geom = feature_df.iloc[0].SHAPE envelope = feature10_geom.envelope coords = envelope.coordinates() coords
array([19450302.04, -4427066.68, 19450400.85, -4426980.61])
- Returns:
A Python
ndarraycontaining the coordinates.
- property geohash
The
geohashmethod retrieves a geohash string of the extent of the ``Envelope.- Returns:
A geohash String
- property geohash_covers
The
geohash_coversmethod retrieves a list of up to the four longest geohash strings that fit within the extent of theEnvelope.- Returns:
A list of geohash Strings
- property geohash_neighbors
Gets a list of the geohash neighbor strings for the extent of the
Envelope.- Returns:
A list of geohash neighbor Strings
- svg(scale_factor: float = 1, fill_color: str | None = None)
Returns a Python
stringrepresentation of an SVG (Scalable Vector Graphic) of the envelope object.Keys
Description
scale_factor
An optional float. Multiplication factor for the SVG circle diameter. Default is 1.
fill_color
An optional string. Hex string for fill color. Default is to use “#66cc99” if geometry is valid, and “#ff3333” if invalid.
- Returns:
A Python
stringrepresentation of an SVG envelope element.
SpatialReference
- class arcgis.geometry.SpatialReference(iterable=None, **kwargs)
Class representing the set of parameters that defines the coordinate system and spatial properties used to locate geomgraphic data on the surface of the earth. Objects of this class can be initialized using a Python
dictor Pythonintcontaining a well-known ID (wkid key) and optionally a latest well-known ID (latestWkid key) or a Pythonstrrepresenting a well-known text (wkt. SeeWKTproperty). The default tolerance and resolution values for the associated coordinate system are used.Objects of this class are also returned using the
spatial_referenceproperty of geometry objects.For further details and explanation of concepts, see Using Spatial References. Also see the Working with Geometries Introduction guide in the Editing section of the API for Python documentation.
For a complete list of well-known ID values, see Coordinate System PDF
Note
The x, y 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 a spatial reference 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.
Objects can optionally include a definition for a vertical coordinate system (VCS), which is used to interpret the z-values of a See Vertical coordinate systems for detailed information. A VCS defines units of measure, the precise location of z = 0, and whether the positive vertical direction is up or down.
Note
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.
Example: Initialize a SpatialReference object with a dictionary
from arcgis.geometry import SpatialReference geo_sr = SpatialReference({"wkid": 4326}) # WGS 1984 Geographic Coordinate System prj_sr = SpatialReference({"wkid": 3857}) # WGS 1984 Web Mercator (Auxiliary Sphere)
Example: Initialize a SpatialReference object with an integer
from arcgis.geometry import SpatialReference geo_sr = SpatialReference(4326) # WGS 1984 Geographic Coordinate System prj_sr = SpatialReference(3857) # WGS 1984 Web Mercator (Auxiliary Sphere)
Example: Get a SpatialReference object from an existing geometry
from arcgis.gis import GIS gis = GIS("home") feature_layer_item = gis.content.get("your_feature_layer_item_id") feature_layer_obj = feature_layer_item.layers[0] # Get the first layer of the feature layer item feature_geom = feature_layer_obj.query( where="OBJECTID=8", as_df=True ).loc[0].SHAPE feature_sr = feature_geom.spatial_reference
SpatialReference({'wkid': 102100, 'latestWkid': 3857})- property JSON
The
JSONmethod retrieves an Esri JSON representation of theGeometryobject as a string.- Returns:
A string representing a
Geometryobject
- property as_arcpy
Gets an ArcPy SpatialReference object.
Note
The ArcPy library is required to return a SpatialReference object.
- svg(scale_factor: float = 1, fill_color: str | None = None)
Retrieves SVG (Scalable Vector Graphic) polygon element for a
SpatialReferencefield. ================ =============================================================================== Keys Description —————- ——————————————————————————- scale_factor An optional float. Multiplication factor for the SVG stroke-width. Default is 1. —————- ——————————————————————————- fill_color An optional string. Hex string for fill color. Default is to use “#66cc99” if geometry isvalid, and “#ff3333” if invalid.
Geometry
- class arcgis.geometry.Geometry(iterable=None, **kwargs)
The base class for all other geometry objects:
Point,Polygon,Polyline,MultiPoint, andEnvelope.You can initialize a new
Geometryobject using the initializer (constructor) with a correctly formed Pythondictionaryrepresenting the specific geometry object you want to create. See the Geometry objects REST API documentation for full details (The examples specifically show JSON formatting, but that syntax mirrors the precise Python dictionary format you would enter using the Python API).The Geometry constructor is able to figure out the specific geometry type based on the structure of the input dictionary.
Geometryobjects can also be obtained from existingFeatureLayerobjects through querying. See the specific geometry object reference documentation for examples.Example: Initialize a Polygon object from the Geometry initializer
from arcgis.geometry import Geometry 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) print(type(geom)) print(isinstance(geom, Polygon)
Polygon <class 'arcgis.geometry._types.Polygon'> True
- property EWKT
Gets the extended well-known text (EWKT) representation of the geometry object. It provides a portable representation of a geometry value as a text string.
Note
A format developed by PostGIS for representing geometries with an associated spatial reference identifier (SRID). See ST_GeomFromEWKT for technical specifics.
Note
Any true curves in the geometry will be densified into approximate curves in the WKT string.
- Returns:
A Python
strcontaining the EWKT representation of the geometry.
- property WKB
Gets the well-known binary (WKB) representation for the geometry object. It provides a portable representation of a geometry value as a contiguous stream of bytes. See Well-known binary representation of geometry for more information.
- Returns:
A Python
bytesobject.
- property WKT
Gets the well-known text (WKT) representation for the geometry object, providing a portable representation of a geometry value as a text string. Originally defined in the OGC Simple Features Specification. See Well-known text representation of geometry for detailed information.
Note
Any true curves in the geometry will be densified into approximate curves in the WKT string.
- Returns:
A Python
strcontaining the WKT representation of the geometry.
- angle_distance_to(second_geometry: Geometry, method: str = 'GEODESIC')
Retrieves the angle and distance to another
Geometryusing a measurement type.Note
Requires ArcPy. If ArcPy is not installed,
NoneTypeis returned.Parameter
Description
second_geometry
Required Geometry. An
Geometryobject.method
Optional String. 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, and LOXODROME measurement types may be chosen as an alternative, if desired.
- Returns:
A tuple of angle and distance to another
Pointusing a measurement type.
from arcgis.gis import GIS libraries_item = gis.content.search( query="City Libraries *", item_type="Feature Layer" )[0] elementary_schools = gis.content.search( query="Elementary Schools *", item_type="Feature Layer" )[0] main_library = libraries_item.layers[0].query( where="library_name = 'Main Library'" as_df=True).loc[0].SHAPE school1 = elementary_schools.layers[0].query( where="school_name = 'School 1'", as_df=True).loc[0].SHAPE school1.angle_distance_to( second_geometry = main_library, method="PLANAR" )
{54.5530, 1000.1111}
- property area
Calculates the area of a
Polygongeometry. The units of the returned area are based off theSpatialReferenceof the geometry.Note
Returns
NoneTypefor all other geometry types.from arcgis.gis import GIS gis = GIS(profile="your_organization_profile") parks_item = gis.content.search( query="title:City Parks *", item_type="Feature Layer" )[0] parks_feature_layer = parks_item.layers[0] park_geom_object = parks_feature_layer.query( where="park_name='City Center Park'", as_df=True).loc[0].SHAPE park_geom_object.spatial_reference
SpatialReference({'wkid': 102100, 'latestWkid': 3857})park_geom_object.area
18297.081000502323 # square meters
- Returns:
A Python
floatof the geometry’s area.
- property as_arcpy
Retrieves the
Geometryobject as an arcobjects Geometry.Note
Requires the arcpy package in the Python environment to return a value. If ArcPy is not installed,
Noneis returned.- Returns:
An arcpy.arcobjects representation of the Geometry object, or Python
NoneTypeif arcpy package not present.
- property as_shapely
Retrieves the
Geometryobject in Shapely <https://shapely.readthedocs.io/en/stable/> format. Requires the shapely library to be installed.- Returns:
A shapely
Geometryobject. If shapely is not installed, None is returned
- boundary()
Constructs the boundary of the
Geometryobject.- Returns:
A
MultiPointobject if the geometry is aPolylineNoneif the geometry is aPointorMultiPoint
- buffer(distance: float)
Constructs a
Polygonaround theGeometryobject at the specified distance.Parameter
Description
distance
Required
float. The distance at which to create the buffer polygon. The distance must be specified in the same units as the spatial reference of thegeometryobject.Note
A negative distance can only be specified against a polygon geometry.
- Returns:
A
Polygonobject
- property centroid
Retrieves the center of the
Geometryobject.Note
For
Pointobject, returns the point itself.from arcgis.gis import GIS gis = GIS("home") feature_layer_item = gis.content.get("item_id") # replace "item_id" with an actual item ID polygon_flayer = feature_layer_item.layers[1] polygon_geom = polygon_flayer.query( where="OBJECTID=4", as_df=True ).loc[0].SHAPE polygon_geom.centroid
# for layer with spatial_reference = {"wkid": 4326} (-97.0684413136644, 32.737611573868016)- Returns:
A Python
tupleof (x, y) values indicating the center of the geometry.
- clip(envelope: tuple(float) | Envelope)
Constructs the intersection of the
Geometryobject and the specified extent of the envelope argument.Parameter
Description
envelope
Required
tuplein the form of (XMin, YMin, XMax, YMax). The first two elements represent the lower-left bounding coordinate, and the last two represent the upper-right coordinate.- Returns:
The
Geometryobject clipped to the extent
- contains(second_geometry: Geometry, relation: str | None = None)
Indicates if the base
Geometryobject contains theGeometryin the second_geometry argument.Parameter
Description
second_geometry
Required
Geometryobject. A second geometryrelation
Optional string. 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.
- Returns:
A Python
booleanindicating containment (True), or no containment (False).
from arcgis.gis import GIS gis = GIS(profile="<your_organization_profile>") cities_item = gis.content.get("<city_item_id>") counties_item = gis.content.get("<county_item_id>") city_df = cities_item.layers[0].query( where="city_name="<City_Name>", as_df=True ) city_geom = city_df.loc[0].SHAPE county_df = counties_item.layers[0].query( where="county_name="<County_Name>", as_df=True ) county_geom = county_df.loc[0].SHAPE county_geom.contains( second_geometry = city_geom, relation="CLEMENTINI" )
True
- convex_hull()
Constructs the smallest
Geometryobject that has no dents or inward curves that completely encloses a given geometry. All rays of the angles point outward away from the vertex (convex).- Returns:
A
Geometryobject
- crosses(second_geometry: Geometry) bool
Indicates if the two
Geometryobjects intersect in a geometry of a lesser shape type.Note
The
crossesmethod requires ArcPy/ShapelyParameter
Description
second_geometry
Required
Geometryobject. A second geometry- Returns:
A boolean indicating yes (True), or no (False)
- cut(cutter: Polyline)
Splits this
Geometryobject into a part left of the cuttingPolylineand a part right of it.Note
The
cutmethod requires ArcPyParameter
Description
cutter
Required
Polyline. The cutting polyline geometry- Returns:
a list of two
Geometryobjects
- densify(distance: float, deviation: float = None, method: str = None)
Creates a new
Geometryobject with added vertices. Returns Pythonnoneif called on aPointorMultipointgeometry.Parameter
Description
distance
Required
float. 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(s). 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
DEPRECATED at 2.4.4. Required
float. Operation 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.method
DEPRECATED at 2.4.4. Required
string. The type of densification:Options:
DISTANCE
ANGLE
GEODESIC
- Returns:
A new
Geometryobject
from arcgis.geometry import Polyline pline = Geometry( { "paths":[ [ [2010338.500592, 8251882.553660],[2010719.584711, 8251378.229761], [2011088.053736, 8250912.087053],[2011294.989821, 8250262.596250], [2011456.130871, 8249646.248064],[2011619.399318, 8249053.077316], [2012653.501244, 8249353.115046],[2012811.899070, 8248822.329305] ] ], "spatialReference": {"wkid":102100, "latestWkid":3857} } ) len(pline.coordinates()[0])
8
pline_dense = pline.densify( distance=100 ) len(pline_dense.coordinates()[0])
52
- difference(second_geometry: Geometry)
Constructs the
Geometryobject that is composed only of the region unique to the base geometry but not part of the other geometry.Parameter
Description
second_geometry
Required
Geometryobject. A second geometry- Returns:
A
Geometryobject
- disjoint(second_geometry: Geometry)
Indicates if the base and comparison
Geometryobjects share noPointlocations in common.Parameter
Description
second_geometry
Required
Geometryobject. A second geometry object to compare with the base geometry for whether anyPointlocations are common.- Returns:
A
booleanindicating True if the geometries share no :class:`points <arcgis.geometry.Point>` in common, and *False if they do.
- distance_to(second_geometry: Geometry) float
Retrieves the minimum distance between two
Geometryobjects. If the geometries intersect, the minimum distance is 0.Note
Both geometries must have the same spatial reference.
Parameter
Description
second_geometry
Required
Geometryobject. The geometry object for which to calculate the minimum distance from the base geometry.- Returns:
A
floatindicating the minimum distance between the two geometries.
- property envelope
Retrieves the
Geometry.geoextentof a geometry object as anEnvelopeobject.- Returns:
An
Envelopeobject.
- equals(second_geometry: Geometry) bool
Indicates if the base and comparison
Geometryobjects 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.Parameter
Description
second_geometry
Required
Geometry. A second geometry- Returns:
A
booleanindicating True if geometries are equivalent, False if they are not.
- property extent
Get the minimum bounding rectangle of the
Geometryobject as a tuple containing the xmin, ymin and xmax, ymax coordinate pairs.from arcgis.geometry import Geometry geom_b = Geometry({ "rings" : [ [ [-97.0628,32.755],[-97.044,32.731], [-97.079,32.720], [-97.090, 32.741], [-97.06326,32.759],[-97.0628,32.755] ] ], "spatialReference" : {"wkid" : 4326} } ) geom_b.extent
(-97.09, 32.72, -97.044, 32.759)
- Returns:
A Python
tupleof (xmin, ymin, xmax, ymax) values indicating the extent of the geometry.
- property first_point
Retrieves first coordinate point of the geometry.
from arcgis.gis import Geometry feature_layer_item = gis.content.get("item_id") # Replace "item_id" with the actual item ID feature_layer = feature_layer_item.layers[0] # Get the first layer feature1 = feature_layer.query( where="OBJECTID=1" ).features[0] feature1_geometry = Geometry(feature1.geometry) feature1.geometry.first_point
{'x': -97.06138, 'y': 32.837, 'spatialReference': {'wkid': 4326, 'latestWkid': 4326}}- Returns:
A
Geometryobject
- classmethod from_shapely(shapely_geometry: Geometry, spatial_reference: dict[str, Any] | None = None)
Creates a Python API Geometry object from a Shapely geometry object.
Note
Requires the shapely library to be installed.
Parameter
Description
shapely_geometry
Required Shapely Geometry. Single instance of Shapely Geometry to be converted to an ArcGIS Python API
geometryinstance.spatial_reference
Optional
SpatialReferenceor dictionary representing the wkid value of the spatial reference. For example,spatial_reference={'wkid': 4326}
- generalize(max_offset: float)
Creates a new simplified
Geometryobject using a specified maximum offset tolerance.Parameter
Description
max_offset
Required float. The maximum offset tolerance.
- Returns:
A
Geometryobject with a reduced set of vertices from the original object.
- property geoextent
Retrieves the current feature’s extent as a tuple of coordinate values representing the smallest bounding box that completely encloses the
geometryobject. The coordinate values represent the lower-left and upper-right corners of the bounding box.Note
Pointgeometries return a tuple with identical xmin, ymin and xmax, ymax values, each pair the coordinate of the point.# Usage Example: A point feature’s geometry extent
from arcgis.gis import GIS from arcgis.geometry import Point gis = GIS(profile="your_organization_profile") pt_flyr_item = gis.content.get("<ITEM_ID") pt_flyr = pt_flyr_item.layers[0] pt_featureset = pt_flyr.query(where="OBJECTID=1") pt_feature = pt_featureset.features[0] pt_feature.geometry
{'x': 387977.1986999996, 'y': 1268942.2853999997, 'spatialReference': {'wkid': 102100, 'latestWkid': 3857}}pt_geom = Point(pt_feature.geometry) pt_geom.geoextent
(387977.1986999996, 1268942.2853999997, 387977.1986999996, 1268942.2853999997)
Usage Example: A polygon feature’s geometry extent
from arcgis.gis import GIS from arcgis.geometry import Polygon gis = GIS(profile="your_organization_profile") poly_flyr_item = gis.content.get("<ITEM_ID>") poly_flyr = poly_flyr_item.layers[0] poly_featureset = poly_flyr.query(where="OBJECTID=1") poly_feature = poly_featureset.features[0] poly_feature.geometry
{'rings': [ [ [-10500881.4800416, 4350175.65831184], [-10500619.3420867, 4350168.68088843], [-10500603.1510862, 4350168.24965229], ... [-10500887.5233649, 4349971.58559592], [-10500881.4800416, 4350175.65831184]] ] ], 'spatialReference': {'wkid': 102100, 'latestWkid': 3857} }poly_geom = Polygon(poly_feature.geometry) poly_geom.geoextent
(-10502408.0915068, 4342638.36340794, -10492063.9950485, 4355527.18295716)
- Returns:
A Python
tupleof coordinate values in the form (xmin, ymin, xmax, ymax)
- property geometry_type
Gets the string value of a specific geometry type.
geom = Geometry({ "rings" : [ [ [-97.06138,32.837],[-97.002754,32.83626],[-96.971,32.792], [-97.1222,32.788],[-97.06138,32.837] ], [ [-97.0628,32.755],[-97.044,32.731], [-97.079,32.720], [-97.090, 32.741], [-97.06326,32.759],[-97.0628,32.755] ] ], "spatialReference" : {"wkid" : 4326} } ) print(geom.geometry_type)
polygon
- Returns:
A Python
stringindicating the geometry type.
- get_area(method: str, units: str | None = None)
Retrieves the area of the
Geometryusing a measurement type.Note
Requires the ArcPy library be installed.
Parameter
Description
method
Required
String. Options: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 - measurements follow the shortest path on the ellipsoid.
GREAT_ELLIPTIC - measurements follow the great elliptic path.
LOXODROME - measurements follow a rhumb line or single compass bearing.
PRESERVE_SHAPE - calculates measurements on the earth ellipsoid while preserving shape.
See getArea ArcPy reference for full details.
units
Optional String. Areal unit of measure keywords:
ACRES - Acres
HECTARES - Hectares
SQUARECENTIMETERS - Square Centimeters
SQUAREDECIMETERS - Square Decimeters
SQUAREINCHES - Square Inches
SQUAREFEET - Square Feet
SQUAREKILOMETERS - Square Kilometers
SQUAREMETERS - Square Meters
SQUAREMILES - Square Miles
SQUAREMILLIMETERS - Square Millimeters
SQUAREYARDS - Square Yards
- get_length(method: str, units: str)
Retrieves the length of the
Geometryusing a measurement type.Note
Requires the ArcPy library be installed.
Parameter
Description
method
Required
String. Options: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). Only available when using a projected coordinate system.
GEODESIC - measurements that account for the curvature of the earth.
GREAT_ELLIPTIC - measurements along the great elliptic.
LOXODROME - measurements along a rhumb line.
PRESERVE_SHAPE - measurements that preserve the shape of the geometry while calculating length on the surface of the earth ellipsoid.
See the ArcPy getLength reference for full details.
units
Required String. Linear unit of measure keywords:
CENTIMETERS
DECIMETERS
FEET
INCHES
KILOMETERS
METERS
MILES
MILLIMETERS
NAUTICALMILES
YARDS
- Returns:
A float indicating the length of the
Geometryobject
- get_part(index: int | None = None)
Retrieves an arcobject array of arcobjects Point objects for a a particular part of a
Geometryobject.Note
Requires the ArcPy library be installed.
Parameter
Description
index
Required Integer. The index position of the specific part of the geometry object. Use the
part_countproperty to determine the total number of parts. Index positions are zero-based.- Returns:
An ArcPy arcobjects array of arcobjects Point objects comprising the part.
- property has_curves: bool
Indicates whether a
PolylineorPolygonhas a curve in it.- Returns:
A Python
boolindicating True or False as to whether the geometry has a curve. See Curve objects for definition of curves.
- property has_m
Indicates if the geometry has a M value.
- Returns:
A Python
boolindicating True or False as to whether the geometry has m values.
- property has_z
Indicates if the geometry has a Z value.
- Returns:
A Python
boolindicating True or False as to whether the geometry has z values.
- property hull_rectangle
Retrieves the space-delimited string of the coordinate pairs of the minimal bounding geometry with straight segments where all interior and exterior angles are less than 180 degrees (a convex hull rectangle).
Note
Requires either the ArcPy or Shapely libraries.
from arcgis.geometry import Polyline polyline_geom = Polyline( { "paths":[ [ [19445677.33, -4386730.6], [19445709.73, -4386788.71] ] ], "spatialReference":{"wkid":102100, "latestWkid":3857} } ) polyline_geom.hull_rectangle()
'19445709.73 -4386788.71 19445709.73 -4386788.71 19445677.33 -4386730.6 19445677.33 -4386730.6'
- Returns:
A space-delimited string
- intersect(second_geometry: Geometry, dimension: int = None)
Constructs a
Geometryobject 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.Parameter
Description
second_geometry
Required
Geometryobject. A second geometrydimension
DEPRECATED at 2.4.4. An
Integerspecifying the topological dimension (shape type) of the resulting geometry.1 - A zero-dimensional geometry (
PointorMultiPoint).2 - A one-dimensional geometry (
Polyline).4 - A two-dimensional geometry (
Polygon).
- Returns:
A
Geometryobject indicating an intersection, or None for no intersection
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} }) type(geom.intersect(second_geometry = geom2, dimension = 4)) arcgis.geometry._types.Polygon
- property is_empty
Determines if the geometry is empty.
- Returns:
A boolean indicating empty (True), or filled (False).
- property is_multipart
Indicates if the
geometryhas more than one part.Note
ArcPy provides an additional layer of Geometry checks than pure Python implementations.
The criteria for results are:
Point - always False
Multipoint - True if it contains more than one point
Polyline - True if it contains more than one path
Polygon - True if it contains more than one exterior ring.
Envelope - always False
Note
Relies on the ring orientation to determine whether it is exterior or interior.
Usage Example 1 - Initialize new geometry
from arcgis.gis import GIS from arcgis.gis import Geometry 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} } ) geom.is_multipart
True
Usage Example 2: Use a Feature’s geometry
flyr_item = gis.content.get("<item_id>") flyr_obj = flyr_item.layers[0] feature4 = flyr_obj.query(where="OBJECTID = 4").features[0] feature4_geom = Geometry(feature4.geometry) feature4_geom.is_multipart
False
- Returns:
A
boolindicating True or False as to whether geometry has more than one part.
- property label_point
Gets the
Pointat which the label is located. The label_point is always located within or on a feature. Retrieves the property as aPointobjectfrom arcgis.geometry import Geometry 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} } ) geom.label_point
{'x': -97.06258999999994, 'y': 32.754333333000034, 'spatialReference': {'wkid': 4326, 'latestWkid': 4326}}
- property last_point
Gets the last coordinate of the geometry as a
Pointobject.from arcgis.geometry import Geometry geom = Geometry({ "rings" : [ [ [31.0776, -17.8449],[31.0819, -17.8448],[31.0819, -17.8433], [31.0879, -17.8411],[31.0901, -17.8431], [31.099, -17.8436], [31.0964, -17.8506],[31.086, -17.8496],[31.0776, -17.8449] ], [ [31.0724, -17.8662],[31.0761, -17.8624],[31.0781, -17.8649], [31.0767, -17.8656],[31.0773, -17.8670], [31.0738, -17.8683], [31.0724, -17.8662] ], "spatialReference" : {"wkid" : 4326} } ) geom.last_point.coordinates().tolist()
[31.0724, -17.8662]
- property length: float
Gets the length of a
PolylineorPolygonobject. The units of the output are the same as theSpatialReferenceof the geometry.Note
Returns zero for
PointandMultiPointfeature types.- Returns:
A
floatof the geometry length.
from arcgis.gis import GIS from arcgis.geometry import Geometry gis = GIS(profile="your_organization_profile") road_feature_lyr_item = gis.content.get("your_feature_layer_item_id") road_feature_lyr = feature_lyr_item.layers[0] road_feature_set = feature_lyr.query( where="road_name="Main St.", return_geometry=True) road_feature = road_feature_set.features[0] road_geom = Geometry(road_feature.geometry) road_geom.length
66.53218845178479
- property length3D: float
The
length3Dmethod retrieves the 3D length of the linear feature. Zero for point and multipoint The length units is the same as theSpatialReferencefield.Note
The
length3Dmethod returns zero forPointandMultiPointfeature types.Note
The
length3Dmethod requires ArcPy or Shapelygeom = 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} }) geom.length3D 0.03033576008004027
- Returns:
A float
- measure_on_line(second_geometry: Geometry, as_percentage: bool = False)
Retrieves a measure from the start
Pointof this line to thein_point.Note
Requires the ArcPy library be installed.
Parameter
Description
second_geometry
Required
Geometryobject. A second geometryas_percentage
Optional Boolean. If False, the measure will be returned as a distance; if True, the measure will be returned as a percentage.
- Returns:
A float
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} }) geom.measure_on_line(second_geometry = geom2, as_percentage = True) 0.33
- overlaps(second_geometry: Geometry)
Indicates if the intersection of the two
Geometryobjects has the same shape type as one of the input geometries and is not equivalent to either of the input geometries.Parameter
Description
second_geometry
Required
Geometryobject. A second geometry- Returns:
A boolean indicating an intersection of same shape type (True), or different type (False)
- property part_count
The
part_countmethod retrieves the number ofGeometryparts for the feature.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} }) geom.part_count 1
- Returns:
An Integer representing the amount of
Geometryparts
- property point_count
The
point_countmethod retrieves total number ofPointobjects for the feature.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} }) geom.point_count 9
- Returns:
An Integer representing the amount of
Pointobjects
- point_from_angle_and_distance(angle: float, distance: float, method: str = 'GEODESCIC')
Retrieves a
Pointat a given angle and distance, in degrees and meters, using the specified measurement type.Note
Requires the ArcPy library be installed.
Parameter
Description
angle
Required Float. The angle in degrees to the returned point.
distance
Required Float. The distance in meters to the returned point.
method
Optional String. 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.
- Returns:
A
Pointobject
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} }) point = geom.point_from_angle_and_distance(angle=60, distance = 100000, method = "PLANAR") point.type "POINT"
- position_along_line(value: float, use_percentage: bool = False)
Retrieves a
Pointon a line at a specified distance from the beginning of the line.Note
Requires either the ArcPy or Shapely libraries be installed.
Parameter
Description
value
Required Float. The distance along the line.
use_percentage
Optional Boolean. 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.
Note
For percentages, the value should be expressed as a double from 0.0 (0%) to 1.0 (100%).
- Returns:
A
Geometryobject
- project_as(spatial_reference: dict[str, Any] | SpatialReference, transformation_name: str = None)
Projects a
Geometryobject and optionally applies a datum transformation (See `Geographic Datum Transformations <https://doc.esri.com/en/arcgis-pro/latest/help/mapping/properties/geographic-coordinate-system-transformation.html`_ for full details).Note
The
project_asmethod requires ArcPy or pyproj>=1.9 and shapelyParameter
Description
spatial_reference
Required SpatialReference. The new spatial reference. This can be a
SpatialReferenceobject or the coordinate system name.transformation_name
Optional String. The name of the geographic transformation to apply.
Note
See Transformation PDFs for a list of available transformation names and well known ids.
- Returns:
A
Geometryobject in the new spatial reference
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} } ) target_sr = SpatialReference({"wkid" : 3857"}) geom2 = geom.project_as(spatial_reference=target_sr) geom2.coordinates().tolist()
[[[-10804823.397292428, 3873688.371653636], [-10804817.831317887, 3873555.8833610276], [-10804807.812563716, 3873290.911252522], [-10804811.152148439, 3873025.94511247], [-10804823.397292428, 3873688.371653636]], [[-10805032.677935118, 3863358.7604676774], [-10804840.095216047, 3862035.1061701835], [-10805001.508477695, 3862829.280913905], [-10805032.677935118, 3863358.7604676774]]]
- query_point_and_distance(second_geometry: Geometry, use_percentage: bool = False)
Finds the
Pointon thePolylinenearest to the second_geometry and the distance between those points. Retrieves information about the side of the line the `` is on as well as the distance along the line where the nearest point occurs.Note
Requires the ArcPy library be installed
Note
Only valid to call on
Polylinegeometries.Parameter
Description
second_geometry
Required
Pointobject. A second geometry to which the nearest point on thepolylinewill be calculated.as_percentage
Optional boolean to indicate if the distance should be returned as a percentage or not. If True, the measure will be a returned as a percentage. If False, the measure will be returned as distance.
- Returns:
- A 4-member tuple consisting of:
The nearest point on the polyline to the second_geometry argument. The object is in ArcPy *PointGeometry*
format.
The distance between the start point of the line and the returned point on the line.
The minimum distance between the polyline and the second_geometry.
A boolean indicating whether the second_geometry is on the right side of the polyline.
Note
The distance values are in the units of the polyline’s spatial reference.
from arcgis.gis import GIS from arcgis.geometry import Geometry gis = GIS("home") highways_item = gis.content.search( query="Interstate Highways", item_type="Feature Layer" )[0] highways_layer = highways_item.layers[0] highway_45_feature = highways_layer.query( where="NAME = 'I-45'").features[0] highway_45_geom = highway_45_feature.geometry hospitals_item = gis.content.search( query="General Hospital", item_type="Feature Layer" )[0] hospitals_layer = hospitals_item.layers[0] hospital_feature = hospitals_layer.query( where="NAME = 'General Hospital'").features[0] hospital_geom = hospital_feature.geometry qpd_point_information = highway_45_geom.query_point_and_distance( second_geometry=hospital_geom ) qpd_point_information
(<PointGeometry object at 0x2b2374b6f50[0x2b238b50540]>, 66.53218845178479, 3320.025639960282, True)
- rotate(theta: float, inplace: bool = False)
Turns a
Geometryobject counter-clockwise by a given angle.Parameter
Description
theta
Required Float. The rotation angle.
inplace
Optional Boolean. If True, the value is updated in the object, False creates a new object
- Returns:
If inplace=False, a polygon
GeometryobjectIf inplace=True, the current object is updated.
- scale(x_scale: float = 1, y_scale: float = 1, inplace: bool = False)
Resize a
Geometryobject based on an origin in either the x, y or both directions.Parameter
Description
x_scale
Optional :class:`float. The x-scale factor. Value can be negative.
y_scale
Optional
float. The y-scale factor. Value can be negative.inplace
Optional Boolean. If True, the value is updated in the object. If False creates a new object. Default is False.
- Returns:
If inplace=False, a polygon
GeometryobjectIf inplace=True, the current object is updated.
# Example usage of the scale method.
from arcgis.geometry import Geometry 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} }) scaled_geom = geom.scale( x_scale = 3, y_scale = 0.5, inplace = False ) print(f"Output object type: {type(scaled_geom)}") print(f"Output coordinates differ from original: {scaled_geom.coordinates()[0] != geom.coordinates()[0]}")
Output object type: arcgis.geometry._types.Polygon Output coordinates differ from original: [ [ True True] [ True True] [ True True] [ True True] [ True True] ]
- segment_along_line(start_measure: float, end_measure: float, use_percentage: bool = False)
Retrieves a
Polylineobject between 2 distance measures along aPolylineobject.Note
Requires the ArcPy library be installed.
Parameter
Description
start_measure
Required
Float. The starting percentage or distance from the beginning of the line.end_measure
Required
Float. The ending percentage or distance from the beginning of the line.use_percentage
Optional
Boolean. The start and end measures may be specified as fixed units or as a ratio. If True, the start_measure and end_measure arguments are read as percentages along the line; if False, the arguments are distance values.Note
For percentages, the measures should be expressed as a double from 0.0 (0 percent) to 1.0 (100 percent).
- Returns:
A
Polylineobject between the start_measure and end_measure.
from arcgis.gis import GIS gis = GIS(profile="your_organization_profile") electric_line_item = gis.content.search( query="City Electric Lines *", item_type="Feature Layer", max_items=1 )[0] electric_line_layer = electric_line_item.layers[0] electric_line_geom = electric_line_layer.query( where="OBJECTID=1", as_df=True).loc[0].SHAPE segment_line = electric_line_geom.segment_along_line( start_measure= 25, end_measure= 50, use_percentage = True ) print(f"Result type: {type(segment_line)}") print(f"Result object: {segment_line}")
Result type: <class 'arcgis.geometry._types.Polyline'> Result object: {'paths': [ [ [19445689.50455819, -4386752.435295573], [19445701.679116387, -4386774.270591147] ] ], 'spatialReference': {'wkid': 102100, 'latestWkid': 3857} }
- skew(x_angle: float = 0, y_angle: float = 0, inplace: bool = False)
Creates a skew transform along one or both axes of a
Polygonobject.Parameter
Description
x_angle
optional Float. Angle to skew in the x coordinate
y_angle
Optional Float. Angle to skew in the y coordinate
inplace
Optional Boolean. If True, the value is updated in the object, False creates a new object
- Returns:
If inplace=False, a polygon
Geometry
object * If inplace=True, the current object is updated.
- snap_to_line(second_geometry: Geometry)
Retrieves a new
Pointbased on where the second_geometry is snapped to aPolylineobject. Only valid to be called on aPolylineobject.Note
Requires the ArcPy library be installed.
Parameter
Description
second_geometry
Required
Pointobject. The point to be snapped to thepolyline.
- property spatial_reference
Gets the
SpatialReferenceof the geometry.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} }) geom.spatial_reference <SpatialReference Class>
- Returns:
A
SpatialReferenceobject
- symmetric_difference(second_geometry: Geometry) _GEOMETRY_TYPES
Constructs a new
Geometryobject that is the union of two geometries minus the intersection of those geometries.Note
The two input geometries must be the same shape type.
Parameter
Description
second_geometry
Required
Geometryobject of the same geometry type as the geometry from which the method is called.- Returns:
A
Geometryobject
- touches(second_geometry: Geometry)
Indicates if the boundaries of the two
Geometryobjects intersect.Parameter
Description
second_geometry
Required
Geometryobject. A geometry object whose boundary will be compared to compare against the base geometry.
- translate(x_offset: float = 0, y_offset: float = 0, inplace: bool = False)
Moves a
Geometryobject in the x and y direction by a given distance.Parameter
Description
x_offset
Optional Float. Translation x offset
y_offset
Optional Float. Translation y offset
inplace
Optional Boolean. If True, updates the existing Geometry,else it creates a new Geometry object
- Returns:
If inplace=False, a polygon
GeometryobjectIf inplace=True, the current object is updated.
# Example usage of the translate method.
from arcgis.geometry import Geometry 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} } ) geom.translate( x_offset = 40, y_offset = 50, inplace = True )
- property true_centroid
Gets the
Pointrepresenting the center of gravity for a feature.Note
The
true_centroidmethod requires ArcPy or Shapelygeom = 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} }) geom.true_centroid {'x': -97.06272135472369, 'y': 32.746201426025, 'spatialReference': {'wkid': 4326, 'latestWkid': 4326}}
- Returns:
A
Pointobject
- union(second_geometry: Geometry)
Constructs the
Geometryobject that is the set-theoretic union of the input geometries.Parameter
Description
second_geometry
Required
Geometryobject. A second geometry- Returns:
A
Geometryobject
- within(second_geometry: Geometry, relation: str | None = None) bool
Indicates if the base
Geometryobject is within the comparisonGeometryobject.Parameter
Description
second_geometry
Required
Geometryobject. A second geometryrelation
DEPRECATED Optional String. 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.
- Returns:
A boolean indicating the
Geometryobject is within (True), or not within (False)
areas_and_lengths
- arcgis.geometry.areas_and_lengths(polygons: Polygon, length_unit: str | LengthUnits, area_unit: str | AreaUnits, calculation_type: str, spatial_ref: int = 4326, gis: GIS | None = None, future: bool = False)
The areas_and_lengths function calculates areas and perimeter lengths for each
Polygonspecified in the input array.Keys
Description
polygons
The list of
Polygonobjects whose areas and lengths are to be computed.length_unit
The length unit in which the perimeters of polygons will be calculated.
If calculation_type is planar, then this argument can be any esriUnits constant string or integer.
If calculationType is not planar, then length_unit must be a linear
LengthUnitsconstant or string. For example:For meters, use 9001 or LengthUnits.METER
For survey miles, use 9035 or LengthUnits.SURVEYMILE
If length_unit is not specified, the units are derived from spatial_ref. If spatial_ref is not specified as well, the units are in meters.
area_unit
The area unit in which areas of polygons will be calculated.
If calculation_type is planar, then area_unit can be any esriAreaUnits constant.
If calculation_type is not planar, then area_unit must be an
AreaUnitsdictionary. For example,for square meters use - {“areaUnit”: “esriSquareMeters”}
for square miles use - {“areaUnit”: “esriSquareMiles”}
If area_unit is not specified, the units are derived from the spatial_ref. If spatial_ref is not specified, then the units are in square meters.
calculation_type
The type defined for the area and length calculation of the input geometries. The type can be one of the following values:
planar - Planar measurements use 2D Euclidean distance to calculate area and length. This should only be used if the area or length needs to be calculated in the given
SpatialReference. Otherwise, use preserveShape.geodesic - Use this type if you want to calculate an area or length using only the vertices of the
Polygonand define the lines between the points as geodesic segments independent of the actual shape of thePolygon. A geodesic segment is the shortest path between two points on an ellipsoid.preserveShape - This type calculates the area or length of the geometry on the surface of the Earth ellipsoid. The shape of the geometry in its coordinate system is preserved.
spatial_ref
Optional integer. The desired spatial reference of the output. Integer value is the wkid value of the spatial reference. Default 4326.
Note
See Using Spatial References for links to comprehensive list of values.
gis
Optional
GISobject. If no argument provided, the active GIS will be used.future
Optional boolean.
If True, a
GeometryJobthat can be queried will be returned and control returns to the user.If False, a dictionary object with results after the function completes.
- Returns:
A dictionary with result output if future=False, or a
GeometryJobobject if future = True.
>>> fl_item = gis.content.get("<item_id>") #Feature Layer item with polygon later >>> poly_lyr = fl_item.layers[0] >>> polygon1 = poly_lyr.query(where="objectid=14, as_df=True).SHAPE.loc[0] >>> polygon2 = poly_lyr.query(where="objectid=38, as_df=True).SHAPE.loc[0] # Usage Example 1 >>> output_1 = areas_and_lengths(polygons =[polygon1, polygon2], length_unit = 9001, area_unit = {"areaUnit": "esriSquareMeters"}, spatial_ref = 3857, calculation_type = "preserveShape") >>> output_1 {'areas': [7845609.082046935, 52794153.65053841], 'lengths': [29042.783436295722, 98763.80242520552]} # Usage Example 2 >>> from arcgis.geometry import LengthUnits, AreaUnits >>> output_2 = areas_and_lengths(polygons =[polygon1, polygon2,...], length_unit = LengthUnits.FOOT, area_unit = AreaUnits.SQUAREFEET, spatial_ref = {"wkid": 3857} calculation_type = "planar", future = True) >>> trials = 0 >>> while trials < 10: >>> if not ft_output.done(): >>> print("...processing...") >>> time.sleep(3) >>> trials += 1 >>> else: >>> print(ft_output.result()) >>> break ...processing... ...processing... {'areas': [84449433.3236774, 568271540.420404], 'lengths': [95284.72256002533, 324028.2231798081]}
auto_complete
- arcgis.geometry.auto_complete(polygons: list[Polygon] | None = None, polylines: list[Polyline] | None = None, spatial_ref: SpatialReference | None = None, gis: GIS | None = None, future: bool = False)
The
auto_completefunction simplifies the process of constructing newPolygonobjects that are adjacent to other polygons. It constructs polygons that fill in the gaps between existing polygons and a set ofPolylineobjects.Keys
Description
polygons
A List of
Polygonobjectspolylines
A List of
Polylineobjectsspatial_ref
A
SpatialReferenceof the input geometries or the integer WKID of the spatial reference.future
Optional boolean.
If True, a
GeometryJobthat can be queried will be returned and control returns to the user.If False, a
Polygonobject will be returned after the function completes.
- Returns:
If future=False, a
Polygonobject. If future=True, aGeometryJobobject. See code example inareas_and_lengthsfor code snippet querying the job.
buffer
- arcgis.geometry.buffer(geometries: list, in_sr: int | dict[str, Any], distances: float | list[float], unit: str | LengthUnits, out_sr: int | dict[str, Any] | None = None, buffer_sr: float | None = None, union_results: bool | None = None, geodesic: bool | None = None, gis: GIS | None = None, future: bool = False)
The
bufferfunction createspolygonsaround each inputGeometryin the list at the specified distance.Note
The options are available to union buffers and to use geodesic distance.
Keys
Description
geometries
The list of
geometriesto buffer.in_sr
The well-known ID, or a
SpatialReferenceobject for the input geometries.distances
The distances that each input
Geometrywill be buffered.unit
The unit of the buffer distances. * If not specified, the units are derived from buffer_sr. * If buffer_sr is also not specified, the units are derived from in_sr.
out_sr
The well-known ID or the
SpatialReferenceobject for the returnedgeometries.buffer_sr
The well-known ID or the
SpatialReferenceobject in which thegeometriesare buffered.union_results
Optional boolean. * If True, all geometries buffered at a given distance are unioned into a single (possibly multipart)
Polygonand the unionedGeometryis placed in the output list. The default is False.geodesic
Optional boolean.
If True, buffer the input geometries using geodesic distance. Geodesic
distance is the shortest path between two points along the ellipsoid of the earth. If False, the 2D Euclidean distance is used
Note
The default value depends on the geometry type, unit and buffer_sr arguments. See buffering using GCS and buffering using PCS for details.
future
Optional boolean.
If True, a
GeometryJobwill be returned for query and the process returns control to the user.If False, the process waits until completion before returning the output
polygons
The default is False.
Note
If setting future to True there is a limitation of 6500 geometries that can be processed in one call.
- Returns:
A list of
Polygonobjects if future=False, or aGeometryJobobject if future=True. Query the job’sresult()method to get results.
>>> from arcgis.gis import GIS >>> from arcgis.geometry import Point, buffer, LengthUnits, AreaUnits >>> gis = GIS(profile="my_enterprise_user") >>> flyr_item = gis.content.get("<item_id>") >>> pts_layer = fl_item.layers[0] >>> geom1 = Point(pts_layer.query(where="name='Water Dept'").features[0].geometry) >>> geom2 = Point(pts_layer.query(where="name='Water Satellite'").features[0].geometry) >>> buffer_res = buffer(geometries =[geom1, geom2], distances=[1000,2000,...], in_sr = {"wkid": 3857}, unit = LengthUnits.FOOT, out_sr = 102009, buffer_sr = 102009, union_results = False, geodesic = True, future = False) >>> buffer_res [{'rings': [[[-1231272.7177999988, -367594.3729999997], [-1231259.824000001, -367596.90949999914],… [-1231285.7353999987, -367592.5767999999], [-1231272.7177999988, -367594.3729999997]]], 'spatialReference': {'wkid': 102009, 'latestWkid': 102009}}, {'rings': [[[-1414089.7775999978, -547764.3929000013], [-1414076.887000002, -547767.1926000006],… [-1414102.8069999963, -547762.3337000012], [-1414089.7775999978, -547764.3929000013]]], 'spatialReference': {'wkid': 102009, 'latestWkid': 102009}}]
convex_hull
- arcgis.geometry.convex_hull(geometries: list[Polygon] | list[Polyline] | list[MultiPoint] | list[Point], spatial_ref: int | dict[str, Any] | None = None, gis: GIS | None = None, future: bool = False)
The convex_hull function is performed on a Geometry Service resource. It returns the minimum bounding shape that contains the input geometry. The input geometry can be a
Point,MultiPoint,Polyline, orPolygonobject.Note
The convex hull is typically a polygon but can also be a polyline or point in degenerate cases.
Keys
Description
geometries
A list of
Point,MultiPoint,Polyline, orPolygonobjects. The structure of each geometry in the array is defined the same as the JSON geometry objects returned by the ArcGIS REST API.Note
Geometryobjects can be obtained by querying aFeatureLayer, returning it as a Pandas data frame, and then assigning variables to a geometry based on the row index.>>> flyr_item = gis.content.search("*", "Feature Layer")[0] >>> flyr_df = flyr_item.query(where="1=1", as_df=True) >>> geom0 = flyr_df.loc[0].SHAPE
spatial_ref
An integer value, or a
SpatialReferenceobject defined using the the Well-Known ID (wkid) of the Spatial Reference.Note
See Spatial Reference in the Geometry objects help, or Using Spatial References for details on concepts and resources for finding specific wkid values.
>>> geom_result = convex_hull(geometries=[geometry_object] spatial_ref=<wkid>)
or
>>> geom_result = convex_hull(geometries=[geometry_object], spatial_ref={"wkid": <wkid>})
or
>>> from arcgis.geometry import SpatialReference >>> sr_obj_wkid = SpatialReference(<wkid>) >>> geom_result = convex_hull(geometries=[geometry_object], spatial_ref=sr_obj_wkid)
future
Optional boolean.
If True, a
GeometryJobwill be returned for query and the process returns control to the user.If False, the process waits until completion before returning the output
polygons
The default is False.
Note
If setting future to True there is a limitation of 6500 geometries that can be processed in one call.
- Returns:
A list containing the
Geometryobject of the result, or iffuture=True, aGeometryJobobject. Call the job’sresult()method to inspect the process and results.
# Usage Example: >>> import time >>> from arcgis.gis import GIS >>> from arcgis.geometry import convex_hull >>> gis = GIS(profile="your_organization_profile") >>> flyr_item = gis.content.get("<item_id for feature layer>") >>> flyr = flyr_item.layers[0] >>> df = flyr.query(where="OBJECTID=1", as_df=True) >>> geom1 = df.loc[0].SHAPE >>> hull_job = convex_hull(geometries=[geom1], spatial_ref={"wkid": 2056}, future=True) >>> trials = 0 >>> while trials < 5: >>> if not hull_job.done(): >>> print("...processing...") >>> time.sleep(3) >>> trials += 1 >>> else: >>> print(hull_job.result()) >>> break ...processing... {'rings': [[[2664507.7925999984, 1212609.7138999999], ..., [2664678.264199998, 1212618.6860999987], [2664507.7925999984, 1212609.7138999999]]], 'spatialReference': {'wkid': {'wkid': 2056}}}
cut
- arcgis.geometry.cut(cutter: Polyline, target: list[Polyline] | list[Polygon], spatial_ref: int | dict[str, Any] | None = None, gis: GIS | None = None, future: bool = False)
The geometry service
cutfunction splits a targetPolylineorPolygongeometry where it is crossed by the cutterPolylinegeometry.Note
At 10.1 and later, this function calls simplify on the input cutter and target geometries.
Keys
Description
cutter
The
Polylinethat will be used to divide the target geometry into pieces where it crosses the target.target
spatial_ref
A
SpatialReferenceobject or well-known ID specifying the spatial reference of the input geometries.future
Optional boolean.
If True, a
GeometryJobobject will be returned and the process returns control to the user.If False, the process waits for the operation to complete before returning results and passing control back to the user.
Note
If future=True, there is a limitation of 6500 geometries that can be processed in one call.
- Returns:
A List of
Geometryobjects if future=False, or aGeometryJobif future=True.
densify
- arcgis.geometry.densify(geometries: list[Polygon] | list[Polyline] | list[MultiPoint] | list[Point], spatial_ref: int | dict[str, Any] | None, max_segment_length: float | None, length_unit: str | LengthUnits | None, geodesic: bool = False, gis: GIS | None = None, future: bool = False)
The
densifyfunction adds vertices toGeometryobjects at regular intervals.Keys
Description
geometries
spatial_ref
The well-known ID or a
SpatialReferenceobject for the inputgeometries.max_segment_len
All segments longer than maxSegmentLength are replaced with sequences of lines no longer than max_segment_length.
length_unit
The length unit of max_segment_length.
If geodesic = False, then the units are derived from the spatial_ref argument and the length_unit argument is ignored
If geodesic = True, then length_unit must be a linear unit
If argument is not provided and the spatial_ref argument is a projected coordinate system, this value is derived from the spatial_ref
If argument is not provided and the spatial_ref argument is a geographic coordinate system, the units are meters
geodesic
Optional boolean.
If True, then geodesic distance is used to calculate max_segment_length.
If False, then 2D Euclidean distance is used to calculate max_segment_length. The default is False.
future
Optional boolean.
If True, a
GeometryJobobject will be returned and the process returns control to the user.If False, the process waits for the operation to complete before returning results and passing control back to the user.
Note
If future=True, there is a limitation of 6500 geometries that can be processed in one call.
- Returns:
If future = False, a list of
Geometryobjects. If future = True, aGeometryJobobject.
difference
- arcgis.geometry.difference(geometries: list[Polygon] | list[Polyline] | list[MultiPoint] | list[Point], spatial_ref: int | dict[str, Any] | None, geometry: Geometry, gis: GIS | None = None, future: bool = False)
The difference function constructs the set-theoretic difference between each member of a list of
geometriesand anotherGeometryobject. In other words, let B be the difference geometry. For each geometry, A, in the input geometry list, it constructs A - B.Note
The operation calls
simplify()on the input geometriesKeys
Description
geometries
An array of
Point,MultiPoint,Polyline, orPolygonobjects.geometry
A single
Geometryobject of any type and of a dimension equal to or greater than the elements of the geometries argument.spatial_ref
A
SpatialReferenceobject or the well-known ID specifying the spatial reference of the input geometries.future
Optional boolean.
If True, a
GeometryJobobject will be returned and the process returns control to the user.If False, the process waits for the operation to complete before returning results and passing control back to the user.
Note
If future=True, there is a limitation of 6500 geometries that can be processed in one call.
- Returns:
If future = False, a list of
Geometryobjects. If future = True, aGeometryJobobject.
distance
- arcgis.geometry.distance(spatial_ref: int | dict[str, Any] | None, geometry1: Geometry, geometry2: Geometry, distance_unit: str | LengthUnits | None = '', geodesic: bool = False, gis: GIS | None = None, future: bool = False)
The
distancefunction is performed on a geometry service resource. It reports the 2D Euclidean or geodesic distance between the twoGeometryobjects.Keys
Description
geometry1
The
Geometryobject from which the distance is measured. The structure of each geometry in the array is the same as the structure of the JSON geometry objects returned by the ArcGIS REST API.geometry2
The
Geometryobject to which the distance is measured. The structure of each geometry in the array is the same as the structure of the JSON geometry objects returned by the ArcGIS REST API.distance_unit
Optional. One of
LengthUnitsenumeration members. See Geometry Service distance for full details.geodesic
If
geodesicis set to true, then the geodesic distance between thegeometry1andgeometry2geometries is returned. Geodesic distance is the shortest path between two points along the ellipsoid of the earth. Ifgeodesicis set to false or not specified, the planar distance is returned. The default value is false.spatial_ref
A
SpatialReferenceof the input geometries Well-Known ID or JSON objectfuture
Optional boolean.
If True, a
GeometryJobobject will be returned and the process returns control to the user.If False, the process waits for the operation to complete before returning results and passing control back to the user.
- Returns:
If future = False, the distance value between the
Geometryobjects. If future = True, aGeometryJobobject.
find_transformation
- arcgis.geometry.find_transformation(in_sr: int | dict[str, Any] | None, out_sr: int | dict[str, Any] | None, extent_of_interest: dict[str, Any] | None = None, num_of_results: int = 1, gis: GIS | None = None, future: bool = False)
The
find_transformationsfunction is performed on aGeometryservice resource. This function returns a list of applicable geographic transformations you should use when projecting geometries from the inputSpatialReferenceto the outputSpatialReference. The transformations are in JSON format and are returned in order of most applicable to least applicable. Recall that a geographic transformation is not needed when the input and output spatial references have the same underlying geographic coordinate systems. In this case, findTransformations returns an empty list.Note
Every returned geographic transformation is a forward transformation meaning that it can be used as-is to project from the input spatial reference to the output spatial reference. In the case where a predefined transformation needs to be applied in the reverse direction, it is returned as a forward composite transformation containing one transformation and a transformForward element with a value of false.
Keys
Description
in_sr
The well-known ID of the
SpatialReferenceor a spatial reference JSON object for the input geometries.out_sr
The well-known ID of the
SpatialReferenceor a spatial reference JSON object for the output geometries.ext_of_interest
The bounding box of the area of interest specified as a JSON envelope.If provided, the extent of interest is used to return the most applicable geographic transformations for the area.
Note
If a
SpatialReferenceis not included in the JSON envelope, thein_sris used for the envelope.num_of_results
The number of geographic transformations to return. The default value is 1.
Note
If
num_of_resultshas a value of -1, all applicable transformations are returned.future
Optional boolean.
If True, a
GeometryJobobject will be returned and the process returns control to the user.If False, the process waits for the operation to complete before returning results and passing control back to the user.
Note
If future=True, there is a limitation of 6500 geometries that can be processed in one call.
- Returns:
If future = False, a list of geographic transformations, or if future = True, a
GeometryJobobject.
from_geo_coordinate_string
- arcgis.geometry.from_geo_coordinate_string(spatial_ref: int | dict[str, Any] | None, strings: list[str], conversion_type: str | None, conversion_mode: str | None = None, gis: GIS | None = None, future: bool = False)
The
from_geo_coordinate_stringfunction is performed on aGeometryservice resource. The function converts an array of well-known strings into xy-coordinates based on the conversion type andSpatialReferencesupplied by the user. An optional conversion mode parameter is available for some conversion types. Seeto_geo_coordinate_stringsfor more information on the opposite conversion.Keys
Description
spatial_ref
A
SpatialReferenceof the input geometries Well-Known ID or JSON objectstrings
An array of strings formatted as specified by conversion_type. Syntax: [<string1>,…,<stringN>]
conversion-type
The conversion type of the input strings.
Note
Valid conversion types are:
MGRS - Military Grid Reference System
USNG - United States National Grid
UTM - Universal Transverse Mercator
GeoRef - World Geographic Reference System
GARS - Global Area Reference System
DMS - Degree Minute Second
DDM - Degree Decimal Minute
DD - Decimal Degree
conversion_mode
Conversion options for MGRS, UTM and GARS conversion types.
Note
Valid conversion modes for MGRS are:
mgrsDefault - Default. Uses the spheroid from the given spatial reference.
mgrsNewStyle - Treats all spheroids as new, like WGS 1984. The 80 degree longitude falls into Zone 60.
mgrsOldStyle - Treats all spheroids as old, like Bessel 1841. The 180 degree longitude falls into Zone 60.
mgrsNewWith180InZone01 - Same as mgrsNewStyle except the 180 degree longitude falls into Zone 01
mgrsOldWith180InZone01 - Same as mgrsOldStyle except the 180 degree longitude falls into Zone 01
Note
Valid conversion modes for UTM are:
utmDefault - Default. No options.
utmNorthSouth - Uses north/south latitude indicators instead of
zone numbers - Non-standard. Default is recommended
future
Optional boolean.
If True, a
GeometryJobobject will be returned and the process returns control to the user.If False, the process waits for the operation to complete before returning results and passing control back to the user.
- Returns:
If future = False, a is of (x,y) coordinates and if future = True, a
GeometryJobobject.
>>> coords = from_geo_coordinate_string(spatial_ref = "wkid", strings = ["01N AA 66021 00000","11S NT 00000 62155", "31U BT 94071 65288"], conversion_type = "MGRS", conversion_mode = "mgrs_default", future = False) >>> coords [[-117.378, 34.233], [14.387, 58.092], [179.0432, 98.653]]
generalize
- arcgis.geometry.generalize(spatial_ref: int | dict[str, Any] | None, geometries: list[Geometry], max_deviation: int, deviation_unit: str | LengthUnits | None = None, gis: GIS | None = None, future: bool = False)
The
generalizesimplifies the input geometries using the _Douglas-Peucker_ algorithm with a specified maximum deviation distance.Note
The output geometries will contain a subset of the original input vertices.
Keys
Description
geometries
Required. The list of
PolylineorPolygonobjects to be generalized.max_deviation
Sets the maximum allowable offset, which determines the degree of simplification. This value limits the distance the output geometry can differ from the input geometry.
deviation_unit
Specifies a unit for the max_deviation argument.
Note
If not specified, the units are derived from spatial_ref
spatial_ref
A
SpatialReferenceobject or the Well-Known ID of the input geometries.future
Optional boolean.
If True, a
GeometryJobobject will be returned and the process returns control to the user.If False, the process waits for the operation to complete before returning results and passing control back to the user.
Note
If future=True, there is a limitation of 6500 geometries that can be processed in one call.
- Returns:
If future = False, a list of the generalized
Geometryobjects, or if future = True, aGeometryJobobject.
intersect
- arcgis.geometry.intersect(spatial_ref: int | dict[str, Any] | None, geometries: list[Geometry], geometry: Geometry, gis: GIS | None = None, future: bool = False)
The
intersectfunction constructs the set-theoretic intersection between a list of geometries <arcgis.geometry.Geometry> and anotherGeometry.Note
The dimension of each resultant geometry is the minimum dimension of the input geometries list and the object serving as the geometry argument.
Keys
Description
geometries
An list of
Point,MultiPoint,Polyline, orPolygonobjects.geometry
A single
Geometryof any type and of a dimension equal to or greater than the elements of geometries.spatial_ref
A
SpatialReferenceobject or the Well-Known ID of the input geometries.future
Optional boolean.
If True, a
GeometryJobobject will be returned and the process returns control to the user.If False, the process waits for the operation to complete before returning results and passing control back to the user.
Note
If future=True, there is a limitation of 6500 geometries that can be processed in one call.
- Returns:
If future = False, the set-theoretic dimension between
Geometryobjects, or if future = True, aGeometryJobobject.
label_points
- arcgis.geometry.label_points(spatial_ref: int | dict[str, Any] | None, polygons: list[Polygon], gis: GIS | None = None, future: bool = False)
The
label_pointsfunction calculates an interiorPointfor eachPolygonspecified in the input list. These interior points can be used by clients for labeling the polygons.Keys
Description
polygons
Required list of
Polygonobjects whose labelPointobjects are to be computed.spatial_ref
A
SpatialReferenceobject or the well-known ID of the spatial reference of the input polygons.future
Optional boolean.
If True, a
GeometryJobobject will be returned and the process returns control to the user.If False, the process waits for the operation to complete before returning results and passing control back to the user.
Note
If future=True, there is a limitation of 6500 geometries that can be processed in one call.
- Returns:
If future = False, a list of
Pointobjects, or if future = True, aGeometryJobobject.
lengths
- arcgis.geometry.lengths(spatial_ref: int | SpatialReference | dict[str, Any], polylines: list[Polyline], length_unit: str | int | LengthUnits, calculation_type: str, gis: GIS | None = None, future: bool = False)
Calculates the 2D Euclidean or geodesic lengths of each
Polylinespecified in the input array.Keys
Description
spatial_ref
A
SpatialReferenceobject or the well-known ID of the spatial reference of the input polygons.polylines
The list of
Polylineobjects to compute.# Usage Example for parameter: >>> from arcgis.geometry import Polyline >>> from arcgis.geometry.functions import lengths >>> polyline1 = Polyline( >>> { >>> "paths": [ >>> [ >>> [-95.5, 30.2], [-95.6, 30.3] >>> ] >>> ], >>> "spatialReference": {"wkid": 4326} >>> } >>> ) >>> length_val = lengths( >>> ... >>> polylines=[polyline1] >>> ... >>> )
length_unit
A
LengthUnitsobject for which unit of measure to return result.If calculation_type is planar - value can be any esriUnits constant
Note
If calculation_type is planar and argument not provided, the units are derived from
spatial_ref.If calculationType is not planar, then must be a
LengthUnitsvalue, such as LengthUnits.METER or LengthUnits.SURVEYMILE
Note
If calculationType is not planar and argument not provided, the value is meters
See valid list of esriUnits constants: esriSRUnitTypeConstants
calculation_type
The length calculation type used for the operation. Can be one of the following:
planar - uses 2D Euclidean distance to calculate length. Only use this if the length needs to be calculated in the given spatial_ref, otherwise use preserveShape
geodesic - uses only the vertices of the polyline and defines the lines between the vertices as geodesic independent of the actual shape of the
Polyline. This segment is the shortest path between two points on an ellipsoid.preserveShape - uses the surface of the earth ellipsoid to calculate the length. The shape of the geometry in its coordinate system is preserved.
future
Optional boolean.
If True, a
GeometryJobobject will be returned and the process returns control to the user.If False, the process waits for the operation to complete before returning results and passing control back to the user.
Note
If future=True, there is a limitation of 6500 geometries that can be processed in one call.
- Returns:
If future = False, a list of 2D-Euclidean or geodesic lengths in float format
If future = True, a
GeometryJobobject.
# Example Usage: Running lengths on a feature's geometry >>> from arcgis.gis import GIS >>> from arcgis.geometry import Polyline >>> from arcgis.geometry import lengths, LengthUnits >>> gis = GIS(profile="your_organization_profile") >>> roads_item = gis.content.search("Major Roads")[0] >>> roads_flayer = roads_item.layers[0] >>> major_road_feature = roads_flyr.query("Carpenter Road").features[0] >>> major_road_line = Polyline(major_read_feature.geometry) >>> usFeet_simple = lengths( >>> spatial_ref=4326, >>> polylines=[major_road_line], >>> length_unit=LengthUnits.FOOT, >>> calculation_type='geodesic', >>> gis=gis >>> ) >>> print(usFeet_simple) [7619.876053]
offset
- arcgis.geometry.offset(geometries: list[Polygon] | list[Polyline] | list[MultiPoint] | list[Point], offset_distance: float, offset_unit: str | LengthUnits, offset_how: str = 'esriGeometryOffsetRounded', bevel_ratio: int = 10, simplify_result: bool = False, spatial_ref: int | dict[str, Any] | None = None, gis: GIS | None = None, future: bool = False)
The
offsetfunction constructsgeometriesthat are offset from the input geometries. If the offset parameter is positive, the constructed offset will be on the right side of the geometry; if negative on the left.Note
Tracing the geometry from its first vertex to the last will give you a direction along the geometry. It is to the right and left perspective of this direction that the positive and negative parameters will dictate where the offset is constructed. In these terms, you may infer where the offset of even horizontal geometries will be constructed.
Keys
Description
geometries
Required list of
Point,MultiPoint,Polyline, orPolygonobjects.offset_distance
Specifies the distance for constructing an offset geometry.
Note
If the
offset_distanceparameter is positive, the constructed offset will be on the right side of the input; if negative on the left.offset_unit
A unit for offset distance. Use
arcgis.geometry.functions.LengthUnitsoptions.offset_how
Determines how outer corners between segments are handled. The three options are as follows:
esriGeometryOffsetRounded - Rounds the corner between extended offsets
esriGeometryOffsetBevelled - Squares off the corner after a given ratio distance
esriGeometryOffsetMitered - Attempts to allow extended offsets to naturally intersect, but if that intersection occurs too far from the corner, the corner is eventually bevelled off at a fixed distance.
bevel_ratio
Value is multiplied by the offset_distance, and determines how far a mitered offset intersection can be located before it is bevelled.
when offset_how = esriGeometryOffsetMitered, argument is ignored and 10 is used internally.
when offset_how = esriGeometryOffsetBevelled, 1.1 will be used if argument not specified
when offset_how = esriGeometryOffsetRounded, argument is ignored
simplify_result
Option boolean. If True, true, then self intersecting loops will be removed. The default is False.
spatial_ref
A
SpatialReferenceobject of the well-known ID of the spatial reference of the of the input geometries.future
Optional boolean.
If True, a
GeometryJobobject will be returned and the process returns control to the user.If False, the process waits for the operation to complete before returning results and passing control back to the user.
Note
If future=True, there is a limitation of 6500 geometries that can be processed in one call.
- Returns:
If future = False, a list of
Geometryobjects, or if future = True, aGeometryJobobject.
# Usage Example: >>> from arcgis.geometry import Polyline, LengthUnits >>> pline = Polyline(iterable={"paths":[[[0,0],[2000,2000],[3000,0]]], :spatialReference: {"wkid": 2229}}) >>> new_geoms = offset(geometries = [pline], offset_distance = 1000, offset_unit = LengthUnits.METER, offset_how = "esriGeometryOffsetMitered", spatial_ref = {"wkid": 2229})
project
- arcgis.geometry.project(geometries: list[Polygon] | list[Polyline] | list[MultiPoint] | list[Point], in_sr: int | dict[str, Any] | None, out_sr: int | dict[str, Any] | None, transformation: str = '', transform_forward: bool = False, gis: GIS | None = None, future: bool = False)
The
projectfunction projects a list of input geometries from the inputSpatialReferenceto the outputSpatialReferenceKeys
Description
geometries
An list of
Point,MultiPoint,Polyline, orPolygonobjects.in_sr
The well-known ID of the spatial reference or a
SpatialReferenceobject specifying the spatial reference of the input geometries.out_sr
The well-known ID of the spatial reference or a
SpatialReferenceobject specifying the spatial reference of the output geometries.transformation
The well-known ID or a dictionary specifying the geographic transformation (also known as datum transformation) to be applied to the projected geometries.
Note
A transformation is needed only if the output
SpatialReferencecontains a different coordinate system from the input spatial reference. For comprehensive list of transformations, see Transformation PDFs.transform_forward
Optional boolean. Indicates whether or not to transform forward.
Note
The forward or reverse direction is implied in the name of the transformation. If transformation is specified, a value for this argument must be provided. The default value is False.
future
Optional boolean.
If True, a
GeometryJobobject will be returned and the process returns control to the user.If False, the process waits for the operation to complete before returning results and passing control back to the user.
Note
If future=True, there is a limitation of 6500 geometries that can be processed in one call.
- Returns:
If future = False, a list of
Geometryobjects in the out_sr coordinate system,, or if future = True, aGeometryJobobject.
#Usage Example >>> result = project(geometries = [{"x": -17568824.55, "y": 2428377.35}, {"x": -17568456.88, "y": 2428431.352}], in_sr = 3857, out_sr = 4326) [{"x": -157.82343617279275, "y": 21.305781607280093}, {"x": -157.8201333369876, "y": 21.306233559873714}]
relation
- arcgis.geometry.relation(geometries1: list[Geometry], geometries2: list[Geometry], spatial_ref: int | dict[str, Any] | None, spatial_relation: str = 'esriGeometryRelationIntersection', relation_param: str = '', gis: GIS | None = None, future: bool = False)
The
relationfunction determines the pairs of geometries from the input list that participate in the specified spatial relation.Note
Both lists are assumed to be in the spatial reference specified by the spatial_ref, which is a required argument. Geometry types cannot be mixed within a list.
Note
The relations are evaluated in 2D. z coordinates are not used.
Keys
Description
geometries1
The first list of
Geometryobjects used to compute the relations.geometries2
The second list of
Geometryobjects used.spatial_ref
A
SpatialReferenceobject or the well-known ID of the spatial reference of the geometries.relation_param
Only relevant when spatial_relation = esriGeometryRelationRelation. The Shape Comparison Language string to be evaluated. See here for more details.
spatial_relation
The spatial relationship to be tested between the two input geometry lists. Options:
esriGeometryRelationCross
esriGeometryRelationDisjoint
esriGeometryRelationIn
`esriGeometryRelationInteriorIntersection `
esriGeometryRelationIntersection
esriGeometryRelationLineCoincidence
esriGeometryRelationLineTouch
esriGeometryRelationOverlap
esriGeometryRelationPointTouch
esriGeometryRelationTouch
esriGeometryRelationWithin
esriGeometryRelationRelation
future
Optional boolean.
If True, a
GeometryJobobject will be returned and the process returns control to the user.If False, the process waits for the operation to complete before returning results and passing control back to the user.
- Returns:
If future = False, a dictionary of geometry index positions of geometries that participate in the specified relation, or if future = True, a
GeometryJobobject.
>>> new_res = relation(geometry1 = [{"x":-104.53,"y":34.74},{"x":-63.53,"y":10.23}], geometry2 = [{"rings":[[[-105,34],[-104,34],[-104,35],[-105,35],[-105,34]]]}], spatial_relation = "esriGeometryRelationWithin", spatial_ref = 4326, future = False) >>> new_res {'relations': [{"geometry1Index": 0, "geometry2Index": 3}, {"geometry1Index": 1, "geometry2Index": 0}]}
reshape
- arcgis.geometry.reshape(spatial_ref: int | dict[str, Any] | None, target: Polyline | Polygon, reshaper: Polyline, gis: GIS | None = None, future: bool = False)
The
reshapefunction modifies aPolylineorPolygonfeature by constructing a polyline over the feature. The feature takes the shape of this reshaper polyline from the first place it intersects the feature to the last.Keys
Description
target
reshaper
The single-part
Polylineobject that reshapes target.spatial_ref
A
SpatialReferenceobject or the well-known ID of the spatial reference of the geometries.future
Optional boolean.
If True, a
GeometryJobobject will be returned and the process returns control to the user.If False, the process waits for the operation to complete before returning results and passing control back to the user.
- Returns:
f *future = False, A reshaped
PolylineorPolygonobject if future = True, aGeometryJobobject.
to_geo_coordinate_string
- arcgis.geometry.to_geo_coordinate_string(spatial_ref: int | dict[str, Any] | None, coordinates: list[list[float]], conversion_type: str, conversion_mode: str = 'mgrsDefault', num_of_digits: int | None = None, rounding: bool = True, add_spaces: bool = True, gis: GIS | None = None, future: bool = False)
The
to_geo_coordinate_stringfunction is performed on aGeometryservice resource. The function converts an array of xy-coordinates into well-known strings based on the conversion type andSpatialReferencesupplied by theUser. Optional parameters are available for some conversion types. Seefrom_geo_coordinate_stringsfor more information on the opposite conversion.Note
If an optional parameter is not applicable for a particular conversion type, but a value is supplied for that parameter, the value will be ignored.
Keys
Description
spatial_ref
A
SpatialReferenceobject or the well-known ID of the spatial reference of the input coordinates.coordinates
An list of xy-coordinates in JSON format to be converted. Syntax:
[[10,10],[10,20]…[30,40]]
conversion-type
The conversion type of the input strings.
Note
Valid conversion types are:
MGRS - Military Grid Reference System
USNG - United States National Grid
UTM - Universal Transverse Mercator
GeoRef - World Geographic Reference System
GARS - Global Area Reference System
DMS - Degree Minute Second
DDM - Degree Decimal Minute
DD - Decimal Degree
conversion_mode
Conversion options for MGRS and UTM conversion types.
Note
Valid conversion modes for MGRS are:
mgrsDefault - Default. Uses the spheroid from the given spatial reference
mgrsNewStyle - Treats all spheroids as new, like WGS 1984. The 80 degree longitude falls into Zone 60
mgrsOldStyle - Treats all spheroids as old, like Bessel 1841. The 180 degree longitude falls into Zone 60
mgrsNewWith180InZone01 - Same as mgrsNewStyle except the 180 degree longitude falls into Zone 01
mgrsOldWith180InZone01 - Same as mgrsOldStyle except the 180 degree longitude falls into Zone 01
Note
Valid conversion modes for UTM are:
utmDefault - Default. No options.
utmNorthSouth - Uses north/south latitude indicators instead of
zone numbers - Non-standard. Default is recommended
num_of_digits
The number of digits to output for each of the numerical portions in the string. The default value for
num_of_digitsvaries depending onconversion_type:MGRS: 5
USNG: 8
UTM: NA
GeoRef: 5
GARS: NA
DMS: 2
DDM: 4
DD: 6
rounding
If True, then numeric portions of the string are rounded to the nearest whole magnitude as specified by num_of_digits
Otherwise, numeric portions of the string are truncated.
Note
The rounding parameter applies only to conversion types MGRS, USNG and GeoRef.
The default value is True.
add_spaces
Option boolean.
If True, then spaces are added between components of the string.
Note
Only applies to conversion_types MGRS, USNG and UTM. The default value for MGRS is False, while the default value for both USNG and UTM is True.
future
Optional boolean.
If True, a
GeometryJobobject will be returned and the process returns control to the user.If False, the process waits for the operation to complete before returning results and passing control back to the user.
- Returns:
A list of strings if future = False, a
GeometryJobobject if future = True.
>>> strings = to_geo_coordinate_string(spatial_ref = 4326, coordinates = [[180,0],[-117,34],[0,52]], conversion_type = "MGRS", conversion_mode = "mgrsNewWith180InZone01", num_of_digits=8, add_spaces=True, future = False) >>> strings ["01N AA 66021 00000","11S NT 00000 62155", "31U BT 94071 65288"]
trim_extend
- arcgis.geometry.trim_extend(spatial_ref: int | dict[str, Any] | None, polylines: list[Polyline], trim_extend_to: Polyline, extend_how: int = 0, gis: GIS | None = None, future: bool = False)
The
trim_extendfunction trims or extends eachPolylinespecified in the input list using the user-specified guide polylines.Note
When trimming features, the part to the left of the oriented cutting line is preserved in the output, and the other part is discarded. An empty
Polylineis added to the output list if the corresponding input polyline is neither cut nor extended.Keys
Description
polylines
A list of
Polylineobjects to trim or extendtrim_extend_to
A
Polylineserving as the guide for trimming or extending input polylines.extend_how
A flag that is used along with the trimExtend function.
0- By default, an extension considers both ends of a path. The old ends remain, and new points are added to the extended ends. The new points have attributes that are extrapolated from adjacent existing segments.1- If an extension is performed at an end, relocate the end point to the new position instead of leaving the old point and adding a new point at the new position.2- If an extension is performed at an end, do not extrapolate the end-segment’s attributes for the new point. Instead, make
its attributes the same as the current end. Incompatible with esriNoAttributes. *
4- If an extension is performed at an end, do not extrapolatethe end-segment’s attributes for the new point. Instead, make its attributes empty. Incompatible with esriKeepAttributes.
8- Do not extend the ‘from’ end of any path.16- Do not extend the ‘to’ end of any path.
spatial_ref
A
SpatialReferenceobject or the well-known ID of the spatial reference of the input geometries.future
Optional boolean.
If True, a
GeometryJobobject will be returned and the process returns control to the user.If False, the process waits for the operation to complete before returning results and passing control back to the user.
- Returns:
A list of
Polylineobjects if future = False, or aGeometryJobobject if future = True.
union
- arcgis.geometry.union(geometries: list[Polygon] | list[Polyline] | list[MultiPoint] | list[Point], spatial_ref: str | dict[str, str] | None = None, gis: GIS | None = None, future: bool = False)
The
unionfunction constructs the set-theoretic union of eachGeometryin the geometries list.Note
All inputs must be of the same type.
Keys
Description
geometries
Required list of
Point,MultiPoint,Polyline, orPolygonobjects.spatial_ref
A
SpatialReferenceobject or the well-known ID of the spatial reference of the input geometries.future
Optional boolean.
If True, a
GeometryJobobject will be returned and the process returns control to the user.If False, the process waits for the operation to complete before returning results and passing control back to the user.
Note
If future=True, there is a limitation of 6500 geometries that can be processed in one call.
- Returns:
If future = False, the set-theoretic union of the
Geometryobjects in the geometries argument, or if future = True, aGeometryJobobject.