Commit 085ba3a6 authored by Bas Couwenberg's avatar Bas Couwenberg

Imported Upstream version 0.0~20150306-1f2b90a

parents
*.swp
.ycm_extra_conf.pyc
#-----------------------------------------------------------------------------
#
# Configuration for YouCompleteMe Vim plugin
#
# http://valloric.github.io/YouCompleteMe/
#
#-----------------------------------------------------------------------------
# some default flags
# for more information install clang-3.2-doc package and
# check UsersManual.html
flags = [
'-Werror',
'-Wall',
'-Wextra',
'-pedantic',
'-Wno-return-type',
'-Wno-unused-parameter',
'-Wno-unused-variable',
'-std=c++11',
# '-x' and 'c++' also required
# use 'c' for C projects
'-x',
'c++',
# libosmium include dirs
'-I../libosmium/include',
'-I/usr/include/gdal',
]
# youcompleteme is calling this function to get flags
# You can also set database for flags. Check: JSONCompilationDatabase.html in
# clang-3.2-doc package
def FlagsForFile( filename ):
return {
'flags': flags,
'do_cache': True
}
#-----------------------------------------------------------------------------
#
# CMake Config
#
# OSMCoastline
#
#-----------------------------------------------------------------------------
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
#-----------------------------------------------------------------------------
#
# Project version
#
#-----------------------------------------------------------------------------
project(osmcoastline)
set(OSMCOASTLINE_VERSION_MAJOR 2)
set(OSMCOASTLINE_VERSION_MINOR 0)
set(OSMCOASTLINE_VERSION_PATCH 0)
set(OSMCOASTLINE_VERSION
${OSMCOASTLINE_VERSION_MAJOR}.${OSMCOASTLINE_VERSION_MINOR}.${OSMCOASTLINE_VERSION_PATCH})
#-----------------------------------------------------------------------------
#
# Find external dependencies
#
#-----------------------------------------------------------------------------
find_package(Osmium COMPONENTS io gdal)
include_directories(${OSMIUM_INCLUDE_DIRS})
if(MSVC)
find_path(GETOPT_INCLUDE_DIR getopt.h)
find_library(GETOPT_LIBRARY NAMES wingetopt)
if(GETOPT_INCLUDE_DIR AND GETOPT_LIBRARY)
include_directories(${GETOPT_INCLUDE_DIR})
list(APPEND OSMIUM_LIBRARIES ${GETOPT_LIBRARY})
else()
set(GETOPT_MISSING 1)
endif()
endif()
#-----------------------------------------------------------------------------
#
# Decide which C++ version to use (Minimum/default: C++11).
#
#-----------------------------------------------------------------------------
if(NOT MSVC)
if(NOT USE_CPP_VERSION)
set(USE_CPP_VERSION c++11)
endif()
message(STATUS "Use C++ version: ${USE_CPP_VERSION}")
# following only available from cmake 2.8.12:
# add_compile_options(-std=${USE_CPP_VERSION})
# so using this instead:
add_definitions(-std=${USE_CPP_VERSION})
endif()
#-----------------------------------------------------------------------------
#
# Compiler and Linker flags
#
#-----------------------------------------------------------------------------
if(MSVC)
set(USUAL_COMPILE_OPTIONS "/Ox")
else()
set(USUAL_COMPILE_OPTIONS "-O3 -g")
endif()
if(WIN32)
add_definitions(-DWIN32 -D_WIN32 -DMSWIN32 -DBGDWIN32
-DWINVER=0x0500 -D_WIN32_WINNT=0x0500 -D_WIN32_IE=0x0600)
endif()
set(CMAKE_CXX_FLAGS_DEV "${USUAL_COMPILE_OPTIONS}"
CACHE STRING "Flags used by the compiler during developer builds."
FORCE)
set(CMAKE_EXE_LINKER_FLAGS_DEV ""
CACHE STRING "Flags used by the linker during developer builds."
FORCE)
mark_as_advanced(
CMAKE_CXX_FLAGS_DEV
CMAKE_EXE_LINKER_FLAGS_DEV
)
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${USUAL_COMPILE_OPTIONS}"
CACHE STRING "Flags used by the compiler during RELWITHDEBINFO builds."
FORCE)
#-----------------------------------------------------------------------------
#
# Build Type
#
#-----------------------------------------------------------------------------
set(CMAKE_CONFIGURATION_TYPES "Debug Release RelWithDebInfo MinSizeRel Dev")
# In 'Dev' mode: compile with very strict warnings and turn them into errors.
if(CMAKE_BUILD_TYPE STREQUAL "Dev")
if(NOT MSVC)
add_definitions(-Werror -fno-omit-frame-pointer)
endif()
add_definitions(${OSMIUM_WARNING_OPTIONS})
endif()
# Force RelWithDebInfo build type if none was given
if(CMAKE_BUILD_TYPE)
set(build_type ${CMAKE_BUILD_TYPE})
else()
set(build_type "RelWithDebInfo")
endif()
set(CMAKE_BUILD_TYPE ${build_type}
CACHE STRING
"Choose the type of build, options are: ${CMAKE_CONFIGURATION_TYPES}."
FORCE)
#-----------------------------------------------------------------------------
#
# Optional "cppcheck" target that checks C++ code
#
#-----------------------------------------------------------------------------
message(STATUS "Looking for cppcheck")
find_program(CPPCHECK cppcheck)
if(CPPCHECK)
message(STATUS "Looking for cppcheck - found")
set(CPPCHECK_OPTIONS --enable=all)
# cpp doesn't find system includes for some reason, suppress that report
set(CPPCHECK_OPTIONS ${CPPCHECK_OPTIONS} --suppress=missingIncludeSystem)
file(GLOB ALL_CODE *.cpp)
set(CPPCHECK_FILES ${ALL_CODE})
add_custom_target(cppcheck
${CPPCHECK}
--std=c++11 ${CPPCHECK_OPTIONS}
${CPPCHECK_FILES}
)
else()
message(STATUS "Looking for cppcheck - not found")
message(STATUS " Build target 'cppcheck' will not be available.")
endif(CPPCHECK)
#-----------------------------------------------------------------------------
find_library(GEOS_C_LIBRARIES NAMES geos_c)
add_definitions(${OSMIUM_WARNING_OPTIONS})
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_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})
configure_file(
${PROJECT_SOURCE_DIR}/runtest.sh.in
${PROJECT_BINARY_DIR}/runtest.sh
)
configure_file(
${PROJECT_SOURCE_DIR}/coastline_sqlite.qgs
${PROJECT_BINARY_DIR}/coastline_sqlite.qgs
)
configure_file(
${PROJECT_SOURCE_DIR}/coastline_sources.qgs
${PROJECT_BINARY_DIR}/coastline_sources.qgs
)
#-----------------------------------------------------------------------------
#
# Documentation
#
#-----------------------------------------------------------------------------
add_subdirectory(doc)
#-----------------------------------------------------------------------------
#
# Packaging
#
#-----------------------------------------------------------------------------
set(CPACK_PACKAGE_VERSION_MAJOR ${OSMCOASTLINE_VERSION_MAJOR})
set(CPACK_PACKAGE_VERSION_MINOR ${OSMCOASTLINE_VERSION_MINOR})
set(CPACK_PACKAGE_VERSION_PATCH ${OSMCOASTLINE_VERSION_PATCH})
if(WIN32)
set(CPACK_GENERATOR ZIP)
else()
set(CPACK_GENERATOR TGZ)
endif()
include(CPack)
#-----------------------------------------------------------------------------
This diff is collapsed.
# OSMCoastline
OSMCoastline extracts the coastline from an OSM planet file and assembles all
the pieces into polygons for use in map renderers etc.
http://wiki.openstreetmap.org/wiki/OSMCoastline
https://github.com/osmcode/osmcoastline
## Prerequisites
### Libosmium
http://github.com/osmcode/libosmium
http://osmcode.org/libosmium
### zlib (for PBF support)
http://www.zlib.net/
Debian/Ubuntu: zlib1g-dev
### GDAL (for OGR support)
http://gdal.org/
Debian/Ubuntu: libgdal1-dev
(Must be built with Spatialite and GEOS support which is true for
Debian/Ubuntu packages. You need GDAL 1.7.0 or greater, consider using
https://wiki.ubuntu.com/UbuntuGIS when using Ubuntu to get newer
versions of GIS libraries.)
### GEOS
http://trac.osgeo.org/geos/
Debian/Ubuntu: libgeos-dev
### Sqlite/Spatialite
http://www.gaia-gis.it/gaia-sins/
Debian/Ubuntu: sqlite3
## Building
You'll need all the prerequisites including `libosmium` installed.
OSMCoastline uses CMake for building:
mkdir build
cd build
cmake ..
make
Call `make doc` to build the Doxygen API documentation which will be available
in the `doc/html` directory.
## Testing
Run the script `runtest.sh` from the directory you built the program in. It
will read the supplied `testdata.osm` and create output in the `testdata.db`
spatialite database.
It is normal for this program to create errors and warnings, because it is
testing a rather broken input file. You will get messages such as "Closing
ring between node -84 and node -74" and "Warning 1: Self-intersection
at or near point 7.48488 53.8169". At the end it should print:
There were 35 warnings.
There were 1 errors.
You can use the supplied `coastline_sqlite.qgs` QGIS project file to open the
output with QGIS.
Call `runtest.sh -v` to run the tests under Valgrind.
## Running
Note that you might want to run `osmcoastline_filter` first, see below under
**Filtering**.
Run: `osmcoastline -o DBFILE PLANET-FILE`
For example: `osmcoastline -o coastline.db planet.osm.pbf`
This will create a spatialite database named `DBFILE` and write several tables
with the output into it.
Use `--verbose` to see whats going on. Start with `--help` to see other
options.
## Output
The output is a spatialite database with the following tables. All tables are
always created but depending on the command line options only some of them
might contain anything.
* `error_lines` Lines that have errors (for instance not closed rings or
self-intersections).
* `error_points` Problematic points such as intersections.
* `rings` Coastline rings as linestrings. The table is not populated by default,
because this is only needed for finding errors in the coastline. Use the
command line option `--output-rings` to populate this table.
* `land_polygons` Finished assembled land polygons. Depending on `--max-points`
option this will contain complete or split polygons. Only filled if the
option `--output-polygons=land` (thats the default) or `=both` has been given.
* `water_polygons` Finished assembled water polygons. Only filled if option
`--output-polygons=water` or `=both` has been given.
* `lines` Coastlines as linestrings. Depending on `--max-points` option this
will contain complete or split linestrings. Only filled if the option
`--output-lines` has been given.
By default all output is in WGS84. You can use the option `--srs=3857` to
create output in "Google Mercator". (Other projections are currently not
supported.)
OSMCoastline always creates only this one database. If you need shapefiles
use ogr2ogr to convert the data:
ogr2ogr -f "ESRI Shapefile" land_polygons.shp coastline.db land_polygons
By default geometry indexes are created for all tables. This makes the database
larger, but faster to use. You can use the option `--no-index` to suppress
this, for instance if you never use the data directly anyway but want to
transform it into something else.
Coastlines and polygons are never simplified, but contain the full detail.
See `simplify.sql` for a way to simplify polygons. See the `simplify_and_split`
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.
## Steps
OSMCoastline runs in several steps, each can optionally create some output.
In most cases you will only be interested in the end result but preliminary
results are supplied for debugging or other special uses.
**Step 1**: Filter out all nodes and ways tagged `natural=coastline` and all
nodes needed by those ways. (This can also be done with the
`osmcoastline_filter` program, see below)
**Step 2**: Assemble all coastline ways into rings. Rings that are not closed
in the OSM data will be closed depending on the `--close-distance`
option.
**Step 3**: Assemble polygons from the rings, possibly including holes for
water areas.
**Step 4**: Split up large polygons into smaller ones. The options
`--max-points` and `--bbox-overlap` are used here.
**Step 5**: Create water polygons as the "inverse" of the land polygons.
The errors encountered in each step are written to the `error_points` and
`error_lines` tables.
## Options
-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.
-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.
-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.
-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.
Run `osmcoastline --help` to see all options.
## Return codes
`osmcoastline` uses the following return codes:
0 - OK
1 - Warning
2 - Error
3 - Fatal error (output file could not be opened etc.)
4 - Error parsing command line arguments
The difference between warnings and errors is somewhat muddy. Warnings are
geometry problems that have either been fixed automatically or seem to be
small. Errors are larger problems that couldn't be fixed. If there were errors
you probably do not want to use the generated data but fix the OSM data first.
If there were warnings the data might be okay, but there still could be data
missing or geometry problems such as self-intersections in the coastline. But
the classification of problems into warnings and errors is difficult, so to be
on the safe side you might only want to use the data if there are no warnings
and no errors at all.
## Antarctica
OSMCoastline has special code for the coastline of Antarctica. This is the only
coastline that can remain open. The coastline starts somewhere around 180°
East, 77° South and ends around 180° West and 77° South. OSMCoastline will find
those open ends and connect them by adding several "nodes" forming a proper
polygon. Depending on the output projection (EPSG:4326 or EPSG:3857) this
polygon will either go to the South Pole or to the 85.0511° line.
## Filtering
The program `osmcoastline_filter` can be used to filter from an OSM planet file
all nodes and ways needed for building the coastlines and writing them out in
OSM format. This 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`.
Run it as follows: `osmcoastline_filter -o OUTFILE.osm.pbf INFILE.osm.pbf`
`osmcoastline_filter` can read PBF and XML files, but write only PBF files. PBF
files are much smaller and faster to read and write.
## License
OSMCoastline is available under the GNU GPL version 3 or later.
## Authors
Jochen Topf (jochen@topf.org)
OSMCoastline TODO
=================
* write out statistics to meta table
* make fixing of direction optional?
* only when there are no warnings?
* determine best defaults for bbox overlap, max-points and close distance
* Magic number 100 in split_bbox?
#
# Locate OSMPBF library
#
# This module defines
# OSMPBF_FOUND - if false, do not try to link to OSMPBF
# OSMPBF_LIBRARIES - full library path name
# OSMPBF_INCLUDE_DIRS - where to find OSMPBF.hpp
#
# Note that the expected include convention is
# #include <osmpbf/osmpbf.h>
# and not
# #include <osmpbf.h>
#
find_path(OSMPBF_INCLUDE_DIR osmpbf/osmpbf.h
HINTS $ENV{OSMPBF_DIR}
PATH_SUFFIXES include
PATHS
~/Library/Frameworks
/Library/Frameworks
/usr/local
/usr
/opt/local # DarwinPorts
/opt
)
find_library(OSMPBF_LIBRARY
NAMES osmpbf
HINTS $ENV{OSMPBF_DIR}
PATH_SUFFIXES lib64 lib
PATHS
~/Library/Frameworks
/Library/Frameworks
/usr/local
/usr
/opt/local
/opt
)
# Handle the QUIETLY and REQUIRED arguments and set OSMPBF_FOUND to TRUE if
# all listed variables are TRUE.
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(OSMPBF DEFAULT_MSG OSMPBF_LIBRARY OSMPBF_INCLUDE_DIR)
# Copy the results to the output variables.
if(OSMPBF_FOUND)
set(OSMPBF_INCLUDE_DIRS ${OSMPBF_INCLUDE_DIR})
set(OSMPBF_LIBRARIES ${OSMPBF_LIBRARY})
endif()
This diff is collapsed.
#
# Mapserver configuration
#
# For rendering using this file see render_image.sh.
#
MAP
NAME coastline
IMAGECOLOR 255 255 255
LAYER
NAME polygons
TYPE POLYGON
STATUS ON
CONNECTIONTYPE OGR
CONNECTION "coastline-mapserver.db"
DATA "land_polygons"
CLASS
STYLE
COLOR 0 0 0
END
END
END
END
#ifndef COASTLINE_HANDLERS_HPP
#define COASTLINE_HANDLERS_HPP
/*
Copyright 2012-2015 Jochen Topf <jochen@topf.org>.
This file is part of OSMCoastline.
OSMCoastline is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OSMCoastline is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OSMCoastline. If not, see <http://www.gnu.org/licenses/>.
*/
#include <osmium/handler.hpp>
#include <osmium/geom/ogr.hpp>
#include "coastline_ring_collection.hpp"
#include "output_database.hpp"
/**
* Osmium handler for the first pass over the input file in which
* all ways tagged with 'natural=coastline' are read and CoastlineRings
* are created.
*/
class CoastlineHandlerPass1 : public osmium::handler::Handler {
CoastlineRingCollection& m_coastline_rings;
public:
CoastlineHandlerPass1(CoastlineRingCollection& coastline_rings) :
m_coastline_rings(coastline_rings)
{
}
void way(const osmium::Way& way) {
// We are only interested in ways tagged with natural=coastline.
const char* natural = way.tags().get_value_by_key("natural");
if (natural && !strcmp(natural, "coastline")) {
const char* bogus = way.tags().get_value_by_key("coastline");
if (bogus && !strcmp(bogus, "bogus")) {
return; // ignore bogus coastline in Antarctica
}
m_coastline_rings.add_way(way);
}
}
};
/**
* Osmium handler for the second pass over the input file in which
* node coordinates are added to the CoastlineRings.
*/
class CoastlineHandlerPass2 : public osmium::handler::Handler {
CoastlineRingCollection& m_coastline_rings;
/**
* Multimap for a mapping from node ID to all places where the
* position of this node should be written to. Those places
* are in the CoastlineRings created from the ways. This map
* is set up first thing when the handler is instantiated and
* thereafter used for each node coming in.
*/
posmap_type m_posmap;
OutputDatabase& m_output;
osmium::geom::OGRFactory<> m_factory;
public:
CoastlineHandlerPass2(CoastlineRingCollection& coastline_rings, OutputDatabase& output) :
m_coastline_rings(coastline_rings),
m_posmap(),
m_output(output)
{
m_coastline_rings.setup_positions(m_posmap);
}
void node(const osmium::Node& node) {
const char* natural = node.tags().get_value_by_key("natural");
if (natural && !strcmp(natural, "coastline")) {
try {
m_output.add_error_point(m_factory.create_point(node), "tagged_node", node.id());
} catch (osmium::geometry_error&) {
std::cerr << "Ignoring illegal geometry for node " << node.id() << ".\n";
}
}
std::pair<posmap_type::iterator, posmap_type::iterator> ret = m_posmap.equal_range(node.id());
for (auto it=ret.first; it != ret.second; ++it) {
*(it->second) = node.location();
}
}
};
#endif // COASTLINE_HANDLERS_HPP
This diff is collapsed.
#ifndef COASTLINE_POLYGONS_HPP
#define COASTLINE_POLYGONS_HPP
/*
Copyright 2012-2015 Jochen Topf <jochen@topf.org>.
This file is part of OSMCoastline.
OSMCoastline is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OSMCoastline is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the