points to polygons

518
32
10-12-2012 12:29 PM
SiranErysian
New Contributor
I???m trying to delineate polygons along a river channel delineated by points representing different n values. I was wondering if anyone knew of a tool that would allow me to create polygons based on the same input value instead of what I am doing now which is connecting the dots. I tried Thiessen polygons but it gave me shapes that went way outside the boundaries of the points. Anyone know of such a function? See attachment for screen capture.
0 Kudos
32 Replies
T__WayneWhitley
Frequent Contributor
Depends... if you have sequence IDs as a means to determine the order of "connecting the dots" so to speak, then yes, that can be easily scripted - if there is no other ready means (other than visual inspection), that's another story.  I saw your pic - those IDs group the points and that's fine, but are there more available attributes?  Are these GPS points?
0 Kudos
SiranErysian
New Contributor
It appears that there are FID numbers but what I want to connect would be the odd numbers on one side of the bank and the even numbers on the other side. These are the numbers on the new attachment. Is this possible?

There are no other attributes to the file. THey were generated from a Hec GeoRas model.
0 Kudos
T__WayneWhitley
Frequent Contributor
So you really need to connect in an order as in, for example:
['point1', 'point3', 'point5', 'point6', 'point4', 'point2']

Basically, your solution lies in that with arcpy geom methods you can load points into an array to in turn load into a line or polygon geometry object.  The 'puzzle', if you will, is what sequence you feed the points in... it's late, so I don't have the finished code sample at the moment, but consider this (and make sure it is based on accurate assumptions):

You said you had points in a sequence, odd on one side, even on the other.  I've seen your picture - just not sure yet how the 'polygon' closes, but this is not as critical as it is to at least get an algorithm going for 'connecting the dots'...

So what you need is a device for loading odd points, then even points...
-- (This may not be optimal code, but it'll work.)---

# For example say instead of the string list shown, the following is a python list of point objects:
>>> points = ['point1', 'point2', 'point3', 'point4', 'point5', 'point6']

# Define 2 new lists to load for left and right sides:
>>> pointsLeft = []
>>> pointsRight = []

Now you need a looping mechanism to load the empty lists:
>>> for i in range(0,len(points)-1,2):
 pointsLeft.append(points)
 pointsRight.append(points[i+1])

# Now the lists are 'segregated' odd and even:
>>> print pointsLeft
['point1', 'point3', 'point5']

>>> print pointsRight
['point2', 'point4', 'point6']

# Reverse the order, say on the right, to set up 'connecting' the 2 lines:
>>> pointsRight.sort(reverse=True)

>>> print pointsRight
['point6', 'point4', 'point2']

# Now the list can be 'mashed' together:
>>> for eachPoint in pointsRight:
 pointsLeft.append(eachPoint)

# Still called 'pointsLeft', but it's really a sequence around both sides... 
>>> print pointsLeft
['point1', 'point3', 'point5', 'point6', 'point4', 'point2']
>>>
0 Kudos
SiranErysian
New Contributor
Wow, Thanks. I'll have to read this over several times to absorb it. Not a real expert on Python but its practical stuff and makes sense when I read it. Will get back to you.
0 Kudos
T__WayneWhitley
Frequent Contributor
Well, then, once you've digested that, getting your point objects into the list (I guess you'll be doing this with a searchcursor), the rest isn't too difficult.  This may not be the way you go exactly, but could be an example, if not too premature to load you up with more to read---

# these are point objects (no longer text)
points = [point1, point2, point3, point4, point5, point6]

array = arcpy.Array()

for point in points:
     array.add(point)
     
# close the poly
array.add(points[0])

# load the array into geometry object
polygon = arcpy.Polygon(array)


# Here, you'll probably want an insertcursor to loop and load geometry for multiple features...
# But for demo on a single feature, you can use copy features:
arcpy.CopyFeatures_management(polygon, r'C:\JustTesting.shp')
0 Kudos
SiranErysian
New Contributor
Thanks. I have been off on another project but will get back to this in the next day or so.

You mentioned closing the polygons: I'd like to do this where the n-values change (manning's coefficient value) which is in the attribute table as n-value. Would this be possible to insert somewhere in the code or I can just split the polygon created at those locations? See attachment. Upper number in label is the FID and lower number is the n-value.
0 Kudos
T__WayneWhitley
Frequent Contributor
Certainly.  Can you attach a sample of your data?  I ask because at this point it would probably be easiest to write the code specifically adapted to your input, whether that be a point feature class with these n-values in the attribute table or other format, such as a text input file containing these values in addition to XY point coords.  It would be easier to explain it with comments in the code which I can post here.  In short, I can give you the below explanation (along with that above for sorting the input).

If you already have a point feature class, you can use a sorted search cursor to access each table row and transfer point object geometry directly to an object array.  Or, if you have a text file (or just a table, no geometry yet), you can read each line in the file (or row in the table), create point geometry from the read XY coordinates, and load the resultant points into an object array.

So how are the sets defined during iteration?...i.e., when do you stop loading the object array to load the point object set into a feature polygon geometry?  By detecting change in the aforementioned n-values read with each row (or, if txt file input, with each line) - when the n-value changes, that's the end of the set.  The array load is then interrupted to load the array into the polygon feature's geometry which in turn is inserted into a destination polygon feature class (your output feature table).

The iteration continues on in similar fashion with each successive set... there won't be any n-value change detected on the last set, so the final set will of course load the array but will not be loaded into polygon feature geometry within the loop - this final polygon must be completed outside the loop.
0 Kudos
SiranErysian
New Contributor
I will get back to you either today or Tuesday witha sample data set.
0 Kudos
SiranErysian
New Contributor
I have attached 2 files, one showing points Reach1B_Banks) but only for part of the stretch of river I am trying to calculate, and the other a line file (Reach1B). Values were not included from the spreadsheet but are included in the cross section line file. I hope the script can handle values in this file. What I need to do is combine the N_values for the left bank, channel and right bank which are in the attribute table as Left_Bank_N, Channel_N and Right_bank_N. These values will determine the  changes in flow. The screen shot shows how I connected the dots but Reach 1B point does not have values so I want to use the red lines which have values.

Does this make sense? Will it work?
0 Kudos