Python Calculate Latitude Longitude based on offsets

3534
5
07-03-2012 09:58 AM
JamesCunningham1
Deactivated User
Does anyone have a script that will take a latitude and longitude value in decimal degrees and calculate a new latitude and longitude value, based on moving from the given lat/long east 350 ft and south 750 feet for example?
Tags (2)
0 Kudos
5 Replies
JakeSkinner
Esri Esteemed Contributor
Are you reading the lat/long values from a feature class?  If you are using a Search or Update cursor you can specify a spatial reference that uses feet, rather than decimal degrees, and the coordinates will be projected on the fly.
0 Kudos
JamesCunningham1
Deactivated User
The calculations need to be outside of ArcMap.  Maybe I am thinking of this incorrectly.  I now believe the calculations will need to be in something such as SQL.
0 Kudos
JakeSkinner
Esri Esteemed Contributor
Is your SQL database spatially enabled (SDE installed)?  Or was the table created within SQL Server, and the database is not spatially enabled?
0 Kudos
SteveXu
Regular Contributor
I don't have a python example, however, I did it in ArcObjects several years ago. The procedure below should be a reference:

I did it without using ArcGIS.

First just load the original data (Decimal degree) into a table in database
The trick is to create a point shape file (or sde FC) by selecting the projected coordinate system you want.
Then read each lat/long pair data to your shape file (create each points)
I think Python can use ArcGIS database management to do all above.
0 Kudos
JakeSkinner
Esri Esteemed Contributor
Here is an example on how to create an XY event layer from your SQL table and then reproject the coordinates from decimal degrees to feet:

import arcpy
from arcpy import env
env.workspace = r"Database Connections\PUBS.sde"

table = "pubs.dbo.XY"

arcpy.MakeXYEventLayer_management(table, "X", "Y", "XY_layer", r"C:\data\test.gdb\Airports_WGS84")


rows = arcpy.SearchCursor("XY_layer", "", r"C:\data\test.gdb\Airports_NAD83_feet")
for row in rows:
    print row.shape.centroid.X, row.shape.centroid.Y

del row, rows


The XY event layer is created with the same coordinate system as the Airports_WGS84 feature class.  In this case it is geographic.  Then, the XY coordinates are returned based off of a NAD83_feet coordinate system using the SearchCursor function and printed out.

If you are looking to update the SQL table with these values, SDE will need to be installed and the table will need to be registered with the geodatabse.  You can then use the 'UpdateCursor' to update new fields.
0 Kudos