3

I have a CSV table as following :

ID;POLYGON
1;(-7.59443,33.55933):(-7.59416,33.55937):(-7.59414,33.55922)
2;(-7.58361,33.56655):(-7.58148,33.56655):(-7.58148,33.56486):(-7.58361,33.56486)

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
5

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',
    spatial_reference=arcpy.SpatialReference(4326))

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])

Result:

enter image description here

3

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

0

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:

https://www.dropbox.com/s/znzxnx2qyg5q1rq/csv22none.zip?dl=0

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.