0

I have been given a CSV which has a mixture of point and polygon data. I am trying to open this up in ArcMap 10.5.1

I have no idea what I should be doing! I have tried to look for answers online but pretty much everything is a python script that is just dealing with points, and looks like it isn't much data, compared to my mix of types and large set.

Any suggestions on how I can view this data in my map??

enter image description here

  • 2
    You can create a geometry from WKT in python, the problem is that you can't store different geometries in the same feature class.. you need to create a python script to read this, splitting by comma and then use FromWKT resources.arcgis.com/en/help/main/10.2/index.html#//…, discard/switch if it's the wrong type otherwise insert into a feature class.. how is your python ability? – Michael Stimson Apr 27 '18 at 2:06
  • 1
    Comma split isn't going to work when POLYGON WKT is present. You'll need a more sophisticated parsing protocol just to partition geometry strings. – Vince Apr 27 '18 at 4:50
  • 2
    Could you edit the question and add a sample of the csv as text? Individual geometries can be split by re.split(r",\s*(?![^()]*\))", text) = only commas outside parenthesis split. – BERA Apr 27 '18 at 8:26
  • Is 'SpatialLocation' the only column in this file? Or are there others? – Son of a Beach May 16 at 22:25
1

You could try a Python script something like this one below. It expects your CSV to have only one columnn (ie, only the WKT field) and no header row. It also can only handle one geometry type (either points, lines or polygons, not a mixture). So you will need to either split your CSV into multiple files (one for each feature type) or modify the script further to detect which type of geometry it is reading for each line, and write the resulting feature to the appropriate feature class. For the sake of simplicity, I will assume the former (but the latter is not difficult to do).

If your CSV has more fields that just the WKT ('SpatialLocation') column then open it in Excel (or some other spreadsheet editor) and delete all other columns. Then delete the header column. Then save as a new file (text/CSV). Then resave in three separate CSV files, each of which has only POINTS, LINES or POLYGONS respectively.

Then run create and run the following Python script on on each of these files (changing the first two lines each time to point to the respective Point/Line/Polygon CSV to be read in and the Point/Line/Polygon feature class to be created):

inFile = "path/to/CSV/file"
outFC = "path/to/new/feature_class"
srs = arcpy.SpatialReference(<YOUR_EPSG_CODE_ETC>)

arcpy.CreateFeatureclass_management(os.path.dirname(outFC), os.path.basename(outFC), geom.type, spatial_reference=srs)

with open(inFile, 'r') as f:
    inWKT = f.readline()
    while inWKT:
        geom = arcpy.FromWKT(inWKT, srs)
        with arcpy.da.InsertCursor(outFC, ["SHAPE@"]) as cur:
            cur.insertRow([geom])
        inWKT = f.readline()

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.