Is there any well working way to extract the X and Y coordinates of a polygon from shapefile to some sort of text (preferably csv)? The whole process should be somehow done automated through a (python-) script, since there are a lot of polygons. For now it doesn't matter if there is a solution in ArcGIS 10 or somethin hidden within the gdal-libraries or any other OS-GIS.

OpenJump GIS is able to show the coordinates of any object within a shapefile (which could be copied by hand). But as far as I know its not possible to use this function automated.

  • 1
    Placing multiple coordinates inside a CSV is going to cause confusion. Generating well-known text (WKT) in a tab- or pipe-delimited ASCII file would be a better target.
    – Vince
    Jan 7, 2015 at 11:42
  • Well sure, actually cvs should be ";"-delimited too (or any other sign) and hold a linebreak after each pair of coordinates for each line of the polygon. Also there is only one polygon per shape which would lead in a 1st step to one file per polygon. Wether csv or ASCII doesn't matter for now. Main thing is, to get the geometry inside such textfile. Any ideas?
    – knutella
    Jan 7, 2015 at 11:48
  • 1
  • Oh, just saw your 2nd comment! That defenitly seems worth a look! Thanks for the find!
    – knutella
    Jan 7, 2015 at 19:56

2 Answers 2


I got what I need and I want to sum up two possible solutions:

First one was the link posted by @Vince in the comments:

It uses Python in connection with ArcPy.

Another solution, using Python only is script called shapefile.py. It can be found at https://code.google.com/p/pyshp/ A very simple script to iterate over the points of a polygon and print them to screen would look like this:

import shapefile    
sf = shapefile.Reader("my_shapefile")
shapes = sf.shapes()

#shape[0] represents the 1st polygon of the shapefile
for point in shapes[0].points:
print point

Seems to be easy, you just need to create the XY coordinate field in your polygone table and later in the script use the arcpy.da.SearchCursor(Poligone.shp,"FieldXY")in something similar to this. Hope this works for you ^^

with arcpy.da.SearchCursor("Poligone.shp",'Field') as Buscador:
    with open(nombarch2,"a+")as c:
        for row in Buscador:
            for cell in row:
                conv= str(cell)
                c.write(" ")
  • Okay, seems logically, but how to fill the xy-field with values in arcgis? All I know is, that ArcGIS can only calculate the X-Y-values for the centroid of a polygon. What I need is the outline.
    – knutella
    Jan 7, 2015 at 10:53
  • if you have the info in your shp you only need to read it and write back in a text so the first part of my response its not necesary you only need to insert a cursor and write the data. But if you need to calculate the XYcentroids of the outline i'm "out" ^^
    – Gsanez
    Jan 7, 2015 at 11:10
  • Okay, I guess, my question wasn't clear. I edited it already. The coordinate information is not stored as an attribute in the shapefile. The geometry which I need is just the polygon outline as seen on any screen, which displays the shapefile. Sorry for the confusing question and thx for the quick answer.
    – knutella
    Jan 7, 2015 at 11:37
  • The geometry is an attribute of the shapefile, since that's how it's modelled. The coordinates are a property of the geometry.
    – Vince
    Jan 7, 2015 at 11:50
  • Yes. And is it possible f.e. in ArcGIS to see the coordinates of the polygones outline as numbers? Somewhere in the attribute-table of the shapefile? For now I only know how to add columns and calculate the XY of the centroid there.
    – knutella
    Jan 7, 2015 at 19:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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