How to get the vertex coordinates of a feature in ArcPy

Get the vertices of each polygon in the polygon feature layer

Data structure of polygon feature layer

--Layer class (arcpy._mp.Layer) SHAPE @ ┐ --Polygon class (arcpy.arcobjects.geometries.Polygon) getPart () ┐ --Array class (arcpy.arcobjects.arcobjects.Array) getObject (0) ┐ --Array class (arcpy.arcobjects.arcobjects.Array) getObject (i) ┐ --Point class (arcpy.arcobjects.arcobjects.Point)

Python code

GetPolygonVertex.py


import arcpy

#Check input parameters
arcpy.AddMessage("GetArgumentCount() = {0}".format(arcpy.GetArgumentCount()))
for i in range(arcpy.GetArgumentCount()):
    param = arcpy.GetParameter(i)
    paramText = arcpy.GetParameterAsText(i)
    
    arcpy.AddMessage("GetParameter({0}) = {1}".format(i, param))
    arcpy.AddMessage("GetParameter({0}).__class__ = {1}".format(i, param.__class__))
    arcpy.AddMessage("GetParameter({0}).__class__.__name__ = {1}".format(i, param.__class__.__name__))
    arcpy.AddMessage("GetParameterAsText({0}) = {1}".format(i, paramText))

inFeatureLayer = arcpy.GetParameterAsText(0)

#Check the contents of the feature layer
with arcpy.da.SearchCursor(inFeatureLayer, ["OID@", "SHAPE@"]) as cursor:
    for row in cursor:
        oid = row[0]
        shape = row[1]

        # oid
        arcpy.AddMessage("*****************************************************************************************************")
        arcpy.AddMessage("-- oid = OID@ --")
        arcpy.AddMessage("OID@ = {0}".format(oid))
        arcpy.AddMessage("OID@.__class__ = {0}".format(oid.__class__))
        arcpy.AddMessage("OID@.__class__.__name__ = {0}".format(oid.__class__.__name__))

        # shape
        arcpy.AddMessage("-- shape = SHAPE@ --")
        arcpy.AddMessage("shape = {0}".format(shape))
        arcpy.AddMessage("shape.__class__ = {0}".format(shape.__class__))
        arcpy.AddMessage("shape.__class__.__name__ = {0}".format(shape.__class__.__name__))
        arcpy.AddMessage("shape.partCount = {0}".format(shape.partCount))
        arcpy.AddMessage("shape.pointCount = {0}".format(shape.pointCount))

        # shape.getPart()
        arcpy.AddMessage("-- shape.getPart() --")
        arcpy.AddMessage("shape.getPart() = {0}".format(shape.getPart()))
        arcpy.AddMessage("shape.getPart().__class__ = {0}".format(shape.getPart().__class__))
        arcpy.AddMessage("shape.getPart().__class__.__name__ = {0}".format(shape.getPart().__class__.__name__))
        arcpy.AddMessage("shape.getPart().count = {0}".format(shape.getPart().count))

        # shape.getPart().getObject(0)
        arcpy.AddMessage("-- shape.getPart().getObject(0) --")
        arcpy.AddMessage("shape.getPart().getObject(0) = {0}".format(shape.getPart().getObject(0)))
        arcpy.AddMessage("shape.getPart().getObject(0).__class__ = {0}".format(shape.getPart().getObject(0).__class__))
        arcpy.AddMessage("shape.getPart().getObject(0).__class__.__name__ = {0}".format(shape.getPart().getObject(0).__class__.__name__))
        arcpy.AddMessage("shape.getPart().getObject(0).count = {0}".format(shape.getPart().getObject(0).count))

        # shape.getPart().getObject(0).getObject(i)
        for i in range(shape.getPart().getObject(0).count):
            point = shape.getPart().getObject(0).getObject(i)
            
            arcpy.AddMessage("-- point = shape.getPart().getObject(0).getObject({0}) --".format(i))
            arcpy.AddMessage("point = {0}".format(point))
            arcpy.AddMessage("point.__class__ = {0}".format(point.__class__))
            arcpy.AddMessage("point.__class__.__name__ = {0}".format(point.__class__.__name__))
            
        arcpy.AddMessage("*****************************************************************************************************")
del cursor

Execution result

When executed as input with a feature layer containing two polygons.

2020-01-12-22-27-37.png

GetArgumentCount() = 1
GetParameter(0) =Test polygon
GetParameter(0).__class__ = <class 'arcpy._mp.Layer'>
GetParameter(0).__class__.__name__ = Layer
GetParameterAsText(0) =Test polygon
*****************************************************************************************************
-- oid = OID@ --
OID@ = 1
OID@.__class__ = <class 'int'>
OID@.__class__.__name__ = int
-- shape = SHAPE@ --
shape = <geoprocessing describe geometry object object at 0x0000017A10D30EE0>
shape.__class__ = <class 'arcpy.arcobjects.geometries.Polygon'>
shape.__class__.__name__ = Polygon
shape.partCount = 1
shape.pointCount = 5
-- shape.getPart() --
shape.getPart() = <geoprocessing array object object at 0x0000017A1020A450>
shape.getPart().__class__ = <class 'arcpy.arcobjects.arcobjects.Array'>
shape.getPart().__class__.__name__ = Array
shape.getPart().count = 1
-- shape.getPart().getObject(0) --
shape.getPart().getObject(0) = <geoprocessing array object object at 0x0000017A1020A970>
shape.getPart().getObject(0).__class__ = <class 'arcpy.arcobjects.arcobjects.Array'>
shape.getPart().getObject(0).__class__.__name__ = Array
shape.getPart().getObject(0).count = 5
-- point = shape.getPart().getObject(0).getObject(0) --
point = 132.084696427 31.297648687 0 NaN
point.__class__ = <class 'arcpy.arcobjects.arcobjects.Point'>
point.__class__.__name__ = Point
-- point = shape.getPart().getObject(0).getObject(1) --
point = 135.36789933 32.2200581310001 0 NaN
point.__class__ = <class 'arcpy.arcobjects.arcobjects.Point'>
point.__class__.__name__ = Point
-- point = shape.getPart().getObject(0).getObject(2) --
point = 136.569792838 29.41042809 0 NaN
point.__class__ = <class 'arcpy.arcobjects.arcobjects.Point'>
point.__class__.__name__ = Point
-- point = shape.getPart().getObject(0).getObject(3) --
point = 133.286589935 28.4353141970001 0 NaN
point.__class__ = <class 'arcpy.arcobjects.arcobjects.Point'>
point.__class__.__name__ = Point
-- point = shape.getPart().getObject(0).getObject(4) --
point = 132.084696427 31.297648687 0 NaN
point.__class__ = <class 'arcpy.arcobjects.arcobjects.Point'>
point.__class__.__name__ = Point
*****************************************************************************************************
*****************************************************************************************************
-- oid = OID@ --
OID@ = 2
OID@.__class__ = <class 'int'>
OID@.__class__.__name__ = int
-- shape = SHAPE@ --
shape = <geoprocessing describe geometry object object at 0x0000017A10D308C8>
shape.__class__ = <class 'arcpy.arcobjects.geometries.Polygon'>
shape.__class__.__name__ = Polygon
shape.partCount = 1
shape.pointCount = 5
-- shape.getPart() --
shape.getPart() = <geoprocessing array object object at 0x0000017A1020AA50>
shape.getPart().__class__ = <class 'arcpy.arcobjects.arcobjects.Array'>
shape.getPart().__class__.__name__ = Array
shape.getPart().count = 1
-- shape.getPart().getObject(0) --
shape.getPart().getObject(0) = <geoprocessing array object object at 0x0000017A10F19CB0>
shape.getPart().getObject(0).__class__ = <class 'arcpy.arcobjects.arcobjects.Array'>
shape.getPart().getObject(0).__class__.__name__ = Array
shape.getPart().getObject(0).count = 5
-- point = shape.getPart().getObject(0).getObject(0) --
point = 146.643152231 39.990418811 0 NaN
point.__class__ = <class 'arcpy.arcobjects.arcobjects.Point'>
point.__class__.__name__ = Point
-- point = shape.getPart().getObject(0).getObject(1) --
point = 145.658068329 37.1688505340001 0 NaN
point.__class__ = <class 'arcpy.arcobjects.arcobjects.Point'>
point.__class__.__name__ = Point
-- point = shape.getPart().getObject(0).getObject(2) --
point = 142.19148511 38.2163059420001 0 NaN
point.__class__ = <class 'arcpy.arcobjects.arcobjects.Point'>
point.__class__.__name__ = Point
-- point = shape.getPart().getObject(0).getObject(3) --
point = 143.176569012 40.99087202 0 NaN
point.__class__ = <class 'arcpy.arcobjects.arcobjects.Point'>
point.__class__.__name__ = Point
-- point = shape.getPart().getObject(0).getObject(4) --
point = 146.643152231 39.990418811 0 NaN
point.__class__ = <class 'arcpy.arcobjects.arcobjects.Point'>
point.__class__.__name__ = Point
*****************************************************************************************************

reference

reference

Recommended Posts

How to get the vertex coordinates of a feature in ArcPy
How to get the number of digits in Python
How to get a list of files in the same directory with python
How to get the last (last) value in a list in Python
How to get a list of built-in exceptions in python
How to get a quadratic array of squares in a spiral!
How to get a stacktrace in python
How to determine the existence of a selenium element in Python
How to get all the possible values in a regular expression
How to check the memory size of a dictionary in Python
Create a function to get the contents of the database in Go
Get the caller of a function in Python
How to get the files in the [Python] folder
[Linux] Command to get a list of commands executed in the past
How to pass the execution result of a shell command in a list in Python
How to get the variable name itself in python
How to mention a user group in slack notification, how to check the id of the user group
[NNabla] How to get the output (variable) of the middle layer of a pre-built network
How to count the number of elements in Django and output to a template
A memorandum of how to execute the! Sudo magic command in Jupyter Notebook
[Introduction to Python] How to get the index of data with a for statement
How to get the "name" of a field whose value is limited by the choice attribute in Django's model
How to save the feature point information of an image in a file and use it for matching
How to display the modification date of a file in C language up to nanoseconds
How to check in Python if one of the elements of a list is in another list
How to increase the processing speed of vertex position acquisition
[Ubuntu] How to delete the entire contents of a directory
How to use the __call__ method in a Python class
Get the number of specific elements in a python list
How to develop in a virtual environment of Python [Memo]
How to generate a query using the IN operator in Django
How to get all the keys and values in the dictionary
How to find the scaling factor of a biorthogonal wavelet
How to get an overview of your data in Pandas
[Shell] How to get the remote default branch in Git
How to get a list of links from a page from wikipedia
How to connect the contents of a list into a string
How to get the Python version
[Linux] [C / C ++] How to get the return address value of a function and the function name of the caller
How to display the regional mesh of the official statistics window (eStat) in a web browser
Get the value of a specific key up to the specified index in the dictionary list in Python
[OCI] Python script to get the IP address of a compute instance in Cloud Shell
How to quickly count the frequency of appearance of characters from a character string in Python?
I tried to create a Python script to get the value of a cell in Microsoft Excel
How to plot the distribution of bacterial composition from Qiime2 analysis data in a box plot
How to pass the execution result of a shell command in a list in Python (non-blocking version)
How to display a specified column of files in Linux (awk)
How to handle multiple versions of CUDA in the same environment
[sh] How to store the command execution result in a variable
How to implement Java code in the background of RedHat (LinuxONE)
Try to get a list of breaking news threads in Python.
How to change the color of just the button pressed in Tkinter
How to get the ID of Type2Tag NXP NTAG213 with nfcpy
[Python] How to get the first and last days of the month
How to get a string from a command line argument in python
Here's a brief summary of how to get started with Django
[Introduction to Python] How to use the in operator in a for statement?
[TensorFlow 2] How to check the contents of Tensor in graph mode
How to find the memory address of a Pandas dataframe value
How to create a large amount of test data in MySQL? ??
[NNabla] How to remove the middle tier of a pre-built network