Select to view content in your preferred language

points to polygons

6935
32
10-12-2012 12:29 PM
SiranErysian
Deactivated User
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
Honored Contributor
OK, I looked briefly at your attachments and will look further into it when I have more time...probably later today.

I would suggest 1st that if you know how to better combine your data, I would write everything to a temp workspace - that way, your orig data is preserved and you hopefully will have intermediate output that's simply easier to work with (or at least appears less complicated).

Sounds like you may benefit from either joining, sorting, or otherwise housing the data in a single table?  That way, when you go building the geom, you then don't have to go to multiple lookup tables, etc., for attributes if it isn't necessary.  I haven't looked into it yet at that detail, but sometimes it's more expedient to work with what scripts you've already experimented with and go ahead if at all possible to 'clean up' or adapt the data accordingly... I'll get back to this shortly.  Meanwhile, if you have a breakthrough, certainly post it!
0 Kudos
T__WayneWhitley
Honored Contributor
Okay, I've had a chance to get back to this - I haven't done much, just taken a look and attached a couple of files.  Looks more like a 2-part problem, that maybe you'd like to 'see' data in a single table?  Otherwise the problem statement is as you stated from the beginning to create a polygon based on ordering of FIDs, odd on one side, even on the other.  Is there any change to that?

Pertaining to the data table, it seems to me you could do a spatial join, to 'combine' or join the line attribute data to the points.  Make sure this data is accurate, see the attached.  I used the one-to-many option of Spatial Join making the points the target so that you'd be able to 'look' at the data in a single table.  Still it is redundant though - you could condense the table further to see a single record for each line (reversing the join, more or less).  Anyway, I don't see how this really affects your orig problem creating polygons - have I missed something?

If all is as I understand it, I'll run the solution and attach it tomorrow.
0 Kudos
T__WayneWhitley
Honored Contributor
I meant to get back to you with this.  Basically, it's a demo of IDLE commands that can be refined as you wish into a finished script.  All I did was this:

- Took a subset of your point shapefile as defined in a query on the search cursor.
- Loaded the point geometry objects into a python list.
- According to the order you wanted based on your input, used the 'device' already described above for 'odd' and 'even' sides.
- Resorted the point objects to form the perimeter of a polygon.
- Created a new row via insertcursor in an existing polygon shapefile into which the point objects are to define new poly geom.
- Loaded the result into an object array (thought I could load the py object list directly into the insert row, but that didn't work).
- Loaded the object array into the Shape field for the new row.  (See the pdf view of the result attached.)

Here's the rough code (again, this was done by trial and error within IDLE), see below.  If you want to create 1 huge poly out of the point shapefile, you can - simply remove the query.  Otherwise, if you want to create individual polygons out of progressive sets of points from the input shapefile, you can set up a looping cursor either based on a common ID code in the point table or redefining your query.  Hope that helps.
>>> import arcpy
>>> arcpy.env.workspace = r'C:\Documents and Settings\whitley-wayne\Desktop\pointsToPolySerysian\Reach1_Banks'
>>> polyArray = arcpy.Array()
>>> where_clause = '"FID" > 1131 AND "FID" < 1148'
>>> inputPts = "Reach1_Banks.shp"

>>> pointsLeft = []
>>> pointsRight = []
>>> points = []

>>> rows = arcpy.SearchCursor(inputPts, where_clause)
>>> for row in rows:
 pnt = row.Shape.getPart()
 points.append(pnt)

>>> for i in range(0,len(points)-1,2):
 pointsLeft.append(points)
 pointsRight.append(points[i+1])

>>> len(pointsRight)
8

>>> pointsRight2 = []

>>> for i in range(len(pointsRight)-1,-1,-1):
 pointsRight2.append(pointsRight)

>>> len(pointsRight2)
8

>>> for eachPoint in pointsRight2:
 pointsLeft.append(eachPoint)
 
>>> len(pointsLeft)
16

>>> cur = arcpy.InsertCursor("testPolys.shp")
>>> feat = cur.newRow()

>>> for eachPoint in pointsLeft:
 polyArray.add(eachPoint)

 
>>> feat.Shape = polyArray
>>> cur.insertRow(feat)
>>> del cur
>>> 
0 Kudos
SiranErysian
Deactivated User
Yes I get the code. Will need to study it further. Not sure what IDLE is. I would like to use an excel spreadsheet I have with all the values I need: left bank, channel, right bank, as you mentioned above. Will that work? Need to create polygons where values change at each of these locations. I only had points for a short section. None were created for the other sections. I am assuming that no spatial join is needed if I have all the data in an attribute table? Just join the excel table to the line file? Thinking out loud...will get back to you once I study the code a bit more and see if I can make it work on some of the data.
0 Kudos
T__WayneWhitley
Honored Contributor
IDLE is simply the interactive editor/debugger app I use to test commands as I am typing each one, sort of like the command window you can now open within ArcMap to execute Python.  Basically, if you take out the command prompts  " >>> "  and a few extraneous print commands, etc., get the indentation right, then you have a working script.

Not sure I yet understand what form all your data is in...are you saying you have XY coordinate values in Excel?  Is there a reason why you have data in multiple forms, or is this because you just haven't assimilated it yet, or is all part of your data conversion process?

Yes, if you have coord vals in Excel, a search cursor can access that directly and assign each coord pair to a point object (in the code provided, the search cursor accessed the point shapefile and captured each point object directly - no need for the XY values).

Note:  Not sure what you mean by creating polys "where values change" but if you happen to have ID values in Excel as in the input file used in the sample of the Writing Geometries help file, you can use this as your means to loop on a specific set or range of values, breaking the polygons where you wish.
Also, about the spatial join, I was using that because I thought you were missing a reliable common field on which to make an attribute join.  I didn't need this to create the points although it appears this extra data may be needed to define where to 'break'.
0 Kudos
SiranErysian
Deactivated User
Thanks for your last message and the code. I hope I haven't been sending you around in circles. Here is where I am: I have values in Excel that correspond with the left, channel and right banks of the river. I joined this table to the line file based on a common field. (I am not going to use the point file since the values exist only for a short section of the river and I need the whole). So are you saying that  the code will assign coordinates based on those values to a line file with no need for xy values? See attachment of values along the cross sections. Top label is left, middle is channel and bottom is right bank. As I mentioned earlier, where the values change is where the break point would be. Can I substitute the shp file in the code with another and can I substitute lines for points?
Is there anything else on the code that would have to be revised?
0 Kudos
T__WayneWhitley
Honored Contributor
What I'm saying is, if you have it, you can directly use point geometry (as I last demonstrated) or you can use XY coordinate values if you have that in a table, Excel, txt, or whatever.  Or if you can derive those points somehow from the lines - I didn't see how, maybe I'm just being dense, but you know your data better than I.

Only real difference in using coord vals is you'd need to fetch the coord pairs from the table to assign to point objects before loading them in the array (the last sample simply fetches the point objects themselves from the point shapefile).

I'm slightly confused about 1 thing: what exactly you want polygons to represent.
The channel cross-sections bank-to-bank is what the lines represent, correct?  But the points shown before were, as I understood it visually, where the 'normal' or main channel is?  So you do not want a polygon bank-to-bank but the actual channel?  Correct me if I'm wrong in these assumptions, and tell me how these 'channel points' are determined and did I somehow miss that from the table?

At this point (if the above assumptions are correct), I'm thinking if the 'inner' channel points are related to the measure of the line cross-sections, then the point locations you want to form the channel polygon out of can be derived.  Just curious, why do you only have points for part of the channel?

Anyway, I can look at this again probably tomorrow and figure it out -- fill me in when you can and we'll solve this quicker.
0 Kudos
SiranErysian
Deactivated User
In response to your message: Paragraph 1: I don't have point geometry for all the channel. It was derived from a model only for that section for some reason. So I have to use the values in the cross section lines. Forget about the points. Paragraph 3: The lines represent the cross section of not just the channel but the left and right bank values for flow.(N) The polygons will represent the values from line to line connecting the same values as polygons--for the channel, left bank and right bank. So there will be 3 sets of polygons. You are correct that the points represented the channel but I don't have that data for the rest of the river. Paragraph 4: How do we derive the inner channel or any of the polygons if we don't have xy locations? In the previous correspondence, I was assuming that we could assign coordinated based on some value in the cross section line file? If it is not possible to form polygons for all three areas, left, right and channel, maybe we can just do the channel.
0 Kudos
T__WayneWhitley
Honored Contributor
OK, I've had a chance to look at this again... unfortunately it's toward the end of the day and I need to test a hunch since I'm not accustomed to this type of data.  I'm just touching base with you before proceeding further.  I don't think we need to compute anything , at least not for polygon geometry, with the fields pertaining to N values (is this not pertaining to flow?) -- I'm talking about these fields, according to what you attached:

channel_N2
leftbandN
rightbank_


However, I may have discovered a pattern with these fields (I have to test to see if my hunch is true though.):

LeftBank
RightBank
Shape_Leng

Looking at a single 'strand' cross-section line, say FID 171, with the values LeftBank 0.3254, RightBank 0.41533, Shape_Leng 1641.142808, it seems you can locate the points along the line with:

0.3254(1641.142808) = 534.028 (approx.)
0.41533(1641.142808) = 681.616 (approx.)

Then 681.616 - 534.028 = 147.588

...and if I carefully measure along that line FID 171 between the points in the shapefile you provided, using ArcMap's measuring tool, I get 147.58792.

So I'd say we have a winner algorithm for computing the points - I'll test further by 'chopping' your lines with the points for the segment lengths, make the computation as in the above, and make sure the results closely match the GIS computed length geom segments...pretty sure this isn't coincidental.

From there, I believe there are python methods for getting the 3 polygon sets you ask.  Well, it's looking up, what do you think?
0 Kudos
SiranErysian
Deactivated User
Thanks for touching base. This sounds great! Yes the N values pertain to flow. I would have never thought to look at the shape length. That would be great if the points could be computed with those values. Get back to me once you have tested your hunch.
0 Kudos