Select to view content in your preferred language

Questions regarding the difference between reading a geometry and writing a geometry?

458
1
Jump to solution
12-13-2022 06:04 AM
RPGIS
by
Regular Contributor

Hi,

I have some questions regarding geometries in python. I am currently working on a script to read/write the geometry of one feature class and analyzing the contains method to determine if the center of a line is contained by the input polygon geometry. A question that I have is, what is the difference between making a new geometry object vs reading and utilizing the existing geometry object?

Ex: ['SHAPE@'] field to read the geometry vs Polygon (inputs, {spatial_reference}, {has_z}, {has_m}) to make a new geometry object.

The other question is can this be utilized with the contains method or will I need to create a whole new object in order to do so?

Any help on this would be greatly appreciated.

0 Kudos
1 Solution

Accepted Solutions
JohannesLindner
MVP Frequent Contributor

what is the difference between making a new geometry object vs reading and utilizing the existing geometry object?

There is no difference. Reading the SHAPE@ token returns a geometry object, same as when you create it on your own.

extracted_geometry = [row[0] for row in arcpy.da.SearchCursor("TestPoints", ["SHAPE@"])][0]
created_geometry = arcpy.PointGeometry(arcpy.Point(523433, 5848821), arcpy.SpatialReference(25832))

extracted_geometry
#<PointGeometry object at ...>
created_geometry
#<PointGeometry object at ...>

 

can this be utilized with the contains method or will I need to create a whole new object in order to do so?

contains() is a method of the Geometry classes, so you can call it on the extracted geometries without problem.


Have a great day!
Johannes

View solution in original post

0 Kudos
1 Reply
JohannesLindner
MVP Frequent Contributor

what is the difference between making a new geometry object vs reading and utilizing the existing geometry object?

There is no difference. Reading the SHAPE@ token returns a geometry object, same as when you create it on your own.

extracted_geometry = [row[0] for row in arcpy.da.SearchCursor("TestPoints", ["SHAPE@"])][0]
created_geometry = arcpy.PointGeometry(arcpy.Point(523433, 5848821), arcpy.SpatialReference(25832))

extracted_geometry
#<PointGeometry object at ...>
created_geometry
#<PointGeometry object at ...>

 

can this be utilized with the contains method or will I need to create a whole new object in order to do so?

contains() is a method of the Geometry classes, so you can call it on the extracted geometries without problem.


Have a great day!
Johannes
0 Kudos