-
Notifications
You must be signed in to change notification settings - Fork 1
/
run.py
141 lines (101 loc) · 3.97 KB
/
run.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
from shapefileClasses import ShapeGenerate
from functions.classes import GetData, ProcessData
from functions.types import esri_geometry,shape_types
import argparse
parser = argparse.ArgumentParser(description='Requires URL for service with query endpoint and output name')
parser.add_argument('-url','-u', required=True)
parser.add_argument('-output','-o', required=True)
parser.add_argument('-srid','-s')
parser.add_argument('-fields','-f', nargs="*")
args= parser.parse_args()
url = args.url
output = args.output
params1 = {'where':'1=1', 'f':'pjson', "returnGeometry":"false","outFields":'*','returnIdsOnly':'true' }
params2 = {'f':'pjson', 'where':''}
if args.fields != None:
if len(args.fields)>1:
params2["outFields"] = ",".join(args.fields)
elif len(args.fields)==0:
params2["outFields"] = args.fields[0]
else:
params2["outFields"] = "*"
else:
params2["outFields"] = "*"
if args.srid != None:
params2["outSR"] = args.srid
else:
params2["outSR"] = "4326"
shape = ShapeGenerate()
# Make call to URL to get all object IDs
gets = GetData(url, params1)
gets.get_request()
oids = gets.data['objectIds']
# Start processing of features
print("Number of Features: {0}".format(len(oids)))
noids = len(oids)
loids = list(range(0,len(oids),500))
if len(oids)> 1000:
start = 0
for count,block in enumerate(loids[1:]):
if count ==0:
params2['objectIds'] = ",".join(map(str,oids[start:block]))
gets = GetData(url, params2)
gets.get_request_urllib()
gets.create_fields()
shape.create(esri_geometry[gets.data["geometryType"]])
print("Geometry Type of Feature: {0}".format(shape_types[esri_geometry[gets.data["geometryType"]]]))
fields = gets.fields
process = ProcessData(gets.data, fields)
process.create_geometries()
process.create_attributes()
for field in process.fields:
shape.make_fields(field)
for row in process.attributes:
shape.process_atts(row)
for geom in process.geometries:
shape.process_geom(geom)
print("Features: {0} to {1}".format(start+1,block))
else:
print("Features: {0} to {1}".format(start+1,block))
params2['objectIds'] = ",".join(map(str,oids[start:block]))
gets = GetData(url, params2)
gets.get_request_urllib()
process = ProcessData(gets.data, fields)
process.create_geometries()
process.create_attributes()
for row in process.attributes:
shape.process_atts(row)
for geom in process.geometries:
shape.process_geom(geom)
start=block
if len(oids) % block >0:
print("Features: {0} to {1}".format(start+1,len(oids)))
params2['objectIds'] = ",".join(map(str,oids[start:len(oids)]))
gets = GetData(url, params2)
gets.get_request_urllib()
process = ProcessData(gets.data, fields)
process.create_geometries()
process.create_attributes()
for row in process.attributes:
shape.process_atts(row)
for geom in process.geometries:
shape.process_geom(geom)
else:
print("Features: {0} to {1}".format(1,len(oids)))
params2['objectIds'] = ",".join(map(str,oids))
gets = GetData(url, params2)
gets.get_request_urllib()
gets.create_fields()
shape.create(esri_geometry[gets.data["geometryType"]])
print("Geometry Type of Feature: {0}".format(shape_types[esri_geometry[gets.data["geometryType"]]]))
fields = gets.fields
process = ProcessData(gets.data, fields)
process.create_geometries()
process.create_attributes()
for field in process.fields:
shape.make_fields(field)
for row in process.attributes:
shape.process_atts(row)
for geom in process.geometries:
shape.process_geom(geom)
shape.save(output)