I received shape files, and imported it. I can see the shapes, but I need to export the cordinate points of the shape to an excel or csv file in order to import into another program.
If you are looking for the XY coordinates of Centroid of polygons, you could add two Fields to Attribute Table, viz, X and Y and use Calculate Geometry to populate the fields with the X and Y coordinate of the Centroid. Then you can use Table to Excel geoprocessing tool to export to Excel.
But, if you want the XY coordinates of all the vertices of the polygon, you will need to convert feature vertices to points, add the XY fields to attribute table and populate using Calculate Geometry. Then Go for Table to Excel.
For all points for all license levels, there are other workarounds
The key is the explode_to_points which busts up the geometry into its constituent points. Rows 1 to 5 form the clockwise points of a square in this example. Once busted up, bring it back in as table and export to excel, or there are tools to simply send the array to excel directly...
Hi Dan,
Is it possible to export the coordinates of vertices of a polygon into excel or as a text file in the following format: Polygon1: y,x ; y,x ;y,x ; y,x
Therefore, all coordinates that make up a polygon should be in one row?
Liesl Not without coding the output to from numpy to a row format. If you have a use case, you might want to start another question describing the need to go to excel and why WKT or similar output format is needed
Hi Liesl De Swardt ,
I guess you could do something like this with a bit of Python code:
<SPAN class="keyword token">def</SPAN> <SPAN class="token function">main</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">import</SPAN> arcpy fc <SPAN class="operator token">=</SPAN> r<SPAN class="string token">'C:\GeoNet\WKT\data.gdb\polygons'</SPAN> <SPAN class="comment token"># the input polygons</SPAN> fld_id <SPAN class="operator token">=</SPAN> <SPAN class="string token">'OID@'</SPAN> <SPAN class="comment token"># use the OID as ID field in the output</SPAN> txt <SPAN class="operator token">=</SPAN> r<SPAN class="string token">'C:\GeoNet\WKT\output2.txt'</SPAN> <SPAN class="comment token"># teh output text file to load into Excel</SPAN> <SPAN class="keyword token">with</SPAN> open<SPAN class="punctuation token">(</SPAN>txt<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'w'</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">as</SPAN> f<SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">with</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>da<SPAN class="punctuation token">.</SPAN>SearchCursor<SPAN class="punctuation token">(</SPAN>fc<SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">(</SPAN>fld_id<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'SHAPE@'</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">as</SPAN> curs<SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">for</SPAN> row <SPAN class="keyword token">in</SPAN> curs<SPAN class="punctuation token">:</SPAN> polygon <SPAN class="operator token">=</SPAN> row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN> result <SPAN class="operator token">=</SPAN> GetYXcrdList<SPAN class="punctuation token">(</SPAN>polygon<SPAN class="punctuation token">.</SPAN>WKT<SPAN class="punctuation token">)</SPAN> f<SPAN class="punctuation token">.</SPAN>write<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"{}\t{}\n"</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> result<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">def</SPAN> <SPAN class="token function">GetYXcrdList</SPAN><SPAN class="punctuation token">(</SPAN>wkt<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN> wkt <SPAN class="operator token">=</SPAN> wkt<SPAN class="punctuation token">.</SPAN>replace<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'MULTIPOLYGON ((('</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">''</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN>replace<SPAN class="punctuation token">(</SPAN><SPAN class="string token">')))'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">''</SPAN><SPAN class="punctuation token">)</SPAN> lst <SPAN class="operator token">=</SPAN> wkt<SPAN class="punctuation token">.</SPAN>split<SPAN class="punctuation token">(</SPAN><SPAN class="string token">','</SPAN><SPAN class="punctuation token">)</SPAN> result <SPAN class="operator token">=</SPAN> <SPAN class="string token">""</SPAN> <SPAN class="keyword token">for</SPAN> crd <SPAN class="keyword token">in</SPAN> lst<SPAN class="punctuation token">:</SPAN> xy <SPAN class="operator token">=</SPAN> crd<SPAN class="punctuation token">.</SPAN>strip<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN>split<SPAN class="punctuation token">(</SPAN><SPAN class="string token">' '</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">if</SPAN> result <SPAN class="operator token">==</SPAN> <SPAN class="string token">''</SPAN><SPAN class="punctuation token">:</SPAN> result <SPAN class="operator token">=</SPAN> <SPAN class="string token">"{},{}"</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>xy<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> xy<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">else</SPAN><SPAN class="punctuation token">:</SPAN> result <SPAN class="operator token">+=</SPAN> <SPAN class="string token">";{},{}"</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>xy<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> xy<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">return</SPAN> result <SPAN class="keyword token">if</SPAN> __name__ <SPAN class="operator token">==</SPAN> <SPAN class="string token">'__main__'</SPAN><SPAN class="punctuation token">:</SPAN> main<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
Just change:
Below the result of a test run:
What do you want to do with this list of Lat, Lon coordinates in Excel?
i cant run this code
Xander Bakker
if you can make a video for this code, it will be great....
You still have a shapefile...
Line 9.... it is Shape@ , not Shape*
I prefer https://community.esri.com/message/672481-re-how-do-i-export-cordinates-of-polygon-shapes-to-excel?commentID=672481#comm…
""You still have a shapefile..."" what would file i need ??
i changed it to shape@ but still same, can you use this code and run it ? then you can find the point i fail, thanks you very much because help me ....
Hi Havan Cong ,
When you look at the original code I provided, you will see on line 4:
fc <SPAN class="operator token">=</SPAN> r<SPAN class="string token">'C:\GeoNet\WKT\data.gdb\polygons'</SPAN> # the input polygons<SPAN class="line-numbers-rows"><SPAN></SPAN></SPAN>
In my case, I have a featureclass named "polygons" which is stored inside a file geodatabase called "data.gdb" inside the folder "C:\GeoNet\WKT".
In your case you have:
fc <SPAN class="operator token">=</SPAN> r<SPAN class="string token">'C:\GeoNet\WKT\data.gdb\polygons.shp'</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN></SPAN>
You are using a shapefile called "polygons.shp" which is located inside a folder called "C:\GeoNet\WKT\data.gdb". Possibly using a folder name with a point in it is causing the problems or maybe there is something wrong with the polygon shapefile. Is it possible to attach a ZIP file with the shapefile to this thread to see what is causing the problem?
The error indicates that it cannot open the shapefile.
Thank you for your help Xander, it's worked. But the result of a test run i get not like my wish
example: the coordinates of polygon i use is a GCS_WGS_1984 and the result show me like this
but the file result i want to receive like below :
the type coordinates is Degree same like coordinates of Google earth file
Could you please help me change a little bit of the code and then export the coordinates like i hope
thank you very much Xander....
Los miembros registrados pueden publicar, seguir actualizaciones y más. ¿Nuevo aquí? Regístrate gratis.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.