Hey all,
I am working through Zanderberg's Python Scripting for Arcgis. I am on chapter 8 exercise 1 which asks me to create a box Shapefile from the coordinates (0,0), (0,1,000),(1000,0),(1,000,1,000). I am able to get the code work, but the final output looks like two triangles and not a box. I decided to remove one of the coordinates an indeed got a proper triangle so I am wondering if it has to do with how I typed out my coordinates in Notepad?
See the screenshot of my code, input coordinates (.txt file) and output. Any help is appreciated.
Also: I am new to this forum and coding in general and not sure how to code samples to show up in that snazzy window that lets me copy them so apologies for having all of this crammed into a screenshot.
Solved! Go to Solution.
Hey Jon Cicarelli,
The issue is indeed with with order in which the coordinates are specified. When we create a polygons from points like this, arcpy is basically drawing a line between each of the points we specify, in the same order that we specify them.
So with the current order we're placing the first point in the bottom left point at 0,0, then the next point in top left at 0,1000 - which is all ok so far. Where things go askew is that the next point we place is at the bottom right at 1000,0 (instead of the top right) then finally we place a point in the top right at 1000,1000. Then lastly arcpy will always automatically place a final point at the same location of whatever we specified as the first point to ensure our polygon forms an enclosed.
In the text file, if we swap the position of point 3 and point 4 - the order that points are specified will then form a square instead of two triangles.
Hey Jon Cicarelli,
The issue is indeed with with order in which the coordinates are specified. When we create a polygons from points like this, arcpy is basically drawing a line between each of the points we specify, in the same order that we specify them.
So with the current order we're placing the first point in the bottom left point at 0,0, then the next point in top left at 0,1000 - which is all ok so far. Where things go askew is that the next point we place is at the bottom right at 1000,0 (instead of the top right) then finally we place a point in the top right at 1000,1000. Then lastly arcpy will always automatically place a final point at the same location of whatever we specified as the first point to ensure our polygon forms an enclosed.
In the text file, if we swap the position of point 3 and point 4 - the order that points are specified will then form a square instead of two triangles.
Thank you, James!