I have a CSV table as following :


The coordinate system used is WGS84. Polygons have no holes and they are all single parts.

I need to convert it to a Polygon feature class/shapefile. I have access to QGIS or ArcGIS, but welcome answers in other software as well.

Any ideas on how to proceed?

  • Do you have any python ability? This wouldn't be too difficult in either QGIS or ArcGIS in python. – Michael Stimson Sep 2 '18 at 23:02
  • Unfortunately I have no idea about the source of data :/ – geocoder Sep 2 '18 at 23:05
  • @Luke, they have no holes, they are singleparts. Thanks for Your interaction – geocoder Sep 2 '18 at 23:12
  • 1
    @AndreSilva, the software to use doesn't matter, i juste need to convert the CSV to polygon/shapfile – geocoder Sep 2 '18 at 23:13
  • Separated by semicolons – geocoder Sep 2 '18 at 23:31

That is a format I'm not familiar with, possibly a custom format. Below is an ArcGIS arcpy solution that reads in your CSV (assuming only 2 columns, ID and POLYGON!).

import csv
import arcpy

csvfile = 'C:/Temp/test.csv'
outpath, outshp = 'C:/Temp', 'test.shp'

outshp = arcpy.CreateFeatureclass_management (
    outpath, outshp, geometry_type='POLYGON',

arcpy.AddField_management(outshp, "ID", "LONG")

with open(csvfile) as csvfile, arcpy.da.InsertCursor(outshp, ['ID', 'SHAPE@']) as cursor:
    csvreader = csv.reader(csvfile, delimiter=';')

    #Skip header row
    next(csvreader, None)

    for id, coords in csvreader:
        coords = [eval(xy) for xy in coords.split(':')]
        # could also use the following if you don't trust `eval`
        # coords = [map(float, xy[1:-1].split(',')) for xy in coords.split(':')]
        print(id, coords)
        cursor.insertRow([id, coords])


enter image description here


You can convert your coordinates to Well-Known Text (WKT) if you open your CSV in Excel and use this formula:

="POLYGON(("&SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(B2,","," "),"(",""),")",""),":",",")&"))"

Where B2 is your existing coordinates.

Then copy/paste values back in so your new CSV has the formula's output, and using QGIS (there is probably a way using ArcGIS too), import it in using the "Create a Layer from a Delimited Text File" option:

enter image description here

enter image description here

enter image description here

Then you can right-click the layer in the Layers Panel, select "Save As", and save it as a shapefile (you can also change the coordinate system if you want).enter image description here


You can easily achieve this with FME Desktop if you have a license or you can use a fully functional trial license to test it out. Below is a screenshot of the workspace. You need to save the data in csv/text file as per the attached file. The workspace was using FME Desktop 2018.0

FME Workspace Converting the data to Polygon

The files can be downloaded from here:


import shapefile
import csv
import ast
with open(r"Sample_Data.csv", encoding="utf8") as csvfile:
    # dict create
    # create writable shapefile
    w = shapefile.Writer('Sample_Data.shp')
    # create attribute
    w.field('id', 'C')
    w.field('nieghborho', 'C')
    w.field('plan_no', 'C')
    # row from dict
    for row in dictReader:
        # write row attribute
        w.record(row['id'], row['nieghborhood'], row['plan_no'])
        # write geom
    # create prj file
    prj = open("Sample_Data.prj", "w")
    epsg = 'GEOGCS["WGS 84",'
    epsg += 'DATUM["WGS_1984",'
    epsg += 'SPHEROID["WGS 84",6378137,298.257223563]]'
    epsg += ',PRIMEM["Greenwich",0],'
    epsg += 'UNIT["degree",0.0174532925199433]]'
    # save prj file
    # close above shapefile

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.