Create a polygon shapefile

2165
2
03-07-2013 01:25 AM
NigelDsouza
Occasional Contributor
Hi,
I have four points say a {51.646932,5.053536}, b{51.645907,5.051111} , c{51.644695,5.051283} and d{51.644735,5.055017}
I am new to python and want to know how to create a polygon with the help of these four points using arcpy?  I want to insert these hard coded values in the code.
Can anyone help.
When i run the script i would like that it should  save the newly created polygon shapefile to a location i specify.

Regards,
nigel.
Tags (2)
0 Kudos
2 Replies
MathewCoyle
Frequent Contributor
See the code sample at the bottom of this help page.

http://resources.arcgis.com/en/help/main/10.1/index.html#//018z00000061000000
0 Kudos
PatrickFischer1
New Contributor III
It's actually a pretty simple setup, you can use the link that mzcoyle posted and it can help you. It should end up looking something like this.

Import arcpy

SpatialReference = #Your Spatial Reference of choice, ie. WGS 1984
Output = #the place you want to put it, as well as the name. If you are doing multiple coordinates and individual shapefiles but all in the same folder, you can setup a workspace.


Lowerleft = a
Lowerright = b
Upperright = c
Upperleft = d

array = arcpy.Array()
array.add(Lowerleft)
array.add(Lowerright)
array.add(Upperright)
array.add(Upperleft)
array.add(Lowerleft)
polygon = arcpy.Polygon(array, SpatialReference)
#this next step is if you want to have  it be in different shapefiles or all in one. Also if you are running this as a tool in ArcGIS that a user can use, instead of putting in set variables, use Arcpy.GetParameterAsText() The number inside the paranthesis (starting at 0) will be the order that you set them up in the tool when you create it in ArcGIS.
if arcpy.Exists(output):
  arcpy.Append_management(polygon, output)
else:
  arcpy.CopyFeatures_management(polygon, output)

That should help you get a start on it. Let me know if you have any questions.
0 Kudos