Skip to content

Commit

Permalink
Began work on the tag translator for Zoomstack
Browse files Browse the repository at this point in the history
  • Loading branch information
citizenfish committed Feb 16, 2024
1 parent 0155944 commit f087093
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 1 deletion.
26 changes: 26 additions & 0 deletions build/split_contours.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

# Path to your input geopackage
input_geopackage="/opt/data/zoomstack/contours.gpkg"

# Path to the generated grid shapefile
grid_shapefile="/opt/data/zoomstack/uk_grid_50x50km.gpkg"

# Output directory for the split geopackages
output_dir="/opt/data/zoomstack/osm_contours"
docker_dir="/app/data/zoomstack/osm_contours"

# Read each feature (grid cell) from the grid shapefile
ogrinfo -al -geom=NO ${grid_shapefile} | grep OGRFeature | cut -d' ' -f2 | while read feature_id; do
# Define the output filename based on the feature ID
output_geopackage="${output_dir}/contour_${feature_id}.gpkg"
input_geopackage="${docker_dir}/contour_${feature_id}.gpkg"
output_osm="${output_dir}/contour_${feature_id}.osm.pbf"

# Use ogr2ogr to clip the input geopackage by the current grid cell and output to a new geopackage
ogr2ogr -f GPKG ${output_geopackage} ${input_geopackage} -progress -clipsrc ${grid_shapefile} ${feature_id}

# Use ogr2osm to make the final output file
docker run -ti --rm -v /opt/:/app roelderickx/ogr2osm ${input_geopackage} -f --pbf -e 27700 -o ${output_osm} -t /app/dev/bikepackmaps/translations/bikepack_translator.py --id 11571092201
done

45 changes: 45 additions & 0 deletions build/test_new_build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import os
import sys
sys.path.append(os.path.abspath('lib'))
from tools import OSZoomStack, Splitter, Mkgmap, GetMaxOSMID, OSMMerge, OSMSort


zoomstack_destination='./build/data/zoomstack'
extract_bbox = [134340, 20297, 407049, 164276]
osm_output = './build/data/great-britain-latest.osm.pbf'
output_dir = './build/output'
splitter_dir = './build/splitter'
styles_dir = './style/mkgmap_styles'
typ_file = './style/typ_files/mkgmap-typ-files/bikepack.txt'
precomp_sea = './build/data/sea/sea-latest.zip'
bounds = './build/data/bounds/bounds-latest.zip'
merged_output = f'{output_dir}/merged.osm.pbf'

sorted_output='/opt/dev/bikepackmaps/build/data/bikepack_osm_sorted.osm.pbf'
# Split the file up into tiles for processing and then create the map
splitter = Splitter(output_dir=splitter_dir,
input_file=sorted_output,
num_tiles=10
)
splitter.run()

# make_map = Mkgmap(
# style_file=styles_dir,
# style='bikepack',
# gmapsupp=None,
# output_dir=f'{output_dir}/Garmin',
# typ_file=typ_file,
# keep_going=None,
# split_name_index=None,
# merge_lines=None,
# index=None,
# nsis=None,
# draw_priority='31',
# location_autofill='is_in,nearest',
# generate_sea=None,
# precomp_sea=precomp_sea,
# bounds=bounds,
# # Note well that this has to be the last argument otherwise all those before it are ignored
# read_config=f'{splitter_dir}/template.args',)
#
# make_map.run()
2 changes: 1 addition & 1 deletion docs/prototyping.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Manual process

```bash
ogr2ogr -f GPKG contours.gpkg OS_Open_Zoomstack.gpkg contours
ogr2ogr -f GPKG contours.gpkg OS_Open_Zoomstack.gpkg contours -progress -nlt Linestring
python build/get_max_id.py /Volumes/Extreme\ Pro/mapping_data/osm/great-britain-latest.osm.pbf
ogr2osm /Volumes/Extreme\ Pro/mapping_data/zoomstack/contours.gpkg -f --pbf --no-memory-copy -e 27700 -o /Volumes/Extreme\ Pro/mapping_data/zoomstack/contours.osm.pbf -t translations/bikepack_translator.py --id 11571092201
```
Expand Down
30 changes: 30 additions & 0 deletions lib/scripts/make_contours_osm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash

# Path to your input geopackage
input_geopackage="/opt/data/zoomstack/contours.gpkg"

# Path to the generated grid shapefile
grid_shapefile="/opt/data/zoomstack/uk_grid_50x50km.gpkg"

# Output directory for the split geopackages
output_dir="/opt/data/zoomstack/osm_contours"
docker_dir="/app/data/zoomstack/osm_contours"
COUNTER=0

# Read each feature (grid cell) from the grid shapefile
ogrinfo -al ${grid_shapefile} | grep POLYGON | while read feature_id; do
let COUNTER++
# Define the output filename based on the feature ID
output_geopackage="${output_dir}/contour_${COUNTER}.gpkg"
input_osm="${docker_dir}/contour_${COUNTER}.gpkg"
output_osm="${docker_dir}/contour_${COUNTER}.osm.pbf"

# Use ogr2ogr to clip the input geopackage by the current grid cell and output to a new geopackage
#echo "ogr2ogr -f GPKG ${output_geopackage} ${input_geopackage} -progress -clipsrc '${feature_id}'"
ogr2ogr -f GPKG ${output_geopackage} ${input_geopackage} -nlt LINESTRING -progress -clipsrc "${feature_id}" -skipfailures -makevalid

# Use ogr2osm to make the final output file
echo "Starting with : $(cat /opt/data/zoomstack/idfile)"
docker run --rm -v /opt/:/app roelderickx/ogr2osm ${input_osm} -f --pbf -o ${output_osm} -t /app/dev/bikepackmaps/translations/bikepack_translator.py --positive-id --idfile /app/data/zoomstack/idfile --saveid /app/data/zoomstack/idfile
echo "Ending with : $(cat /opt/data/zoomstack/idfile)"
done
25 changes: 25 additions & 0 deletions lib/scripts/merge_osm_contours.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

# Define the directory containing the .pbf files
input_directory="osm_contours"

# Directory for sorted files
sorted_directory="sorted_files"
mkdir -p "$sorted_directory"

# Sort each .pbf file in the input directory
for input_file in "$input_directory"/*.pbf; do
filename=$(basename "$input_file")
sorted_file="$sorted_directory/sorted_$filename"
echo "Sorting file $filename..."
osmium sort "$input_file" --overwrite -o "$sorted_file"
done

echo "All files sorted."

# Merge sorted files
output_file="merged_contours.osm.pbf"
sorted_files=$(ls "$sorted_directory"/*.osm.pbf)
osmium merge $sorted_files --overwrite -o "$output_file"
osmium sort $output_file --overwrite -o "sorted_$output_file"
echo "Merge completed. Output file: sorted_$output_file"

0 comments on commit f087093

Please sign in to comment.