top of page

Create Polygon​

The Python scipt creates a new polygon feature class containing a single ( square ) polygon with the following coordinates: ( 0, 0 ), ( 0, 1,000 ),(1,000, 0), and ( 1,000, 1,000 ).

# Ehsan Momeni

import arcpy
import fileinput
import string
from arcpy import env, da, Array

env.workspace = r"C:\Users\emomeni\"  # workspace
env.overwriteOutput = True

infile = r"C:\Users\emomeni\Coordinates.txt"  # coordinate files
outpath = r"C:\Users\emomeni\\"  # output path

newfc = "Polygon.shp"  # new shapefile name
arcpy.CreateFeatureclass_management(outpath, newfc, "POLYGON")  # creating new shapefile

cursor = da.InsertCursor(newfc, ["SHAPE@"])  # inserting coordinates
array = Array()

for line in fileinput.input(infile):
    ID, X, Y = string.split(line," ")
    array.add(arcpy.Point(X, Y))


cursor.insertRow([arcpy.Polygon(array)])
fileinput.close()


del cursor

 

google_scholar1-300x150.png
ResearchGate.png
Ehsan Momeni ORCID GIS Remote Sensing Ur
Ehsan Momeni LinkedIn GIS Remote Sensing
ncbi-300x150.png
academia.png

(Information on this website may not be up to date)

bottom of page