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 sys
from tqdm import tqdm
import argparse
parser = argparse.ArgumentParser(description='viz1090 SVG Map Converter')
parser.add_argument("--resolution", default=250, type=int, nargs=1, help="downsample resolution")
parser.add_argument("file", nargs=1, help="filename")
parser.add_argument("--resolution", default=250, type=int, help="downsample resolution")
parser.add_argument("file", nargs="+", help="filename")
args = parser.parse_args()
if(len(args.file) == 0):
print("No input filename given")
exit()
parser = ElementTree.XMLParser(recover=True)
tree = ElementTree.parse(args.file[0], parser)
polys = tree.xpath('//polygon')
bin_file = open("mapdata.bin", "wb")
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
prevy = 0
print("Reading points")
for i in tqdm(range(len(data['features']))):
temp = []
for i in range(int(len(currentPoints)/2)):
#currentPoints[2 * i + 0] = "%.*f" % (precision, float(currentPoints[2 * i + 0]))
#currentPoints[2 * i + 1] = "%.*f" % (precision, float(currentPoints[2 * i + 1]))
if(data['features'][i]['geometry']['type'] == 'LineString'):
prevx = 0
prevy = 0
currentPoints[2 * i + 0] = float(int(resolution * float(currentPoints[2 * i + 0]))) / resolution
currentPoints[2 * i + 1] = float(int(resolution * float(currentPoints[2 * i + 1]))) / resolution
temp = []
if(currentPoints[2 * i + 0] != prevx or currentPoints[2 * i + 1] != prevy):
temp.extend([currentPoints[2 * i + 0],currentPoints[2 * i + 1]])
for currentPoint in data['features'][i]['geometry']['coordinates']:
prevx = currentPoints[2 * i + 0]
prevy = currentPoints[2 * i + 1]
currentx = float(int(resolution * float(currentPoint[0]))) / resolution
currenty = float(int(resolution * float(currentPoint[1]))) / resolution
if(len(currentPoints) > 6): #must be at least a triangle
outlist.extend(temp)
#outlist.extend([temp[0],temp[1]])
outlist.extend(["0","0"])
if(currentx != prevx or currenty != prevy):
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"])
outlist.extend(temp)
np.asarray(outlist).astype(np.single).tofile(bin_file)
bin_file.close()