Create polygon from click

1610
11
05-31-2014 04:12 PM
BradleyHorner
New Contributor
Hello,

I am trying to figure out some code.  I have a TIN basemap and a raster file as a maximum height over the TIN.  The idea is I need to click a random point on the TIN, have it bring up a window where I can enter length, width, and angle.  This would then create a polygon.  I then need to find the volume of that polygon made up of the TIN basemap, raster topsurface, length and width.  The angle is to take the different heights of the TIN into account when calculating the volume.

Thanks!
Tags (2)
0 Kudos
11 Replies
KimOllivier
Occasional Contributor III
You can do this with the standard toolbox using the featureset input type. This will capture one or more mouse clicks to draw an interactive graphic of whatever type template you have used for the featureset. It will also have fields that you can fill in the properties to be included in the new feature. In your example you would have a point feature and some properties, maybe filled with defaults.
When you execute the tool you capture the input parameter as a geometry object to either convert to a featureclass or process further. In this case you would just get out the XY of the point and calculate the boundaries of a polygon to create a polygon geometry object for output.

But maybe you would just create the polygon directly with a polygon template.
http://resources.arcgis.com/en/help/main/10.1/index.html#//002w00000023000000

You could make a really slick interface that picked a coordinate using python AddIns, but that does not easily allow a form to input additional information like a featureset. Addins are much harder to debug.
0 Kudos
BradleyHorner
New Contributor
Thank you for the response.

However, this is for an offsite user, not myself.  It needs to be in tool form so that a beginning user can click the tool in Arcmap and away they go.  THat is where I am having the trouble.  I am still trying to figure out the code to have int input for length and width.  The calculation will compute l, w, TIN, and max height as the calculations.

Thanks in advance.
0 Kudos
KimOllivier
Occasional Contributor III
I was intending to explain the only obscure part of your question as best as I could guess from your description.

Getting an interactive point using a standard ArcTool is easy with a custom tool that you would need to write. I assume you were intending to write a script for the tool yourself? I can only guess that you want a volume from the seabed to a water surface.

Here is a sample tool, the script that reads the parameters, and images before and afterwards.
You will have to create your own template point featureclass to use as a template to indicate that you want points collected, not polylines or polygons.

#-------------------------------------------------------------------------------
# Name:        VolumeCalculator.py
# Purpose:     Calculate a volume under an arbitary rectangle
#
# Author:      kimo
#
# Created:     05/06/2014
# Copyright:   (c) kimo 2014
# Licence:     Creative Commons 3.0 NZ
#-------------------------------------------------------------------------------

import arcpy
import math

fds = arcpy.GetParameter(0)
width = arcpy.GetParameter(1)
length = arcpy.GetParameter(2)
angle = arcpy.GetParameter(3)
raster = arcpy.GetParameter(4)
tin = arcpy.GetParameter(5)

# the fds is an in_memory featureclass, get the first point
with arcpy.da.SearchCursor(fds,["SHAPE@X","SHAPE@Y"]) as cur:
    row = cur.next()
    x = row[0]
    y = row[1]

# feedback for demo
msg = "{} {} {} {} {} {} {}".format(x,y,width,length,angle,raster,tin)
arcpy.AddMessage(msg)
# calculate volume....
0 Kudos
BruceHarold
Esri Regular Contributor

Kimo where is the script for the tool?  It wasn't embedded.

Cheers

0 Kudos
KimOllivier
Occasional Contributor III

How do I insert a zip file? It seems that Geonet is just a facebook gossip app. I could only insert images. Instead here is a link to my own website. I don't think the questioner really wanted to use python, they were just confirming that someone else would have to be commissioned to do the work! http://www.ollivier.co.nz/download/voltoolbox.zip

BradleyHorner
New Contributor
Is there a way to do this in C#?  All my sources say this is too hard to do in Python and what I need is ArcObjects.  Basically the same idea where the user will click on the map, a box appears to enter length, width, and angle, and it will calculate the volume by pixel of the raster.
0 Kudos
curtvprice
MVP Esteemed Contributor

> Basically the same idea where the user will click on the map, a box appears to enter length, width, and angle, and it will calculate the volume by pixel of the raster.

You can do this in ModelBuilder with a feature set, and some creative work with the Calculate Value tool to set up an extent for the Raster Calculator tool. 

0 Kudos
KimOllivier
Occasional Contributor III
Too hard in Python? Compared to C# or .NET? You must not have tried to use ArcObjects! This is a much steeper learning curve, but I agree that .NET or C# has better tools for building an interactive form. If you are not familiar with either but your coder is familiar with C# then let him/her go for it.

I am only familiar with Python and Arcpy and this is a python forum.

You can now use AddIns with ArcPy and Python (instead of .Net) that allows you to build a tool that works on the cursor message queue that can pick a point and interactively build a rectangle for example. The sample in the help draws a grid by dragging a box on the screen. All in Python. The main deficiency in creating interactive tools with Python is the lack of an integrated dialog builder other than the inital dialog. It is possible to use Tkinter but it puts up a separate window outside the ArcMap instance. I wonder if this will be improved in 10.3 or ArcGIS Pro? Note that there will be no AddIns in ArcGIS Pro, so that option will be closed.
0 Kudos
BradleyHorner
New Contributor
Hi there,

The tool does not click a point on a TIN though.  I tried it on the point file, but there are gaps in the points.  The tool needs to be able to click in a gap and still pick up a point.
0 Kudos