Python Tool class supported geometries

396
5
10-18-2011 03:17 AM
MarkCorbin
New Contributor III
Hello,

The Tool coumentation mentiones that only three types of shape are supported:


  1. Line

  2. Rectangle

  3. Circle


What about Point or Polygon gemetries? Is there any implicit or explicit way to get them?

Thanks,
Szymon Piskula
Tags (2)
0 Kudos
5 Replies
JasonPardy
New Contributor
Hi Szymon,

There is no specific shape for point or polygon.

To construct the point, you must use onMouseDown or onMouseDownMap. Using the x and y coordindates you can construct the point geometry.

pt_geom = arcpy.PointGeometry(arcpy.Point(x, y))


For polygon, we hope to include this for final. For now, you would need to use line and close it off. Here is an example:

class LineToPolyTool(object):
    """Implementation for LineToPoly_addin.linetopoly (Tool)"""
    def __init__(self):
        self.enabled = True
        self.cursor = 3
        self.shape = "Line"

    def onLine(self, line_geometry):
        array = arcpy.Array()
        part = line_geometry.getPart(0)
        for pt in part:
            print pt.X, pt.Y
            array.add(pt)
        array.add(line_geometry.firstPoint)
        polygon = arcpy.Polygon(array)

I hope this is helpful.

Jason Pardy
Esri
0 Kudos
DanPatterson_Retired
MVP Emeritus
Jason
could you throw your code within the code blocks in the HTML editor (ie # symbol after selecting your code)
0 Kudos
BobBaker1
New Contributor
Does anyone know where we can get documention for the line_geometry object that onLine produces?

I am trying to simply create a line with onLine and turn it into a polyline.




Hi Szymon,

There is no specific shape for point or polygon.

To construct the point, you must use onMouseDown or onMouseDownMap. Using the x and y coordindates you can construct the point geometry.

pt_geom = arcpy.PointGeometry(arcpy.Point(x, y))


For polygon, we hope to include this for final. For now, you would need to use line and close it off. Here is an example:

class LineToPolyTool(object):
    """Implementation for LineToPoly_addin.linetopoly (Tool)"""
    def __init__(self):
        self.enabled = True
        self.cursor = 3
        self.shape = "Line"

    def onLine(self, line_geometry):
        array = arcpy.Array()
        part = line_geometry.getPart(0)
        for pt in part:
            print pt.X, pt.Y
            array.add(pt)
        array.add(line_geometry.firstPoint)
        polygon = arcpy.Polygon(array)

I hope this is helpful.

Jason Pardy
Esri
0 Kudos
JasonScheirer
Occasional Contributor III
It's just a Polyline object.
0 Kudos
BobBaker1
New Contributor
It's just a Polyline object.



I just realized that after I found the documentation. Thanks!
0 Kudos