Converting Degrees to Meters from table, no Datum information

830
2
Jump to solution
10-27-2021 04:23 AM
Vakhtang_Zubiashvili
Occasional Contributor III

Hi everybody,

I am trying to make python tool in ArcGIS desktop, where user can select row in e.g. excel table, that has written X and Y in next format X: 44.919644, Y: 41.691083. But i am using Meters (Projected Coordinate System: WGS_1984_UTM_Zone_38N, Geographic Coordinate System: GCS_WGS_1984
Datum: D_WGS_1984
) in my database and when i insert this points it goes somewhere at the edge of the world. I tried to add spatial_reference like this:

arcpy.da.SearchCursor("Watersupply_GWP.DBO.%GIS_ACCIDENTS",["PointCoordinateX","PointCoordinateY"], None, spatial_reference = 32638)as cursor:

but i get same result. One problem is that, i do not know Datum, these coordinates taken by Android tablet, so i have only coordinates and could not use projectAs() method. 

Any help, idea appreciated.

0 Kudos
1 Solution

Accepted Solutions
Tomasz_Tarchalski
New Contributor III

your table has no geometry, and you cannot apply convertion directly to fields within table. if you are using desktop and arcpy 2.7 you could do sth like that:

#create empty point object
point = arcpy.Point()

#define projection in /out
sr_in = arcpy.SpatialReference(4326)
sr_out = arcpy.SpatialReference(32638)

table_in ="my_table"
fields = ["PointCoordinateX","PointCoordinateY"]
with arcpy.da.SearchCursor(table_in, fields) as recs:
    for rec in recs:
        # set temporary point object
        point.X = rec[0]
        point.Y = rec[1]
        # create point geometry from point object
        pointGeometry_in = arcpy.PointGeometry(point, sr_in)
        # reproject, no transformation
        point_Geometry_out = pointGeometry_in.projectAs(sr_out)
        # print output
        print(point_Geometry_out.centroid.X, point_Geometry_out.centroid.Y)

View solution in original post

2 Replies
Tomasz_Tarchalski
New Contributor III

your table has no geometry, and you cannot apply convertion directly to fields within table. if you are using desktop and arcpy 2.7 you could do sth like that:

#create empty point object
point = arcpy.Point()

#define projection in /out
sr_in = arcpy.SpatialReference(4326)
sr_out = arcpy.SpatialReference(32638)

table_in ="my_table"
fields = ["PointCoordinateX","PointCoordinateY"]
with arcpy.da.SearchCursor(table_in, fields) as recs:
    for rec in recs:
        # set temporary point object
        point.X = rec[0]
        point.Y = rec[1]
        # create point geometry from point object
        pointGeometry_in = arcpy.PointGeometry(point, sr_in)
        # reproject, no transformation
        point_Geometry_out = pointGeometry_in.projectAs(sr_out)
        # print output
        print(point_Geometry_out.centroid.X, point_Geometry_out.centroid.Y)
Vakhtang_Zubiashvili
Occasional Contributor III

Thank you Tomasz, you save me ❤️ I simply integrated your code in my code and now it works fine. Thanks

0 Kudos