scgraph 2.8.2__tar.gz → 2.10.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {scgraph-2.8.2/scgraph.egg-info → scgraph-2.10.0}/PKG-INFO +87 -1
- {scgraph-2.8.2 → scgraph-2.10.0}/README.md +86 -0
- {scgraph-2.8.2 → scgraph-2.10.0}/pyproject.toml +1 -1
- {scgraph-2.8.2 → scgraph-2.10.0}/scgraph/__init__.py +86 -0
- {scgraph-2.8.2 → scgraph-2.10.0}/scgraph/geograph.py +553 -178
- {scgraph-2.8.2 → scgraph-2.10.0}/scgraph/grid.py +7 -3
- scgraph-2.10.0/scgraph/helpers/geojson.py +215 -0
- scgraph-2.10.0/scgraph/helpers/kd_tree.py +241 -0
- scgraph-2.10.0/scgraph/helpers/visvalingam.py +161 -0
- scgraph-2.10.0/scgraph/helpers/xyz.py +49 -0
- {scgraph-2.8.2 → scgraph-2.10.0}/scgraph/utils.py +47 -0
- {scgraph-2.8.2 → scgraph-2.10.0/scgraph.egg-info}/PKG-INFO +87 -1
- {scgraph-2.8.2 → scgraph-2.10.0}/scgraph.egg-info/SOURCES.txt +5 -1
- {scgraph-2.8.2 → scgraph-2.10.0}/setup.cfg +1 -1
- {scgraph-2.8.2 → scgraph-2.10.0}/LICENSE +0 -0
- {scgraph-2.8.2 → scgraph-2.10.0}/scgraph/cache.py +0 -0
- {scgraph-2.8.2 → scgraph-2.10.0}/scgraph/core.py +0 -0
- {scgraph-2.8.2 → scgraph-2.10.0}/scgraph/geographs/__init__.py +0 -0
- {scgraph-2.8.2 → scgraph-2.10.0}/scgraph/geographs/marnet.py +0 -0
- {scgraph-2.8.2 → scgraph-2.10.0}/scgraph/geographs/north_america_rail.py +0 -0
- {scgraph-2.8.2 → scgraph-2.10.0}/scgraph/geographs/oak_ridge_maritime.py +0 -0
- {scgraph-2.8.2 → scgraph-2.10.0}/scgraph/geographs/us_freeway.py +0 -0
- {scgraph-2.8.2 → scgraph-2.10.0}/scgraph/graph.py +0 -0
- {scgraph-2.8.2 → scgraph-2.10.0}/scgraph/helpers/__init__.py +0 -0
- {scgraph-2.8.2 → scgraph-2.10.0}/scgraph/helpers/shape_mover_utils.py +0 -0
- {scgraph-2.8.2 → scgraph-2.10.0}/scgraph/spanning.py +0 -0
- {scgraph-2.8.2 → scgraph-2.10.0}/scgraph.egg-info/dependency_links.txt +0 -0
- {scgraph-2.8.2 → scgraph-2.10.0}/scgraph.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: scgraph
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.10.0
|
|
4
4
|
Summary: Determine an approximate route between two points on earth.
|
|
5
5
|
Author-email: Connor Makowski <conmak@mit.edu>
|
|
6
6
|
Project-URL: Homepage, https://github.com/connor-makowski/scgraph
|
|
@@ -131,6 +131,24 @@ output = marnet_geograph.get_shortest_path(
|
|
|
131
131
|
print('Length: ',output['length']) #=> Length: 19596.4653
|
|
132
132
|
```
|
|
133
133
|
|
|
134
|
+
Adding in a few additional parameters to the `get_shortest_path` function can change the output format and performance of the calculation.
|
|
135
|
+
```py
|
|
136
|
+
# Use a maritime network geograph
|
|
137
|
+
from scgraph.geographs.marnet import marnet_geograph
|
|
138
|
+
|
|
139
|
+
# Get the shortest maritime path between Shanghai, China and Savannah, Georgia, USA
|
|
140
|
+
output = marnet_geograph.get_shortest_path(
|
|
141
|
+
origin_node={"latitude": 31.23,"longitude": 121.47},
|
|
142
|
+
destination_node={"latitude": 32.08,"longitude": -81.09},
|
|
143
|
+
output_units='km',
|
|
144
|
+
node_addition_lat_lon_bound=180, # Optional: The maximum distance in degrees to consider nodes when attempting to add the origin and destination nodes to the graph
|
|
145
|
+
node_addition_type='quadrant', # Optional: Instead of connecting the origin node to the graph by the closest node, connect it to the closest node in each direction (NE, NW, SE, SW) if found within the node_addition_lat_lon_bound
|
|
146
|
+
destination_node_addition_type='all', # Optional: Instead of connecting the destination node to the graph by the closest node, connect it to all nodes found within the node_addition_lat_lon_bound
|
|
147
|
+
# When destination_node_addition_type='all' is set with a node_addition_lat_lon_bound=180, this will guarantee a solution can be found since the destination node will also connect to the origin node
|
|
148
|
+
)
|
|
149
|
+
print('Length: ',output['length']) #=> Length: 19596.4653
|
|
150
|
+
```
|
|
151
|
+
|
|
134
152
|
In the above example, the `output` variable is a dictionary with two keys: `length` and `coordinate_path`.
|
|
135
153
|
|
|
136
154
|
- `length`: The distance between the passed origin and destination when traversing the graph along the shortest path
|
|
@@ -258,6 +276,74 @@ output = marnet_geograph.get_shortest_path(
|
|
|
258
276
|
get_line_path(output, filename='output.geojson')
|
|
259
277
|
```
|
|
260
278
|
|
|
279
|
+
### Building your own Geographs from Open Source Data
|
|
280
|
+
You can build your own geographs using various tools and data sources. For example, you can use OpenStreetMap data to create a high fidelity geograph for a specific area.
|
|
281
|
+
|
|
282
|
+
Expand the secion below for a step by step guide on how to create a geograph from OpenStreetMap data.
|
|
283
|
+
<details>
|
|
284
|
+
<summary>Click to see an example for Michigan, USA</summary>
|
|
285
|
+
|
|
286
|
+
For this example, we will use some various tools to create a geograph for highways (including seconday highways) in Michigan, USA.
|
|
287
|
+
|
|
288
|
+
Download an OSM PBF file using the AWS CLI:
|
|
289
|
+
- Geofabrik is a good source for smaller OSM PBF files. See: https://download.geofabrik.de/
|
|
290
|
+
- To keep things generalizable, you can also download the entire planet OSM PBF file using AWS. But you should consider downloading a smaller region if you are only interested in a specific area.
|
|
291
|
+
- Note: For this, you will need to install the AWS CLI.
|
|
292
|
+
- Note: The planet OSM PBF file is very large (About 100GB)
|
|
293
|
+
```
|
|
294
|
+
aws s3 cp s3://osm-pds/planet-latest.osm.pbf .
|
|
295
|
+
```
|
|
296
|
+
- Use Osmium to filter and extract the highways from the OSM PBF file.
|
|
297
|
+
- Install osmium on macOS:
|
|
298
|
+
```
|
|
299
|
+
brew install osmium-tool
|
|
300
|
+
```
|
|
301
|
+
- Install osmium on Ubuntu:
|
|
302
|
+
```
|
|
303
|
+
sudo apt-get install osmium-tool
|
|
304
|
+
```
|
|
305
|
+
- Download a Poly file for the area you are interested in. This is a polygon file that defines the area you want to extract from the OSM PBF file.
|
|
306
|
+
- For Michigan, you can download the poly file from Geofabrik:
|
|
307
|
+
```
|
|
308
|
+
curl https://download.geofabrik.de/north-america/us/michigan.poly > michigan.poly
|
|
309
|
+
```
|
|
310
|
+
- Google around to find an appropriate poly file for your area of interest.
|
|
311
|
+
- Filter and extract as GeoJSON (EG: Michigan) substituting the poly and pbf file names as needed:
|
|
312
|
+
```
|
|
313
|
+
osmium extract -p michigan.poly --overwrite -o michigan.osm.pbf planet-latest.osm.pbf
|
|
314
|
+
```
|
|
315
|
+
- Filter the OSM PBF file to only areas of interest and export to GeoJSON:
|
|
316
|
+
- See: https://wiki.openstreetmap.org/wiki/
|
|
317
|
+
- EG For Highways, see: https://wiki.openstreetmap.org/wiki/Key:highway
|
|
318
|
+
```
|
|
319
|
+
osmium tags-filter michigan.osm.pbf w/highway=motorway,trunk,primary,motorway_link,trunk_link,primary_link,secondary,secondary_link,tertiary,tertiary_link -t --overwrite -o michigan_roads.osm.pbf
|
|
320
|
+
osmium export michigan_roads.osm.pbf -f geojson --overwrite -o michigan_roads.geojson
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
- Simplify the geojson
|
|
324
|
+
- This uses some tools in the SCGraph library as well as Mapshaper to simplify the geojson files.
|
|
325
|
+
- Mapshaper is a CLI and web tool for simplifying and editing geojson files.
|
|
326
|
+
- To install Mapshaper for CLI use, use NPM:
|
|
327
|
+
```
|
|
328
|
+
npm install -g mapshaper
|
|
329
|
+
```
|
|
330
|
+
- Mapshaper is particularly helpful since it repairs intersections in the lines which is crutial for geographs to work properly.
|
|
331
|
+
- Mapshaper, however, does not handle larger files very well, so it is recommended to simplify the geojson file first using the `scgraph.helpers.geojson.simplify_geojson` function first to reduce the size of the file.
|
|
332
|
+
- Make sure to tailor the parameters to your needs.
|
|
333
|
+
```
|
|
334
|
+
python -c "from scgraph.helpers.geojson import simplify_geojson; simplify_geojson('michigan_roads.geojson', 'michigan_roads_simple.geojson', precision=4, pct_to_keep=100, min_points=3, silent=False)"
|
|
335
|
+
mapshaper michigan_roads_simple.geojson -simplify 10% -filter-fields -o force michigan_roads_simple.geojson
|
|
336
|
+
mapshaper michigan_roads_simple.geojson -snap -clean -o force michigan_roads_simple.geojson
|
|
337
|
+
```
|
|
338
|
+
- Load the newly created geojson file as a geograph:
|
|
339
|
+
- Note: The `GeoGraph.load_from_geojson` function is used to load the geojson file as a geograph.
|
|
340
|
+
- This will create a geograph that can be used to calculate shortest paths between points on the graph.
|
|
341
|
+
```
|
|
342
|
+
from scgraph import GeoGraph
|
|
343
|
+
michigan_roads_geograph = GeoGraph.load_from_geojson('michigan_roads_simple.geojson')
|
|
344
|
+
```
|
|
345
|
+
</details>
|
|
346
|
+
|
|
261
347
|
### Custom Graphs and Geographs
|
|
262
348
|
Modify an existing geograph: See the notebook [here](https://colab.research.google.com/github/connor-makowski/scgraph/blob/main/examples/geograph_modifications.ipynb)
|
|
263
349
|
|
|
@@ -115,6 +115,24 @@ output = marnet_geograph.get_shortest_path(
|
|
|
115
115
|
print('Length: ',output['length']) #=> Length: 19596.4653
|
|
116
116
|
```
|
|
117
117
|
|
|
118
|
+
Adding in a few additional parameters to the `get_shortest_path` function can change the output format and performance of the calculation.
|
|
119
|
+
```py
|
|
120
|
+
# Use a maritime network geograph
|
|
121
|
+
from scgraph.geographs.marnet import marnet_geograph
|
|
122
|
+
|
|
123
|
+
# Get the shortest maritime path between Shanghai, China and Savannah, Georgia, USA
|
|
124
|
+
output = marnet_geograph.get_shortest_path(
|
|
125
|
+
origin_node={"latitude": 31.23,"longitude": 121.47},
|
|
126
|
+
destination_node={"latitude": 32.08,"longitude": -81.09},
|
|
127
|
+
output_units='km',
|
|
128
|
+
node_addition_lat_lon_bound=180, # Optional: The maximum distance in degrees to consider nodes when attempting to add the origin and destination nodes to the graph
|
|
129
|
+
node_addition_type='quadrant', # Optional: Instead of connecting the origin node to the graph by the closest node, connect it to the closest node in each direction (NE, NW, SE, SW) if found within the node_addition_lat_lon_bound
|
|
130
|
+
destination_node_addition_type='all', # Optional: Instead of connecting the destination node to the graph by the closest node, connect it to all nodes found within the node_addition_lat_lon_bound
|
|
131
|
+
# When destination_node_addition_type='all' is set with a node_addition_lat_lon_bound=180, this will guarantee a solution can be found since the destination node will also connect to the origin node
|
|
132
|
+
)
|
|
133
|
+
print('Length: ',output['length']) #=> Length: 19596.4653
|
|
134
|
+
```
|
|
135
|
+
|
|
118
136
|
In the above example, the `output` variable is a dictionary with two keys: `length` and `coordinate_path`.
|
|
119
137
|
|
|
120
138
|
- `length`: The distance between the passed origin and destination when traversing the graph along the shortest path
|
|
@@ -242,6 +260,74 @@ output = marnet_geograph.get_shortest_path(
|
|
|
242
260
|
get_line_path(output, filename='output.geojson')
|
|
243
261
|
```
|
|
244
262
|
|
|
263
|
+
### Building your own Geographs from Open Source Data
|
|
264
|
+
You can build your own geographs using various tools and data sources. For example, you can use OpenStreetMap data to create a high fidelity geograph for a specific area.
|
|
265
|
+
|
|
266
|
+
Expand the secion below for a step by step guide on how to create a geograph from OpenStreetMap data.
|
|
267
|
+
<details>
|
|
268
|
+
<summary>Click to see an example for Michigan, USA</summary>
|
|
269
|
+
|
|
270
|
+
For this example, we will use some various tools to create a geograph for highways (including seconday highways) in Michigan, USA.
|
|
271
|
+
|
|
272
|
+
Download an OSM PBF file using the AWS CLI:
|
|
273
|
+
- Geofabrik is a good source for smaller OSM PBF files. See: https://download.geofabrik.de/
|
|
274
|
+
- To keep things generalizable, you can also download the entire planet OSM PBF file using AWS. But you should consider downloading a smaller region if you are only interested in a specific area.
|
|
275
|
+
- Note: For this, you will need to install the AWS CLI.
|
|
276
|
+
- Note: The planet OSM PBF file is very large (About 100GB)
|
|
277
|
+
```
|
|
278
|
+
aws s3 cp s3://osm-pds/planet-latest.osm.pbf .
|
|
279
|
+
```
|
|
280
|
+
- Use Osmium to filter and extract the highways from the OSM PBF file.
|
|
281
|
+
- Install osmium on macOS:
|
|
282
|
+
```
|
|
283
|
+
brew install osmium-tool
|
|
284
|
+
```
|
|
285
|
+
- Install osmium on Ubuntu:
|
|
286
|
+
```
|
|
287
|
+
sudo apt-get install osmium-tool
|
|
288
|
+
```
|
|
289
|
+
- Download a Poly file for the area you are interested in. This is a polygon file that defines the area you want to extract from the OSM PBF file.
|
|
290
|
+
- For Michigan, you can download the poly file from Geofabrik:
|
|
291
|
+
```
|
|
292
|
+
curl https://download.geofabrik.de/north-america/us/michigan.poly > michigan.poly
|
|
293
|
+
```
|
|
294
|
+
- Google around to find an appropriate poly file for your area of interest.
|
|
295
|
+
- Filter and extract as GeoJSON (EG: Michigan) substituting the poly and pbf file names as needed:
|
|
296
|
+
```
|
|
297
|
+
osmium extract -p michigan.poly --overwrite -o michigan.osm.pbf planet-latest.osm.pbf
|
|
298
|
+
```
|
|
299
|
+
- Filter the OSM PBF file to only areas of interest and export to GeoJSON:
|
|
300
|
+
- See: https://wiki.openstreetmap.org/wiki/
|
|
301
|
+
- EG For Highways, see: https://wiki.openstreetmap.org/wiki/Key:highway
|
|
302
|
+
```
|
|
303
|
+
osmium tags-filter michigan.osm.pbf w/highway=motorway,trunk,primary,motorway_link,trunk_link,primary_link,secondary,secondary_link,tertiary,tertiary_link -t --overwrite -o michigan_roads.osm.pbf
|
|
304
|
+
osmium export michigan_roads.osm.pbf -f geojson --overwrite -o michigan_roads.geojson
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
- Simplify the geojson
|
|
308
|
+
- This uses some tools in the SCGraph library as well as Mapshaper to simplify the geojson files.
|
|
309
|
+
- Mapshaper is a CLI and web tool for simplifying and editing geojson files.
|
|
310
|
+
- To install Mapshaper for CLI use, use NPM:
|
|
311
|
+
```
|
|
312
|
+
npm install -g mapshaper
|
|
313
|
+
```
|
|
314
|
+
- Mapshaper is particularly helpful since it repairs intersections in the lines which is crutial for geographs to work properly.
|
|
315
|
+
- Mapshaper, however, does not handle larger files very well, so it is recommended to simplify the geojson file first using the `scgraph.helpers.geojson.simplify_geojson` function first to reduce the size of the file.
|
|
316
|
+
- Make sure to tailor the parameters to your needs.
|
|
317
|
+
```
|
|
318
|
+
python -c "from scgraph.helpers.geojson import simplify_geojson; simplify_geojson('michigan_roads.geojson', 'michigan_roads_simple.geojson', precision=4, pct_to_keep=100, min_points=3, silent=False)"
|
|
319
|
+
mapshaper michigan_roads_simple.geojson -simplify 10% -filter-fields -o force michigan_roads_simple.geojson
|
|
320
|
+
mapshaper michigan_roads_simple.geojson -snap -clean -o force michigan_roads_simple.geojson
|
|
321
|
+
```
|
|
322
|
+
- Load the newly created geojson file as a geograph:
|
|
323
|
+
- Note: The `GeoGraph.load_from_geojson` function is used to load the geojson file as a geograph.
|
|
324
|
+
- This will create a geograph that can be used to calculate shortest paths between points on the graph.
|
|
325
|
+
```
|
|
326
|
+
from scgraph import GeoGraph
|
|
327
|
+
michigan_roads_geograph = GeoGraph.load_from_geojson('michigan_roads_simple.geojson')
|
|
328
|
+
```
|
|
329
|
+
</details>
|
|
330
|
+
|
|
245
331
|
### Custom Graphs and Geographs
|
|
246
332
|
Modify an existing geograph: See the notebook [here](https://colab.research.google.com/github/connor-makowski/scgraph/blob/main/examples/geograph_modifications.ipynb)
|
|
247
333
|
|
|
@@ -12,7 +12,7 @@ build-backend = "setuptools.build_meta"
|
|
|
12
12
|
|
|
13
13
|
[project]
|
|
14
14
|
name = "scgraph"
|
|
15
|
-
version = "2.
|
|
15
|
+
version = "2.10.0"
|
|
16
16
|
description = "Determine an approximate route between two points on earth."
|
|
17
17
|
authors = [
|
|
18
18
|
{name="Connor Makowski", email="conmak@mit.edu"}
|
|
@@ -116,6 +116,24 @@ output = marnet_geograph.get_shortest_path(
|
|
|
116
116
|
print('Length: ',output['length']) #=> Length: 19596.4653
|
|
117
117
|
```
|
|
118
118
|
|
|
119
|
+
Adding in a few additional parameters to the `get_shortest_path` function can change the output format and performance of the calculation.
|
|
120
|
+
```py
|
|
121
|
+
# Use a maritime network geograph
|
|
122
|
+
from scgraph.geographs.marnet import marnet_geograph
|
|
123
|
+
|
|
124
|
+
# Get the shortest maritime path between Shanghai, China and Savannah, Georgia, USA
|
|
125
|
+
output = marnet_geograph.get_shortest_path(
|
|
126
|
+
origin_node={"latitude": 31.23,"longitude": 121.47},
|
|
127
|
+
destination_node={"latitude": 32.08,"longitude": -81.09},
|
|
128
|
+
output_units='km',
|
|
129
|
+
node_addition_lat_lon_bound=180, # Optional: The maximum distance in degrees to consider nodes when attempting to add the origin and destination nodes to the graph
|
|
130
|
+
node_addition_type='quadrant', # Optional: Instead of connecting the origin node to the graph by the closest node, connect it to the closest node in each direction (NE, NW, SE, SW) if found within the node_addition_lat_lon_bound
|
|
131
|
+
destination_node_addition_type='all', # Optional: Instead of connecting the destination node to the graph by the closest node, connect it to all nodes found within the node_addition_lat_lon_bound
|
|
132
|
+
# When destination_node_addition_type='all' is set with a node_addition_lat_lon_bound=180, this will guarantee a solution can be found since the destination node will also connect to the origin node
|
|
133
|
+
)
|
|
134
|
+
print('Length: ',output['length']) #=> Length: 19596.4653
|
|
135
|
+
```
|
|
136
|
+
|
|
119
137
|
In the above example, the `output` variable is a dictionary with two keys: `length` and `coordinate_path`.
|
|
120
138
|
|
|
121
139
|
- `length`: The distance between the passed origin and destination when traversing the graph along the shortest path
|
|
@@ -243,6 +261,74 @@ output = marnet_geograph.get_shortest_path(
|
|
|
243
261
|
get_line_path(output, filename='output.geojson')
|
|
244
262
|
```
|
|
245
263
|
|
|
264
|
+
### Building your own Geographs from Open Source Data
|
|
265
|
+
You can build your own geographs using various tools and data sources. For example, you can use OpenStreetMap data to create a high fidelity geograph for a specific area.
|
|
266
|
+
|
|
267
|
+
Expand the secion below for a step by step guide on how to create a geograph from OpenStreetMap data.
|
|
268
|
+
<details>
|
|
269
|
+
<summary>Click to see an example for Michigan, USA</summary>
|
|
270
|
+
|
|
271
|
+
For this example, we will use some various tools to create a geograph for highways (including seconday highways) in Michigan, USA.
|
|
272
|
+
|
|
273
|
+
Download an OSM PBF file using the AWS CLI:
|
|
274
|
+
- Geofabrik is a good source for smaller OSM PBF files. See: https://download.geofabrik.de/
|
|
275
|
+
- To keep things generalizable, you can also download the entire planet OSM PBF file using AWS. But you should consider downloading a smaller region if you are only interested in a specific area.
|
|
276
|
+
- Note: For this, you will need to install the AWS CLI.
|
|
277
|
+
- Note: The planet OSM PBF file is very large (About 100GB)
|
|
278
|
+
```
|
|
279
|
+
aws s3 cp s3://osm-pds/planet-latest.osm.pbf .
|
|
280
|
+
```
|
|
281
|
+
- Use Osmium to filter and extract the highways from the OSM PBF file.
|
|
282
|
+
- Install osmium on macOS:
|
|
283
|
+
```
|
|
284
|
+
brew install osmium-tool
|
|
285
|
+
```
|
|
286
|
+
- Install osmium on Ubuntu:
|
|
287
|
+
```
|
|
288
|
+
sudo apt-get install osmium-tool
|
|
289
|
+
```
|
|
290
|
+
- Download a Poly file for the area you are interested in. This is a polygon file that defines the area you want to extract from the OSM PBF file.
|
|
291
|
+
- For Michigan, you can download the poly file from Geofabrik:
|
|
292
|
+
```
|
|
293
|
+
curl https://download.geofabrik.de/north-america/us/michigan.poly > michigan.poly
|
|
294
|
+
```
|
|
295
|
+
- Google around to find an appropriate poly file for your area of interest.
|
|
296
|
+
- Filter and extract as GeoJSON (EG: Michigan) substituting the poly and pbf file names as needed:
|
|
297
|
+
```
|
|
298
|
+
osmium extract -p michigan.poly --overwrite -o michigan.osm.pbf planet-latest.osm.pbf
|
|
299
|
+
```
|
|
300
|
+
- Filter the OSM PBF file to only areas of interest and export to GeoJSON:
|
|
301
|
+
- See: https://wiki.openstreetmap.org/wiki/
|
|
302
|
+
- EG For Highways, see: https://wiki.openstreetmap.org/wiki/Key:highway
|
|
303
|
+
```
|
|
304
|
+
osmium tags-filter michigan.osm.pbf w/highway=motorway,trunk,primary,motorway_link,trunk_link,primary_link,secondary,secondary_link,tertiary,tertiary_link -t --overwrite -o michigan_roads.osm.pbf
|
|
305
|
+
osmium export michigan_roads.osm.pbf -f geojson --overwrite -o michigan_roads.geojson
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
- Simplify the geojson
|
|
309
|
+
- This uses some tools in the SCGraph library as well as Mapshaper to simplify the geojson files.
|
|
310
|
+
- Mapshaper is a CLI and web tool for simplifying and editing geojson files.
|
|
311
|
+
- To install Mapshaper for CLI use, use NPM:
|
|
312
|
+
```
|
|
313
|
+
npm install -g mapshaper
|
|
314
|
+
```
|
|
315
|
+
- Mapshaper is particularly helpful since it repairs intersections in the lines which is crutial for geographs to work properly.
|
|
316
|
+
- Mapshaper, however, does not handle larger files very well, so it is recommended to simplify the geojson file first using the `scgraph.helpers.geojson.simplify_geojson` function first to reduce the size of the file.
|
|
317
|
+
- Make sure to tailor the parameters to your needs.
|
|
318
|
+
```
|
|
319
|
+
python -c "from scgraph.helpers.geojson import simplify_geojson; simplify_geojson('michigan_roads.geojson', 'michigan_roads_simple.geojson', precision=4, pct_to_keep=100, min_points=3, silent=False)"
|
|
320
|
+
mapshaper michigan_roads_simple.geojson -simplify 10% -filter-fields -o force michigan_roads_simple.geojson
|
|
321
|
+
mapshaper michigan_roads_simple.geojson -snap -clean -o force michigan_roads_simple.geojson
|
|
322
|
+
```
|
|
323
|
+
- Load the newly created geojson file as a geograph:
|
|
324
|
+
- Note: The `GeoGraph.load_from_geojson` function is used to load the geojson file as a geograph.
|
|
325
|
+
- This will create a geograph that can be used to calculate shortest paths between points on the graph.
|
|
326
|
+
```
|
|
327
|
+
from scgraph import GeoGraph
|
|
328
|
+
michigan_roads_geograph = GeoGraph.load_from_geojson('michigan_roads_simple.geojson')
|
|
329
|
+
```
|
|
330
|
+
</details>
|
|
331
|
+
|
|
246
332
|
### Custom Graphs and Geographs
|
|
247
333
|
Modify an existing geograph: See the notebook [here](https://colab.research.google.com/github/connor-makowski/scgraph/blob/main/examples/geograph_modifications.ipynb)
|
|
248
334
|
|