Import CSV data and convert to polygon shapefile

32127
6
09-29-2015 08:48 AM
OmarMcDoom
New Contributor

Dear all,

I have GIS data in csv file format that describes polygons (administrative districts).  There are four values: 1. Longitude 2. Latitude 3. Unique identifier 4. Text name of the administrative districts.

A polygon then is described in the following manner: Note the first vertex point is repeated at the end to indicate the extent of the polygon before a new polygon is described. 

     

DescriptionIDLongitudeLatitude
Adams (Pob.)12801001120.864618.4333
Adams (Pob.)12801001120.866518.4391
Adams (Pob.)12801001120.867718.4424
Adams (Pob.)12801001120.868518.449301
Adams (Pob.)12801001120.869118.4515
Adams (Pob.)12801001120.870818.4554
Adams (Pob.)12801001120.87218.459
Adams (Pob.)12801001120.873518.462999
Adams (Pob.)12801001120.864618.4333

Can someone tell me, if it is possible, how to import these data into ArcGIS and create a polygon shape file?  My ultimate objective is to calculate the area of district. 


Much appreciated!

0 Kudos
6 Replies
ChrisDonohue__GISP
MVP Alum

Hmmm, shapefiles, CSV - I bet Dan Patterson has a solution.  One caveat - it may involve Python

Chris Donohue, GISP

0 Kudos
ZackaryKing
New Contributor II

@Omar Mcdoom I think the answer to your question can be found here: Format for CSV to import as polygons (rectangles)?

ChrisDonohue__GISP
MVP Alum

This ESRI article suggests several methods:

43993 - Convert a point feature class to a polygon feature class

Note that some of the processes require higher level licenses and one solution requires a third-party software (ET Geowizards).

Chris Donohue, GISP

0 Kudos
DarrenWiens2
MVP Honored Contributor

Here's a starting point using Python. This only reads your csv and outputs a polygon for all the points. It gets a little more complicated to create separate polygons for each ID, to write out all the attributes, etc.

>>> import csv # import csv library
... polys = [] # list to hold polygon geometry
... with open(r'C:\junk\pointcsv.csv', 'rb') as csvFile: # open csv file
...    csvFile.readline() # skip header
...    csvReader = csv.reader(csvFile) # create csv reader
...    polyPoints = arcpy.Array() # array to hold points
...    for row in csvReader: # read csv
...        polyPoints.append(arcpy.Point(row[2],row[3])) # create point and add to array
...    polys.append(arcpy.Polygon(polyPoints,arcpy.SpatialReference(4326))) # create polygon and add to list
... arcpy.CopyFeatures_management(polys, r'in_memory\polys') # write out polygons

Unless you're committed to learning Python, your best bet is probably to add your csv as points, convert to line, then convert to polygon.

OmarMcDoom
New Contributor

Thank you for the suggestions.  I am not a Python and find it easier to use the built-in windows-driven tools.

When I use the "Points to Line" feature, what do I specify for "Line field" "Sort field" and "Close line" boxes?  If I enter nothing, I then receive the error message when I try to draw the line layer/shapefile stating  "a lock cannot be acquired".

What am I missing here?  Thank you!

0 Kudos
DarrenWiens2
MVP Honored Contributor

Line field is the field controlling the line IDs (tells the tool when to end the current line and move to the next line), Sort field sorts the records from first to last (if they aren't in the correct order already) and Close line forces the lines closed (if they aren't already).