Skip to main content
added 67 characters in body
Source Link
user2856
  • 69.6k
  • 6
  • 119
  • 203

BelowThat 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

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

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

added 156 characters in body
Source Link
user2856
  • 69.6k
  • 6
  • 119
  • 203

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

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(':')]
        print(id, coords)
        cursor.insertRow([id, coords])

Result:

enter image description here

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

added 2 characters in body
Source Link
Andre Silva
  • 10.3k
  • 12
  • 55
  • 109

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(':')]
        print(id, coords)
        cursor.insertRow([id, coords])

Result:

enter image description here

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(':')]
        print(id, coords)
        cursor.insertRow([id, coords])

Result:

enter image description here

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(':')]
        print(id, coords)
        cursor.insertRow([id, coords])

Result:

enter image description here

Source Link
user2856
  • 69.6k
  • 6
  • 119
  • 203
Loading