This is an automated email from the git hooks/post-receive script. sebastic pushed a commit to branch master in repository osmcoastline.
commit 7fc8d8577c5fbbb1ba047dd5f090b6e71184a04e Author: Bas Couwenberg <sebas...@xs4all.nl> Date: Tue Mar 31 23:07:20 2015 +0200 Imported Upstream version 2.0.1 --- .ycm_extra_conf.py | 6 +- CHANGELOG.md | 18 ++++ CMakeLists.txt | 77 +++++++++++++-- README.md | 14 ++- fix-formatting.sh | 7 ++ man/manpage.template | 28 ++++++ man/osmcoastline.md | 110 +++++++++++++++++++++ man/osmcoastline_filter.md | 55 +++++++++++ man/osmcoastline_readmeta.md | 28 ++++++ man/osmcoastline_ways.md | 34 +++++++ osmcoastline_readmeta | 87 ++++++++++++++++ osmcoastline_readmeta.sh | 85 ---------------- runtest.sh.in | 2 +- src/CMakeLists.txt | 20 ++++ .../coastline_handlers.hpp | 9 +- .../coastline_polygons.cpp | 2 +- .../coastline_polygons.hpp | 4 +- coastline_ring.cpp => src/coastline_ring.cpp | 0 coastline_ring.hpp => src/coastline_ring.hpp | 41 +++++--- .../coastline_ring_collection.cpp | 0 .../coastline_ring_collection.hpp | 26 +++-- ogr_include.hpp => src/ogr_include.hpp | 0 options.cpp => src/options.cpp | 39 ++++---- options.hpp => src/options.hpp | 0 osmcoastline.cpp => src/osmcoastline.cpp | 2 +- osmcoastline.hpp => src/osmcoastline.hpp | 0 .../osmcoastline_filter.cpp | 0 osmcoastline_ways.cpp => src/osmcoastline_ways.cpp | 20 ++-- output_database.cpp => src/output_database.cpp | 3 +- output_database.hpp => src/output_database.hpp | 0 output_layers.cpp => src/output_layers.cpp | 15 +-- output_layers.hpp => src/output_layers.hpp | 0 srs.cpp => src/srs.cpp | 0 srs.hpp => src/srs.hpp | 20 +++- stats.hpp => src/stats.hpp | 0 verbose_output.hpp => src/verbose_output.hpp | 3 + taginfo.json | 2 +- 37 files changed, 589 insertions(+), 168 deletions(-) diff --git a/.ycm_extra_conf.py b/.ycm_extra_conf.py index f2f1e01..53b3175 100644 --- a/.ycm_extra_conf.py +++ b/.ycm_extra_conf.py @@ -6,6 +6,10 @@ # #----------------------------------------------------------------------------- +from os.path import realpath, dirname + +basedir = dirname(realpath(__file__)) + # some default flags # for more information install clang-3.2-doc package and # check UsersManual.html @@ -26,7 +30,7 @@ flags = [ 'c++', # libosmium include dirs -'-I../libosmium/include', +'-I%s/../libosmium/include' % basedir, '-I/usr/include/gdal', ] diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..900c06b --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,18 @@ + +# Change Log + +All notable changes to this project will be documented in this file. +This project adheres to [Semantic Versioning](http://semver.org/). + +## [unreleased] - + +## [2.0.1] - 2015-03-31 + +### Changed + +- Added man pages + + +[unreleased]: https://github.com/osmcode/osmium-tool/compare/v2.0.1...HEAD +[2.0.1]: https://github.com/osmcode/osmium-tool/compare/v2.0.0...v2.0.1 + diff --git a/CMakeLists.txt b/CMakeLists.txt index 1bdea83..7d8b573 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,11 +20,13 @@ project(osmcoastline) set(OSMCOASTLINE_VERSION_MAJOR 2) set(OSMCOASTLINE_VERSION_MINOR 0) -set(OSMCOASTLINE_VERSION_PATCH 0) +set(OSMCOASTLINE_VERSION_PATCH 1) set(OSMCOASTLINE_VERSION ${OSMCOASTLINE_VERSION_MAJOR}.${OSMCOASTLINE_VERSION_MINOR}.${OSMCOASTLINE_VERSION_PATCH}) +set(AUTHOR "Jochen Topf <joc...@topf.org>") + #----------------------------------------------------------------------------- # @@ -156,19 +158,69 @@ endif(CPPCHECK) #----------------------------------------------------------------------------- +# +# Optional "man" target to generate man pages +# +#----------------------------------------------------------------------------- +message(STATUS "Looking for pandoc") +find_program(PANDOC pandoc) + +function(add_man_page _section _name) + file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/man/man${_section}) + set(_output_file ${CMAKE_BINARY_DIR}/man/man${_section}/${_name}.${_section}) + set(_source_file ${CMAKE_SOURCE_DIR}/man/${_name}.md) + set(_install_dir "share/man/man{$_section}") + string(TOUPPER ${_name} _name_upcase) + add_custom_command(OUTPUT ${_output_file} + COMMAND ${PANDOC} + ${PANDOC_MAN_OPTIONS} + --variable "title=${_name_upcase}" + --variable "section=${_section}" + -o ${_output_file} + ${_source_file} + DEPENDS ${_source_file} + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + COMMENT "Building manpage ${_name}.${_section}" + VERBATIM) + set(ALL_MAN_PAGES "${ALL_MAN_PAGES};${_output_file}" PARENT_SCOPE) +endfunction() + + +if(PANDOC) + message(STATUS "Looking for pandoc - found") + message(STATUS " Manual pages will be built") + execute_process(COMMAND date "+%Y-%m-%d" OUTPUT_VARIABLE PUBDATE OUTPUT_STRIP_TRAILING_WHITESPACE) + set(PANDOC_MAN_OPTIONS + -s + -t man + --template ${CMAKE_CURRENT_SOURCE_DIR}/man/manpage.template + --variable "description=osmcoastline/${OSMCOASTLINE_VERSION}" + --variable "date=${PUBDATE}" + --variable "author=${AUTHOR}" + ) + set(PANDOC_HTML_OPTIONS -s -t html) -find_library(GEOS_C_LIBRARIES NAMES geos_c) + add_man_page(1 osmcoastline) + add_man_page(1 osmcoastline_filter) + add_man_page(1 osmcoastline_readmeta) + add_man_page(1 osmcoastline_ways) -add_definitions(${OSMIUM_WARNING_OPTIONS}) + install(DIRECTORY ${CMAKE_BINARY_DIR}/man DESTINATION share) -add_executable(osmcoastline osmcoastline.cpp coastline_ring.cpp coastline_ring_collection.cpp coastline_polygons.cpp output_database.cpp output_layers.cpp srs.cpp options.cpp) -target_link_libraries(osmcoastline ${OSMIUM_IO_LIBRARIES} ${GDAL_LIBRARIES} ${GEOS_C_LIBRARIES}) + add_custom_target(man ALL DEPENDS ${ALL_MAN_PAGES}) +else() + message(STATUS "Looking for pandoc - not found") + message(STATUS " Manual pages will not be built") +endif(PANDOC) -add_executable(osmcoastline_filter osmcoastline_filter.cpp) -target_link_libraries(osmcoastline_filter ${OSMIUM_IO_LIBRARIES}) -add_executable(osmcoastline_ways osmcoastline_ways.cpp osmcoastline.hpp) -target_link_libraries(osmcoastline_ways ${OSMIUM_IO_LIBRARIES} ${GDAL_LIBRARIES}) +#----------------------------------------------------------------------------- + +find_library(GEOS_C_LIBRARIES NAMES geos_c) + +add_definitions(${OSMIUM_WARNING_OPTIONS}) + +add_subdirectory(src) configure_file( ${PROJECT_SOURCE_DIR}/runtest.sh.in @@ -185,6 +237,13 @@ configure_file( ${PROJECT_BINARY_DIR}/coastline_sources.qgs ) +configure_file( + ${PROJECT_SOURCE_DIR}/osmcoastline_readmeta + ${PROJECT_BINARY_DIR}/osmcoastline_readmeta + COPYONLY +) +install(PROGRAMS osmcoastline_readmeta DESTINATION bin) + #----------------------------------------------------------------------------- # diff --git a/README.md b/README.md index 3584893..78bf4b7 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # OSMCoastline -OSMCoastline extracts the coastline from an OSM planet file and assembles all -the pieces into polygons for use in map renderers etc. +OSMCoastline extracts the coastline data from an OSM planet file and assembles +all the pieces into polygons for use in map renderers etc. http://wiki.openstreetmap.org/wiki/OSMCoastline @@ -40,10 +40,16 @@ https://github.com/osmcode/osmcoastline http://www.gaia-gis.it/gaia-sins/ Debian/Ubuntu: sqlite3 +### Pandoc (optional, to build documentation) + + http://johnmacfarlane.net/pandoc/ + Debian/Ubuntu: pandoc + (If pandoc is found by CMake, the manpages will automatically be built.) + ## Building -You'll need all the prerequisites including `libosmium` installed. +You'll need the prerequisites including `libosmium` installed. OSMCoastline uses CMake for building: @@ -138,7 +144,7 @@ directory for some more ways of doing this. The database tables `options` and `meta` contain the command line options used to create the database and some metadata. You can use the script -`osmcoastline_readmeta.sh` to look at them. +`osmcoastline_readmeta` to look at them. ## Steps diff --git a/fix-formatting.sh b/fix-formatting.sh new file mode 100755 index 0000000..41ae193 --- /dev/null +++ b/fix-formatting.sh @@ -0,0 +1,7 @@ +#!/bin/sh +# +# fix-formatting +# + +exec astyle --style=java --indent-namespaces --indent-switches --pad-header --lineend=linux --suffix=none src/*pp + diff --git a/man/manpage.template b/man/manpage.template new file mode 100644 index 0000000..e03becc --- /dev/null +++ b/man/manpage.template @@ -0,0 +1,28 @@ +$if(has-tables)$ +.\"t +$endif$ +.TH "$title$" "$section$" "$date$" "$footer$" "$header$" +$for(header-includes)$ +$header-includes$ +$endfor$ +$for(include-before)$ +$include-before$ +$endfor$ +$body$ +$for(include-after)$ +$include-after$ +$endfor$ +$if(author)$ +.SH COPYRIGHT +.PP +Copyright (C) 2012\-2015 Jochen Topf <joc...@topf.org>. +License GPLv3+: GNU GPL version 3 or later +<http://gnu.org/licenses/gpl.html>. +This is free software: you are free to change and redistribute it. +There is NO WARRANTY, to the extent permitted by law. +.SH CONTACT +.PP +http://osmcode.org/contact.html +.SH AUTHORS +$for(author)$$author$$sep$; $endfor$. +$endif$ diff --git a/man/osmcoastline.md b/man/osmcoastline.md new file mode 100644 index 0000000..275e3a7 --- /dev/null +++ b/man/osmcoastline.md @@ -0,0 +1,110 @@ + +# NAME + +osmcoastline - extract coastline from OSM data + + +# SYNOPSIS + +**osmcoastline** \[*OPTIONS*\] --output=*OUTPUT-DB* *INPUT-FILE* + + +# DESCRIPTION + +**osmcoastline** extracts the coastline data from the *INPUT-FILE*, ususally +a planet file (or the output of the **osmcoastline_filter** program, see below) +and assembles all the pieces into polygons for use in map renderers etc. + +The output is written to the Spatialite database *OUTPUT-DB*. Depending on the +options it will contains the coastlines in different formats. See the +description of the options below and the README.md for details. + + +# OPTIONS + +-h, --help +: Display usage information. + +-b, --bbox-overlap=OVERLAP +: Polygons that are too large are split into two halves (recursively if need + be). Where the polygons touch the OVERLAP is added, because two polygons + just touching often lead to rendering problems. The value is given in the + units used for the projection (for WGS84 (4326) this is in degrees, for + Mercator (3857) this is in meters). If this is set too small you might get + rendering artefacts where polygons touch. The larger you set this the + larger the output polygons will be. The best values depend on the map scale + or zoom level you are preparing the data for. Disable the overlap by + setting it to 0. Default is 0.0001 for WGS84 and 10 for Mercator. + +-c, --close-distance=DISTANCE +: **osmcoastline** assembles ways tagged `natural=coastline` into rings. + Sometimes there is a gap in the coastline in the OSM data. OSMCoastline + will close this gap if it is smaller than DISTANCE. Use 0 to disable this + feature. + +-d, --debug +: Enable debugging output. + +-f, --overwrite +: Overwrite output file if it already exists. + +-i, --no-index +: Do not create spatial indexes in output db. The default is to create those + indexes which makes the database larger, but the data is faster to use. + +-l, --output-lines +: Output coastlines as lines to database file. + +-m, --max-points=NUM +: Set this to 0 to prevent splitting of large polygons and linestrings. If + set to any other positive integer **osmcoastline** will try to split + polygons/linestrings to not have more than this many points. Depending on + the overlap defined with **-b** and the shape of the polygons it is + sometimes not possible to get the polygons small enough. **osmcoastline** + will warn you on STDERR if this is the case. Default is 1000. + +-o, --output=FILE +: Spatialite database file for output. This option must be set. + +-p, --output-polygons=land|water|both|none +: Which polygons to write out (default: land). + +-r, --output-rings +: Output rings to database file. This is used for debugging purposes. + +-s, --srs=EPSGCODE +: Set spatial reference system/projection. Use 4326 for WGS84 or 3857 for + "Google Mercator". If you want to use the data for the usual tiled web + maps, 3857 is probably right. For other uses, especially if you want to + re-project to some other projection, 4326 is probably right. Other + projections are curently not supported. Default is 4326. + +-v, --verbose +: Gives you detailed information on what **osmcoastline** is doing, + including timing. + + +# NOTES + +To speed up processing you might want to run the **osmcoastline_filter** +program first. See its man page for details. + + +# EXAMPLES + +Run **osmcoastline** on a planet file using default options: + + osmcoastline -o coastline.db planet.osm.pbf + +Running **osmcoastline_filter** first: + + osmcoastline_filter -o coastline.osm.pbf planet.osm.pbf + osmcoastline -o coastline.db coastline.osm.pbf + + +# SEE ALSO + +* `README.md` +* **osmcoastline_filter**(1), **osmcoastline_readmeta**(1), **osmcoastline_ways**(1) +* [OSMCoastline in OSM wiki](http://wiki.openstreetmap.org/wiki/OSMCoastline) + diff --git a/man/osmcoastline_filter.md b/man/osmcoastline_filter.md new file mode 100644 index 0000000..edc1219 --- /dev/null +++ b/man/osmcoastline_filter.md @@ -0,0 +1,55 @@ + +# NAME + +osmcoastline_filter - filter coastline data from OSM file + + +# SYNOPSIS + +**osmcoastline_filter** --output=*OUTPUT_FILE* *INPUT-FILE* + +**osmcoastline_filter** --help + + +# DESCRIPTION + +**osmcoastline_filter** is used to filter all nodes and ways needed for +building the coastlines from an OSM planet. The data is written to the +output file in PBF format. + +This output file will be a lot smaller (less than 1%) than the original planet +file, but it contains everything needed to assemble the coastline polygons. + +If you are playing around or want to run **osmcoastline** several times with +different parameters, run **osmcoastline_filter** once first and use its output +as the input for **osmcoastline**. + +**osmcoastline_filter** can read PBF and XML files, but write only PBF files. +PBF files are much smaller and faster to read and write than XML files. The +output file will first contain all ways tagged "natural=coastline", then all +nodes used for those ways (and all nodes tagged "natural=coastline"). Having +the ways first and the nodes later in the file is unusual for OSM files, but +the **osmcoastline** and **osmcoastline_ways** programs work fine with it. + + +# OPTIONS + +-h, --help +: Display usage information + +-o, --output=OSMFILE +: Where to write output (default: none) + + +# EXAMPLES + +Run it as follows: + + osmcoastline_filter -o coastline-data.osm.pbf planet.osm.pbf + + +# SEE ALSO + +* **osmcoastline**(1), **osmcoastline_ways**(1) +* [OSMCoastline in OSM wiki](http://wiki.openstreetmap.org/wiki/OSMCoastline) + diff --git a/man/osmcoastline_readmeta.md b/man/osmcoastline_readmeta.md new file mode 100644 index 0000000..e096179 --- /dev/null +++ b/man/osmcoastline_readmeta.md @@ -0,0 +1,28 @@ + +# NAME + +osmcoastline_readmeta - display metadata from database create by osmcoastline + + +# SYNOPSIS + +**osmcoastline_readmeta** \[*COASTLINE-DB*\] + + +# DESCRIPTION + +This program displays various meta data from a database created by the +**osmcoastline** program. + +If no database name is specified on the command line "testdata.db" is used. + +Displayed are the command line options used to create the database, some +statistics about the coastline, the number of warnings and errors detected +and more. + + +# SEE ALSO + +* **osmcoastline**(1) +* [OSMCoastline in OSM wiki](http://wiki.openstreetmap.org/wiki/OSMCoastline) + diff --git a/man/osmcoastline_ways.md b/man/osmcoastline_ways.md new file mode 100644 index 0000000..8ec3b25 --- /dev/null +++ b/man/osmcoastline_ways.md @@ -0,0 +1,34 @@ + +# NAME + +osmcoastline_ways - extract coastline ways from OSM data + + +# SYNOPSIS + +**osmcoastline_ways** *INPUT-FILE* \[*OUTPUT-DB*\] + + +# DESCRIPTION + +**osmcoastline_ways** extracts coastline ways from OSM data and writes them +into a Spatialite database. The output data is meant for debugging and +statistics. Use the **osmcoastline** program to assemble coastlines for +"real" use. + +You have to run **osmcoastline_ways** on the output of the +**osmcoastline_filter** program, otherwise it will not work correctly! + +The data is written to the Spatialite database *OUTPUT-DB*. If *OUTPUT-DB* is +not set, the default "coastline-ways.db" is used. A single table "ways" is +written. It contains the IDs of all ways, their geometries, and the contents +of their "name" and "source" tags. + +**osmcoastline_ways** outputs the sum of all way lengths. + + +# SEE ALSO + +* **osmcoastline**(1), **osmcoastline_filter**(1) +* [OSMCoastline in OSM wiki](http://wiki.openstreetmap.org/wiki/OSMCoastline) + diff --git a/osmcoastline_readmeta b/osmcoastline_readmeta new file mode 100755 index 0000000..f1478b3 --- /dev/null +++ b/osmcoastline_readmeta @@ -0,0 +1,87 @@ +#!/bin/sh +# +# osmcoastline_readmeta [COASTLINEDB] +# + +SQLEXEC="sqlite3" + +if [ "x$1" = "x" ]; then + DBFILE=testdata.db +else + DBFILE=$1 +fi + +if [ ! -e $DBFILE ]; then + echo "Can't open '$DBFILE'" + exit 1 +fi + +echo "Options used to create this data:\n" + +echo -n " Overlap (--bbox-overlap/-b): " +$SQLEXEC $DBFILE "SELECT overlap FROM options;" + +echo -n " Close gaps in coastline smaller than (--close-distance/-c): " +$SQLEXEC $DBFILE "SELECT close_distance FROM options;" + +echo -n " Max points in polygons (--max-points/-m): " +$SQLEXEC $DBFILE "SELECT max_points_in_polygons FROM options;" + +echo -n " Split large polygons: " +$SQLEXEC $DBFILE "SELECT CASE split_large_polygons WHEN 0 THEN 'no' ELSE 'yes' END FROM options;" + +echo -n " Spatial reference system (--srid/-s): " +$SQLEXEC $DBFILE "SELECT CASE srid WHEN 4326 THEN '4326 (WGS84)' WHEN 3857 THEN '3857 (Mercator)' ELSE srid END FROM geometry_columns WHERE f_table_name='land_polygons';" + +echo "\nMetadata:\n" + +echo -n " Database created at: " +$SQLEXEC $DBFILE "SELECT timestamp FROM meta;" + +echo -n " Runtime (minutes): " +$SQLEXEC $DBFILE "SELECT CAST(round(CAST(runtime AS REAL)/60) AS INT) FROM meta;" + +echo -n " Memory usage (MB): " +$SQLEXEC $DBFILE "SELECT memory_usage FROM meta;" + +echo -n " Ways tagged natural=coastline: " +$SQLEXEC $DBFILE "SELECT num_ways FROM meta;" + +echo -n " Number of nodes where coastline is not closed (before fixing): " +$SQLEXEC $DBFILE "SELECT num_unconnected_nodes FROM meta;" + +echo -n " Coastline rings: " +$SQLEXEC $DBFILE "SELECT num_rings FROM meta;" + +echo -n " Coastline rings created from a single way: " +$SQLEXEC $DBFILE "SELECT num_rings_from_single_way FROM meta;" + +echo -n " Coastline rings created from more then one way: " +$SQLEXEC $DBFILE "SELECT num_rings - num_rings_from_single_way FROM meta;" + +echo -n " Number of rings fixed (closed): " +$SQLEXEC $DBFILE "SELECT num_rings_fixed FROM meta;" + +echo -n " Number of rings turned around: " +$SQLEXEC $DBFILE "SELECT num_rings_turned_around FROM meta;" + +echo -n " Number of land polygons before split: " +$SQLEXEC $DBFILE "SELECT num_land_polygons_before_split FROM meta;" + +echo -n " Number of land polygons after split: " +$SQLEXEC $DBFILE "SELECT CASE num_land_polygons_after_split WHEN 0 THEN 'NOT SPLIT' ELSE num_land_polygons_after_split END FROM meta;" + +echo "\nErrors/warnings (Points):\n" +echo ".width 3 20\nSELECT count(*), error FROM error_points GROUP BY error;" | $SQLEXEC -column $DBFILE | sed -e 's/^/ /' + +echo "\nErrors/warnings (LineStrings):\n" +echo ".width 3 20\nSELECT count(*), error FROM error_lines GROUP BY error;" | $SQLEXEC -column $DBFILE | sed -e 's/^/ /' + +echo "\nOutput:\n" +echo "SELECT count(*), 'land_polygons' FROM land_polygons;" | $SQLEXEC -column $DBFILE | sed -e 's/^/ /' +echo "SELECT count(*), 'water_polygons' FROM water_polygons;" | $SQLEXEC -column $DBFILE | sed -e 's/^/ /' +echo "SELECT count(*), 'lines' FROM lines;" | $SQLEXEC -column $DBFILE | sed -e 's/^/ /' +echo "SELECT count(*), 'rings' FROM rings;" | $SQLEXEC -column $DBFILE | sed -e 's/^/ /' + +echo + diff --git a/osmcoastline_readmeta.sh b/osmcoastline_readmeta.sh deleted file mode 100755 index 14f04be..0000000 --- a/osmcoastline_readmeta.sh +++ /dev/null @@ -1,85 +0,0 @@ -#!/bin/sh -# -# osmcoastline_readmeta.sh [COASTLINEDB] -# - -if [ "x$1" = "x" ]; then - DBFILE=testdata.db -else - DBFILE=$1 -fi - -if [ ! -e $DBFILE ]; then - echo "Can't open '$DBFILE'" - exit 1 -fi - -echo "Options used to create this data:\n" - -echo -n " Overlap (--bbox-overlap/-b): " -sqlite3 $DBFILE "SELECT overlap FROM options;" - -echo -n " Close gaps in coastline smaller than (--close-distance/-c): " -sqlite3 $DBFILE "SELECT close_distance FROM options;" - -echo -n " Max points in polygons (--max-points/-m): " -sqlite3 $DBFILE "SELECT max_points_in_polygons FROM options;" - -echo -n " Split large polygons: " -sqlite3 $DBFILE "SELECT CASE split_large_polygons WHEN 0 THEN 'no' ELSE 'yes' END FROM options;" - -echo -n " Spatial reference system (--srid/-s): " -sqlite3 $DBFILE "SELECT CASE srid WHEN 4326 THEN '4326 (WGS84)' WHEN 3857 THEN '3857 (Mercator)' ELSE srid END FROM geometry_columns WHERE f_table_name='land_polygons';" - -echo "\nMetadata:\n" - -echo -n " Database created at: " -sqlite3 $DBFILE "SELECT timestamp FROM meta;" - -echo -n " Runtime (minutes): " -sqlite3 $DBFILE "SELECT CAST(round(CAST(runtime AS REAL)/60) AS INT) FROM meta;" - -echo -n " Memory usage (MB): " -sqlite3 $DBFILE "SELECT memory_usage FROM meta;" - -echo -n " Ways tagged natural=coastline: " -sqlite3 $DBFILE "SELECT num_ways FROM meta;" - -echo -n " Number of nodes where coastline is not closed (before fixing): " -sqlite3 $DBFILE "SELECT num_unconnected_nodes FROM meta;" - -echo -n " Coastline rings: " -sqlite3 $DBFILE "SELECT num_rings FROM meta;" - -echo -n " Coastline rings created from a single way: " -sqlite3 $DBFILE "SELECT num_rings_from_single_way FROM meta;" - -echo -n " Coastline rings created from more then one way: " -sqlite3 $DBFILE "SELECT num_rings - num_rings_from_single_way FROM meta;" - -echo -n " Number of rings fixed (closed): " -sqlite3 $DBFILE "SELECT num_rings_fixed FROM meta;" - -echo -n " Number of rings turned around: " -sqlite3 $DBFILE "SELECT num_rings_turned_around FROM meta;" - -echo -n " Number of land polygons before split: " -sqlite3 $DBFILE "SELECT num_land_polygons_before_split FROM meta;" - -echo -n " Number of land polygons after split: " -sqlite3 $DBFILE "SELECT CASE num_land_polygons_after_split WHEN 0 THEN 'NOT SPLIT' ELSE num_land_polygons_after_split END FROM meta;" - -echo "\nErrors/warnings (Points):\n" -echo ".width 3 20\nSELECT count(*), error FROM error_points GROUP BY error;" | sqlite3 -column $DBFILE | sed -e 's/^/ /' - -echo "\nErrors/warnings (LineStrings):\n" -echo ".width 3 20\nSELECT count(*), error FROM error_lines GROUP BY error;" | sqlite3 -column $DBFILE | sed -e 's/^/ /' - -echo "\nOutput:\n" -echo "SELECT count(*), 'land_polygons' FROM land_polygons;" | sqlite3 -column $DBFILE | sed -e 's/^/ /' -echo "SELECT count(*), 'water_polygons' FROM water_polygons;" | sqlite3 -column $DBFILE | sed -e 's/^/ /' -echo "SELECT count(*), 'lines' FROM lines;" | sqlite3 -column $DBFILE | sed -e 's/^/ /' -echo "SELECT count(*), 'rings' FROM rings;" | sqlite3 -column $DBFILE | sed -e 's/^/ /' - -echo - diff --git a/runtest.sh.in b/runtest.sh.in index bb92c6d..acd4a4e 100755 --- a/runtest.sh.in +++ b/runtest.sh.in @@ -4,5 +4,5 @@ if [ "x$1" = "x-v" ]; then osmcoastline_valgrind="valgrind --leak-check=full --show-reachable=yes" fi -exec $osmcoastline_valgrind ./osmcoastline --debug --verbose --overwrite --output-lines --output-polygons=both --output-rings -o testdata.db @PROJECT_SOURCE_DIR@/testdata.osm +exec $osmcoastline_valgrind src/osmcoastline --debug --verbose --overwrite --output-lines --output-polygons=both --output-rings -o testdata.db @PROJECT_SOURCE_DIR@/testdata.osm diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..93f2d6b --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,20 @@ +#----------------------------------------------------------------------------- +# +# CMake Config +# +# OSMCoastline +# +#----------------------------------------------------------------------------- + +add_executable(osmcoastline osmcoastline.cpp coastline_ring.cpp coastline_ring_collection.cpp coastline_polygons.cpp output_database.cpp output_layers.cpp srs.cpp options.cpp) +target_link_libraries(osmcoastline ${OSMIUM_IO_LIBRARIES} ${GDAL_LIBRARIES} ${GEOS_C_LIBRARIES}) +install(TARGETS osmcoastline DESTINATION bin) + +add_executable(osmcoastline_filter osmcoastline_filter.cpp) +target_link_libraries(osmcoastline_filter ${OSMIUM_IO_LIBRARIES}) +install(TARGETS osmcoastline_filter DESTINATION bin) + +add_executable(osmcoastline_ways osmcoastline_ways.cpp osmcoastline.hpp) +target_link_libraries(osmcoastline_ways ${OSMIUM_IO_LIBRARIES} ${GDAL_LIBRARIES}) +install(TARGETS osmcoastline_ways DESTINATION bin) + diff --git a/coastline_handlers.hpp b/src/coastline_handlers.hpp similarity index 96% rename from coastline_handlers.hpp rename to src/coastline_handlers.hpp index f6a9d24..2eeca6f 100644 --- a/coastline_handlers.hpp +++ b/src/coastline_handlers.hpp @@ -22,6 +22,9 @@ */ +#include <iostream> +#include <utility> + #include <osmium/handler.hpp> #include <osmium/geom/ogr.hpp> @@ -40,8 +43,7 @@ class CoastlineHandlerPass1 : public osmium::handler::Handler { public: CoastlineHandlerPass1(CoastlineRingCollection& coastline_rings) : - m_coastline_rings(coastline_rings) - { + m_coastline_rings(coastline_rings) { } void way(const osmium::Way& way) { @@ -82,8 +84,7 @@ public: CoastlineHandlerPass2(CoastlineRingCollection& coastline_rings, OutputDatabase& output) : m_coastline_rings(coastline_rings), m_posmap(), - m_output(output) - { + m_output(output) { m_coastline_rings.setup_positions(m_posmap); } diff --git a/coastline_polygons.cpp b/src/coastline_polygons.cpp similarity index 99% rename from coastline_polygons.cpp rename to src/coastline_polygons.cpp index 8f472a7..8094327 100644 --- a/coastline_polygons.cpp +++ b/src/coastline_polygons.cpp @@ -315,7 +315,7 @@ void CoastlinePolygons::split_bbox(OGREnvelope e, polygon_vector_type&& v) { break; } } - } catch(...) { + } catch (...) { std::cerr << "ignoring exception\n"; } } else { diff --git a/coastline_polygons.hpp b/src/coastline_polygons.hpp similarity index 98% rename from coastline_polygons.hpp rename to src/coastline_polygons.hpp index 8b39b39..7d7e8a4 100644 --- a/coastline_polygons.hpp +++ b/src/coastline_polygons.hpp @@ -92,7 +92,9 @@ public: } /// Number of polygons - int num_polygons() const { return m_polygons.size(); } + int num_polygons() const { + return m_polygons.size(); + } polygon_vector_type::const_iterator begin() const { return m_polygons.begin(); diff --git a/coastline_ring.cpp b/src/coastline_ring.cpp similarity index 100% rename from coastline_ring.cpp rename to src/coastline_ring.cpp diff --git a/coastline_ring.hpp b/src/coastline_ring.hpp similarity index 89% rename from coastline_ring.hpp rename to src/coastline_ring.hpp index 80f3c29..e930b7a 100644 --- a/coastline_ring.hpp +++ b/src/coastline_ring.hpp @@ -24,6 +24,8 @@ #include <map> #include <memory> +#include <ostream> +#include <vector> #include <osmium/geom/ogr.hpp> #include <osmium/osm/undirected_segment.hpp> @@ -91,8 +93,7 @@ public: m_ring_id(way.id()), m_nways(1), m_fixed(false), - m_outer(false) - { + m_outer(false) { m_way_node_list.reserve(way.is_closed() ? way.nodes().size() : 1000); m_way_node_list.insert(m_way_node_list.begin(), way.nodes().begin(), way.nodes().end()); } @@ -106,19 +107,29 @@ public: } /// ID of first node in the ring. - osmium::object_id_type first_node_id() const { return m_way_node_list.front().ref(); } + osmium::object_id_type first_node_id() const { + return m_way_node_list.front().ref(); + } /// ID of last node in the ring. - osmium::object_id_type last_node_id() const { return m_way_node_list.back().ref(); } + osmium::object_id_type last_node_id() const { + return m_way_node_list.back().ref(); + } /// Position of the first node in the ring. - osmium::Location first_position() const { return m_way_node_list.front().location(); } + osmium::Location first_position() const { + return m_way_node_list.front().location(); + } /// Position of the last node in the ring. - osmium::Location last_position() const { return m_way_node_list.back().location(); } + osmium::Location last_position() const { + return m_way_node_list.back().location(); + } /// Return ID of this ring (defined as smallest ID of the ways making up the ring). - osmium::object_id_type ring_id() const { return m_ring_id; } + osmium::object_id_type ring_id() const { + return m_ring_id; + } /** * Set ring ID. The ring will only get the new ID if it is smaller than the @@ -131,16 +142,24 @@ public: } /// Returns the number of ways making up this ring. - unsigned int nways() const { return m_nways; } + unsigned int nways() const { + return m_nways; + } /// Returns the number of points in this ring. - unsigned int npoints() const { return m_way_node_list.size(); } + unsigned int npoints() const { + return m_way_node_list.size(); + } /// Returns true if the ring is closed. - bool is_closed() const { return first_node_id() == last_node_id(); } + bool is_closed() const { + return first_node_id() == last_node_id(); + } /// Was this ring fixed because of missing/wrong OSM data? - bool is_fixed() const { return m_fixed; } + bool is_fixed() const { + return m_fixed; + } /** * When there are two different nodes with the same position diff --git a/coastline_ring_collection.cpp b/src/coastline_ring_collection.cpp similarity index 100% rename from coastline_ring_collection.cpp rename to src/coastline_ring_collection.cpp diff --git a/coastline_ring_collection.hpp b/src/coastline_ring_collection.hpp similarity index 87% rename from coastline_ring_collection.hpp rename to src/coastline_ring_collection.hpp index 42d7eef..09502a8 100644 --- a/coastline_ring_collection.hpp +++ b/src/coastline_ring_collection.hpp @@ -23,6 +23,8 @@ */ #include <list> +#include <map> +#include <memory> #include <vector> #include <osmium/geom/ogr.hpp> @@ -65,7 +67,9 @@ public: CoastlineRingCollection(); /// Return the number of CoastlineRings in the collection. - size_t size() const { return m_list.size(); } + size_t size() const { + return m_list.size(); + } /** * Add way to collection. A new CoastlineRing will be created for the way @@ -81,13 +85,21 @@ public: } } - unsigned int num_ways() const { return m_ways; } + unsigned int num_ways() const { + return m_ways; + } - unsigned int num_rings_from_single_way() const { return m_rings_from_single_way; } + unsigned int num_rings_from_single_way() const { + return m_rings_from_single_way; + } - unsigned int num_unconnected_nodes() const { return m_start_nodes.size() + m_end_nodes.size(); } + unsigned int num_unconnected_nodes() const { + return m_start_nodes.size() + m_end_nodes.size(); + } - unsigned int num_fixed_rings() const { return m_fixed_rings; } + unsigned int num_fixed_rings() const { + return m_fixed_rings; + } void setup_positions(posmap_type& posmap); @@ -124,7 +136,9 @@ private: } // Used in std::sort - static bool sort_by_distance(const Connection& a, const Connection& b) { return a.distance > b.distance; } + static bool sort_by_distance(const Connection& a, const Connection& b) { + return a.distance > b.distance; + } }; diff --git a/ogr_include.hpp b/src/ogr_include.hpp similarity index 100% rename from ogr_include.hpp rename to src/ogr_include.hpp diff --git a/options.cpp b/src/options.cpp similarity index 79% rename from options.cpp rename to src/options.cpp index ae99b0d..339c56d 100644 --- a/options.cpp +++ b/src/options.cpp @@ -45,8 +45,7 @@ Options::Options(int argc, char* argv[]) : epsg(4326), simplify(false), tolerance(0), - verbose(false) -{ + verbose(false) { static struct option long_options[] = { {"bbox-overlap", required_argument, 0, 'b'}, {"close-distance", required_argument, 0, 'c'}, @@ -175,23 +174,23 @@ int Options::get_epsg(const char* text) { void Options::print_help() const { std::cout << "osmcoastline [OPTIONS] OSMFILE\n" - << "\nOptions:\n" - << " -h, --help - This help message\n" - << " -c, --close-distance=DIST - Distance between nodes under which open rings\n" - << " are closed (0 - disable closing of rings)\n" - << " -b, --bbox-overlap=OVERLAP - Set overlap when splitting polygons\n" - << " -i, --no-index - Do not create spatial indexes in output db\n" - << " -d, --debug - Enable debugging output\n" - << " -f, --overwrite - Overwrite output file if it already exists\n" - << " -l, --output-lines - Output coastlines as lines to database file\n" - << " -m, --max-points=NUM - Split lines/polygons with more than this many\n" - << " points (0 - disable splitting)\n" - << " -o, --output-database=FILE - Spatialite database file for output\n" - << " -p, --output-polygons=land|water|both|none\n" - << " - Which polygons to write out (default: land)\n" - << " -r, --output-rings - Output rings to database file\n" - << " -s, --srs=EPSGCODE - Set SRS (4326 for WGS84 (default) or 3857)\n" - << " -v, --verbose - Verbose output\n" - << "\n"; + << "\nOptions:\n" + << " -h, --help - This help message\n" + << " -c, --close-distance=DIST - Distance between nodes under which open rings\n" + << " are closed (0 - disable closing of rings)\n" + << " -b, --bbox-overlap=OVERLAP - Set overlap when splitting polygons\n" + << " -i, --no-index - Do not create spatial indexes in output db\n" + << " -d, --debug - Enable debugging output\n" + << " -f, --overwrite - Overwrite output file if it already exists\n" + << " -l, --output-lines - Output coastlines as lines to database file\n" + << " -m, --max-points=NUM - Split lines/polygons with more than this many\n" + << " points (0 - disable splitting)\n" + << " -o, --output-database=FILE - Spatialite database file for output\n" + << " -p, --output-polygons=land|water|both|none\n" + << " - Which polygons to write out (default: land)\n" + << " -r, --output-rings - Output rings to database file\n" + << " -s, --srs=EPSGCODE - Set SRS (4326 for WGS84 (default) or 3857)\n" + << " -v, --verbose - Verbose output\n" + << "\n"; } diff --git a/options.hpp b/src/options.hpp similarity index 100% rename from options.hpp rename to src/options.hpp diff --git a/osmcoastline.cpp b/src/osmcoastline.cpp similarity index 99% rename from osmcoastline.cpp rename to src/osmcoastline.cpp index cd04804..c63bcfd 100644 --- a/osmcoastline.cpp +++ b/src/osmcoastline.cpp @@ -236,7 +236,7 @@ int main(int argc, char *argv[]) { stats.rings_fixed = coastline_rings.num_fixed_rings(); warnings += coastline_rings.num_fixed_rings(); vout << " Closed " << coastline_rings.num_fixed_rings() << " rings. This left " - << coastline_rings.num_unconnected_nodes() << " nodes where the coastline could not be closed.\n"; + << coastline_rings.num_unconnected_nodes() << " nodes where the coastline could not be closed.\n"; errors += coastline_rings.num_unconnected_nodes(); } else { vout << "Not closing broken rings (because you used the option --close-distance/-c 0).\n"; diff --git a/osmcoastline.hpp b/src/osmcoastline.hpp similarity index 100% rename from osmcoastline.hpp rename to src/osmcoastline.hpp diff --git a/osmcoastline_filter.cpp b/src/osmcoastline_filter.cpp similarity index 100% rename from osmcoastline_filter.cpp rename to src/osmcoastline_filter.cpp diff --git a/osmcoastline_ways.cpp b/src/osmcoastline_ways.cpp similarity index 90% rename from osmcoastline_ways.cpp rename to src/osmcoastline_ways.cpp index c27c28b..35b97ab 100644 --- a/osmcoastline_ways.cpp +++ b/src/osmcoastline_ways.cpp @@ -21,6 +21,7 @@ #include <iostream> #include <set> +#include <string> #include <osmium/geom/haversine.hpp> #include <osmium/geom/ogr.hpp> @@ -46,7 +47,7 @@ class CoastlineWaysHandler : public osmium::handler::Handler { public: - CoastlineWaysHandler() : + CoastlineWaysHandler(const std::string& db_filename) : m_length(0.0) { OGRRegisterAll(); @@ -59,7 +60,7 @@ public: CPLSetConfigOption("OGR_SQLITE_SYNCHRONOUS", "FALSE"); const char* options[] = { "SPATIALITE=TRUE", nullptr }; - m_data_source.reset(driver->CreateDataSource("coastline-ways.db", const_cast<char**>(options))); + m_data_source.reset(driver->CreateDataSource(db_filename.c_str(), const_cast<char**>(options))); if (!m_data_source) { std::cerr << "Creation of output file failed.\n"; exit(return_code_fatal); @@ -139,21 +140,28 @@ public: }; int main(int argc, char* argv[]) { - if (argc != 2) { - std::cerr << "Usage: osmcoastline_ways OSMFILE\n"; + if (argc != 2 && argc != 3) { + std::cerr << "Usage: osmcoastline_ways OSMFILE [WAYSDB]\n"; exit(return_code_cmdline); } + std::string input_osm_filename { argv[1] }; + std::string output_db_filename { "coastline-ways.db" }; + + if (argc >= 3) { + output_db_filename = argv[2]; + } + index_type store_pos; index_type store_neg; node_location_handler_type location_handler(store_pos, store_neg); - osmium::io::File infile(argv[1]); + osmium::io::File infile(input_osm_filename); osmium::io::Reader reader1(infile, osmium::osm_entity_bits::node); osmium::apply(reader1, location_handler); reader1.close(); - CoastlineWaysHandler coastline_ways_handler; + CoastlineWaysHandler coastline_ways_handler(output_db_filename); osmium::io::Reader reader2(infile, osmium::osm_entity_bits::way); osmium::apply(reader2, location_handler, coastline_ways_handler); reader2.close(); diff --git a/output_database.cpp b/src/output_database.cpp similarity index 99% rename from output_database.cpp rename to src/output_database.cpp index 2db050e..87116d3 100644 --- a/output_database.cpp +++ b/src/output_database.cpp @@ -44,8 +44,7 @@ OutputDatabase::OutputDatabase(const std::string& outdb, bool with_index) : m_layer_rings(), m_layer_land_polygons(), m_layer_water_polygons(), - m_layer_lines() -{ + m_layer_lines() { OGRRegisterAll(); const char* driver_name = "SQLite"; diff --git a/output_database.hpp b/src/output_database.hpp similarity index 100% rename from output_database.hpp rename to src/output_database.hpp diff --git a/output_layers.cpp b/src/output_layers.cpp similarity index 99% rename from output_layers.cpp rename to src/output_layers.cpp index b35e024..969eea2 100644 --- a/output_layers.cpp +++ b/src/output_layers.cpp @@ -48,8 +48,7 @@ void Layer::commit() { /***************************************************************/ LayerErrorPoints::LayerErrorPoints(OGRDataSource* data_source, const char** options) : - Layer() -{ + Layer() { m_layer = data_source->CreateLayer("error_points", srs.out(), wkbPoint, const_cast<char**>(options)); if (!m_layer) { std::cerr << "Creating layer 'error_points' failed.\n"; @@ -93,8 +92,7 @@ void LayerErrorPoints::add(OGRPoint* point, const char* error, osmium::object_id /***************************************************************/ LayerErrorLines::LayerErrorLines(OGRDataSource* data_source, const char** options) : - Layer() -{ + Layer() { m_layer = data_source->CreateLayer("error_lines", srs.out(), wkbLineString, const_cast<char**>(options)); if (!m_layer) { std::cerr << "Creating layer 'error_lines' failed.\n"; @@ -138,8 +136,7 @@ void LayerErrorLines::add(OGRLineString* linestring, const char* error, osmium:: /***************************************************************/ LayerRings::LayerRings(OGRDataSource* data_source, const char** options) : - Layer() -{ + Layer() { m_layer = data_source->CreateLayer("rings", srs.out(), wkbPolygon, const_cast<char**>(options)); if (!m_layer) { std::cerr << "Creating layer 'rings' failed.\n"; @@ -269,8 +266,7 @@ void LayerRings::add(OGRPolygon* polygon, int osm_id, int nways, int npoints, bo LayerPolygons::LayerPolygons(OGRDataSource* data_source, const char** options, const char* name) : Layer(), - m_name(name) -{ + m_name(name) { m_layer = data_source->CreateLayer(name, srs.out(), wkbPolygon, const_cast<char**>(options)); if (!m_layer) { std::cerr << "Creating layer '" << name << "' failed.\n"; @@ -298,8 +294,7 @@ void LayerPolygons::add(OGRPolygon* polygon) { /***************************************************************/ LayerLines::LayerLines(OGRDataSource* data_source, const char** options) : - Layer() -{ + Layer() { m_layer = data_source->CreateLayer("lines", srs.out(), wkbLineString, const_cast<char**>(options)); if (!m_layer) { std::cerr << "Creating layer 'lines' failed.\n"; diff --git a/output_layers.hpp b/src/output_layers.hpp similarity index 100% rename from output_layers.hpp rename to src/output_layers.hpp diff --git a/srs.cpp b/src/srs.cpp similarity index 100% rename from srs.cpp rename to src/srs.cpp diff --git a/srs.hpp b/src/srs.hpp similarity index 83% rename from srs.hpp rename to src/srs.hpp index 2f53e89..ff4e530 100644 --- a/srs.hpp +++ b/src/srs.hpp @@ -60,8 +60,12 @@ public: */ bool set_output(int epsg); - OGRSpatialReference* wgs84() { return &m_srs_wgs84; } - OGRSpatialReference* out() { return &m_srs_out; } + OGRSpatialReference* wgs84() { + return &m_srs_wgs84; + } + OGRSpatialReference* out() { + return &m_srs_out; + } /** * Transform geometry to output SRS (if it is not in the output SRS @@ -79,9 +83,15 @@ public: * bogus. They are near the antimeridian or southern edge of the * map and only there to close the coastline polygons. */ - double max_x() const { return m_transform ? 20037500.0 : 179.9999; } - double min_x() const { return m_transform ? -20037500.0 : -179.9999; } - double min_y() const { return m_transform ? -20037400.0 : -85.049; } + double max_x() const { + return m_transform ? 20037500.0 : 179.9999; + } + double min_x() const { + return m_transform ? -20037500.0 : -179.9999; + } + double min_y() const { + return m_transform ? -20037400.0 : -85.049; + } }; diff --git a/stats.hpp b/src/stats.hpp similarity index 100% rename from stats.hpp rename to src/stats.hpp diff --git a/verbose_output.hpp b/src/verbose_output.hpp similarity index 96% rename from verbose_output.hpp rename to src/verbose_output.hpp index 555a592..5284b0b 100644 --- a/verbose_output.hpp +++ b/src/verbose_output.hpp @@ -1,6 +1,9 @@ #ifndef VERBOSE_OUTPUT_HPP #define VERBOSE_OUTPUT_HPP +#include <iostream> +#include <sstream> + class VerboseOutput { time_t m_start; diff --git a/taginfo.json b/taginfo.json index a9eed7b..3360c60 100644 --- a/taginfo.json +++ b/taginfo.json @@ -8,7 +8,7 @@ "doc_url": "https://github.com/osmcode/osmcoastline", "icon_url": "http://osmcode.org/img/logo-osmcoastline-16x16.png", "contact_name": "Jochen Topf", - "contact_email": "joc...@remote.org", + "contact_email": "joc...@topf.org", "keywords": [ "export" ] -- Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-grass/osmcoastline.git _______________________________________________ Pkg-grass-devel mailing list Pkg-grass-devel@lists.alioth.debian.org http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-grass-devel