-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWKT_Export.py
70 lines (58 loc) · 2.12 KB
/
WKT_Export.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
import arcpy
import requests
import pandas as pd
import os
import time
# setup
arcpy.env.workspace = "C:\GIS\Scratch.gdb"
arcpy.env.overwriteOutput = True
# network path to connection files
filePath = "C:\\GIS\\DB_CONNECT"
sdeBase = os.path.join(filePath, "Vector.sde")
parcelBase = os.path.join(sdeBase, 'SDE.Parcels\SDE.Parcels_Base')
newShapeCSV= os.path.join()
#output projected in-memory feature class
parcelLayerProjected = "ParcelLayerProjected"
# Set output coordinate system to be WGS 1984
outCS = arcpy.SpatialReference(4326)
# run project tool
arcpy.Project_management(parcelBase, parcelLayerProjected, outCS)
# get list of shapes by APN
dfShape = pd.read_csv(newShapeCSV)
# get tuple of new shapes
newShapes = tuple(dfShape.APN)
# where clause to limit parcels
where = f"APN IN {newShapes}"
# # make feature layer from parcel base
parcelLayer = arcpy.management.MakeFeatureLayer("ParcelLayerProjected", "Parcel_Layer", where_clause=where)
# parcelLayer = arcpy.management.MakeFeatureLayer("ParcelLayerProjected", "Parcel_Layer")
# time a function function
## use as decorator @timer
def timer(func):
def wrapper(*args, **kwargs):
start_time = time.time()
result = func(*args, **kwargs)
end_time = time.time()
print(f"Function {func.__name__} took {end_time - start_time} seconds to execute.")
return result
return wrapper
# create dictionary and post
@timer
def post_parcel_geom_update(featureLayer, url):
# Use a SearchCursor to iterate through the features
with arcpy.da.SearchCursor(featureLayer, ['SHAPE@WKT', 'APN']) as cursor:
total_count = 0
for row in cursor:
total_count +=1
if (total_count%1000)==0:
print(f"Updating row {total_count}")
# setup dictionary
feature_dict = {
'APN': row[1],
'WKT': row[0]
}
print(feature_dict)
requests.post(url, feature_dict)
# post geometries
post_url = 'https://laketahoeinfo.org/api/UpdateParcelGeometry/1A77D078-B83E-44E0-8CA5-8D7429E1A6B4'
post_parcel_geom_update(parcelLayer, post_url)