Select to view content in your preferred language

Get vertices of a graphic polygon

922
5
Jump to solution
05-16-2012 07:24 AM
JimCousins
MVP Alum
I wish to sketch a polygon (graphic drawing) on the screen, and then get the vertices of that polygon into a table for use as input in a different software tool. Is this possible?
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
MathewCoyle
Honored Contributor
I do not believe arcpy has access to graphics in ArcGIS 10. ArcObjects could do this for you.

View solution in original post

0 Kudos
5 Replies
MathewCoyle
Honored Contributor
I do not believe arcpy has access to graphics in ArcGIS 10. ArcObjects could do this for you.
0 Kudos
KimOllivier
Honored Contributor
You can interactively create a sketch in a tool using a featureset type.
This is then passed into the script as a feature which you can manipulate just like any other feature.
Here is an example where I get a polygon drawn in ArcMap, get an autoincrement number and write it out to a featureclass.
This is available from 9.3+

mpa = gp.GetParameter(0)
# get the id and name from first record if set
cur = gp.SearchCursor(mpa)
row = cur.next()
MPAName = row.MPAName
mpaid = row.mpaid
del row,cur

if MPAName == None and mpaid == None :
    MPAName = "MPA" 
    mpaid = 0
elif mpaid > 0 and MPAName == None:
    MPAName = "MPA"+str(mpaid)
elif mpaid == None and MPAName != None :
    # keep override name
    mpaid = int(MPAName[3:])
else :
    gp.AddWarning(MPAName)
    gp.AddWarning(mpaid)
    
# rename all parts with a unique name for a dissolve
# increments to highest number or blank or zero
if not gp.Exists("MPA") :
    gp.CopyFeatures("template_mpa","MPA")
if not gp.Exists("MPA0") :
    gp.CopyFeatures("template_mpa","MPA0")    
fcName = gp.CreateUniqueName(MPAName,ws)
fcName = os.path.basename(fcName)
MPAName = fcName # update
mpaid = int(MPAName[3:])
## gp.AddWarning(str(mpaid)+" "+MPAName)
cur = gp.UpdateCursor(mpa)
row = cur.next()
while row:
    row.MPAName = fcName
    row.mpaid = mpaid
    cur.updateRow(row)
    row = cur.next()
del row,cur
0 Kudos
T__WayneWhitley
Honored Contributor
Kim, I haven't finished my research on this yet, surprised I haven't looked at this before....can you elaborate further on how this is done?  How to accept input interactively and commit a few vertices to a polygon (or line), say, while executing a tool.  I need something where a user interacts with selected polys on screen where I will attempt to capture via their sketch where they'd like to clip one or more of the selected polygons.

Is this my understanding of what is possible?

Thanks in advance...

Enjoy,
Wayne
0 Kudos
KimOllivier
Honored Contributor
The standard tool interface has a feature type called 'featureset' (in the dropdown list that has featureclass, layer, string...)

This enables you to sketch a graphic on the screen that is passed into the script as a parameter. The input parameter needs a layer template set to use as a symbol reference and to define the shape type : point, line or polygon and any attributes required.

When you start the tool (by opening the dialog) you can draw some features and even fill in some attributes.

In my script example I create a featureset called 'mpa' in my script and then save it to a featureclass after updating the ID. i then use it to clip some layers and run statistics.

online help reference

While you could at 10.1 use Add-Ins to track the mouse, it is overkill if you just want to enter a simple polygon, line or a set of points interactively.
0 Kudos
T__WayneWhitley
Honored Contributor
Kim, thank you very much, I can't wait to experiment further with this tomorrow, think it's just the ticket.
Pretty interesting, I like the 'lightweight' quality of it as well, with no particularly special added considerations for distribution...other than where to write 'scratch' results which I am hoping I can set as 'relative-pathed' or check via script the scratch env var (if there is such a thing), processing as quickly as possible on the local user machine (not the server).

I too have experienced problems with in_memory workspace and am intrigued by your related posts concerning in_memory workarounds without noticably sacrificing performance.

Thanks again and cheers,
Wayne
0 Kudos