load geojson files from ogr2ogr convert of shapefile

Former-commit-id: ad655164cf995c553ba491eb340c0ac75d92c9fe
This commit is contained in:
nathan 2020-06-17 22:04:16 -07:00
parent 14f0e15c76
commit 6b219b43e7

View file

@ -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
prevx = 0 print("Reading points")
prevy = 0 for i in tqdm(range(len(data['features']))):
temp = []
for i in range(int(len(currentPoints)/2)): if(data['features'][i]['geometry']['type'] == 'LineString'):
#currentPoints[2 * i + 0] = "%.*f" % (precision, float(currentPoints[2 * i + 0])) prevx = 0
#currentPoints[2 * i + 1] = "%.*f" % (precision, float(currentPoints[2 * i + 1])) prevy = 0
currentPoints[2 * i + 0] = float(int(resolution * float(currentPoints[2 * i + 0]))) / resolution temp = []
currentPoints[2 * i + 1] = float(int(resolution * float(currentPoints[2 * i + 1]))) / resolution
if(currentPoints[2 * i + 0] != prevx or currentPoints[2 * i + 1] != prevy): for currentPoint in data['features'][i]['geometry']['coordinates']:
temp.extend([currentPoints[2 * i + 0],currentPoints[2 * i + 1]])
prevx = currentPoints[2 * i + 0] currentx = float(int(resolution * float(currentPoint[0]))) / resolution
prevy = currentPoints[2 * i + 1] currenty = float(int(resolution * float(currentPoint[1]))) / resolution
if(len(currentPoints) > 6): #must be at least a triangle if(currentx != prevx or currenty != prevy):
outlist.extend(temp) temp.extend([currentx,currenty])
#outlist.extend([temp[0],temp[1]])
outlist.extend(["0","0"])
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"])
outlist.extend(temp)
np.asarray(outlist).astype(np.single).tofile(bin_file) np.asarray(outlist).astype(np.single).tofile(bin_file)
bin_file.close() bin_file.close()