Skip to content

Commit

Permalink
Remove download-osm make-dc, gen bbox (#297)
Browse files Browse the repository at this point in the history
Simplify `download-osm` to only generate bbox value, without the overly complex (and unneeded) docker-compose config file.

New functionality:
* `--bbox` will generate a simple text file containing the bounding box string. The value will be either computed based on the geofabrik's catalog, or for other sources it will continue using `osmconvert`
* `download-osm bbox <pbf-file> <bbox-file>` will parse pbf file to generate the same text file with bbox string
* The `--output` param is now required when used with `--bbox`

Removed functionality:
* `--make-dc` parameter and `make-dc` command.
  • Loading branch information
nyurik authored Sep 28, 2020
1 parent 86e8933 commit 223dd07
Show file tree
Hide file tree
Showing 9 changed files with 151 additions and 240 deletions.
239 changes: 79 additions & 160 deletions bin/download-osm

Large diffs are not rendered by default.

25 changes: 25 additions & 0 deletions openmaptiles/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,31 @@ def __init__(self, bbox=None,
except ValueError:
self.center_zoom = float(center_zoom)

@staticmethod
def from_geometry(geo):
"""Given GeoJSON geometry, compute the bounding box"""
bbox = Bbox()
bbox.min_lon, bbox.max_lon = bbox.max_lon, bbox.min_lon
bbox.min_lat, bbox.max_lat = bbox.max_lat, bbox.min_lat

def minmax(vals):
if isinstance(vals[0], List):
for v in vals:
minmax(v)
else:
lon, lat = vals
if lon < bbox.min_lon:
bbox.min_lon = lon
if lon > bbox.max_lon:
bbox.max_lon = lon
if lat < bbox.min_lat:
bbox.min_lat = lat
if lat > bbox.max_lat:
bbox.max_lat = lat

minmax(geo)
return bbox

def bounds_str(self):
return ','.join(map(str, self.bounds()))

Expand Down
78 changes: 40 additions & 38 deletions tests/cache/Geofabrik.json
Original file line number Diff line number Diff line change
@@ -1,63 +1,65 @@
{
"DESCRIPTION": "This is a fake catalog of Geofabrik areas used in testing",
"type": "FeatureCollection",
"features": [
"DESCRIPTION" : "This is a fake catalog of Geofabrik areas used in testing",
"type" : "FeatureCollection",
"features" : [
{
"type": "Feature",
"properties": {
"id": "monaco-test",
"parent": "europe",
"iso3166-1:alpha2": [
"MC"
],
"name": "A test file",
"urls": {
"pbf": "http://localhost:8555/monaco-20150428.osm.pbf",
"updates": "http://localhost:8555/fake-updates/"
"id" : "monaco-test",
"parent" : "europe",
"iso3166-1:alpha2" : [ "MC" ],
"name" : "A test file",
"urls" : {
"pbf" : "http://localhost:8555/monaco-20150428.osm.pbf",
"updates" : "http://localhost:8555/fake-updates/"
}
}
},
"geometry" : { "type" : "MultiPolygon", "coordinates" : [[[[7.448637,43.739920],[7.420651,43.723350],[7.409205,43.729330],[7.410161,43.730720],[7.411732,43.731390],[7.413011,43.731620],[7.412909,43.733790],[7.412364,43.734290],[7.415174,43.736180],[7.421612,43.740330],[7.421557,43.740800],[7.423117,43.741350],[7.424507,43.740690],[7.426007,43.742260],[7.427535,43.743690],[7.428709,43.745900],[7.430755,43.748850],[7.431923,43.748560],[7.433675,43.749520],[7.435904,43.749790],[7.437361,43.750830],[7.436782,43.751490],[7.437709,43.751690],[7.438827,43.751330],[7.438466,43.748990],[7.441831,43.745050],[7.448637,43.739920]]]]}
},
{
"type": "Feature",
"properties": {
"id": "us/michigan",
"parent": "north-america",
"iso3166-2": [
"id" : "us/michigan",
"parent" : "north-america",
"iso3166-2" : [
"US-MI"
],
"name": "Michigan",
"urls": {
"pbf": "https://download.geofabrik.de/north-america/us/michigan-latest.osm.pbf",
"bz2": "https://download.geofabrik.de/north-america/us/michigan-latest.osm.bz2",
"shp": "https://download.geofabrik.de/north-america/us/michigan-latest-free.shp.zip",
"pbf-internal": "https://osm-internal.download.geofabrik.de/north-america/us/michigan-latest-internal.osm.pbf",
"history": "https://osm-internal.download.geofabrik.de/north-america/us/michigan-internal.osh.pbf",
"taginfo": "https://taginfo.geofabrik.de/north-america/us/michigan/",
"updates": "https://download.geofabrik.de/north-america/us/michigan-updates"
"name" : "Michigan",
"urls" : {
"pbf" : "https://download.geofabrik.de/north-america/us/michigan-latest.osm.pbf",
"bz2" : "https://download.geofabrik.de/north-america/us/michigan-latest.osm.bz2",
"shp" : "https://download.geofabrik.de/north-america/us/michigan-latest-free.shp.zip",
"pbf-internal" : "https://osm-internal.download.geofabrik.de/north-america/us/michigan-latest-internal.osm.pbf",
"history" : "https://osm-internal.download.geofabrik.de/north-america/us/michigan-internal.osh.pbf",
"taginfo" : "https://taginfo.geofabrik.de/north-america/us/michigan/",
"updates" : "https://download.geofabrik.de/north-america/us/michigan-updates"
}
}
},
"geometry" : { "type" : "MultiPolygon", "coordinates" : [[[[7.448637,43.739920],[7.420651,43.723350]]]]}
},
{
"type": "Feature",
"properties": {
"id": "europe",
"name": "Europe",
"urls": {
"pbf": "https://download.geofabrik.de/europe-latest.osm.pbf",
"updates": "http://localhost:8555/fake-europe-updates/"
"id" : "europe",
"name" : "Europe",
"urls" : {
"pbf" : "https://download.geofabrik.de/europe-latest.osm.pbf",
"updates" : "http://localhost:8555/fake-europe-updates/"
}
}
},
"geometry" : { "type" : "MultiPolygon", "coordinates" : [[[[7.448637,43.739920],[7.420651,43.723350]]]]}
},
{
"type": "Feature",
"properties": {
"id": "north-america",
"name": "North America",
"urls": {
"pbf": "https://download.geofabrik.de/north-america-latest.osm.pbf",
"updates": "http://localhost:8555/fake-north-america-updates/"
"id" : "north-america",
"name" : "North America",
"urls" : {
"pbf" : "https://download.geofabrik.de/north-america-latest.osm.pbf",
"updates" : "http://localhost:8555/fake-north-america-updates/"
}
}
},
"geometry" : { "type" : "MultiPolygon", "coordinates" : [[[[7.448637,43.739920],[7.420651,43.723350]]]]}
}
]
}
10 changes: 0 additions & 10 deletions tests/expected/monaco-dc.yml

This file was deleted.

10 changes: 0 additions & 10 deletions tests/expected/monaco-dc2.yml

This file was deleted.

10 changes: 0 additions & 10 deletions tests/expected/monaco-dc3.yml

This file was deleted.

1 change: 1 addition & 0 deletions tests/expected/monaco.bbox
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
7.3830115,43.516333,7.500333,43.7543525
1 change: 1 addition & 0 deletions tests/expected/monaco2.bbox
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
7.409205,43.72335,7.448637,43.75169
17 changes: 5 additions & 12 deletions tests/test-tools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,22 +65,15 @@ python -m http.server 8555 -d "$HTTPDIR" &
trap "kill $!" EXIT

download-osm url http://localhost:8555/monaco-20150428.osm.pbf \
--verbose --make-dc "$BUILD/monaco-dc.yml" --id raw-url --minzoom 0 --maxzoom 10 -- --dir "$TEMP_DIR"
--output "$TEMP_DIR/monaco-20150428.osm.pbf" --verbose --bbox "$BUILD/monaco.bbox"

# Test downloader support for env vars
export OSM_AREA_NAME=monaco-test2
export MIN_ZOOM=3
export MAX_ZOOM=5
export MAKE_DC_VERSION=2.2
download-osm url http://localhost:8555/monaco-20150428.osm.pbf \
--verbose --make-dc "$BUILD/monaco-dc2.yml" --output "$TEMP_DIR/delete_me.pbf"
diff --brief "$HTTPDIR/monaco-20150428.osm.pbf" "$TEMP_DIR/delete_me.pbf"
rm "$TEMP_DIR/delete_me.pbf"
unset OSM_AREA_NAME MIN_ZOOM MAX_ZOOM MAKE_DC_VERSION
download-osm bbox "$TEMP_DIR/monaco-20150428.osm.pbf" "$BUILD/monaco.bbox" --verbose
diff --brief "$HTTPDIR/monaco-20150428.osm.pbf" "$TEMP_DIR/monaco-20150428.osm.pbf"
rm "$TEMP_DIR/monaco-20150428.osm.pbf"

download-osm geofabrik monaco-test \
--verbose --imposm-cfg "$BUILD/monaco-cfg.json" --kv foo=bar --kv replication_interval=4h \
--make-dc "$BUILD/monaco-dc3.yml" --minzoom 5 --maxzoom 6 --dc-ver 2.1 -- --dir "$TEMP_DIR"
--bbox "$BUILD/monaco2.bbox" --output "$TEMP_DIR/monaco-20150428.osm.pbf"
diff --brief "$HTTPDIR/monaco-20150428.osm.pbf" "$TEMP_DIR/monaco-20150428.osm.pbf"
rm "$TEMP_DIR/monaco-20150428.osm.pbf"

Expand Down

0 comments on commit 223dd07

Please sign in to comment.