AnsweredAssumed Answered

How do you project a single pointGeometry object with arcpy?

Question asked by dzestis94 on May 1, 2017
Latest reply on May 2, 2017 by rvburton

Hi everyone,

 

So I got a task, and I don`t know how to do it. In csv file, i have to create two new columns which shows WGS-84 coordinates. Maybe someone, have solution for this ? I can`t undertstand what is in 29 line... I tried to google it.. And I found the example... but without explanation.

 

Thanks for any help

 

import arcpy 
import csv

fc = r"#"
out_csv = r"#"

fields = {
    "OBJECTID": "OBJECTID",
    "Global_ID": "Global_ID",
    "Global_Copy": "Global_Copy",
    "SHAPE@X": "POINT_X",
    "SHAPE@Y": "POINT_Y",
    "SHAPE@X": "LAT",
    "SHAPE@Y": "LONG"
}

table_fields = []
csv_fields = []
for field in fields:
    table_fields.append(field)
    csv_fields.append(fields[field])

def tableToCSV(fc, out_csv):
    with open(out_csv, 'wb') as csv_file:
        writer = csv.writer(csv_file, delimiter=';', lineterminator='\n')
        writer.writerow(csv_fields)
        with arcpy.da.SearchCursor(fc, table_fields) as cursor:
            for row in cursor:
                arcpy.PointGeometry(arcpy.Point(X,Y),arcpy.SpatialReference(3346)).projectAs(arcpy.SpatialReference(4326))
                point = Point(row[idxLAT],row[idxLONG])
                #TODO: reproject
                reppoint = point
                row[idxLAT] = reppoint.x
                row[idxLONG] = reppoint.y
               
                writer.writerow(row)
        print out_csv 
    #csv_file.close()

tableToCSV(fc, out_csv)

Outcomes