Select to view content in your preferred language

creating shapes from coordinates eneterd manually through GP dialog box

2394
3
05-22-2013 01:00 AM
GISAnalyst
Deactivated User
Dear All

I am trying to build Geoprocessing tool either by Model builder or by Python that do the following

"Create Polygon from Coordinate values that entered manually within the dialog box of the GP tool"
does any body ever do that?

This is easier and straight forward when text file already generated with the desired format required for polygons "it can be done using the command Write text file to feature" but actually what i am looking for is manually entering the coordinate values that makes the polygon shape inside an entry dialog within the GP tool and then execute the command needed for building the polygon geometry


I had attached the python script used (from one of the samples) in addition to the dialogue box i want to use to enter the coordinates (actually the type of input is recordset) and using GetParameterAsText (0) does not return anything for me ! in addition to that what i am asking for is how to retrieve these entered values through the code and create array list out of them and iterate through this array (iterating has many samples provided by ESRI) , but my major issue is how through python code retrieve the input values and create List out for them (similar to coordList?!
Your assistance is highly appreciated

Thanks
0 Kudos
3 Replies
by Anonymous User
Not applicable
Original User: mdenil

A quick and dirty snippit: No error checking, very basic entry, no insert cursor.
Just getting the coordinates into the script and making a point.
The tool parameters panel is also shown as an image...

import arcpy

zero = arcpy.GetParameterAsText(0)
one = arcpy.GetParameterAsText(1)
two = arcpy.GetParameterAsText(2)

arcpy.AddMessage(zero)
arcpy.AddMessage(one)
arcpy.AddMessage(two)

inPointList = [zero, one, two]
outPointList = []

for inPoint in inPointList:
    if len(inPoint) > 0:
        coordList = inPoint.split(',')
        if len(coordList) == 2:
            pointList = [float(coordList[0]),
                         float(coordList[1])]
            outPointList.append(pointList)

for coordPair in outPointList:
    point = arcpy.Point(coordPair[0], coordPair[1])
##  insert this point into a shapefile or feature class
0 Kudos
GISAnalyst
Deactivated User
Thanks again mark , using this way how can i  create polygons?!
what need to be modified in the script?

The purpose of using the tool i am asking for is constructing polygons , so at least four points will be required , and as we don't know how many points the polygons could consist of (in case of irregular shape and not rectangle)  , adding fixed entries as (point 1 , point 2 , ...etc) will not be sufficient , that's why i thought about using a  dialog box a recordset data type.

Your continuous assistance is highly appreciated.

Thanks
0 Kudos
by Anonymous User
Not applicable
Original User: mdenil

Well, here in Euclidian Space we need only three non-liner points for a polygon, not 4; but be that as it may...

You build a polygon array out of points.

You simply have to parse out a longer input string (  "x, y, x, y, x, y, ..." ) after accepting it as an input parameter.
Then you build the points from pairs of coordinates.

Value tables are not likely to be what you seem to need.
have a look at the help file for ValueTable. The ValueTable example 2 shows how to create valuetable
and load it from an entered parameter string.
Note that you have to declare the length of the value table when you create it.
Since you don't know how many of the valueTable fields you will be using (x and y for how many points)
You will either have to test the input string to find out how many fields you want
0 Kudos