-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnormalize.py
More file actions
52 lines (46 loc) · 1.2 KB
/
normalize.py
File metadata and controls
52 lines (46 loc) · 1.2 KB
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
#!/usr/bin/python
# normalize.py
import io, ast, sys
types = {
"Point": 'geometry',
"MultiPoint": 'geometry',
"LineString": 'geometry',
"MultiLineString": 'geometry',
"Polygon": 'geometry',
"MultiPolygon": 'geometry',
"GeometryCollection": 'geometry',
"Feature": 'feature',
"FeatureCollection": 'featurecollection'
}
def normalize(gj):
print (gj)
if (not gj or not gj["type"]):
return None
type = types[gj["type"]]
if not type:
return None
if type == 'geometry':
return {
"type": 'FeatureCollection',
"features": [{
"type": 'Feature',
"properties": {},
"geometry": gj
}]
}
elif type == 'feature':
return {
"type": 'FeatureCollection',
"features": [gj]
}
elif type == 'featurecollection':
return gj
# test
if __name__ == "__main__":
gj = {"type": "Point","coordinates": [125.6, 10.1]}
print (normalize(gj))
# print (str(sys.argv[1]))
# data = ""
# for line in open(str(sys.argv[1])):
# print (line)
# print (normalize( open(ast.literal_eval(str(sys.argv[1]))) ))