# Swapping Lat and Lon coordinates of shapefile?

I have a shapefile that consists of one polygon whose boundary is defined by a large number of points. Whoever originally made the file inverted the latitude and longitude coordinates, so the data displays at 38 degrees east of Greenwich and 122 degrees south of the equator, which is well south of the south pole, or off in space, or somewhere on the imaginary number line, or something. How can I fix this? I could make another shapefile and manually enter the correct coordinates, but this particular polygon is defined by several hundered vertices so I would rather not do it that way. Is there a python script or GP tool that can help me?

You can do it easily with Python. You can do the following in ArcMap's Python Window:

``````with arcpy.da.UpdateCursor("your_layer_name", ['SHAPE@XY']) as rows:
for r in rows:
rows.updateRow((r[0][::-1],))
``````

You'll need to refresh the active view afterwards. You can do that with the refresh button or `arcpy.RefreshActiveView()`. Then you should see the points shift.

EDIT:

Just reread your question again. If you want to skip the point adjustment, and reverse the coordinates for all the vertices of the polygons themselves, the code becomes slightly more complicated but retains the same general principal:

``````with arcpy.da.UpdateCursor("your_layer_name", ['SHAPE@']) as rows:
for r in rows:
# reverse points within polygon (supports multipart polygons as well)
rows.updateRow((arcpy.Polygon(arcpy.Array(arcpy.Array([arcpy.Point(p.Y, p.X) for p in part]) for part in r[0])),))
``````
• The other answers work just fine, but I guarantee this is the fastest/cleanest way as you don't have to create any intermediate data/tables. Do not fear the coding :) Dec 31, 2015 at 18:46
• Yeah but for those beginners Editors that don't know how to use coding...They need to find around .. Dec 31, 2015 at 19:02
• The OP asked for a Python script or GP Tool... Dec 31, 2015 at 19:02
• This IS neat. Thanks. Evidently I should learn some more coding. Dec 31, 2015 at 19:46
• Indeed, once you get past the initial frustrations of learning the basics, you'll find it rewarding and it definitely boosts productivity/efficiency. Good luck! :) Dec 31, 2015 at 19:52

Does the attribute information hold x and y points? If not you could try Feature to Point to create them and then switch the X and Y.

• The attribute table doesn't have x and y points, and unfortunately I don't have the needed licenses for Feature to Point. Dec 31, 2015 at 19:46
• Try downloading Xtools. This is an extension for ArcGIS with some extra tools you can use with a basic license. xtoolspro.com/tools.asp Jan 4, 2016 at 14:39

Export your shapefile as a table, right click the table and choose "Display XY Data". When you enter in the latitude/longitude fields, switch the order of your fields, and now will you have a correct X/Y event layer, which you can export into a gdb as a feature class

You can create new add two fields columns to the shapefile and then calcuate them from the old field column such as X coordinate and Y coordinate to the new field. Then you can delete the old ones from the shapefile.

• Polygon shapefiles have multiple vertices. This approach is only valid for point shapefiles. Dec 31, 2015 at 19:17