├── .gitignore ├── example └── US5OH10M │ ├── US5OH10A.TXT │ ├── US5OH10M.000 │ ├── US5OH10C.TXT │ ├── US5OH10D.TXT │ ├── US5OH10B.TXT │ └── US5OH10E.TXT ├── Dockerfile ├── LICENSE ├── README.md └── cli.py /.gitignore: -------------------------------------------------------------------------------- 1 | output_geojson 2 | output_mbtiles -------------------------------------------------------------------------------- /example/US5OH10M/US5OH10A.TXT: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Greenroom-Robotics/enc-mapbox-converter/HEAD/example/US5OH10M/US5OH10A.TXT -------------------------------------------------------------------------------- /example/US5OH10M/US5OH10M.000: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Greenroom-Robotics/enc-mapbox-converter/HEAD/example/US5OH10M/US5OH10M.000 -------------------------------------------------------------------------------- /example/US5OH10M/US5OH10C.TXT: -------------------------------------------------------------------------------- 1 | For bascule bridges, whose spans do not 2 | open to a full upright or vertical position, unlimited 3 | vertical clearance is not available for the entire 4 | charted horizontal clearance. -------------------------------------------------------------------------------- /example/US5OH10M/US5OH10D.TXT: -------------------------------------------------------------------------------- 1 | Administration Area 2 | This area covers land, internal waters, and territorial sea. The territorial sea is a maritime 3 | zone over which the United States exercises sovereignty extending to the airspace as 4 | well as to its bed and subsoil. For more information, please refer to the Coast Pilot. -------------------------------------------------------------------------------- /example/US5OH10M/US5OH10B.TXT: -------------------------------------------------------------------------------- 1 | The military exercise area controlled by the Federal Aviation 2 | Administration. Also, DANGER ZONES (CFR 334.850, Note A), which 3 | are used for ground based exercises, exist within the screened 4 | area. Mariners should use caution and should consult both U.S. 5 | Coast Pilot 6 and the U.S. Coast Guard Local Notice to Mariners. -------------------------------------------------------------------------------- /example/US5OH10M/US5OH10E.TXT: -------------------------------------------------------------------------------- 1 | CAUTION - QUALITY OF BATHYMETRIC DATA 2 | 3 | The areas represented by the object M_QUAL (Quality of data) are approximate due 4 | to generalizing for clarity. Caution is advised, particularly for nearshore navigation 5 | or voyage planning. M_QUAL represents areas of uniform quality of bathymetric 6 | data. The CATZOC (Category of zone of confidence in data) attribute of M_QUAL 7 | provides an assessment of the overall zone of confidence. Channels maintained by 8 | the U.S. Army Corps of Engineers are periodically resurveyed and the quality of data 9 | in these channels has not been assessed. -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:20.04 2 | 3 | ARG DEBIAN_FRONTEND="noninteractive" 4 | 5 | # Install python and deps for gdal 6 | RUN apt-get update 7 | RUN apt-get install -y python3 python3-pip build-essential gdal-bin python3-gdal libgdal-dev wget 8 | RUN echo 'PATH="$HOME/.local/bin/:$PATH"' >>~/.bashrc 9 | RUN pip install "GDAL<=$(gdal-config --version)" 10 | 11 | # Install deps for tippecanoe 12 | RUN apt-get -y install build-essential libsqlite3-dev zlib1g-dev git 13 | RUN git clone https://github.com/mapbox/tippecanoe.git 14 | WORKDIR /tippecanoe 15 | 16 | # Build tippecanoe 17 | RUN make \ 18 | && make install 19 | 20 | # Run the tippecanoe tests 21 | CMD make test 22 | 23 | # Add other python deps 24 | RUN pip install click 25 | 26 | COPY . /app 27 | 28 | WORKDIR /app 29 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | ISC License 2 | 3 | Copyright (c) 2021 Greenroom Robotics Pty Ltd 4 | 5 | Permission to use, copy, modify, and/or distribute this software for any 6 | purpose with or without fee is hereby granted, provided that the above 7 | copyright notice and this permission notice appear in all copies. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH 10 | REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 11 | AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, 12 | INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 13 | LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR 14 | OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 15 | PERFORMANCE OF THIS SOFTWARE. 16 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ENC Mapbox converter 2 | 3 | This tool is used to convert ENC files (S-57) to mbtiles. 4 | 5 | Internally this uses: 6 | 7 | - `enc` to `geojson` using gdal's `ogr2ogr` 8 | - `geojson` to `mbtiles` using mapbox's `tippecanoe` 9 | 10 | ## Requirements 11 | 12 | - Git 13 | - Docker 14 | 15 | ## Usage 16 | 17 | This tool uses a bunch of tools internally so it has been dockerised with a simple cli exposed. 18 | 19 | 1. Clone this repo: 20 | 21 | ```bash 22 | git clone git@github.com:Greenroom-Robotics/enc-mapbox-converter.git 23 | ``` 24 | 25 | 2. Build the docker container 26 | 27 | ```bash 28 | docker build . -t enc-converter 29 | ``` 30 | 31 | 3. Run the cli. Be sure to replace `` 32 | 33 | ```bash 34 | docker run -it -v /$PWD:/app enc-converter python3 cli.py 35 | ``` 36 | 37 | 4. You will be prompted for an input file and output name. For example. 38 | 39 | ``` 40 | Input file path: /app/example/US5OH10M/US5OH10M.000 41 | Output file name: output_mb_tiles_file 42 | 43 | ``` 44 | 45 | 5. Look in `./output_mbtiles` and you will find your `.mbtiles` file! 46 | -------------------------------------------------------------------------------- /cli.py: -------------------------------------------------------------------------------- 1 | from osgeo import ogr 2 | import subprocess 3 | import click 4 | 5 | OGR_S57_OPTIONS = "SPLIT_MULTIPOINT=ON,ADD_SOUNDG_DEPTH=ON" 6 | 7 | DEFAULT_INPUT = "/app/example/US5OH10M/US5OH10M.000" 8 | DEFAULT_OUTPUT = "output_mb_tiles_file" 9 | 10 | 11 | @click.command() 12 | @click.option("--input", prompt="Input file path", default=DEFAULT_INPUT) 13 | @click.option("--output", prompt="Output file name", default=DEFAULT_OUTPUT) 14 | def convert(input=DEFAULT_INPUT, output=DEFAULT_OUTPUT): 15 | input_file = ogr.Open(input, 0) 16 | 17 | # Get the layers in the file 18 | enc_layers = [] 19 | for featsClass_idx in range(input_file.GetLayerCount()): 20 | featsClass = input_file.GetLayerByIndex(featsClass_idx) 21 | enc_layer = featsClass.GetName() 22 | enc_layers.append(enc_layer) 23 | 24 | # Convert them into geojson 25 | geojson_layers = [] 26 | for enc_layer in enc_layers: 27 | print(f"Converting {enc_layer} to geojson...") 28 | geojson_layer = f"./output_geojson/{enc_layer}.geojson" 29 | geojson_layers.append(geojson_layer) 30 | 31 | # Use ogr2ogr to extract geojson from the enc file 32 | subprocess.call( 33 | f"OGR_S57_OPTIONS={OGR_S57_OPTIONS} ogr2ogr -f GeoJSON -t_srs EPSG:4326 {geojson_layer} {input} {enc_layer}", 34 | shell=True, 35 | ) 36 | 37 | geojson_layers_str = " ".join(geojson_layers) 38 | subprocess.call( 39 | f"tippecanoe --output=./output_mbtiles/{output}.mbtiles {geojson_layers_str}", 40 | shell=True, 41 | ) 42 | 43 | 44 | if __name__ == "__main__": 45 | convert() 46 | --------------------------------------------------------------------------------