-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCountyParcel_ParcelPoints.py
78 lines (63 loc) · 2.55 KB
/
CountyParcel_ParcelPoints.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#--------------------------------------------------------------------------------------------------------#
# import packages and modules
import arcpy
import pandas as pd
from time import strftime
import utils
# environment settings
arcpy.env.overwriteOutput = True
arcpy.env.outputCoordinateSystem = arcpy.SpatialReference(26910)
#Create database connection
inWorkspace = "F:\GIS\PARCELUPDATE\Workspace\Vector.sde"
arcpy.env.workspace = inWorkspace
# Specify the name of the new version and the parent version
new_version_name = "Parcel_Point_Update_" + strftime("%Y-%m-%d")
parent_version = "SDE.DEFAULT"
version_name_full = "SDE." + new_version_name
version_list = arcpy.da.ListVersions(inWorkspace)
version_exists = False
for version in version_list:
if version.name == version_name_full:
version_exists = True
break
if version_exists:
# Delete the version
arcpy.management.DeleteVersion(inWorkspace, version_name_full)
# Create a new version
arcpy.CreateVersion_management(inWorkspace, parent_version, new_version_name, "PUBLIC")
# Create Local Database Connection
# Enterprise geodatabase connection parameters
server_name = "sql12"
database_name = "sde"
username = "sde"
password = "staff"
arcpy.CreateDatabaseConnection_management(
out_folder_path='db_connections/',
out_name="ConnectionFile.sde",
database_platform="SQL_SERVER", # Replace with your DBMS type (e.g., ORACLE, SQL_SERVER, POSTGRESQL)
instance=server_name,
database=database_name,
account_authentication="DATABASE_AUTH", # Use "OPERATING_SYSTEM" for OS authentication
username=username,
password=password,
version_type='TRANSACTIONAL',
version=version_name_full
)
points_fc_path = r'SDE.Parcels\SDE.ParcelPoints'
new_points_fc = "F:/GIS/PARCELUPDATE/Workspace/ParcelStaging.gdb/Parcel_Points"
old_fc = 'Old_Feature_Class'
arcpy.MakeFeatureLayer_management(points_fc_path,old_fc)
database_connection = 'db_connections/ConnectionFile.sde'
arcpy.ChangeVersion_management(old_fc,'TRANSACTIONAL', version_name_full, '')
edit = arcpy.da.Editor(database_connection)
edit.startEditing(False, True)
#Delete all the rows in points_fc_path
arcpy.DeleteRows_management(old_fc)
# Selet the Parcel_points where Within_TRPA_BNDY = 1
temp_layer = arcpy.SelectLayerByAttribute_management(new_points_fc,"NEW_SELECTION", "Within_TRPA_BNDY = 1")
# Append the selected points to the ParcelPoints
arcpy.Append_management(temp_layer, old_fc, "NO_TEST")
#Save and stop the edit session
edit.stopOperation()
edit.stopEditing(True)
print("Parcel Points updated successfully")