mirror of
https://github.com/JHUAPL/SIMoN.git
synced 2026-01-08 22:37:56 -05:00
Dockerize the graph construction tool
Former-commit-id: 23f78dba4890c89fa77f93e57584f20b0932b335
This commit is contained in:
3
Makefile
3
Makefile
@@ -18,3 +18,6 @@ clean:
|
||||
|
||||
purge:
|
||||
cd build && docker-compose -p simon down --rmi all
|
||||
|
||||
graph:
|
||||
cd graphs && docker build -t simon-graph:latest . && docker run -v `pwd`:/opt -d simon-graph:latest
|
||||
|
||||
12
graphs/Dockerfile
Normal file
12
graphs/Dockerfile
Normal file
@@ -0,0 +1,12 @@
|
||||
FROM ubuntu:18.04
|
||||
RUN apt-get update && apt-get install -y python3-dev=3.6.7-1~18.04 python3-pip=9.0.1-2.3~ubuntu1.18.04.1 cmake=3.10.2-1ubuntu2.18.04.1 wget && apt-get -qy autoremove && apt-get clean && rm -r /var/lib/apt/lists/*
|
||||
RUN wget https://github.com/libspatialindex/libspatialindex/releases/download/1.9.3/spatialindex-src-1.9.3.tar.gz -P /
|
||||
RUN tar xfvz /spatialindex-src-1.9.3.tar.gz
|
||||
WORKDIR /spatialindex-src-1.9.3
|
||||
RUN cmake -DCMAKE_INSTALL_PREFIX=/libspatialindex .
|
||||
RUN make
|
||||
RUN make install
|
||||
ENV LD_LIBRARY_PATH=/libspatialindex/lib
|
||||
COPY ./requirements.txt /
|
||||
RUN pip3 install -r /requirements.txt
|
||||
ENTRYPOINT ["python3", "/opt/build.py"]
|
||||
@@ -16,6 +16,10 @@ import itertools
|
||||
from collections import defaultdict
|
||||
import uuid
|
||||
import os
|
||||
import json
|
||||
|
||||
with open(os.path.join(os.path.dirname(__file__), "config.json")) as f:
|
||||
config = json.load(f)
|
||||
|
||||
# where to save the graphs
|
||||
save_dir = os.path.join(os.path.dirname(__file__), "out")
|
||||
@@ -24,19 +28,19 @@ save_dir = os.path.join(os.path.dirname(__file__), "out")
|
||||
shapefile_dir = os.path.join(os.path.dirname(__file__), "shapefiles")
|
||||
|
||||
# the coordinate reference system the shapefiles are defined on
|
||||
projection = 3085
|
||||
projection = config["projection"]
|
||||
|
||||
# scale the areas calculated for shapefile geometries from square kilometers to square meters
|
||||
scale_factor = 10**6
|
||||
scale_factor = config["scale_factor"]
|
||||
|
||||
# the minimum area of a meet node (a node formed by the interestion of two disparate geograophic granularities), in square kilometers
|
||||
minimum_intersection_area = 1
|
||||
minimum_intersection_area = config["minimum_intersection_area"]
|
||||
|
||||
# Define the abstract graph with a list of tuples with the form (source, destination), where source is a higher lower resolution granularity that encompasses destination, a higher resolution granularity.
|
||||
abstract_edges = [("usa48", "state"), ("state", "county"), ("usa48", "nerc"), ("usa48", "huc8"), ("usa48", "latlon")]
|
||||
abstract_edges = config["abstract_edges"]
|
||||
|
||||
# Save the instance graph with its geometries included. This will create a very large graph.
|
||||
save_shapes = False
|
||||
save_shapes = config["save_shapes"]
|
||||
|
||||
# open the shapefiles for each granularity
|
||||
states = read_file(f"{shapefile_dir}/state.shp").to_crs(epsg=projection)
|
||||
@@ -257,7 +261,7 @@ print(metadata)
|
||||
|
||||
# save the instance graph with its geometries (very large)
|
||||
if save_shapes:
|
||||
with open("{}/{}-official-instance-graph-{}-shapes_{}km_simple1km.geojson".format(save_dir, "-".join(abstract_nodes), projection, minimum_intersection_area), mode='w') as outfile:
|
||||
with open("{}/instance-graph_{}_{}_{}_{}_shapes.geojson".format(save_dir, "-".join(abstract_nodes), projection, minimum_intersection_area, config["tag"]), mode='w') as outfile:
|
||||
geojson.dump(json_graph.node_link_data(instance_graph), outfile)
|
||||
|
||||
# remove geometries from the instance graph (much smaller)
|
||||
@@ -267,9 +271,9 @@ for node in instance_graph_noshapes['nodes']:
|
||||
del node['shape']
|
||||
|
||||
# save graphs to JSON files
|
||||
with open("{}/abstract-graph_{}_{}_{}km_simple1km.geojson".format(save_dir, "-".join(abstract_nodes), projection, minimum_intersection_area), mode='w') as outfile:
|
||||
with open("{}/abstract-graph_{}_{}_{}_{}.geojson".format(save_dir, "-".join(abstract_nodes), projection, minimum_intersection_area, config["tag"]), mode='w') as outfile:
|
||||
geojson.dump(json_graph.node_link_data(abstract_graph), outfile)
|
||||
with open("{}/instance-graph_{}_{}_{}km_simple1km.geojson".format(save_dir, "-".join(abstract_nodes), projection, minimum_intersection_area), mode='w') as outfile:
|
||||
with open("{}/instance-graph_{}_{}_{}_{}.geojson".format(save_dir, "-".join(abstract_nodes), projection, minimum_intersection_area, config["tag"]), mode='w') as outfile:
|
||||
geojson.dump(instance_graph_noshapes, outfile)
|
||||
|
||||
print("done building graphs")
|
||||
|
||||
19
graphs/config.json
Normal file
19
graphs/config.json
Normal file
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"projection": 3085,
|
||||
|
||||
"scale_factor": 1000000,
|
||||
|
||||
"minimum_intersection_area": 1,
|
||||
|
||||
"abstract_edges": [
|
||||
["usa48", "state"],
|
||||
["state", "county"],
|
||||
["usa48", "nerc"],
|
||||
["usa48", "huc8"],
|
||||
["usa48", "latlon"]
|
||||
],
|
||||
|
||||
"save_shapes": false,
|
||||
|
||||
"tag": "latest"
|
||||
}
|
||||
Reference in New Issue
Block a user