question about coordinates

04-28-2017 05:38 AM
New Contributor III

Hi everyone!

I need your help again... So I have this code now, which takes all columns from database I need. The X and the Y coordinates fields isn`t at the database. How do I add two new columns only in exporting CSV file ? 

Thanks for any help!  

import arcpy 
import csv

fc = r"#"
out_csv = r"#.csv"

fields = ["#", "#"]

def tableToCSV(fc, out_csv):
    fld_list = arcpy.ListFields(fc)
    fld_names = [ for fld in fld_list]
    with open(out_csv, 'wb') as csv_file:
        writer = csv.writer(csv_file, delimiter=';', lineterminator='\n')
        with arcpy.da.SearchCursor(fc, fields) as cursor:
            for row in cursor:
        print out_csv  

tableToCSV(fc, out_csv)
Tags (2)
0 Kudos
3 Replies
MVP Frequent Contributor

Sorry, a bit confused here.

Are you asking how to get the XY coordinates out of the fc and into the text file? This is a point feature I take it.

MVP Legendary Contributor

just call the builtin rather than doing it the hard way

you can zip that into your script prior to csv'ing it ... check the code snippet at the bottom

0 Kudos
MVP Regular Contributor

To add  Point_X and Point_Y attribute fields to a feature to export to csv or excel table, I like to use:

spatial_reference = arcpy.SpatialReference("WGS 1984")

# AddGeometryAttributes_management (Input_Features, Geometry_Properties, {Length_Unit}, {Area_Unit}, {Coordinate_System})