How is it possible to invert the lat/lon?

3244
5
Jump to solution
02-28-2017 02:46 AM
VincentLaunstorfer
Occasional Contributor III

Hi,

I have a polyline shapefile which opens incorrectly in ArcMap. When ArcMap expects latitude (northing), it reads the longitude in shapefile (eastings). And when it expects longitude (eastings), it reads the latitude in the shapefile (northings). It is weird! 

The shapefile wich should be in the Netherlands ends up offshore Somalia East Africa! As shown attached.

How is it possible to invert the lat/lon? In order to open the shapefile correctly...

Here attached is a polyline sample if it helps.

Thanks

0 Kudos
1 Solution

Accepted Solutions
JayantaPoddar
MVP Esteemed Contributor

Try the following steps:

1. Convert the vertices of lines to Points.

2. To the above point layer, add two fields, viz., Lat and Lon, and assign opposite coordinates to each using Calculate Geometry. Say X coordinate for Lat and Y coordinate for Lon.

3. Export the Table to Excel.

4. Add XY data from excel sheet as a layer. Export the event layer to a shapefile/feature class.

5. Convert Points to Line using Orig_FID as the LINE_FIELD.

Hope it will resolve the issue.



Think Location

View solution in original post

5 Replies
DanPatterson_Retired
MVP Emeritus

where did the shapefile come from, or how was it created?  If it never appears in the correct place, I would suspect the errors lies in how it was created, perhaps from gps data, which often has a bad habit of offering latitude/longitude as the order of coordinates.

0 Kudos
JayantaPoddar
MVP Esteemed Contributor

Try the following steps:

1. Convert the vertices of lines to Points.

2. To the above point layer, add two fields, viz., Lat and Lon, and assign opposite coordinates to each using Calculate Geometry. Say X coordinate for Lat and Y coordinate for Lon.

3. Export the Table to Excel.

4. Add XY data from excel sheet as a layer. Export the event layer to a shapefile/feature class.

5. Convert Points to Line using Orig_FID as the LINE_FIELD.

Hope it will resolve the issue.



Think Location
VinceAngelo
Esri Esteemed Contributor

That is an exceptionally convoluted path to do what ArcPy can do in under a page of code (with a da.UpdateCursor, swapping ordinate order).

I wouldn't recommend passing ANY GIS data through Excel, just on principle.

- V

JoshuaBixby
MVP Esteemed Contributor

To illustrate Vince's point/comment:

>>> fc = # path to feature class
>>> with arcpy.da.UpdateCursor(fc, "SHAPE@") as cur:
...     for polyline, in cur:
...         SR = polyline.spatialReference
...         polyline = arcpy.Polyline(
...             arcpy.Array(
...                 (arcpy.Point(pt.Y, pt.X) for pt in part)
...                 for part
...                 in polyline.getPart()
...             ), SR
...         )
...         cur.updateRow([polyline])
...         
>>> arcpy.RecalculateFeatureClassExtent_management(fc)
VincentLaunstorfer
Occasional Contributor III

Thanks

It did work! I was not sure about the point "ordering" when converting Points to Line. Also, I made an export to a tab .txt file to avoid Excel (via .dbf).