|
|
|
@@ -1,6 +1,7 @@ |
|
|
|
import json |
|
|
|
import sys |
|
|
|
import subprocess |
|
|
|
from tqdm import tqdm |
|
|
|
|
|
|
|
config = json.load(open(sys.argv[1])) |
|
|
|
|
|
|
|
@@ -61,6 +62,7 @@ elif config["mode"] == "filter": |
|
|
|
shell=True, |
|
|
|
stderr=subprocess.STDOUT |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
for item in config["items"]: |
|
|
|
CMD = ( |
|
|
|
@@ -91,14 +93,15 @@ elif config["mode"] == "filter": |
|
|
|
if not found: |
|
|
|
print("Did not find ", item["name"]) |
|
|
|
continue |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CMD = ( |
|
|
|
f"""mapshaper -i temp.shp """ |
|
|
|
f"""-filter "{config["base-filter"]}" """ |
|
|
|
f"""-filter "{item["filter"]}" """ |
|
|
|
f"""-simplify interval={config["simplify-size"]} """ |
|
|
|
f"""-proj "+proj=ortho +lat_0={lat} +lon_0={lon}" """ |
|
|
|
f"""-info """ + |
|
|
|
f"""-info """ |
|
|
|
f"""-style stroke-width={config["stroke-width"]} """ |
|
|
|
f"""-o "../../{config["directory"]}/{item["name"]}.svg" margin={config["stroke-width"]/2} height=1000 """ |
|
|
|
) |
|
|
|
@@ -123,3 +126,97 @@ elif config["mode"] == "filter": |
|
|
|
results.append([item["name"], height]) |
|
|
|
|
|
|
|
print(results) |
|
|
|
elif config["mode"] == "forms": |
|
|
|
results = [] |
|
|
|
|
|
|
|
CMD = ( |
|
|
|
f"""mapshaper -i {config["shapefile"]} """ |
|
|
|
f"""-filter "{config["base-filter"]}" """ |
|
|
|
f"""-o temp.shp""" |
|
|
|
) |
|
|
|
|
|
|
|
result = subprocess.check_output( |
|
|
|
CMD, |
|
|
|
shell=True, |
|
|
|
stderr=subprocess.STDOUT |
|
|
|
) |
|
|
|
|
|
|
|
CMD = ( |
|
|
|
f"""mapshaper -i temp.shp """ |
|
|
|
f"""encoding=utf-8 """ |
|
|
|
f"""-each "console.log(JSON.stringify({{id: this.id, name: name, key: {config["form-key"]} }}))" """ |
|
|
|
f"""-split """ |
|
|
|
f"""-o tmp/ format=topojson singles target=* """ |
|
|
|
) |
|
|
|
|
|
|
|
try: |
|
|
|
result = subprocess.check_output( |
|
|
|
CMD, |
|
|
|
shell=True |
|
|
|
) |
|
|
|
except subprocess.CalledProcessError as e: |
|
|
|
print(e.output) |
|
|
|
|
|
|
|
entities = [] |
|
|
|
|
|
|
|
for line in result.decode("utf-8").split("\n"): |
|
|
|
if len(line) > 0: |
|
|
|
print(line) |
|
|
|
entities.append(json.loads(line)) |
|
|
|
|
|
|
|
for item in tqdm(entities): |
|
|
|
CMD = ( |
|
|
|
f"""mapshaper -i tmp/temp-{item["id"] + 1}.json """ |
|
|
|
f"""encoding=utf-8 """ |
|
|
|
f"""-simplify interval=1000 """ |
|
|
|
f"""-info """ |
|
|
|
) |
|
|
|
|
|
|
|
result = subprocess.check_output( |
|
|
|
CMD, |
|
|
|
shell=True, |
|
|
|
stderr=subprocess.STDOUT |
|
|
|
) |
|
|
|
|
|
|
|
found = False |
|
|
|
for line in result.decode("utf-8").split("\n"): |
|
|
|
if "Bounds:" in line: |
|
|
|
coords = list(map(float, line[7:].strip().split(","))) |
|
|
|
lat = coords[1] + coords[3] |
|
|
|
lat /= 2 |
|
|
|
lon = coords[0] + coords[2] |
|
|
|
lon /= 2 |
|
|
|
found = True |
|
|
|
break |
|
|
|
|
|
|
|
if not found: |
|
|
|
print("Did not find ", item["name"]) |
|
|
|
continue |
|
|
|
|
|
|
|
CMD = ( |
|
|
|
f"""mapshaper -i tmp/temp-{item["id"] + 1}.json """ |
|
|
|
f"""encoding=utf-8 """ |
|
|
|
f"""-simplify interval={config["simplify-size"]} """ |
|
|
|
f"""-proj "+proj=ortho +lat_0={lat} +lon_0={lon}" """ |
|
|
|
f"""-info """ |
|
|
|
f"""-style stroke-width={config["stroke-width"]} """ |
|
|
|
f"""-o "../../{config["directory"]}/{item["key"]}/{item["name"]}.svg" margin={config["stroke-width"]/2} height=1000 """ |
|
|
|
) |
|
|
|
|
|
|
|
try: |
|
|
|
result = subprocess.check_output( |
|
|
|
CMD, |
|
|
|
shell=True, |
|
|
|
stderr=subprocess.STDOUT |
|
|
|
) |
|
|
|
except subprocess.CalledProcessError as exc: |
|
|
|
print(exc.output.decode("utf-8")) |
|
|
|
continue |
|
|
|
|
|
|
|
for line in result.decode("utf-8").split("\n"): |
|
|
|
if "Bounds:" in line: |
|
|
|
coords = list(map(float, line[7:].strip().split(","))) |
|
|
|
height = coords[3] - coords[1] |
|
|
|
height *= 1000 / (1000 - config["stroke-width"]) # accounts for the margin |
|
|
|
results.append({"name": item["name"], "form": item["key"], "height": round(height)}) |
|
|
|
print(results) |