load geojson files from ogr2ogr convert of shapefile
Former-commit-id: ad655164cf995c553ba491eb340c0ac75d92c9fe
This commit is contained in:
parent
14f0e15c76
commit
6b219b43e7
|
@ -1,63 +1,74 @@
|
||||||
from lxml import etree as ElementTree
|
import json
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import sys
|
import sys
|
||||||
from tqdm import tqdm
|
from tqdm import tqdm
|
||||||
import argparse
|
import argparse
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description='viz1090 SVG Map Converter')
|
parser = argparse.ArgumentParser(description='viz1090 SVG Map Converter')
|
||||||
parser.add_argument("--resolution", default=250, type=int, nargs=1, help="downsample resolution")
|
parser.add_argument("--resolution", default=250, type=int, help="downsample resolution")
|
||||||
parser.add_argument("file", nargs=1, help="filename")
|
parser.add_argument("file", nargs="+", help="filename")
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
if(len(args.file) == 0):
|
if(len(args.file) == 0):
|
||||||
print("No input filename given")
|
print("No input filename given")
|
||||||
exit()
|
exit()
|
||||||
|
|
||||||
parser = ElementTree.XMLParser(recover=True)
|
|
||||||
tree = ElementTree.parse(args.file[0], parser)
|
|
||||||
polys = tree.xpath('//polygon')
|
|
||||||
|
|
||||||
bin_file = open("mapdata.bin", "wb")
|
bin_file = open("mapdata.bin", "wb")
|
||||||
|
|
||||||
outlist = []
|
outlist = []
|
||||||
|
|
||||||
|
resolution = args.resolution
|
||||||
|
|
||||||
resolution = args.resolution[0]
|
for file in args.file:
|
||||||
|
with open(file, "r") as read_file:
|
||||||
|
data = json.load(read_file)
|
||||||
|
|
||||||
print("Reading points")
|
|
||||||
for i in tqdm(range(len(polys))):
|
|
||||||
#for i in range(40):
|
|
||||||
p = polys[i]
|
|
||||||
currentPoints = (p.attrib['points']).replace(","," ").split()
|
|
||||||
|
|
||||||
if(len(currentPoints) == 14): #remove little circles in the McCurley maps
|
|
||||||
continue
|
|
||||||
|
|
||||||
|
print("Reading points")
|
||||||
|
for i in tqdm(range(len(data['features']))):
|
||||||
|
|
||||||
|
|
||||||
|
if(data['features'][i]['geometry']['type'] == 'LineString'):
|
||||||
prevx = 0
|
prevx = 0
|
||||||
prevy = 0
|
prevy = 0
|
||||||
|
|
||||||
temp = []
|
temp = []
|
||||||
|
|
||||||
for i in range(int(len(currentPoints)/2)):
|
for currentPoint in data['features'][i]['geometry']['coordinates']:
|
||||||
#currentPoints[2 * i + 0] = "%.*f" % (precision, float(currentPoints[2 * i + 0]))
|
|
||||||
#currentPoints[2 * i + 1] = "%.*f" % (precision, float(currentPoints[2 * i + 1]))
|
|
||||||
|
|
||||||
currentPoints[2 * i + 0] = float(int(resolution * float(currentPoints[2 * i + 0]))) / resolution
|
currentx = float(int(resolution * float(currentPoint[0]))) / resolution
|
||||||
currentPoints[2 * i + 1] = float(int(resolution * float(currentPoints[2 * i + 1]))) / resolution
|
currenty = float(int(resolution * float(currentPoint[1]))) / resolution
|
||||||
|
|
||||||
if(currentPoints[2 * i + 0] != prevx or currentPoints[2 * i + 1] != prevy):
|
if(currentx != prevx or currenty != prevy):
|
||||||
temp.extend([currentPoints[2 * i + 0],currentPoints[2 * i + 1]])
|
temp.extend([currentx,currenty])
|
||||||
|
|
||||||
|
prevx = currentx
|
||||||
|
prevy = currenty
|
||||||
|
temp.extend(["0","0"])
|
||||||
|
else:
|
||||||
|
prevx = 0
|
||||||
|
prevy = 0
|
||||||
|
|
||||||
|
temp = []
|
||||||
|
|
||||||
|
for currentLine in data['features'][i]['geometry']['coordinates']:
|
||||||
|
for currentPoint in currentLine:
|
||||||
|
|
||||||
|
currentx = float(int(resolution * float(currentPoint[0]))) / resolution
|
||||||
|
currenty = float(int(resolution * float(currentPoint[1]))) / resolution
|
||||||
|
|
||||||
|
if(currentx != prevx or currenty != prevy):
|
||||||
|
temp.extend([currentx,currenty])
|
||||||
|
|
||||||
|
prevx = currentx
|
||||||
|
prevy = currenty
|
||||||
|
|
||||||
|
temp.extend(["0","0"])
|
||||||
|
|
||||||
prevx = currentPoints[2 * i + 0]
|
|
||||||
prevy = currentPoints[2 * i + 1]
|
|
||||||
|
|
||||||
if(len(currentPoints) > 6): #must be at least a triangle
|
|
||||||
outlist.extend(temp)
|
outlist.extend(temp)
|
||||||
#outlist.extend([temp[0],temp[1]])
|
|
||||||
outlist.extend(["0","0"])
|
|
||||||
|
|
||||||
|
|
||||||
np.asarray(outlist).astype(np.single).tofile(bin_file)
|
np.asarray(outlist).astype(np.single).tofile(bin_file)
|
||||||
bin_file.close()
|
bin_file.close()
|
||||||
|
|
Loading…
Reference in a new issue