-
Notifications
You must be signed in to change notification settings - Fork 0
/
AddNewXYFields.py
46 lines (32 loc) · 1.21 KB
/
AddNewXYFields.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
"""--------------------------------------------------------------------------------
AddNewXYFields.py
Description:
Add new fields, New_X and New_Y fields and calculate the X and Y coords
Input:
1) A geodatabase or folder holding polygon layers
Output:
1) Feature class with new fields
Version 0.1
Created by: Juel Paul/Land Analytical
Date: March 18, 2020
--------------------------------------------------------------------------------"""
# Import modules
import arcpy
from arcpy import env
inGDB = arcpy.GetParameterAsText(0)
# Set workspace and environment variables
arcpy.env.workspace = inGDB
arcpy.env.overwriteOutput = True
arcpy.AddMessage("Searching the geodatabase now...")
fcList = arcpy.ListFeatureClasses("*", "point")
fcCount = len(fcList)
arcpy.AddMessage("{0} application points layers in this geodatabase.".format(fcCount))
# Use list to add fields and calculate XY
for fc in fcList:
arcpy.management.AddFields(
fc,
[['Updated_X', 'DOUBLE', 'Updated X'],
['Updated_Y', 'DOUBLE', 'Updated Y']])
arcpy.CalculateGeometryAttributes_management(fc,
[["Updated_X", "POINT_X"], ["Updated_Y", "POINT_Y"]])
arcpy.AddMessage("Fields added and geometry calulated for {0}".format(fc))