-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathreformat_geojson.py
27 lines (24 loc) · 1.2 KB
/
reformat_geojson.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
import sys
def main():
if(len(sys.argv) != 2):
print("Pass in one geojson file in the command line")
with open("../" + sys.argv[1]) as f: #Add the file that needs to be reformated
formattedFile = "../formatted_" + sys.argv[1]
with open(formattedFile, "w") as f1:
for line in f:
newLine = line[0:line.find("[34")] + "[34."
restOfLine = line[line.find("[34") + 3: None]
newLine += restOfLine[0:restOfLine.find(", -119")] + ", -119."
restOfLine = restOfLine[restOfLine.find(", -119") + 6: None]
while len(restOfLine) > 0:
if restOfLine.find("[34") == -1:
newLine += restOfLine
restOfLine = ""
else:
newLine += restOfLine[0:restOfLine.find("[34")] + "[34."
restOfLine = restOfLine[restOfLine.find("[34") + 3: len(line)]
newLine += restOfLine[0:restOfLine.find(", -119")] + ", -119."
restOfLine = restOfLine[restOfLine.find(", -119") + 6: None]
f1.write(newLine)
if __name__ == "__main__":
main()