├── docs ├── CNAME └── how_to_release.md ├── tools ├── doxygen │ ├── Makefile │ ├── images │ │ └── pgrouting-logo.png │ └── DoxygenLayout.xml ├── initial_commit.txt ├── osmium │ ├── README.md │ ├── restrictions_end.sql │ ├── cmake │ │ ├── FindLibPQXX.cmake │ │ └── FindPostgreSQL.cmake │ ├── restrictions.sql │ ├── include │ │ ├── utilities │ │ │ └── quotes_handling.h │ │ └── collectors │ │ │ └── turn_restrictions.h │ ├── CMakeLists.txt │ └── src │ │ ├── utilities │ │ └── quotes_handling.cpp │ │ └── getrestrictions.cpp ├── data │ └── getdata.sh └── spelling │ ├── typos_whitelist.txt │ └── fix_typos.sh ├── .gitignore ├── AUTHORS.md ├── Vagrantfile ├── include ├── utilities │ ├── handle_pgpass.h │ ├── utilities.h │ ├── prog_options.h │ └── print_progress.h ├── configuration │ ├── tag_value.h │ ├── tag_key.h │ └── configuration.h ├── parser │ ├── ConfigurationParserCallback.h │ ├── OSMDocumentParserCallback.h │ └── XMLParser.h ├── osm_elements │ ├── osm_tag.h │ ├── Relation.h │ ├── osm_element.h │ ├── Node.h │ ├── Way.h │ └── OSMDocument.h └── database │ ├── table_management.h │ └── Export2DB.h ├── mapconfig_for_pedestrian.xml ├── BOOST_LICENSE_1_0.txt ├── mapconfig_for_cars.xml ├── src ├── utilities │ ├── utilities.cpp │ ├── handle_pgpass.cpp │ └── prog_options.cpp ├── osm_elements │ ├── osm_tag.cpp │ ├── Node.cpp │ ├── Relation.cpp │ └── osm_element.cpp ├── configuration │ ├── tag_value.cpp │ ├── tag_key.cpp │ └── configuration.cpp ├── parser │ ├── ConfigurationParserCallback.cpp │ ├── XMLParser.cpp │ └── OSMDocumentParserCallback.cpp └── database │ ├── configuration_config.cpp │ ├── vertices_config.cpp │ ├── osm_relations_config.cpp │ ├── osm_nodes_config.cpp │ ├── osm_ways_config.cpp │ ├── pois_config.cpp │ └── edges_config.cpp ├── cmake ├── FindPQXX.cmake └── FindPostgreSQL.cmake ├── mapconfig.xml ├── CONTRIBUTING.md ├── .github └── workflows │ └── ubuntu.yml ├── mapconfig_for_bicycles.xml ├── CMakeLists.txt ├── README.md ├── CODE_OF_CONDUCT.md └── NEWS /docs/CNAME: -------------------------------------------------------------------------------- 1 | osm.pgrouting.org 2 | -------------------------------------------------------------------------------- /tools/doxygen/Makefile: -------------------------------------------------------------------------------- 1 | all: doxygen 2 | 3 | doxygen: 4 | mkdir -p ../../build/doxy/ 5 | doxygen 6 | -------------------------------------------------------------------------------- /tools/initial_commit.txt: -------------------------------------------------------------------------------- 1 | https://github.com/pgRouting/osm2pgrouting/tree/88372f829877f4c5ed4def7e395ddfd5316944dc 2 | -------------------------------------------------------------------------------- /tools/doxygen/images/pgrouting-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pgRouting/osm2pgrouting/HEAD/tools/doxygen/images/pgrouting-logo.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | bin/* 3 | Sample/* 4 | build 5 | osm2pgrouting 6 | tools/vagrant/packaging.sh 7 | fix_typos 8 | *.o 9 | *.out 10 | *.osm 11 | *.osm.bz2 12 | *.osm.gz 13 | *.tar.gz 14 | *~ 15 | .project 16 | .cproject 17 | .vagrant 18 | run.sh 19 | LOG.txt 20 | .directory 21 | *.swp 22 | -------------------------------------------------------------------------------- /AUTHORS.md: -------------------------------------------------------------------------------- 1 | # Project contributors: 2 | 3 | ## pgROuting Team: 4 | 5 | * Daniel Kastl 6 | * Ko Nagase 7 | * Regina Obe 8 | * Virginia Vergara 9 | 10 | ## Other contributors: 11 | 12 | * Aakash Sharma 13 | * Adrien Pavie 14 | * Anton Patrushev 15 | * Daniel Wendt (Initial author) 16 | * Jordan Anderson 17 | * J Kishore Kumar 18 | * Luís de Sousa 19 | * Sarthak Agarwal 20 | -------------------------------------------------------------------------------- /tools/osmium/README.md: -------------------------------------------------------------------------------- 1 | # Libosmium 2 | 3 | Instructions to install Libosmium library on Ubuntu: 4 | 5 | ### 16.04 (Xenial) 6 | 7 | You need to install libosmium2-dev package: 8 | 9 | ``` 10 | $ apt update && apt install -y libosmium2-dev 11 | ``` 12 | 13 | Do not install libosmium-dev package. This is an old version of Libosmium and you can not use with osm2pgrouting. 14 | -------------------------------------------------------------------------------- /Vagrantfile: -------------------------------------------------------------------------------- 1 | # -*- mode: ruby -*- 2 | # vi: set ft=ruby : 3 | 4 | pgbox = ENV['BOX'] || "precise64" 5 | 6 | Vagrant.configure("2") do |config| 7 | 8 | # Vagrant box configuration 9 | config.vm.box = pgbox 10 | config.vm.box_url = "http://files.vagrantup.com/%s.box" % [pgbox] 11 | 12 | # Bootstrap script 13 | config.vm.provision :shell, :path => "tools/vagrant/bootstrap.sh" 14 | 15 | # Forward SSH agent to host 16 | config.ssh.forward_agent = true 17 | 18 | # Create synced folder for GnuPG keys 19 | config.vm.synced_folder "~/.gnupg", "/home/vagrant/.gnupg" 20 | config.vm.synced_folder "../", "/home/vagrant/repos" 21 | 22 | end 23 | -------------------------------------------------------------------------------- /tools/osmium/restrictions_end.sql: -------------------------------------------------------------------------------- 1 | 2 | 3 | -- On a created table the delete is not needed 4 | -- FROM pg >= 9.5 this delete is not needed 5 | DELETE FROM __osm_restrictions_tmp WHERE osm_id IN (SELECT osm_id FROM foo.osm_restrictions); 6 | 7 | INSERT INTO foo.osm_restrictions 8 | SELECT * 9 | FROM __osm_restrictions_tmp; 10 | -- FROM pg >= 9.5 this line is needed 11 | -- ON CONFLICT DO NOTHING 12 | 13 | -- With if the table had the primary key then it wont create it 14 | DO $$ 15 | BEGIN 16 | BEGIN 17 | ALTER TABLE ONLY foo.osm_restrictions 18 | ADD CONSTRAINT foo.osm_restrictions_pkey PRIMARY KEY (osm_id); 19 | EXCEPTION 20 | WHEN OTHERS THEN 21 | RAISE NOTICE 'Primary key "foo.osm_restrictions_pkey" EXISTS' 22 | USING HINT = 'postgreSQL code #' || SQLSTATE || ': ' || SQLERRM; 23 | END; 24 | END 25 | $$; 26 | 27 | COMMIT; 28 | -------------------------------------------------------------------------------- /tools/osmium/cmake/FindLibPQXX.cmake: -------------------------------------------------------------------------------- 1 | # - Find libpqxx 2 | # Find the libpqxx includes and client library 3 | # This module defines 4 | # PQXX_INCLUDE_DIRS 5 | # PQXX_LIBRARIES 6 | # PQXX_FOUND 7 | 8 | include (FindPackageHandleStandardArgs) 9 | 10 | # 11 | # Look for an installation. 12 | # 13 | find_path(LIBPQXX_INCLUDE_DIR NAMES /include/pqxx/connection.hxx PATH_SUFFIXES ${SUFFIX_FOR_INCLUDE_PATH} PATHS 14 | 15 | # Look in other places. 16 | ${LIBPQXX_DIR_SEARCH} 17 | 18 | # Help the user find it if we cannot. 19 | DOC "The ${LIBPQXX_INCLUDE_DIR_MESSAGE}" 20 | ) 21 | 22 | # Now try to get the include and library path. 23 | if(LIBPQXX_INCLUDE_DIR) 24 | 25 | if(EXISTS "${LIBPQXX_INCLUDE_DIR}") 26 | set(LIBPQXX_INCLUDE_DIRS 27 | ${LIBPQXX_INCLUDE_DIR}/include 28 | ) 29 | endif() 30 | endif() 31 | 32 | find_library (LIBPQXX_LIBRARIES 33 | NAMES 34 | pqxx 35 | ) 36 | 37 | FIND_PACKAGE_HANDLE_STANDARD_ARGS("PQXX" 38 | "libpqxx couldn't be found" 39 | LIBPQXX_LIBRARIES 40 | LIBPQXX_INCLUDE_DIRS 41 | ) 42 | 43 | mark_as_advanced (PQXX_INCLUDE_DIR PQXX_LIBRARY) 44 | -------------------------------------------------------------------------------- /include/utilities/handle_pgpass.h: -------------------------------------------------------------------------------- 1 | /*PGR-GNU***************************************************************** 2 | 3 | Copyright (c) 2017 pgRouting developers 4 | Mail: project@pgrouting.org 5 | 6 | ------ 7 | This program is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation; either version 2 of the License, or 10 | (at your option) any later version. 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | ********************************************************************PGR-GNU*/ 19 | 20 | /** @file **/ 21 | 22 | #include 23 | #include 24 | 25 | namespace po = boost::program_options; 26 | 27 | 28 | void 29 | handle_pgpass(po::variables_map &vm); 30 | -------------------------------------------------------------------------------- /mapconfig_for_pedestrian.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /include/utilities/utilities.h: -------------------------------------------------------------------------------- 1 | /*PGR-GNU***************************************************************** 2 | 3 | Copyright (c) 2017 pgRouting developers 4 | Mail: project@pgrouting.org 5 | 6 | ------ 7 | This program is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation; either version 2 of the License, or 10 | (at your option) any later version. 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | ********************************************************************PGR-GNU*/ 19 | 20 | /** @file **/ 21 | 22 | 23 | #include 24 | #include 25 | 26 | 27 | std::string 28 | comma_separated(const std::vector &columns); 29 | std::string 30 | tab_separated(const std::vector &columns); 31 | -------------------------------------------------------------------------------- /tools/osmium/restrictions.sql: -------------------------------------------------------------------------------- 1 | 2 | BEGIN; 3 | --DROP TABLE if EXISTS foo.osm_restrictions; 4 | 5 | -- 6 | -- osm2pgRouting osm_restrictions dump 7 | -- 8 | 9 | SET statement_timeout = 0; 10 | SET lock_timeout = 0; 11 | SET client_encoding = 'UTF8'; 12 | SET standard_conforming_strings = on; 13 | SET check_function_bodies = false; 14 | SET client_min_messages = warning; 15 | 16 | SET search_path = public, pg_catalog; 17 | 18 | SET default_tablespace = ''; 19 | 20 | SET default_with_oids = false; 21 | 22 | -- 23 | -- Name: osm_restrictions; Type: TABLE; Schema: public; Owner: -; Tablespace: 24 | -- 25 | 26 | CREATE SCHEMA IF NOT EXISTS foo; 27 | 28 | CREATE TABLE IF NOT EXISTS foo.osm_restrictions( 29 | osm_id BIGINT PRIMARY KEY, 30 | osm_from BIGINT[], 31 | osm_to BIGINT[], 32 | osm_via BIGINT[], 33 | via_type char, 34 | osm_location_hint BIGINT, 35 | attributes hstore, 36 | tags hstore); 37 | 38 | -- On a created table the temporary table is not needed 39 | CREATE TEMP TABLE __osm_restrictions_tmp 40 | ON COMMIT DROP 41 | AS 42 | SELECT * 43 | FROM foo.osm_restrictions 44 | WITH NO DATA; 45 | 46 | 47 | -- On a created table Use the original table 48 | COPY __osm_restrictions_tmp ( 49 | osm_id, 50 | osm_from, osm_to, osm_via, 51 | via_type, 52 | osm_location_hint, 53 | attributes, tags) FROM STDIN; 54 | -------------------------------------------------------------------------------- /BOOST_LICENSE_1_0.txt: -------------------------------------------------------------------------------- 1 | Boost Software License - Version 1.0 - August 17th, 2003 2 | 3 | Permission is hereby granted, free of charge, to any person or organization 4 | obtaining a copy of the software and accompanying documentation covered by 5 | this license (the "Software") to use, reproduce, display, distribute, 6 | execute, and transmit the Software, and to prepare derivative works of the 7 | Software, and to permit third-parties to whom the Software is furnished to 8 | do so, all subject to the following: 9 | 10 | The copyright notices in the Software and this entire statement, including 11 | the above license grant, this restriction and the following disclaimer, 12 | must be included in all copies of the Software, in whole or in part, and 13 | all derivative works of the Software, unless such copies or derivative 14 | works are solely in the form of machine-executable object code generated by 15 | a source language processor. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 20 | SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 21 | FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 22 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23 | DEALINGS IN THE SOFTWARE. 24 | -------------------------------------------------------------------------------- /mapconfig_for_cars.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /docs/how_to_release.md: -------------------------------------------------------------------------------- 1 | # How to release a new version 2 | 3 | This document explains step by step how to release a new version for osm2pgrouting. 4 | 5 | 6 | ## Steps to follow 7 | 0. Make sure that the NEWS file has the changes for the release. (review issues closed in milestone). 8 | 9 | 1. Clone branch master: 10 | 11 | ``` 12 | $ git clone git@github.com:pgRouting/osm2pgrouting.git 13 | ``` 14 | 15 | 2. Make sure you are in the last update: 16 | 17 | ``` 18 | $ git pull origin main 19 | ``` 20 | 21 | 3. Make sure last updates was compiled without errors in Travis CI: https://travis-ci.org/pgRouting/osm2pgrouting/builds 22 | 23 | 4. Make the tag for this version (change version number from example): 24 | 25 | ``` 26 | $ git tag -a -m "Create osm2pgrouting v2.3.4 tag" v2.3.4 27 | ``` 28 | 29 | 5. Push the tag (change version number from example): 30 | 31 | ``` 32 | $ git push origin v2.3.4 33 | ``` 34 | 35 | 6. Go to Github repository and make sure the new tag was created: https://github.com/pgRouting/osm2pgrouting/releases 36 | 37 | 7. Click on the tag number then click on the edit tag button for release title (use the same number, i.e. v2.3.4). 38 | 39 | 8. Write comments about changes introduced by this new release (review issues closed in milestone or the NEWS file). Click on update release button. 40 | 41 | 9. Close milestone. 42 | 43 | 10. Prepare next release: 44 | - Create new milestone. 45 | - Update version in this file: https://github.com/pgRouting/osm2pgrouting/blob/master/src/osm_elements/osm2pgrouting.cpp#L101. 46 | -------------------------------------------------------------------------------- /tools/osmium/include/utilities/quotes_handling.h: -------------------------------------------------------------------------------- 1 | /*PGR-GNU***************************************************************** 2 | File: quotes_handling.h 3 | 4 | Copyright (c) 2017 pgRouting developers 5 | 6 | File developer: Celia Virginia Vergara Castillo (2017) 7 | 8 | 9 | ------ 10 | This program is free software; you can redistribute it and/or modify 11 | it under the terms of the GNU General Public License as published by 12 | the Free Software Foundation; either version 2 of the License, or 13 | (at your option) any later version. 14 | This program is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | You should have received a copy of the GNU General Public License 19 | along with this program; if not, write to the Free Software 20 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 21 | ********************************************************************PGR-GNU*/ 22 | 23 | /*! @file */ 24 | 25 | #ifndef TOOLS_OSMIUM_INCLUDE_UTILITIES_QUOTES_HANDLING_H_ 26 | #define TOOLS_OSMIUM_INCLUDE_UTILITIES_QUOTES_HANDLING_H_ 27 | 28 | #include 29 | #include 30 | 31 | std::string 32 | add_quotes(const std::string str, bool force = false); 33 | 34 | std::string 35 | pg_null(const std::ostringstream &original); 36 | 37 | std::string 38 | pg_null_array(const std::ostringstream &original); 39 | 40 | #endif // TOOLS_OSMIUM_INCLUDE_UTILITIES_QUOTES_HANDLING_H_ 41 | -------------------------------------------------------------------------------- /src/utilities/utilities.cpp: -------------------------------------------------------------------------------- 1 | /*PGR-GNU***************************************************************** 2 | 3 | Copyright (c) 2017 pgRouting developers 4 | Mail: project@pgrouting.org 5 | 6 | ------ 7 | This program is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation; either version 2 of the License, or 10 | (at your option) any later version. 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | ********************************************************************PGR-GNU*/ 19 | 20 | #include 21 | #include 22 | 23 | #include "boost/algorithm/string/replace.hpp" 24 | 25 | 26 | std::string 27 | comma_separated(const std::vector &columns) { 28 | std::string result(" "); 29 | for (auto column: columns) { 30 | result += column + ","; 31 | } 32 | result[result.size() - 1] = ' '; 33 | return result; 34 | } 35 | 36 | std::string 37 | tab_separated(const std::vector &columns) { 38 | std::string result(" "); 39 | for (auto column: columns) { 40 | if (column.empty() || column == "") { 41 | result += "\\N\t"; 42 | } else { 43 | boost::replace_all(column, "\\", "\\\\"); 44 | result += column + "\t"; 45 | } 46 | } 47 | result[result.size() - 1] = '\n'; 48 | return result; 49 | } 50 | -------------------------------------------------------------------------------- /include/utilities/prog_options.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (C) 2016 by pgRouting developers * 3 | * project@pgrouting.org * 4 | * * 5 | * This program is free software; you can redistribute it and/or modify * 6 | * it under the terms of the GNU General Public License as published by * 7 | * the Free Software Foundation; either version 2 of the License, or * 8 | * (at your option) any later version. * 9 | * * 10 | * This program is distributed in the hope that it will be useful, * 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 13 | * GNU General Public License t &or more details. * 14 | * * 15 | * You should have received a copy of the GNU General Public License * 16 | * along with this program; if not, write to the * 17 | * Free Software Foundation, Inc., * 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 19 | ***************************************************************************/ 20 | 21 | 22 | #ifndef SRC_PROG_OPTIONS_H_ 23 | #define SRC_PROG_OPTIONS_H_ 24 | 25 | #include 26 | #include 27 | namespace po = boost::program_options; 28 | 29 | 30 | using namespace std; 31 | 32 | void get_option_description(po::options_description &od_desc); 33 | void process_command_line(po::variables_map &vm); 34 | 35 | #endif // SRC_PROG_OPTIONS_H_ 36 | -------------------------------------------------------------------------------- /cmake/FindPQXX.cmake: -------------------------------------------------------------------------------- 1 | # - Find libpqxx 2 | # Find the libpqxx includes and client library 3 | # This module defines 4 | # PQXX_INCLUDE_DIRS 5 | # PQXX_LIBRARIES 6 | # PQXX_FOUND 7 | 8 | include (FindPackageHandleStandardArgs) 9 | 10 | # 11 | # Look for an installation. 12 | # 13 | find_path( 14 | PQXX_INCLUDE_DIR 15 | NAMES pqxx/pqxx 16 | PATHS 17 | ${_PQXX_DIR}/include 18 | ${_PQXX_DIR} 19 | ${CMAKE_INSTALL_PREFIX}/include 20 | /usr/local/pgsql/include 21 | /usr/local/include 22 | /usr/include 23 | DOC "pqxx include directories" 24 | ) 25 | mark_as_advanced (PQXX_INCLUDE_DIR) 26 | 27 | find_library (PQXX_LIBRARIES 28 | NAMES pqxx 29 | DOC "pqxx library" 30 | ) 31 | mark_as_advanced (PQXX_LIBRARY) 32 | 33 | 34 | if (PQXX_INCLUDE_DIR) 35 | if (EXISTS "${PQXX_INCLUDE_DIR}/pqxx/version.hxx") 36 | set (PQXX_VERSION_FILE "${PQXX_INCLUDE_DIR}/pqxx/version.hxx") 37 | message(STATUS "PQXX_VERSION_FILE=${PQXX_VERSION_FILE}") 38 | file(READ "${PQXX_VERSION_FILE}" PQXX_FILE) 39 | string(REGEX MATCH "PQXX_VERSION \"([0-9]*).([0-9]*).([0-9]*)" PQXX_VERSION_LINE ${PQXX_FILE}) 40 | string(REGEX REPLACE "PQXX_VERSION \"([0-9]*).([0-9]*).([0-9]*)" "\\1" PQXX_VERSION_MAYOR ${PQXX_VERSION_LINE}) 41 | string(REGEX REPLACE "PQXX_VERSION \"([0-9]*).([0-9]*).([0-9]*)" "\\2" PQXX_VERSION_MINOR ${PQXX_VERSION_LINE}) 42 | string(REGEX REPLACE "PQXX_VERSION \"([0-9]*).([0-9]*).([0-9]*)" "\\3" PQXX_VERSION_MICRO ${PQXX_VERSION_LINE}) 43 | set(PQXX_VERSION "${PQXX_VERSION_MAYOR}.${PQXX_VERSION_MINOR}.${PQXX_VERSION_MICRO}") 44 | message(STATUS "PQXX_VERSION=${PQXX_VERSION}") 45 | message(STATUS "PQXX_VERSION_MAYOR=${PQXX_VERSION_MAYOR}") 46 | message(STATUS "PQXX_VERSION_MINOR=${PQXX_VERSION_MINOR}") 47 | message(STATUS "PQXX_VERSION_MICRO=${PQXX_VERSION_MICRO}") 48 | unset(PQXX_VERSION_MAYOR) 49 | unset(PQXX_VERSION_MINOR) 50 | unset(PQXX_VERSION_MICRO) 51 | unset(PQXX_FILE) 52 | unset(PQXX_VERSION_LINE) 53 | endif() 54 | endif() 55 | 56 | 57 | 58 | FIND_PACKAGE_HANDLE_STANDARD_ARGS("PQXX" 59 | VERSION_VAR PQXX_VERSION 60 | REQUIRED_VARS PQXX_LIBRARIES PQXX_INCLUDE_DIR 61 | FAIL_MESSAGE "libpqxx couldn't be found" 62 | ) 63 | 64 | 65 | -------------------------------------------------------------------------------- /mapconfig.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # How to contribute 2 | 3 | We are really glad you are reading this, because we need volunteer developers to help this project. 4 | 5 | If you have not already, come find us in [![Join the chat at https://gitter.im/pgRouting/pgrouting](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/pgRouting/pgrouting?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) or contact us via [mailing list](http://lists.osgeo.org/mailman/listinfo/pgrouting-dev). We want you working on things you're excited about. Drop a message and if some one can assist you, will contact you back ASAP. 6 | 7 | Here are some important resources: 8 | 9 | * [pgRouting Documentation](http://docs.pgrouting.org/) The plugin is based on pgRouting 10 | * [Wish list on the wiki](https://github.com/pgRouting/pgrouting/wiki/GSoC-Ideas) is the foot view of what we think the community needs and can be done by GSoC students. 11 | * [Additional wish list](https://github.com/pgRouting/osm2pgrouting/issues?q=is%3Aopen+is%3Aissue+label%3A%22Functionality+Request%22). 12 | * Participate on the [discussions](https://github.com/pgRouting/osm2pgrouting/issues?q=is%3Aopen+is%3Aissue+label%3ADiscussion). 13 | * Participate fixing [Documentation](https://github.com/pgRouting/osm2pgrouting/issues?q=is%3Aopen+is%3Aissue+label%3ADocumentation). 14 | * Find a bug? [Let us know](https://github.com/pgRouting/osm2pgrouting/issues). 15 | 16 | ## Contribution agreement 17 | 18 | Any kind of contribution will automatically fall to the following Licences: 19 | 20 | - Code contribution: GNU GENERAL PUBLIC LICENSE Version 2, 21 | - Directly by making a pul explicit pull request. 22 | - Indirectly by posting code on issues/wiki/gitter/mailng lists 23 | - Documentation contribution: 24 | - Creative Commons Attribution-Share Alike 3.0 25 | 26 | ## Submitting changes 27 | 28 | 29 | Write a clear log message for your commits. One-line messages are fine for small changes, but bigger changes should have more information. 30 | Fill the commit message template. 31 | 32 | ## Coding conventions 33 | 34 | This is open source software. Consider the people who will read your code, and make it look nice for them. 35 | 36 | * We indent using four spaces (soft tabs) 37 | 38 | Thanks, 39 | pgRouting team 40 | -------------------------------------------------------------------------------- /tools/data/getdata.sh: -------------------------------------------------------------------------------- 1 | #!sh 2 | 3 | exit(0); 4 | 5 | # https://github.com/GeographicaGS/osm-itinera/blob/master/itinera/const.py#L43 6 | BBOX="1.97180,41.26684,2.26478,41.55818" 7 | wget --progress=dot:mega -O "bcn.osm" "http://www.overpass-api.de/api/xapi?*[bbox=${BBOX}][@meta]" 8 | 9 | BBOX="13.15,47.24,13.52,47.45" 10 | wget --progress=dot:mega -O "restrictions.osm" "http://www.overpass-api.de/api/xapi?*[bbox=${BBOX}][@meta]" 11 | 12 | #query to get germany restrictions 13 | #(53.5,11.0,54.5,11.5) 14 | wget --progress=dot:mega -O "germany_restrictions.osm" "http://overpass-api.de/api/interpreter?data=(relation(53.5,11.0,54.5,11.5)[\"type\"~\"^restriction\"];);(._;>;);out;" 15 | 16 | #query to get world restrictions 17 | #times out does not work well 18 | wget --progress=dot:mega -O "world_restrictions.osm" "http://overpass-api.de/api/interpreter?data=(relation[\"type\"~\"^restriction\"];);(._;>;);out;" 19 | 20 | 21 | BBOX="-122.8,45.4,-122.5,45.6" 22 | wget --progress=dot:mega -O "sampledata.osm" "http://www.overpass-api.de/api/xapi?*[bbox=${BBOX}][@meta]" 23 | BBOX="-122.65,45.5, -122.5,45.6" 24 | wget --progress=dot:mega -O "sampledataNE.osm" "http://www.overpass-api.de/api/xapi?*[bbox=${BBOX}][@meta]" 25 | BBOX="-122.65,45.4, -122.5,45.5" 26 | wget --progress=dot:mega -O "sampledataSE.osm" "http://www.overpass-api.de/api/xapi?*[bbox=${BBOX}][@meta]" 27 | BBOX="-122.8,45.5, -122.65,45.6" 28 | wget --progress=dot:mega -O "sampledataNW.osm" "http://www.overpass-api.de/api/xapi?*[bbox=${BBOX}][@meta]" 29 | BBOX="-122.8,45.4, -122.65,45.5" 30 | wget --progress=dot:mega -O "sampledataSW.osm" "http://www.overpass-api.de/api/xapi?*[bbox=${BBOX}][@meta]" 31 | 32 | BBOX="-122.65,45.4, -122.6,45.45" 33 | wget --progress=dot:mega -O "small.osm" "http://www.overpass-api.de/api/xapi?*[bbox=${BBOX}][@meta]" 34 | 35 | BBOX="4.2878,50.8139,4.5023,50.8926" 36 | wget --progress=dot:mega -O "brussels.osm" "http://www.overpass-api.de/api/xapi?*[bbox=${BBOX}][@meta]" 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /src/osm_elements/osm_tag.cpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (C) 2016 by pgRouting developers * 3 | * project@pgrouting.org * 4 | * * 5 | * This program is free software; you can redistribute it and/or modify * 6 | * it under the terms of the GNU General Public License as published by * 7 | * the Free Software Foundation; either version 2 of the License, or * 8 | * (at your option) any later version. * 9 | * * 10 | * This program is distributed in the hope that it will be useful, * 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 13 | * GNU General Public License t &or more details. * 14 | * * 15 | * You should have received a copy of the GNU General Public License * 16 | * along with this program; if not, write to the * 17 | * Free Software Foundation, Inc., * 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 19 | ***************************************************************************/ 20 | 21 | 22 | #include "osm_elements/osm_tag.h" 23 | #include 24 | #include 25 | 26 | namespace osm2pgr { 27 | 28 | 29 | Tag::Tag(const char **atts) { 30 | auto **attribut = atts; 31 | while (*attribut != NULL) { 32 | std::string name = *attribut++; 33 | std::string value = *attribut++; 34 | if (name == "k") { 35 | std::transform(value.begin(), value.end(), value.begin(), [](char ch) { 36 | return ch == ' ' ? '_' : ch;}); 37 | m_key = value; 38 | } else if (name == "v") { 39 | m_value = value; 40 | } 41 | } 42 | } 43 | 44 | std::ostream& operator<<(std::ostream &os, const Tag& tag) { 45 | os << tag.m_key << "=>" << tag.m_value; 46 | return os; 47 | } 48 | 49 | } // namespace osm2pgr 50 | -------------------------------------------------------------------------------- /include/configuration/tag_value.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (C) 2016 by pgRouting developers * 3 | * project@pgrouting.org * 4 | * * 5 | * This program is free software; you can redistribute it and/or modify * 6 | * it under the terms of the GNU General Public License as published by * 7 | * the Free Software Foundation; either version 2 of the License, or * 8 | * (at your option) any later version. * 9 | * * 10 | * This program is distributed in the hope that it will be useful, * 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 13 | * GNU General Public License t &or more details. * 14 | * * 15 | * You should have received a copy of the GNU General Public License * 16 | * along with this program; if not, write to the * 17 | * Free Software Foundation, Inc., * 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 19 | ***************************************************************************/ 20 | 21 | #ifndef SRC_CLASS_H_ 22 | #define SRC_CLASS_H_ 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | namespace osm2pgr { 32 | 33 | class Tag_value : public Element { 34 | public: 35 | Tag_value() = default; 36 | Tag_value(const Tag_value &) = default; 37 | /** @brief build it */ 38 | explicit Tag_value(const char ** attributes); 39 | 40 | 41 | /** @brief get it */ 42 | inline int64_t id() const {return osm_id();} 43 | std::string name() const; 44 | std::string get(const std::string &str) const; 45 | std::vector export_values() const; 46 | 47 | }; 48 | 49 | 50 | } // end namespace osm2pgr 51 | #endif // SRC_CLASS_H_ 52 | -------------------------------------------------------------------------------- /include/utilities/print_progress.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (C) 2016 by pgRouting developers * 3 | * project@pgrouting.org * 4 | * * 5 | * This program is free software; you can redistribute it and/or modify * 6 | * it under the terms of the GNU General Public License as published by * 7 | * the Free Software Foundation; either version 2 of the License, or * 8 | * (at your option) any later version. * 9 | * * 10 | * This program is distributed in the hope that it will be useful, * 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 13 | * GNU General Public License t &or more details. * 14 | * * 15 | * You should have received a copy of the GNU General Public License * 16 | * along with this program; if not, write to the * 17 | * Free Software Foundation, Inc., * 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 19 | ***************************************************************************/ 20 | 21 | #ifndef SRC_PRINT_PROGRESS_H_ 22 | #define SRC_PRINT_PROGRESS_H_ 23 | #pragma once 24 | 25 | 26 | #include 27 | #include 28 | 29 | template < typename T1 , typename T2> 30 | void 31 | print_progress(T1 wantProgress, T2 currentProgress) { 32 | int length = 50; 33 | double percent = static_cast (currentProgress) / static_cast (wantProgress); 34 | int fillerLength = static_cast(percent * length); 35 | 36 | std::string bar = "["; 37 | for (int i = 0; i < fillerLength; i++) { 38 | bar += "*"; 39 | } 40 | 41 | bar += "|"; 42 | for (int i = 0; i < length - fillerLength; i++) { 43 | bar += " "; 44 | } 45 | 46 | bar += "]"; 47 | std::cout << "\r" 48 | << bar 49 | << " (" << static_cast(100 * percent) << "%)" 50 | << " Total processed: " << currentProgress << std::flush; 51 | } 52 | #endif // SRC_PRINT_PROGRESS_H_ 53 | -------------------------------------------------------------------------------- /src/configuration/tag_value.cpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (C) 2016 by pgRouting developers * 3 | * project@pgrouting.org * 4 | * * 5 | * This program is free software; you can redistribute it and/or modify * 6 | * it under the terms of the GNU General Public License as published by * 7 | * the Free Software Foundation; either version 2 of the License, or * 8 | * (at your option) any later version. * 9 | * * 10 | * This program is distributed in the hope that it will be useful, * 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 13 | * GNU General Public License t &or more details. * 14 | * * 15 | * You should have received a copy of the GNU General Public License * 16 | * along with this program; if not, write to the * 17 | * Free Software Foundation, Inc., * 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 19 | ***************************************************************************/ 20 | 21 | #include "configuration/tag_value.h" 22 | #include 23 | #include 24 | #include 25 | 26 | 27 | 28 | namespace osm2pgr { 29 | 30 | 31 | Tag_value::Tag_value(const char **atts) : 32 | Element(atts){ 33 | assert(has_attribute("name")); 34 | } 35 | 36 | std::string 37 | Tag_value::get(const std::string &str) const { 38 | assert(has_attribute(str)); 39 | return get_attribute(str); 40 | } 41 | 42 | #if 0 43 | std::string 44 | Tag_value::priority() const { 45 | assert(has_attribute("priority")); 46 | return get_attribute("priority"); 47 | } 48 | 49 | std::string 50 | Tag_value::maxspeed() const { 51 | assert(has_attribute("maxspeed")); 52 | return get_attribute("maxspeed"); 53 | } 54 | #endif 55 | 56 | std::string 57 | Tag_value::name() const { 58 | assert(has_attribute("name")); 59 | return get_attribute("name"); 60 | } 61 | 62 | 63 | 64 | 65 | } // end namespace osm2pgr 66 | -------------------------------------------------------------------------------- /tools/osmium/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | PROJECT(getrestirction) 2 | CMAKE_MINIMUM_REQUIRED(VERSION 3.2) 3 | 4 | if ( ${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR} ) 5 | message(FATAL_ERROR "In-source builds not allowed. 6 | Please make a new directory (called a build directory) and run CMake from there. 7 | You may need to remove CMakeCache.txt." ) 8 | endif() 9 | 10 | LIST(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake") 11 | SET(SHARE_DIR "/usr/share/getrestrictions") 12 | 13 | FIND_PACKAGE(PostgreSQL REQUIRED) 14 | find_package(LibPQXX REQUIRED) 15 | FIND_PACKAGE(EXPAT REQUIRED) 16 | 17 | 18 | find_package(Osmium REQUIRED COMPONENTS io pbf xml) 19 | if(NOT OSMIUM_FOUND) 20 | message(WARNING "Libosmium not found!\n") 21 | endif() 22 | include_directories(SYSTEM ${OSMIUM_INCLUDE_DIRS}) 23 | 24 | 25 | 26 | 27 | 28 | 29 | FIND_PACKAGE(Boost) 30 | if(Boost_INCLUDE_DIRS) 31 | message(STATUS "Boost headers were found here: ${Boost_INCLUDE_DIRS}") 32 | else(Boost_INCLUDE_DIRS) 33 | message(FATAL_ERROR " Please check your Boost installation ") 34 | endif(Boost_INCLUDE_DIRS) 35 | 36 | FIND_PACKAGE(Boost COMPONENTS program_options REQUIRED) 37 | 38 | FILE(GLOB SRC "${CMAKE_SOURCE_DIR}/src/*.cpp" "${CMAKE_SOURCE_DIR}/src/*/*.cpp") 39 | 40 | set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_FILE_OFFSET_BITS=64 -std=c++0x") 41 | set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall -g -Wconversion -pedantic -Wextra -frounding-math -Wno-deprecated -fmax-errors=10") 42 | 43 | 44 | set (OSM2PGROUTING_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/include") 45 | message(STATUS "LIBPQXX_INCLUDE_DIRS: ${LIBPQXX_INCLUDE_DIRS}") 46 | message(STATUS "POSTGRESQL_INCLUDE_DIR: ${POSTGRESQL_INCLUDE_DIR}") 47 | message(STATUS "EXPAT_INCLUDE_DIRS: ${EXPAT_INCLUDE_DIRS}") 48 | message(STATUS "Boost_INCLUDE_DIRS: ${Boost_INCLUDE_DIRS}") 49 | message(STATUS "POSTGRESQL_LIBRARIES: ${POSTGRESQL_LIBRARIES}") 50 | message(STATUS "Boost_LIBRARIES: ${boost_LIBRARIES}") 51 | message(STATUS "LIBPQXX_LIBRARIES: ${LIBPQXX_LIBRARIES}") 52 | 53 | INCLUDE_DIRECTORIES(src 54 | ${LIBPQXX_INCLUDE_DIRS} 55 | ${POSTGRESQL_INCLUDE_DIR} 56 | ${EXPAT_INCLUDE_DIRS} 57 | ${Boost_INCLUDE_DIRS} 58 | ${OSM2PGROUTING_INCLUDE_DIRS} 59 | ) 60 | 61 | ADD_EXECUTABLE(getrestrictions ${SRC}) 62 | 63 | TARGET_LINK_LIBRARIES(getrestrictions 64 | ${LIBPQXX_LIBRARIES} 65 | ${POSTGRESQL_LIBRARIES} 66 | ${EXPAT_LIBRARIES} 67 | ${Boost_LIBRARIES} 68 | ${OSMIUM_LIBRARIES} 69 | ) 70 | 71 | INSTALL(TARGETS getrestrictions 72 | RUNTIME DESTINATION "/usr/bin" 73 | ) 74 | 75 | -------------------------------------------------------------------------------- /tools/spelling/typos_whitelist.txt: -------------------------------------------------------------------------------- 1 | // FIXME: is it a typo here or in IRIS itself: Perspective or Prespective ? 2 | "Prespective from geosync","Equidistant cylindrical","Gnomonic", 3 | /* 160 */ {"Bas_St_Wol", "Untergrenze strat. Bew|lkung", "hft", UC_NONE}, 4 | /* 161 */ {"Bas_St_Wol", "Untergrenze strat. Bew|lkung", "hPa", UC_NONE}, 5 | /* 164 */ {"Top_St_Wol", "Obergrenze strat. Bew|lkung", "hft", UC_NONE}, 6 | /* 165 */ {"Top_St_Wol", "Obergrenze strat. Bew|lkung", "hPa", UC_NONE}, 7 | "Icing Regime 1.Guess(1=gen,2=conv,3=strat,4=freez)", "1", 8 | "Icing Regime(1=general,2=convect,3=strat,4=freez)", "1", 9 | * The generated swig_type_info structures are assigned staticly to an initial 10 | * The generated swig_type_info structures are assigned staticly to an initial 11 | YUR = 0.0; 12 | YUR = oES.YUR; 13 | double YUR; 14 | l_segment->YUR = seg_data.GetDouble(nPos+215, 22); 15 | seg_data.Put(psOrbit->YUR,nPos+215,22,"%22.14f"); 16 | /* Putting statics in headers is trouble. */ 17 | See COMMITERS file. 18 | /* When multiple interpeters are used, a module could have already been initialized in 19 | const char* pszNAM = record->GetStringSubfield("DSI", 0, "NAM", 0); 20 | const char* pszNAM = record->GetStringSubfield("FDR", iFDRFieldInstance++, "NAM", 0); 21 | "PRT!NAM", 22 | sizeOfFields[nFields] += WriteSubFieldStr(fd, osBaseFileName, 8); /* NAM */ 23 | sizeOfFields[nFields] += WriteSubFieldStr(fd, osNAM.c_str(), 8); /* NAM */ 24 | "NAM!STR!PRT!SWO!SWA!NEO!NEA", 25 | sizeOfFields[nFields] += WriteSubFieldStr(fd, osBaseFileName, 8); /* NAM */ 26 | {136, "Socialist Republic of Viet Nam"}, 27 | double eps[NANGLES], ua, va, ang, epsa; 28 | ang = uv2ang(ua, va); 29 | i = (int) ang; 30 | epsa = fabs(ang - (i+.5)); 31 | " UN=Metres,SD=HHWLT,DX=2.500000,DY=2.500000\n"); 32 | pszUnitsPer = CPLGetXMLValue( psSrcXML, "metresPerUnit", NULL ); 33 | {"kilometre", /* 15 */ 12, 13, 1000.0}, 34 | oSRS.SetLinearUnits( "kilometre", 1000.0 ); 35 | { "kilometre", SRS_UL_KILOMETER_CONV, "km" }, // Leave as 'kilometre' instead of SRS_UL_KILOMETER due to historical usage 36 | passport.stMapDescription.eUnitInPlan = SXF_COORD_MU_CENTIMETRE; 37 | passport.stMapDescription.eUnitInPlan = SXF_COORD_MU_MILLIMETRE; 38 | SXF_COORD_MU_CENTIMETRE, 39 | SXF_COORD_MU_MILLIMETRE, 40 | -------------------------------------------------------------------------------- /src/parser/ConfigurationParserCallback.cpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (C) 2016 by pgRouting developers * 3 | * project@pgrouting.org * 4 | * * 5 | * This program is free software; you can redistribute it and/or modify * 6 | * it under the terms of the GNU General Public License as published by * 7 | * the Free Software Foundation; either version 2 of the License, or * 8 | * (at your option) any later version. * 9 | * * 10 | * This program is distributed in the hope that it will be useful, * 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 13 | * GNU General Public License t &or more details. * 14 | * * 15 | * You should have received a copy of the GNU General Public License * 16 | * along with this program; if not, write to the * 17 | * Free Software Foundation, Inc., * 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 19 | ***************************************************************************/ 20 | 21 | #include "parser/ConfigurationParserCallback.h" 22 | 23 | #include 24 | #include 25 | 26 | #include "osm_elements/OSMDocument.h" 27 | #include "configuration/configuration.h" 28 | 29 | namespace osm2pgr { 30 | 31 | /*! 32 | Parser callback for configuration files 33 | */ 34 | void ConfigurationParserCallback::StartElement( 35 | const char *name, 36 | const char** atts) { 37 | /* the type is the tag_key */ 38 | if (strcmp(name, "tag_name") == 0) { 39 | m_current = new Tag_key(atts); 40 | /* the class is the tag_value */ 41 | } else if (strcmp(name, "tag_value") == 0) { 42 | m_current->add_tag_value(Tag_value(atts)); 43 | } else if (strcmp(name, "configuration") == 0) { 44 | } 45 | } 46 | 47 | 48 | void ConfigurationParserCallback::EndElement(const char* name) { 49 | /* the type is the tag_key */ 50 | if (strcmp(name, "tag_name") == 0) { 51 | m_config.add_tag_key(*m_current); 52 | delete m_current; 53 | } 54 | } 55 | 56 | } // namespace osm2pgr 57 | -------------------------------------------------------------------------------- /include/parser/ConfigurationParserCallback.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (C) 2016 by pgRouting developers * 3 | * project@pgrouting.org * 4 | * * 5 | * This program is free software; you can redistribute it and/or modify * 6 | * it under the terms of the GNU General Public License as published by * 7 | * the Free Software Foundation; either version 2 of the License, or * 8 | * (at your option) any later version. * 9 | * * 10 | * This program is distributed in the hope that it will be useful, * 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 13 | * GNU General Public License t &or more details. * 14 | * * 15 | * You should have received a copy of the GNU General Public License * 16 | * along with this program; if not, write to the * 17 | * Free Software Foundation, Inc., * 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 19 | ***************************************************************************/ 20 | 21 | 22 | #ifndef SRC_CONFIGURATIONPARSERCALLBACK_H_ 23 | #define SRC_CONFIGURATIONPARSERCALLBACK_H_ 24 | #pragma once 25 | 26 | #ifdef BOOST_NO_CXX11_NULLPTR 27 | #define nullptr NULL 28 | #endif 29 | 30 | #include 31 | #include "XMLParser.h" 32 | 33 | 34 | namespace osm2pgr { 35 | 36 | class Configuration; 37 | class Tag_key; 38 | 39 | /** 40 | Parser callback for configuration files 41 | */ 42 | class ConfigurationParserCallback : public xml::XMLParserCallback { 43 | public: 44 | /** 45 | * Constructor 46 | */ 47 | explicit ConfigurationParserCallback(Configuration& doc) : 48 | m_config(doc), 49 | m_current(nullptr) { 50 | } 51 | private: 52 | //! reference to a Configuration object 53 | Configuration& m_config; 54 | 55 | //! current type, which will be parsed 56 | Tag_key* m_current; 57 | 58 | virtual void StartElement(const char *name, const char** atts); 59 | 60 | virtual void EndElement(const char* name); 61 | }; 62 | 63 | } // namespace osm2pgr 64 | 65 | #endif // SRC_CONFIGURATIONPARSERCALLBACK_H_ 66 | -------------------------------------------------------------------------------- /src/database/configuration_config.cpp: -------------------------------------------------------------------------------- 1 | /*PGR-GNU***************************************************************** 2 | 3 | Copyright (c) 2017 pgRouting developers 4 | Mail: project@pgrouting.org 5 | 6 | ------ 7 | This program is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation; either version 2 of the License, or 10 | (at your option) any later version. 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | ********************************************************************PGR-GNU*/ 19 | 20 | 21 | #include "boost/lexical_cast.hpp" 22 | #include "database/table_management.h" 23 | #include "utilities/utilities.h" 24 | 25 | namespace osm2pgr { 26 | 27 | 28 | /* 29 | * configuring TABLE configuration 30 | */ 31 | 32 | 33 | Table 34 | Tables::configuration_config() const { 35 | Table table( 36 | /* name */ 37 | "configuration", 38 | 39 | /* schema */ 40 | m_vm["schema"].as(), 41 | 42 | /* full name */ 43 | "configuration", 44 | 45 | /* standard column creation string */ 46 | std::string( 47 | " id serial" 48 | ", tag_id INTEGER" 49 | ", tag_key TEXT" 50 | ", tag_value TEXT" 51 | ", priority double precision" 52 | ", maxspeed double precision" 53 | ", maxspeed_forward double precision" 54 | ", maxspeed_backward double precision" 55 | ", force char"), 56 | 57 | /* other columns */ 58 | "", 59 | 60 | /* geometry */ 61 | ""); 62 | 63 | 64 | 65 | std::vector columns; 66 | columns.push_back("tag_id"); 67 | columns.push_back("tag_key"); 68 | columns.push_back("tag_value"); 69 | columns.push_back("priority"); 70 | columns.push_back("maxspeed"); 71 | columns.push_back("maxspeed_forward"); 72 | columns.push_back("maxspeed_backward"); 73 | columns.push_back("force"); 74 | 75 | table.set_columns(columns); 76 | 77 | return table; 78 | } 79 | 80 | 81 | } //namespace osm2pgr 82 | -------------------------------------------------------------------------------- /tools/osmium/src/utilities/quotes_handling.cpp: -------------------------------------------------------------------------------- 1 | /*PGR-GNU***************************************************************** 2 | * File: quotes_handling.cpp 3 | * 4 | * Copyright (c) 2017 pgRouting developers 5 | * 6 | * File developer: Celia Virginia Vergara Castillo (2017) 7 | * 8 | * 9 | * ------ 10 | * This program is free software; you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation; either version 2 of the License, or 13 | * (at your option) any later version. 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 21 | * ********************************************************************PGR-GNU*/ 22 | 23 | /*! @file */ 24 | 25 | 26 | #include "utilities/quotes_handling.h" 27 | #include 28 | 29 | std::string 30 | add_quotes(const std::string str, bool force) { 31 | std::string result(""); 32 | 33 | for (auto c : str) { 34 | if ( c == '"' ) { 35 | /* 36 | * To avoid problems with json & hstore 37 | * all quotes are converted to single quotes 38 | */ 39 | result += "\'\'"; 40 | continue; 41 | } else if ( c == '\\' ) { 42 | result += '\\'; 43 | } else if (c == '\'') { 44 | result += '\''; 45 | } else if (c == '\n') { 46 | result += "\\n"; 47 | continue; 48 | } else if (c == '\r') { 49 | result += "\\r"; 50 | continue; 51 | } else if (c == '\t') { 52 | result += "\\t"; 53 | continue; 54 | } 55 | result += c; 56 | } 57 | if (!force) { 58 | for (auto c : result) { 59 | if (c == ' ' || c == ',' || c == '=' || c == '>' || c == ':') { 60 | return std::string("\"") + result + "\""; 61 | } 62 | } 63 | return result; 64 | } 65 | return std::string("\"") + result + "\""; 66 | } 67 | 68 | 69 | std::string 70 | pg_null(const std::ostringstream &original) { 71 | return original.str().empty() ? "\\N" : original.str(); 72 | }; 73 | 74 | std::string 75 | pg_null_array(const std::ostringstream &original) { 76 | return original.str().empty() ? "\\N" : "{" + original.str() + "}"; 77 | }; 78 | 79 | -------------------------------------------------------------------------------- /include/configuration/tag_key.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (C) 2016 by pgRouting developers * 3 | * project@pgrouting.org * 4 | * * 5 | * This program is free software; you can redistribute it and/or modify * 6 | * it under the terms of the GNU General Public License as published by * 7 | * the Free Software Foundation; either version 2 of the License, or * 8 | * (at your option) any later version. * 9 | * * 10 | * This program is distributed in the hope that it will be useful, * 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 13 | * GNU General Public License t &or more details. * 14 | * * 15 | * You should have received a copy of the GNU General Public License * 16 | * along with this program; if not, write to the * 17 | * Free Software Foundation, Inc., * 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 19 | ***************************************************************************/ 20 | 21 | 22 | #ifndef SRC_TYPE_H_ 23 | #define SRC_TYPE_H_ 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include "./tag_value.h" 30 | 31 | namespace osm2pgr { 32 | 33 | class Tag_key : Element { 34 | public: 35 | Tag_key() = default; 36 | Tag_key(const Tag_key &) = default; 37 | /** @brief build it 38 | * @param atts attributes read py the parser 39 | */ 40 | explicit Tag_key(const char **atts); 41 | void add_tag_value(const Tag_value &p_values); 42 | 43 | 44 | /* to have or not to have */ 45 | bool has(const Tag &tag, const std::string &str) const; 46 | bool has_tag_value(const Tag &tag) const; 47 | 48 | /* get it*/ 49 | std::string get(const Tag &tag, const std::string &str) const; 50 | const Tag_value& tag_value(const Tag &tag) const; 51 | inline int64_t id() const {return osm_id();} 52 | inline std::string name() const {return get_attribute("name");} 53 | 54 | /* used in the export function */ 55 | std::vector values( 56 | const std::vector &columns) const; 57 | 58 | private: 59 | std::map m_Tag_values; 60 | }; 61 | 62 | } // namespace osm2pgr 63 | #endif // SRC_TYPE_H_ 64 | -------------------------------------------------------------------------------- /src/database/vertices_config.cpp: -------------------------------------------------------------------------------- 1 | /*PGR-GNU***************************************************************** 2 | 3 | Copyright (c) 2017 pgRouting developers 4 | Mail: project@pgrouting.org 5 | 6 | ------ 7 | This program is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation; either version 2 of the License, or 10 | (at your option) any later version. 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | ********************************************************************PGR-GNU*/ 19 | 20 | #include "boost/lexical_cast.hpp" 21 | #include "database/table_management.h" 22 | #include "utilities/utilities.h" 23 | #include 24 | 25 | namespace osm2pgr { 26 | 27 | 28 | /* 29 | * configuring TABLE vertices_pgr 30 | */ 31 | Table 32 | Tables::ways_vertices_pgr_config() const { 33 | Table table( 34 | /* name */ 35 | "ways_vertices_pgr", 36 | 37 | /* schema */ 38 | m_vm["schema"].as(), 39 | 40 | /* full name */ 41 | std::string( 42 | m_vm["prefix"].as() 43 | + "ways" 44 | + m_vm["suffix"].as() 45 | + "_vertices_pgr"), 46 | 47 | /* standard column creation string */ 48 | std::string( 49 | " id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY" 50 | ", in_edges bigint[]" 51 | ", out_edges bigint[]" 52 | ", x decimal(11,8) GENERATED ALWAYS AS (ST_X(geom)) STORED" 53 | ", y decimal(11,8) GENERATED ALWAYS AS (ST_Y(geom)) STORED" 54 | ", osm_id BIGINT" 55 | ", geom GEOMETRY(POINT, 4326)" 56 | 57 | #if 0 58 | + (m_vm.count("attributes") ? 59 | (std::string(", attributes ") + (m_vm.count("hstore") ? "hstore" : "json")) 60 | : "") 61 | + (m_vm.count("tags") ? 62 | (std::string(", tags ") + (m_vm.count("hstore") ? "hstore" : "json")) 63 | : "") 64 | #endif 65 | ), 66 | 67 | /* other columns */ 68 | "", 69 | 70 | /* geometry */ 71 | ""); 72 | 73 | return table; 74 | } 75 | 76 | 77 | } //namespace osm2pgr 78 | -------------------------------------------------------------------------------- /tools/osmium/cmake/FindPostgreSQL.cmake: -------------------------------------------------------------------------------- 1 | # - Find PostgreSQL 2 | # Find the PostgreSQL includes and client library 3 | # This module defines 4 | # POSTGRESQL_INCLUDE_DIR, where to find POSTGRESQL.h 5 | # POSTGRESQL_LIBRARIES, the libraries needed to use POSTGRESQL. 6 | # POSTGRESQL_FOUND, If false, do not try to use PostgreSQL. 7 | 8 | # Copyright (c) 2006, Jaroslaw Staniek, 9 | # 10 | # Redistribution and use is allowed according to the terms of the BSD license. 11 | # For details see the accompanying COPYING-CMAKE-SCRIPTS file. 12 | 13 | 14 | if(POSTGRESQL_INCLUDE_DIR AND POSTGRESQL_LIBRARIES) 15 | set(POSTGRESQL_FOUND TRUE) 16 | 17 | else(POSTGRESQL_INCLUDE_DIR AND POSTGRESQL_LIBRARIES) 18 | 19 | find_program(POSTGRESQL_PG_CONFIG NAMES pg_config 20 | PATHS 21 | /usr/lib/postgresql/*/bin/ 22 | ) 23 | message(STATUS "POSTGRESQL_PG_CONFIG is " ${POSTGRESQL_PG_CONFIG}) 24 | 25 | if(POSTGRESQL_PG_CONFIG) 26 | execute_process( 27 | COMMAND ${POSTGRESQL_PG_CONFIG} --includedir 28 | OUTPUT_STRIP_TRAILING_WHITESPACE 29 | OUTPUT_VARIABLE T_POSTGRESQL_INCLUDE_DIR) 30 | endif(POSTGRESQL_PG_CONFIG) 31 | 32 | find_path(POSTGRESQL_INCLUDE_DIR libpq-fe.h 33 | ${T_POSTGRESQL_INCLUDE_DIR} 34 | /usr/include 35 | /usr/include/pgsql 36 | /usr/local/include/pgsql 37 | /usr/include/postgresql 38 | /usr/include/postgresql/* 39 | /usr/local/include/postgresql 40 | /usr/local/include/postgresql/* 41 | $ENV{ProgramFiles}/PostgreSQL/*/include 42 | $ENV{SystemDrive}/PostgreSQL/*/include 43 | ) 44 | 45 | if(POSTGRESQL_PG_CONFIG) 46 | execute_process( 47 | COMMAND ${POSTGRESQL_PG_CONFIG} --libdir 48 | OUTPUT_STRIP_TRAILING_WHITESPACE 49 | OUTPUT_VARIABLE T_POSTGRESQL_LIB_DIR) 50 | endif(POSTGRESQL_PG_CONFIG) 51 | 52 | find_library(POSTGRESQL_LIBRARIES NAMES pq libpq 53 | ${T_POSTGRESQL_LIB_DIR} 54 | PATHS 55 | /usr/lib 56 | /usr/local/lib 57 | /usr/lib/postgresql 58 | $ENV{ProgramFiles}/PostgreSQL/*/lib 59 | $ENV{SystemDrive}/PostgreSQL/*/lib 60 | ) 61 | 62 | if(POSTGRESQL_INCLUDE_DIR AND POSTGRESQL_LIBRARIES) 63 | set(POSTGRESQL_FOUND TRUE) 64 | message(STATUS "POSTGRESQL_INCLUDE_DIR: ${POSTGRESQL_INCLUDE_DIR}") 65 | message(STATUS "POSTGRESQL_LIBRARIES: ${POSTGRESQL_LIBRARIES}") 66 | include_directories(${POSTGRESQL_INCLUDE_DIR}) 67 | else(POSTGRESQL_INCLUDE_DIR AND POSTGRESQL_LIBRARIES) 68 | set(POSTGRESQL_FOUND FALSE) 69 | message(STATUS "PostgreSQL not found.") 70 | endif(POSTGRESQL_INCLUDE_DIR AND POSTGRESQL_LIBRARIES) 71 | 72 | mark_as_advanced(POSTGRESQL_INCLUDE_DIR POSTGRESQL_LIBRARIES) 73 | 74 | endif(POSTGRESQL_INCLUDE_DIR AND POSTGRESQL_LIBRARIES) 75 | -------------------------------------------------------------------------------- /cmake/FindPostgreSQL.cmake: -------------------------------------------------------------------------------- 1 | # - Find PostgreSQL 2 | # Find the PostgreSQL includes and client library 3 | # This module defines 4 | # POSTGRESQL_INCLUDE_DIR, where to find POSTGRESQL.h 5 | # POSTGRESQL_LIBRARIES, the libraries needed to use POSTGRESQL. 6 | # POSTGRESQL_FOUND, If false, do not try to use PostgreSQL. 7 | 8 | # Copyright (c) 2006, Jaroslaw Staniek, 9 | # 10 | # Redistribution and use is allowed according to the terms of the BSD license. 11 | # For details see the accompanying COPYING-CMAKE-SCRIPTS file. 12 | 13 | 14 | if(POSTGRESQL_INCLUDE_DIR AND POSTGRESQL_LIBRARIES) 15 | set(POSTGRESQL_FOUND TRUE) 16 | 17 | else(POSTGRESQL_INCLUDE_DIR AND POSTGRESQL_LIBRARIES) 18 | 19 | find_program(POSTGRESQL_PG_CONFIG NAMES pg_config 20 | PATHS 21 | /usr/lib/postgresql/*/bin/ 22 | ) 23 | message(STATUS "POSTGRESQL_PG_CONFIG is " ${POSTGRESQL_PG_CONFIG}) 24 | 25 | if(POSTGRESQL_PG_CONFIG) 26 | execute_process( 27 | COMMAND ${POSTGRESQL_PG_CONFIG} --includedir 28 | OUTPUT_STRIP_TRAILING_WHITESPACE 29 | OUTPUT_VARIABLE T_POSTGRESQL_INCLUDE_DIR) 30 | endif(POSTGRESQL_PG_CONFIG) 31 | 32 | find_path(POSTGRESQL_INCLUDE_DIR libpq-fe.h 33 | ${T_POSTGRESQL_INCLUDE_DIR} 34 | /usr/pgsql-*/include 35 | /usr/include 36 | /usr/include/pgsql 37 | /usr/local/include/pgsql 38 | /usr/include/postgresql 39 | /usr/include/postgresql/* 40 | /usr/local/include/postgresql 41 | /usr/local/include/postgresql/* 42 | $ENV{ProgramFiles}/PostgreSQL/*/include 43 | $ENV{SystemDrive}/PostgreSQL/*/include 44 | ) 45 | 46 | if(POSTGRESQL_PG_CONFIG) 47 | execute_process( 48 | COMMAND ${POSTGRESQL_PG_CONFIG} --libdir 49 | OUTPUT_STRIP_TRAILING_WHITESPACE 50 | OUTPUT_VARIABLE T_POSTGRESQL_LIB_DIR) 51 | endif(POSTGRESQL_PG_CONFIG) 52 | 53 | find_library(POSTGRESQL_LIBRARIES NAMES pq libpq 54 | ${T_POSTGRESQL_LIB_DIR} 55 | PATHS 56 | /usr/pgsql-*/lib 57 | /usr/lib 58 | /usr/local/lib 59 | /usr/lib/postgresql 60 | $ENV{ProgramFiles}/PostgreSQL/*/lib 61 | $ENV{SystemDrive}/PostgreSQL/*/lib 62 | ) 63 | 64 | if(POSTGRESQL_INCLUDE_DIR AND POSTGRESQL_LIBRARIES) 65 | set(POSTGRESQL_FOUND TRUE) 66 | message(STATUS "POSTGRESQL_INCLUDE_DIR: ${POSTGRESQL_INCLUDE_DIR}") 67 | message(STATUS "POSTGRESQL_LIBRARIES: ${POSTGRESQL_LIBRARIES}") 68 | include_directories(${POSTGRESQL_INCLUDE_DIR}) 69 | else(POSTGRESQL_INCLUDE_DIR AND POSTGRESQL_LIBRARIES) 70 | set(POSTGRESQL_FOUND FALSE) 71 | message(STATUS "PostgreSQL not found.") 72 | endif(POSTGRESQL_INCLUDE_DIR AND POSTGRESQL_LIBRARIES) 73 | 74 | mark_as_advanced(POSTGRESQL_INCLUDE_DIR POSTGRESQL_LIBRARIES) 75 | 76 | endif(POSTGRESQL_INCLUDE_DIR AND POSTGRESQL_LIBRARIES) 77 | -------------------------------------------------------------------------------- /src/database/osm_relations_config.cpp: -------------------------------------------------------------------------------- 1 | /*PGR-GNU***************************************************************** 2 | 3 | Copyright (c) 2017 pgRouting developers 4 | Mail: project@pgrouting.org 5 | 6 | ------ 7 | This program is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation; either version 2 of the License, or 10 | (at your option) any later version. 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | ********************************************************************PGR-GNU*/ 19 | 20 | #include "boost/lexical_cast.hpp" 21 | #include "database/table_management.h" 22 | #include "utilities/utilities.h" 23 | 24 | namespace osm2pgr { 25 | 26 | 27 | /* 28 | * configuring TABLE osm_relations 29 | */ 30 | 31 | 32 | Table 33 | Tables::osm_relations_config() const { 34 | Table table( 35 | /* name */ 36 | "osm_relations", 37 | 38 | /* schema */ 39 | m_vm["schema"].as(), 40 | 41 | /* full name */ 42 | "osm_relations", 43 | 44 | /* standard column creation string */ 45 | std::string( 46 | " osm_id bigint PRIMARY KEY" 47 | " , members hstore" 48 | + (m_vm.count("attributes") && m_vm.count("addnodes") ? 49 | (std::string(", attributes hstore")) 50 | : "") 51 | + (m_vm.count("tags") && m_vm.count("addnodes")? 52 | (std::string(", tags hstore")) 53 | : "") 54 | ), 55 | /* other columns */ 56 | // TODO get from the configuration maybe this task is to be done on the configuration*/ 57 | ", tag_name TEXT" 58 | ", tag_value TEXT" 59 | ", name TEXT ", 60 | // end todo 61 | 62 | /* geometry */ 63 | ""); 64 | 65 | 66 | std::vector columns; 67 | columns.push_back("osm_id"); 68 | columns.push_back("members"); 69 | // TODO get from the configuration 70 | columns.push_back("tag_name"); 71 | columns.push_back("tag_value"); 72 | columns.push_back("name"); 73 | // end todo 74 | if (m_vm.count("attributes")) columns.push_back("attributes"); 75 | if (m_vm.count("tags")) columns.push_back("tags"); 76 | 77 | table.set_columns(columns); 78 | 79 | return table; 80 | } 81 | 82 | 83 | } //namespace osm2pgr 84 | -------------------------------------------------------------------------------- /include/parser/OSMDocumentParserCallback.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (C) 2016 by pgRouting developers * 3 | * project@pgrouting.org * 4 | * * 5 | * This program is free software; you can redistribute it and/or modify * 6 | * it under the terms of the GNU General Public License as published by * 7 | * the Free Software Foundation; either version 2 of the License, or * 8 | * (at your option) any later version. * 9 | * * 10 | * This program is distributed in the hope that it will be useful, * 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 13 | * GNU General Public License t &or more details. * 14 | * * 15 | * You should have received a copy of the GNU General Public License * 16 | * along with this program; if not, write to the * 17 | * Free Software Foundation, Inc., * 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 19 | ***************************************************************************/ 20 | 21 | 22 | #ifndef SRC_OSMDOCUMENTPARSERCALLBACK_H_ 23 | #define SRC_OSMDOCUMENTPARSERCALLBACK_H_ 24 | #pragma once 25 | 26 | #ifdef BOOST_NO_CXX11_NULLPTR 27 | #define nullptr NULL 28 | #endif 29 | 30 | 31 | #include 32 | #include "./XMLParser.h" 33 | 34 | namespace osm2pgr { 35 | 36 | class OSMDocument; 37 | class Node; 38 | class Way; 39 | class Relation; 40 | 41 | /** 42 | Parser callback for OSMDocument files 43 | */ 44 | class OSMDocumentParserCallback : 45 | public xml::XMLParserCallback { 46 | //! reference to a OSMDocument object 47 | OSMDocument& m_rDocument; 48 | //! current way, which will be parsed 49 | // Way* m_pActWay; 50 | 51 | virtual void StartElement(const char *name, const char** atts); 52 | 53 | virtual void EndElement(const char* name); 54 | 55 | public: 56 | /** 57 | * Constructor 58 | */ 59 | explicit OSMDocumentParserCallback(OSMDocument& doc) : 60 | m_rDocument(doc), 61 | last_node(nullptr), 62 | last_way(nullptr), 63 | last_relation(nullptr), 64 | m_section(1) { 65 | } 66 | private: 67 | void show_progress(); 68 | 69 | private: 70 | Node *last_node; 71 | Way *last_way; 72 | Relation* last_relation; 73 | int m_section; 74 | }; // class OSMDocumentParserCallback 75 | 76 | } // end namespace osm2pgr 77 | 78 | #endif // SRC_OSMDOCUMENTPARSERCALLBACK_H_ 79 | -------------------------------------------------------------------------------- /.github/workflows/ubuntu.yml: -------------------------------------------------------------------------------- 1 | name: Build for Ubuntu 2 | 3 | # manually triggered workflow 4 | 5 | on: 6 | workflow_dispatch: 7 | push: 8 | pull_request: 9 | 10 | 11 | concurrency: 12 | group: ${{ github.workflow }}-${{ github.ref }} 13 | cancel-in-progress: true 14 | 15 | permissions: 16 | contents: read 17 | 18 | jobs: 19 | build: 20 | name: Ubuntu psql 21 | runs-on: ${{ matrix.os }} 22 | 23 | strategy: 24 | fail-fast: false 25 | matrix: 26 | psql: [13, 14, 15, 16, 17, 18] 27 | postgis: [3] 28 | release: [Debug, Release] 29 | os: [ubuntu-latest, ubuntu-22.04] 30 | compiler: [ gcc-latest, g++-11, clang ] 31 | 32 | steps: 33 | - uses: actions/checkout@v5 34 | 35 | - name: 'Raise Priority for apt.postgresql.org' 36 | run: | 37 | cat << EOF >> ./pgdg.pref 38 | Package: * 39 | Pin: release o=apt.postgresql.org 40 | Pin-Priority: 600 41 | EOF 42 | sudo mv ./pgdg.pref /etc/apt/preferences.d/ 43 | sudo apt update 44 | 45 | - name: Add PostgreSQL APT repository 46 | run: | 47 | sudo apt-get -y purge postgresql-* 48 | sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg-testing main ${{ matrix.psql }}" > /etc/apt/sources.list.d/pgdg.list' 49 | curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/apt.postgresql.org.gpg >/dev/null 50 | 51 | - name: Install compiler 52 | id: install_cc 53 | uses: rlalik/setup-cpp-compiler@master 54 | with: 55 | compiler: ${{ matrix.compiler }} 56 | 57 | - name: Install dependencies 58 | run: | 59 | sudo apt-get update 60 | sudo apt-get install -y \ 61 | libboost-program-options-dev \ 62 | libtap-parser-sourcehandler-pgtap-perl \ 63 | postgresql-${{ matrix.psql }} \ 64 | postgresql-${{ matrix.psql }}-pgtap \ 65 | postgresql-${{ matrix.psql }}-postgis-${{ matrix.postgis }} \ 66 | postgresql-${{ matrix.psql }}-postgis-${{ matrix.postgis }}-scripts \ 67 | postgresql-${{ matrix.psql }}-pgrouting \ 68 | libpqxx-dev \ 69 | postgresql-server-dev-${{ matrix.psql }} 70 | # should be 7 on latest and 6 on 22.04 71 | apt-cache policy libpqxx-dev 72 | 73 | - name: Configure compiler 74 | run: | 75 | export CC=/usr/bin/${{ steps.install_cc.outputs.cc }} 76 | export CXX=/usr/bin/${{ steps.install_cc.outputs.cxx }} 77 | export PATH=/usr/lib/postgresql/${{ matrix.psql }}/bin:$PATH 78 | mkdir build 79 | cd build 80 | cmake -DCMAKE_BUILD_TYPE=${{ matrix.release }} .. 81 | 82 | - name: Build 83 | run: | 84 | cd build 85 | make -j 4 86 | sudo make install 87 | -------------------------------------------------------------------------------- /src/database/osm_nodes_config.cpp: -------------------------------------------------------------------------------- 1 | /*PGR-GNU***************************************************************** 2 | 3 | Copyright (c) 2017 pgRouting developers 4 | Mail: project@pgrouting.org 5 | 6 | ------ 7 | This program is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation; either version 2 of the License, or 10 | (at your option) any later version. 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | ********************************************************************PGR-GNU*/ 19 | 20 | #include "boost/lexical_cast.hpp" 21 | #include "database/table_management.h" 22 | #include "utilities/utilities.h" 23 | 24 | namespace osm2pgr { 25 | 26 | 27 | /* 28 | * configuring TABLE osm_nodes 29 | */ 30 | 31 | 32 | Table 33 | Tables::osm_nodes_config() const { 34 | Table table( 35 | /* name */ 36 | std::string("osm_nodes"), 37 | 38 | /* schema */ 39 | m_vm["schema"].as(), 40 | 41 | /* full name */ 42 | "osm_nodes", 43 | 44 | /* standard column creation string */ 45 | std::string( 46 | " osm_id bigint PRIMARY KEY" 47 | + (m_vm.count("attributes") && m_vm.count("addnodes") ? 48 | (std::string(", attributes hstore")) 49 | : "") 50 | + (m_vm.count("tags") && m_vm.count("addnodes") ? 51 | (std::string(", tags hstore")) 52 | #if 0 53 | (std::string(", tags ") + (m_vm.count("hstore") ? "hstore" : "json")) 54 | #endif 55 | : "")), 56 | 57 | /* other columns */ 58 | // TODO get from the configuration maybe this task is to be done on the configuration*/ 59 | ", tag_name TEXT" 60 | ", tag_value TEXT" 61 | ", name TEXT ", 62 | // end todo 63 | 64 | /* geometry */ 65 | "POINT"); 66 | std::vector columns; 67 | columns.push_back("osm_id"); 68 | columns.push_back("geom"); 69 | // TODO get from the configuration 70 | columns.push_back("tag_name"); 71 | columns.push_back("tag_value"); 72 | columns.push_back("name"); 73 | // end todo 74 | if (m_vm.count("attributes")) columns.push_back("attributes"); 75 | if (m_vm.count("tags")) columns.push_back("tags"); 76 | table.set_columns(columns); 77 | 78 | return table; 79 | } 80 | 81 | 82 | } //namespace osm2pgr 83 | -------------------------------------------------------------------------------- /include/osm_elements/osm_tag.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (C) 2016 by pgRouting developers * 3 | * project@pgrouting.org * 4 | * * 5 | * This program is free software; you can redistribute it and/or modify * 6 | * it under the terms of the GNU General Public License as published by * 7 | * the Free Software Foundation; either version 2 of the License, or * 8 | * (at your option) any later version. * 9 | * * 10 | * This program is distributed in the hope that it will be useful, * 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 13 | * GNU General Public License t &or more details. * 14 | * * 15 | * You should have received a copy of the GNU General Public License * 16 | * along with this program; if not, write to the * 17 | * Free Software Foundation, Inc., * 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 19 | ***************************************************************************/ 20 | 21 | 22 | #ifndef SRC_OSM_TAG_H_ 23 | #define SRC_OSM_TAG_H_ 24 | #pragma once 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | 32 | namespace osm2pgr { 33 | 34 | 35 | /** 36 | @code 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | @endcode 49 | */ 50 | 51 | class Tag { 52 | public: 53 | Tag() = default; 54 | Tag(const Tag&) = default; 55 | /** 56 | * Constructor 57 | * @param atts attributes pointer returned by the XML parser 58 | */ 59 | explicit Tag(const char **atts); 60 | Tag(const std::string &k, const std::string &v) { 61 | m_key = k; 62 | m_value = v; 63 | } 64 | 65 | inline std::string key() const {return m_key;} 66 | inline std::string value() const {return m_value;} 67 | friend std::ostream& operator<<(std::ostream &os, const Tag& tag); 68 | 69 | private: 70 | // ! key 71 | std::string m_key; 72 | // ! value 73 | std::string m_value; 74 | }; 75 | 76 | 77 | } // end namespace osm2pgr 78 | #endif // SRC_OSM_TAG_H_ 79 | -------------------------------------------------------------------------------- /src/database/osm_ways_config.cpp: -------------------------------------------------------------------------------- 1 | /*PGR-GNU***************************************************************** 2 | 3 | Copyright (c) 2017 pgRouting developers 4 | Mail: project@pgrouting.org 5 | 6 | ------ 7 | This program is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation; either version 2 of the License, or 10 | (at your option) any later version. 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | ********************************************************************PGR-GNU*/ 19 | 20 | #include "database/table_management.h" 21 | #include "utilities/utilities.h" 22 | #include 23 | 24 | namespace osm2pgr { 25 | 26 | 27 | /* 28 | * configuring TABLE osm_ways 29 | */ 30 | 31 | 32 | Table 33 | Tables::osm_ways_config() const { 34 | Table table( 35 | /* name */ 36 | "osm_ways", 37 | 38 | /* schema */ 39 | m_vm["schema"].as(), 40 | 41 | /* full name */ 42 | "osm_ways", 43 | 44 | /* standard column creation string */ 45 | std::string( 46 | " osm_id bigint PRIMARY KEY" 47 | " , members hstore" 48 | + (m_vm.count("attributes") && m_vm.count("addnodes") ? 49 | (std::string(", attributes hstore")) 50 | : "") 51 | + (m_vm.count("tags") && m_vm.count("addnodes") ? 52 | (std::string(", tags hstore")) 53 | #if 0 54 | (std::string(", tags ") + (m_vm.count("hstore") ? "hstore" : "json")) 55 | #endif 56 | : "")), 57 | 58 | /* other columns */ 59 | /* TODO get from the configuration maybe this task is to be done on the configuration*/ 60 | std::string( 61 | ", tag_name TEXT" 62 | ", tag_value TEXT" 63 | ", name TEXT "), 64 | // end todo 65 | 66 | /* geometry */ 67 | "LINESTRING"); 68 | 69 | 70 | std::vector columns; 71 | columns.push_back("osm_id"); 72 | columns.push_back("members"); 73 | // TODO get from the configuration 74 | columns.push_back("tag_name"); 75 | columns.push_back("tag_value"); 76 | columns.push_back("name"); 77 | // end todo 78 | if (m_vm.count("attributes")) columns.push_back("attributes"); 79 | if (m_vm.count("tags")) columns.push_back("tags"); 80 | columns.push_back("geom"); 81 | 82 | table.set_columns(columns); 83 | 84 | return table; 85 | } 86 | 87 | 88 | } //namespace osm2pgr 89 | -------------------------------------------------------------------------------- /src/database/pois_config.cpp: -------------------------------------------------------------------------------- 1 | /*PGR-GNU***************************************************************** 2 | 3 | Copyright (c) 2017 pgRouting developers 4 | Mail: project@pgrouting.org 5 | 6 | ------ 7 | This program is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation; either version 2 of the License, or 10 | (at your option) any later version. 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | ********************************************************************PGR-GNU*/ 19 | 20 | #include "boost/lexical_cast.hpp" 21 | #include "database/table_management.h" 22 | #include "utilities/utilities.h" 23 | 24 | namespace osm2pgr { 25 | 26 | 27 | /* 28 | * configuring TABLE osm_nodes 29 | */ 30 | 31 | 32 | Table 33 | Tables::pois_config() const { 34 | Table table( 35 | /* name */ 36 | std::string("pointsofinterest"), 37 | 38 | /* schema */ 39 | m_vm["schema"].as(), 40 | 41 | /* full name */ 42 | std::string( 43 | m_vm["prefix"].as() 44 | + "pointsofinterest" 45 | + m_vm["suffix"].as()), 46 | 47 | 48 | /* standard column creation string */ 49 | std::string( 50 | " pid bigserial" 51 | ", osm_id bigint" 52 | ", vertex_id bigint" 53 | ", edge_id bigint" 54 | ", side CHAR" 55 | ", fraction FLOAT" 56 | ", length_m FLOAT" 57 | + (m_vm.count("attributes") ? 58 | (std::string(", attributes hstore")) 59 | : "") 60 | + (m_vm.count("tags") ? 61 | (std::string(", tags hstore")) 62 | : "")), 63 | 64 | /* other columns */ 65 | std::string( 66 | ", tag_name TEXT" 67 | ", tag_value TEXT" 68 | ", name TEXT "), 69 | // end todo 70 | 71 | /* geometry */ 72 | "POINT"); 73 | std::vector columns; 74 | columns.push_back("osm_id"); 75 | columns.push_back("geom"); 76 | // TODO get from the configuration 77 | columns.push_back("tag_name"); 78 | columns.push_back("tag_value"); 79 | columns.push_back("name"); 80 | // end todo 81 | if (m_vm.count("attributes")) columns.push_back("attributes"); 82 | if (m_vm.count("tags")) columns.push_back("tags"); 83 | table.set_columns(columns); 84 | 85 | return table; 86 | } 87 | 88 | 89 | } //namespace osm2pgr 90 | -------------------------------------------------------------------------------- /include/parser/XMLParser.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (C) 2016 by pgRouting developers * 3 | * project@pgrouting.org * 4 | * * 5 | * This program is free software; you can redistribute it and/or modify * 6 | * it under the terms of the GNU General Public License as published by * 7 | * the Free Software Foundation; either version 2 of the License, or * 8 | * (at your option) any later version. * 9 | * * 10 | * This program is distributed in the hope that it will be useful, * 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 13 | * GNU General Public License t &or more details. * 14 | * * 15 | * You should have received a copy of the GNU General Public License * 16 | * along with this program; if not, write to the * 17 | * Free Software Foundation, Inc., * 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 19 | ***************************************************************************/ 20 | 21 | 22 | #ifndef SRC_XMLPARSER_H_ 23 | #define SRC_XMLPARSER_H_ 24 | 25 | #include 26 | 27 | 28 | namespace xml { 29 | 30 | /** 31 | Callback to be used with XMLParser 32 | */ 33 | class XMLParserCallback { 34 | public: 35 | // ! Constructor_ 36 | XMLParserCallback() {} 37 | // ! Destructor 38 | virtual ~XMLParserCallback() {} 39 | 40 | /** 41 | Implement to construct an element with the given name, 42 | call back for parser event "start element" 43 | 44 | \param name [IN] element name 45 | \param atts [IN] the attributes 46 | */ 47 | virtual void StartElement(const char *name, const char** atts) = 0; 48 | 49 | /** 50 | Implement to process parser event "end element" 51 | */ 52 | virtual void EndElement(const char *elementName) = 0; 53 | }; 54 | 55 | /** 56 | XML-Parser based on expat library by 57 | James Clark http://www.jclark.com/xml/expat.html. 58 | 59 | Fast, event driven, non-validating parser 60 | 61 | Dependencies: 62 | - link with xmlparse.lib 63 | - uses xmlparse.dll 64 | */ 65 | class XMLParser { 66 | public: 67 | //! Constructor 68 | XMLParser() {} 69 | //! Destructor 70 | virtual ~XMLParser() {} 71 | 72 | /** 73 | Parse a file from the file system- 74 | 75 | \param rCallback [IN] the parser callback 76 | \param chFileName [IN] name of the file to be parsed 77 | 78 | \return 0: everything ok, 1: file not found, 2: parsing error 79 | */ 80 | int Parse(XMLParserCallback& rCallback, const char* chFileName); 81 | }; 82 | 83 | } // end namespace xml 84 | #endif // SRC_XMLPARSER_H_ 85 | -------------------------------------------------------------------------------- /tools/osmium/include/collectors/turn_restrictions.h: -------------------------------------------------------------------------------- 1 | /*PGR-GNU***************************************************************** 2 | File: turn_restrictions.h 3 | 4 | Copyright (c) 2017 pgRouting developers 5 | 6 | File developer: Celia Virginia Vergara Castillo (2017) 7 | 8 | 9 | ------ 10 | This program is free software; you can redistribute it and/or modify 11 | it under the terms of the GNU General Public License as published by 12 | the Free Software Foundation; either version 2 of the License, or 13 | (at your option) any later version. 14 | This program is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | You should have received a copy of the GNU General Public License 19 | along with this program; if not, write to the Free Software 20 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 21 | ********************************************************************PGR-GNU*/ 22 | 23 | /*! @file */ 24 | 25 | #ifndef TOOLS_OSMIUM_INCLUDE_COLLECTORS_TURN_RESTRICTIONS_H_ 26 | #define TOOLS_OSMIUM_INCLUDE_COLLECTORS_TURN_RESTRICTIONS_H_ 27 | #pragma once 28 | 29 | #include 30 | #include // for std::cout, std::cerr 31 | 32 | 33 | // For the NodeLocationForWays handler 34 | #include 35 | #include 36 | #include 37 | 38 | 39 | 40 | class MyRelCollector : 41 | public osmium::relations::Collector { 42 | public: 43 | MyRelCollector(); 44 | explicit MyRelCollector(std::ostream &file); 45 | 46 | /** 47 | * Interested in all relations tagged with type=restriction 48 | * 49 | * OSM WIKI about restrictions 50 | * http://wiki.openstreetmap.org/wiki/Relation:restriction 51 | * 52 | * Overwritten from the base class. 53 | */ 54 | bool keep_relation(const osmium::Relation& relation) const; 55 | 56 | /** 57 | * Overwritten from the base class. 58 | */ 59 | bool keep_member( 60 | const osmium::relations::RelationMeta&, 61 | const osmium::RelationMember& member) const; 62 | 63 | /* 64 | * (2654080,'no_right_turn',30513235,30513221,336812979,'n','version=>1,timestamp=>2012-12-22T17:01:50Z,changeset=>14368535,uid=>381316,user=>Schermy'::hstore,'except=>hgv,restriction=>no_right_turn,type=>restriction'::hstore) 65 | */ 66 | std::string attributes_str( 67 | const osmium::Relation& relation) const; 68 | 69 | 70 | std::string tags_str( 71 | const osmium::Relation& relation) const; 72 | 73 | /** A Restriction: 74 | * 75 | * from: is of type way 76 | * to: is of type way 77 | * via: can be of type way or node 78 | * can not have a member relation 79 | * 80 | * Overwritten from the base class. 81 | */ 82 | void complete_relation(osmium::relations::RelationMeta& relation_meta); 83 | 84 | void flush(); 85 | 86 | private: 87 | std::ostream &m_file; 88 | }; 89 | 90 | 91 | #endif // TOOLS_OSMIUM_INCLUDE_COLLECTORS_TURN_RESTRICTIONS_H_ 92 | -------------------------------------------------------------------------------- /src/osm_elements/Node.cpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (C) 2016 by pgRouting developers * 3 | * project@pgrouting.org * 4 | * * 5 | * This program is free software; you can redistribute it and/or modify * 6 | * it under the terms of the GNU General Public License as published by * 7 | * the Free Software Foundation; either version 2 of the License, or * 8 | * (at your option) any later version. * 9 | * * 10 | * This program is distributed in the hope that it will be useful, * 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 13 | * GNU General Public License t &or more details. * 14 | * * 15 | * You should have received a copy of the GNU General Public License * 16 | * along with this program; if not, write to the * 17 | * Free Software Foundation, Inc., * 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 19 | ***************************************************************************/ 20 | 21 | 22 | #if 0 23 | #include 24 | #include 25 | #endif 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include "osm_elements/osm_tag.h" 32 | #include "osm_elements/Node.h" 33 | 34 | namespace osm2pgr { 35 | 36 | 37 | Node::Node(const char **atts) : 38 | Element(atts), 39 | m_numsOfUse(0) { 40 | assert(has_attribute("lat")); 41 | assert(has_attribute("lon")); 42 | } 43 | 44 | void 45 | Node::tag_config(const Tag &tag) { 46 | Element::tag_config(tag); 47 | ++m_numsOfUse; 48 | ++m_numsOfUse; 49 | } 50 | 51 | 52 | double 53 | Node::getLength(const Node &previous) const { 54 | auto y1 = boost::lexical_cast(get_attribute("lat")); 55 | auto x1 = boost::lexical_cast(get_attribute("lon")); 56 | auto y2 = boost::lexical_cast(previous.get_attribute("lat")); 57 | auto x2 = boost::lexical_cast(previous.get_attribute("lon")); 58 | return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); 59 | #if 0 60 | typedef boost::geometry::model::d2::point_xy point_type; 61 | 62 | /* converted point to fit boost.geomtery 63 | * * (`p` and `q` are same as `a ` and `b`) 64 | * */ 65 | point_type p( 66 | boost::lexical_cast(get_attribute("lat")), 67 | boost::lexical_cast(get_attribute("lon"))); 68 | 69 | point_type q( 70 | boost::lexical_cast(previous.get_attribute("lat")), 71 | boost::lexical_cast(previous.get_attribute("lon"))); 72 | 73 | return boost::geometry::distance(p, q); 74 | #endif 75 | } 76 | 77 | 78 | 79 | } // namespace osm2pgr 80 | -------------------------------------------------------------------------------- /src/utilities/handle_pgpass.cpp: -------------------------------------------------------------------------------- 1 | /*PGR-GNU***************************************************************** 2 | 3 | Copyright (c) 2017 pgRouting developers 4 | Mail: project@pgrouting.org 5 | 6 | ------ 7 | This program is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation; either version 2 of the License, or 10 | (at your option) any later version. 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | ********************************************************************PGR-GNU*/ 19 | 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | namespace po = boost::program_options; 30 | 31 | void 32 | handle_pgpass(po::variables_map &vm) { 33 | 34 | if (!vm["password"].as().empty()) { 35 | /* 36 | * nothing to do password is given 37 | */ 38 | return; 39 | } 40 | 41 | 42 | 43 | std::string file; 44 | auto filename(getenv("PGPASSFILE")); 45 | if (!filename) { 46 | #if 0 47 | std::cout << "No PGPASSFILE found \n"; 48 | std::cout << "Looking for .pgpass \n"; 49 | #endif 50 | auto homedir(getenv("HOME")); 51 | if (!homedir) { 52 | std::cout << "No $HOME found \n"; 53 | return; 54 | } 55 | #if 0 56 | std::cout << "home directory" << homedir << "\n"; 57 | #endif 58 | file = std::string(homedir) + "/.pgpass"; 59 | } 60 | else { 61 | file = filename; 62 | } 63 | std::ifstream infile(file.c_str()); 64 | if (!infile.good()) { 65 | return; 66 | } 67 | 68 | 69 | std::string host; 70 | std::string port; 71 | std::string dbase; 72 | std::string user; 73 | std::string passwd; 74 | std::string username = vm["username"].as().empty() ? 75 | getenv("USER") : vm["username"].as(); 76 | vm.at("username").value() = username; 77 | while (std::getline(infile, host, ':')) { 78 | std::getline(infile, port, ':'); 79 | std::getline(infile, dbase, ':'); 80 | std::getline(infile, user, ':'); 81 | std::getline(infile, passwd); 82 | if ((host == "" || host == "*" || host == vm["host"].as()) 83 | && (port == "*" || port == vm["port"].as()) 84 | && (dbase == "*" || dbase == vm["dbname"].as()) 85 | && (user == "*" || user == username) 86 | && (dbase == "*" || host == vm["dbname"].as())) { 87 | infile.close(); 88 | #if 0 89 | std::cout << passwd << "\n"; 90 | #endif 91 | vm.at("password").value() = passwd; 92 | return; 93 | } 94 | } 95 | return; 96 | } 97 | -------------------------------------------------------------------------------- /src/osm_elements/Relation.cpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (C) 2016 by pgRouting developers * 3 | * project@pgrouting.org * 4 | * * 5 | * This program is free software; you can redistribute it and/or modify * 6 | * it under the terms of the GNU General Public License as published by * 7 | * the Free Software Foundation; either version 2 of the License, or * 8 | * (at your option) any later version. * 9 | * * 10 | * This program is distributed in the hope that it will be useful, * 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 13 | * GNU General Public License t &or more details. * 14 | * * 15 | * You should have received a copy of the GNU General Public License * 16 | * along with this program; if not, write to the * 17 | * Free Software Foundation, Inc., * 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 19 | ***************************************************************************/ 20 | 21 | 22 | #include 23 | #include 24 | #include "osm_elements/Relation.h" 25 | 26 | namespace osm2pgr { 27 | 28 | 29 | Relation::Relation(const char **atts) : 30 | Element(atts) { } 31 | 32 | 33 | 34 | int64_t 35 | Relation::add_member(const char **atts) { 36 | #if 0 37 | std::cout << " --> " << __PRETTY_FUNCTION__ << "\n"; 38 | #endif 39 | auto **attribut = atts; 40 | std::string type; 41 | int64_t osm_id(0); 42 | std::string role; 43 | while (*attribut != NULL) { 44 | std::string key = *attribut++; 45 | std::string value = *attribut++; 46 | /* 47 | * currently only adding way 48 | */ 49 | if (key == "type") { 50 | if (value != "way") return -1; 51 | } 52 | if (key == "ref") { 53 | osm_id = boost::lexical_cast(value); 54 | } 55 | if (key == "role") { 56 | role = value; 57 | } 58 | } 59 | m_WayRefs.push_back(osm_id); 60 | #if 0 61 | std::cout << "members" << members_str() << "\n"; 62 | std::cout << " <-- " << __PRETTY_FUNCTION__ << "\n"; 63 | #endif 64 | return osm_id; 65 | } 66 | 67 | std::string 68 | Relation::members_str() const { 69 | std::string way_list(""); 70 | for (const auto &way_ref : m_WayRefs) { 71 | way_list += boost::lexical_cast(way_ref) 72 | /* 73 | * currently only adding way 74 | */ 75 | + "=>\"type=>way\","; 76 | } 77 | size_t n = way_list.size(); 78 | if (n > 0) way_list.resize(n - 1); 79 | 80 | return way_list; 81 | } 82 | 83 | std::ostream& operator<<(std::ostream &os, const Relation &r) { 84 | os << r.members_str(); 85 | return os; 86 | } 87 | 88 | } // end namespace osm2pgr 89 | 90 | -------------------------------------------------------------------------------- /mapconfig_for_bicycles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /src/configuration/tag_key.cpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (C) 2016 by pgRouting developers * 3 | * project@pgrouting.org * 4 | * * 5 | * This program is free software; you can redistribute it and/or modify * 6 | * it under the terms of the GNU General Public License as published by * 7 | * the Free Software Foundation; either version 2 of the License, or * 8 | * (at your option) any later version. * 9 | * * 10 | * This program is distributed in the hope that it will be useful, * 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 13 | * GNU General Public License t &or more details. * 14 | * * 15 | * You should have received a copy of the GNU General Public License * 16 | * along with this program; if not, write to the * 17 | * Free Software Foundation, Inc., * 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 19 | ***************************************************************************/ 20 | 21 | #include "configuration/tag_key.h" 22 | #include "utilities/utilities.h" 23 | #include 24 | #include 25 | #include 26 | 27 | namespace osm2pgr { 28 | 29 | 30 | Tag_key::Tag_key(const char **atts) 31 | : Element(atts) { 32 | } 33 | 34 | void 35 | Tag_key::add_tag_value(const Tag_value &value) { 36 | m_Tag_values[value.name()] = value; 37 | } 38 | 39 | bool 40 | Tag_key::has_tag_value(const Tag &tag) const { 41 | return m_Tag_values.count(tag.value()); 42 | } 43 | 44 | const 45 | Tag_value& 46 | Tag_key::tag_value( 47 | const Tag &tag) const { 48 | return m_Tag_values.at(tag.value()); 49 | } 50 | 51 | bool 52 | Tag_key::has(const Tag &tag, const std::string &str) const { 53 | return tag_value(tag).has_attribute(str) 54 | || this->has_attribute(str); 55 | } 56 | 57 | std::string 58 | Tag_key::get(const Tag &tag, const std::string &str) const { 59 | assert(this->has(tag, str)); 60 | return (tag_value(tag).has_attribute(str)) ? 61 | tag_value(tag).get(str) 62 | : this->get_attribute(str); 63 | } 64 | 65 | 66 | std::vector 67 | Tag_key::values(const std::vector &columns) const { 68 | std::vector export_values; 69 | 70 | for (const auto &item : m_Tag_values) { 71 | auto row = item.second.values(columns, true); 72 | row[1] = name(); 73 | row[2] = item.second.get_attribute("name"); 74 | // row[3] has priority 75 | if (row[4] == "") row[4] = "40"; // max_speed 76 | if (row[5] == "") row[5] = row[4]; 77 | if (row[6] == "") row[6] = row[4]; 78 | if (row[7] == "") row[7] = "N"; 79 | export_values.push_back(tab_separated(row)); 80 | } 81 | return export_values; 82 | } 83 | 84 | 85 | } // end namespace osm2pgr 86 | -------------------------------------------------------------------------------- /include/osm_elements/Relation.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (C) 2016 by pgRouting developers * 3 | * project@pgrouting.org * 4 | * * 5 | * This program is free software; you can redistribute it and/or modify * 6 | * it under the terms of the GNU General Public License as published by * 7 | * the Free Software Foundation; either version 2 of the License, or * 8 | * (at your option) any later version. * 9 | * * 10 | * This program is distributed in the hope that it will be useful, * 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 13 | * GNU General Public License t &or more details. * 14 | * * 15 | * You should have received a copy of the GNU General Public License * 16 | * along with this program; if not, write to the * 17 | * Free Software Foundation, Inc., * 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 19 | ***************************************************************************/ 20 | 21 | #ifndef SRC_RELATION_H_ 22 | #define SRC_RELATION_H_ 23 | 24 | #include 25 | #include 26 | #include 27 | #include "./osm_element.h" 28 | 29 | namespace osm2pgr { 30 | class Way; 31 | 32 | /** 33 | \code 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | \endcode 53 | */ 54 | class Relation : public Element{ 55 | public: 56 | /** 57 | * @param atts attributes read py the parser 58 | */ 59 | explicit Relation(const char ** atts); 60 | Relation() = delete; 61 | ~Relation() {}; 62 | Relation(const Relation&) = default; 63 | std::vector way_refs() const {return m_WayRefs;} 64 | std::vector& way_refs() {return m_WayRefs;} 65 | std::string get_geometry() const {return std::string("");} 66 | 67 | /** 68 | * saves the nodes of the way 69 | * @param atts member attributes read py the parser 70 | */ 71 | int64_t add_member(const char **atts); 72 | std::string members_str() const; 73 | 74 | friend std::ostream& operator<<(std::ostream &os, const Relation &r); 75 | 76 | private: 77 | std::vector m_WayRefs; 78 | }; 79 | 80 | 81 | } // end namespace osm2pgr 82 | #endif // SRC_RELATION_H_ 83 | -------------------------------------------------------------------------------- /tools/spelling/fix_typos.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # -*- coding: utf-8 -*- 3 | ############################################################################### 4 | # $Id$ 5 | # 6 | # Project: GDAL 7 | # Purpose: (Interactive) script to identify and fix typos 8 | # Author: Even Rouault 9 | # 10 | ############################################################################### 11 | # Copyright (c) 2016, Even Rouault 12 | # 13 | # Permission is hereby granted, free of charge, to any person obtaining a 14 | # copy of this software and associated documentation files (the "Software"), 15 | # to deal in the Software without restriction, including without limitation 16 | # the rights to use, copy, modify, merge, publish, distribute, sublicense, 17 | # and/or sell copies of the Software, and to permit persons to whom the 18 | # Software is furnished to do so, subject to the following conditions: 19 | # 20 | # The above copyright notice and this permission notice shall be included 21 | # in all copies or substantial portions of the Software. 22 | # 23 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 24 | # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 26 | # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 28 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 29 | # DEALINGS IN THE SOFTWARE. 30 | ############################################################################### 31 | 32 | if ! test -d fix_typos; then 33 | # Get our fork of codespell that adds --words-white-list and full filename support for -S option 34 | mkdir fix_typos 35 | cd fix_typos 36 | git clone https://github.com/rouault/codespell 37 | cd codespell 38 | git checkout gdal_improvements 39 | cd .. 40 | # Aggregate base dictionary + QGIS one + Debian Lintian one 41 | curl https://raw.githubusercontent.com/qgis/QGIS/master/scripts/spelling.dat | sed "s/:/->/" | grep -v "colour->" | grep -v "colours->" > qgis.txt 42 | curl https://anonscm.debian.org/cgit/lintian/lintian.git/plain/data/spelling/corrections| grep "||" | grep -v "#" | sed "s/||/->/" > debian.txt 43 | cat codespell/data/dictionary.txt qgis.txt debian.txt | awk 'NF' > gdal_dict.txt 44 | echo "difered->deferred" >> gdal_dict.txt 45 | echo "differed->deferred" >> gdal_dict.txt 46 | cd .. 47 | fi 48 | 49 | EXCLUDED_FILES="$EXCLUDED_FILES,*/fix_typos/*,*/build/*" 50 | EXCLUDED_FILES="$EXCLUDED_FILES,*/.git/*" 51 | EXCLUDED_FILES="$EXCLUDED_FILES,*/tools/*" 52 | 53 | #WORDS_WHITE_LIST="poSession,FIDN,TRAFIC,HTINK,repID,oCurr,INTREST,oPosition" 54 | #WORDS_WHITE_LIST="$WORDS_WHITE_LIST,CPL_SUPRESS_CPLUSPLUS,SRP_NAM,ADRG_NAM,'SRP_NAM,AuxilaryTarget" 55 | # IRIS driver metadata item names: FIXME ? 56 | #WORDS_WHITE_LIST="$WORDS_WHITE_LIST,TOP_OF_HEIGTH_INTERVAL,BOTTOM_OF_HEIGTH_INTERVAL" 57 | # libjpeg 58 | #WORDS_WHITE_LIST="$WORDS_WHITE_LIST,JBUF_PASS_THRU" 59 | # libgif 60 | #WORDS_WHITE_LIST="$WORDS_WHITE_LIST,IS_WRITEABLE,E_GIF_ERR_NOT_WRITEABLE" 61 | # libtiff 62 | #WORDS_WHITE_LIST="$WORDS_WHITE_LIST,THRESHHOLD_BILEVEL,THRESHHOLD_HALFTONE,THRESHHOLD_ERRORDIFFUSE" 63 | 64 | python3 fix_typos/codespell/codespell.py -w -i 3 -q 2 -S $EXCLUDED_FILES \ 65 | -x tools/spelling/typos_whitelist.txt --words-white-list=$WORDS_WHITE_LIST \ 66 | -D fix_typos/gdal_dict.txt . 67 | 68 | -------------------------------------------------------------------------------- /src/configuration/configuration.cpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (C) 2016 by pgRouting developers * 3 | * project@pgrouting.org * 4 | * * 5 | * This program is free software; you can redistribute it and/or modify * 6 | * it under the terms of the GNU General Public License as published by * 7 | * the Free Software Foundation; either version 2 of the License, or * 8 | * (at your option) any later version. * 9 | * * 10 | * This program is distributed in the hope that it will be useful, * 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 13 | * GNU General Public License t &or more details. * 14 | * * 15 | * You should have received a copy of the GNU General Public License * 16 | * along with this program; if not, write to the * 17 | * Free Software Foundation, Inc., * 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 19 | ***************************************************************************/ 20 | 21 | 22 | #include "configuration/configuration.h" 23 | #include 24 | #include 25 | #include 26 | 27 | namespace osm2pgr { 28 | 29 | void Configuration::add_tag_key(const Tag_key &t_key) { 30 | if (has_tag_key(t_key.name())) { 31 | std::cerr << "Duplicate Tag_key found in condfiguration file" 32 | << t_key.name() << " .... sikipping\n"; 33 | return; 34 | } 35 | m_Tag_keys[t_key.name()] = t_key; 36 | } 37 | 38 | 39 | bool 40 | Configuration::has_tag_key(const std::string &key) const { 41 | return m_Tag_keys.count(key) != 0; 42 | } 43 | 44 | 45 | bool 46 | Configuration::has_tag(const Tag &tag) const { 47 | return has_tag_key(tag.key()) 48 | && tag_key(tag).has_tag_value(tag); 49 | } 50 | 51 | 52 | const Tag_value& 53 | Configuration::tag_value(const Tag &tag) const { 54 | return tag_key(tag).tag_value(tag); 55 | } 56 | 57 | 58 | const Tag_key& 59 | Configuration::tag_key(const Tag &tag) const { 60 | return m_Tag_keys.at(tag.key()); 61 | } 62 | 63 | 64 | double 65 | Configuration::maxspeed(const Tag &tag) const { 66 | if (tag_key(tag).has(tag, "maxspeed")) 67 | return boost::lexical_cast(tag_key(tag).get(tag, "maxspeed")); 68 | return 50; 69 | } 70 | 71 | double 72 | Configuration::maxspeed_forward(const Tag &tag) const { 73 | if (tag_key(tag).has(tag, "maxspeed:backward")) 74 | return boost::lexical_cast(tag_key(tag).get(tag, "maxspeed:backward")); 75 | return maxspeed(tag); 76 | } 77 | 78 | double 79 | Configuration::maxspeed_backward(const Tag &tag) const { 80 | if (tag_key(tag).has(tag, "maxspeed:forward")) 81 | return boost::lexical_cast(tag_key(tag).get(tag, "maxspeed:backward")); 82 | return maxspeed(tag); 83 | } 84 | 85 | double 86 | Configuration::priority(const Tag &tag) const { 87 | if (tag_key(tag).has(tag, "priority")) 88 | return boost::lexical_cast(tag_key(tag).get(tag, "priority")); 89 | return 0; 90 | } 91 | 92 | 93 | } // end namespace osm2pgr 94 | -------------------------------------------------------------------------------- /src/parser/XMLParser.cpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (C) 2016 by pgRouting developers * 3 | * project@pgrouting.org * 4 | * * 5 | * This program is free software; you can redistribute it and/or modify * 6 | * it under the terms of the GNU General Public License as published by * 7 | * the Free Software Foundation; either version 2 of the License, or * 8 | * (at your option) any later version. * 9 | * * 10 | * This program is distributed in the hope that it will be useful, * 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 13 | * GNU General Public License t &or more details. * 14 | * * 15 | * You should have received a copy of the GNU General Public License * 16 | * along with this program; if not, write to the * 17 | * Free Software Foundation, Inc., * 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 19 | ***************************************************************************/ 20 | 21 | 22 | #include "parser/XMLParser.h" 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | 30 | 31 | namespace xml { 32 | 33 | //------------------------------------- global Expat Callbacks: 34 | 35 | static void startElement(void *userData, const char *name, const char **atts) { 36 | XMLParserCallback* pCallback = 37 | reinterpret_cast(userData); 38 | if (pCallback) pCallback->StartElement(name, atts); 39 | } 40 | 41 | static void endElement(void *userData, const char *name) { 42 | XMLParserCallback* pCallback = 43 | reinterpret_cast(userData); 44 | if (pCallback) pCallback->EndElement(name); 45 | } 46 | 47 | 48 | 49 | 50 | int XMLParser::Parse(XMLParserCallback& rCallback, const char* chFileName) { 51 | int ret = 1; // File not found 52 | 53 | FILE* fp = fopen(chFileName, "rb"); 54 | if (fp) { 55 | XML_Parser parser = XML_ParserCreate(NULL); 56 | 57 | XML_SetUserData(parser, static_cast(&rCallback)); 58 | 59 | // register Callbacks for start- and end-element events of the parser: 60 | XML_SetElementHandler(parser, startElement, endElement); 61 | 62 | int done; 63 | do { // loop over whole file content 64 | char buf[BUFSIZ]; 65 | size_t len = fread(buf, 1, sizeof(buf), fp); // read chunk of data 66 | // end of file reached if buffer not completely filled 67 | done = len < sizeof(buf); 68 | if (!XML_Parse(parser, buf, static_cast(len), done)) { 69 | // a parse error occurred: 70 | std::cerr << 71 | XML_ErrorString(XML_GetErrorCode(parser)) 72 | << " at line " 73 | << static_cast(XML_GetCurrentLineNumber(parser)); 74 | fclose(fp); 75 | ret = 2; // quit, return = 2 indicating parsing error 76 | done = 1; 77 | return ret; 78 | } 79 | } while (!done); 80 | 81 | XML_ParserFree(parser); 82 | fclose(fp); 83 | ret = 0; 84 | } else { 85 | std::cerr << "Error opening " << chFileName << ":" << std::strerror(errno); 86 | } 87 | return ret; // return = 0 indicating success 88 | } 89 | 90 | 91 | 92 | } // end namespace xml 93 | //! \endcond 94 | -------------------------------------------------------------------------------- /include/configuration/configuration.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (C) 2016 by pgRouting developers * 3 | * project@pgrouting.org * 4 | * * 5 | * This program is free software; you can redistribute it and/or modify * 6 | * it under the terms of the GNU General Public License as published by * 7 | * the Free Software Foundation; either version 2 of the License, or * 8 | * (at your option) any later version. * 9 | * * 10 | * This program is distributed in the hope that it will be useful, * 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 13 | * GNU General Public License t &or more details. * 14 | * * 15 | * You should have received a copy of the GNU General Public License * 16 | * along with this program; if not, write to the * 17 | * Free Software Foundation, Inc., * 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 19 | ***************************************************************************/ 20 | #ifndef SRC_CONFIGURATION_H_ 21 | #define SRC_CONFIGURATION_H_ 22 | 23 | #include 24 | #include 25 | #include 26 | #include "configuration/tag_key.h" 27 | #include "configuration/tag_value.h" 28 | #include "osm_elements/osm_tag.h" 29 | 30 | namespace osm2pgr { 31 | class Configuration { 32 | public: 33 | Configuration() = default; 34 | 35 | /** @brief add group of tag_key + all the tag_values 36 | * 37 | * @param[in] t_key Tag_key found in the configuration 38 | */ 39 | void add_tag_key(const Tag_key &t_key); 40 | 41 | /** @brief retrieves the Tag_value (attrributes 42 | * 43 | * @param[in] tag Tag found in the configuration 44 | * @returns Tag_value 45 | */ 46 | const Tag_value& tag_value(const Tag &tag) const; 47 | 48 | /* Is the (key, value) pair in the configuration? 49 | * 50 | * 51 | * @param[in] tag Tag (key, value) pair 52 | */ 53 | bool has_tag(const Tag &tag) const; 54 | 55 | /** retrieves the maxspeed based on the tag 56 | * 57 | * if the (key,value) has a value this is returned 58 | * else if the (key, *) has a value this is returned 59 | * else 50 is returned 60 | */ 61 | 62 | double maxspeed(const Tag &tag) const; 63 | double maxspeed_forward(const Tag &tag) const; 64 | double maxspeed_backward(const Tag &tag) const; 65 | 66 | /** retrieves the priority based on the tag 67 | * 68 | * if the (key,value) has a value this is returned 69 | * else if the (key, *) has a value this is returned 70 | * else 0 is returned 71 | */ 72 | 73 | double priority(const Tag &tag) const; 74 | 75 | /* 76 | * data to be exported to configuration TABLE 77 | */ 78 | const std::map& types() const {return m_Tag_keys;} 79 | 80 | private: 81 | /** @brief is the tag key in the configuration file 82 | * 83 | * @param[in] key tag_key name="key" 84 | */ 85 | 86 | bool has_tag_key(const std::string &key) const; 87 | const Tag_key& tag_key(const Tag &tag) const; 88 | 89 | 90 | private: 91 | std::map m_Tag_keys; 92 | }; 93 | 94 | 95 | } // end namespace osm2pgr 96 | #endif // SRC_CONFIGURATION_H_ 97 | 98 | 99 | 100 | -------------------------------------------------------------------------------- /include/osm_elements/osm_element.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (C) 2016 by pgRouting developers * 3 | * project@pgrouting.org * 4 | * * 5 | * This program is free software; you can redistribute it and/or modify * 6 | * it under the terms of the GNU General Public License as published by * 7 | * the Free Software Foundation; either version 2 of the License, or * 8 | * (at your option) any later version. * 9 | * * 10 | * This program is distributed in the hope that it will be useful, * 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 13 | * GNU General Public License t &or more details. * 14 | * * 15 | * You should have received a copy of the GNU General Public License * 16 | * along with this program; if not, write to the * 17 | * Free Software Foundation, Inc., * 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 19 | ***************************************************************************/ 20 | 21 | 22 | #ifndef SRC_OSM_ELEMENT_H_ 23 | #define SRC_OSM_ELEMENT_H_ 24 | #pragma once 25 | 26 | #include 27 | #include 28 | #include 29 | #include "./osm_tag.h" 30 | 31 | namespace osm2pgr { 32 | 33 | 34 | /** @brief osm elements 35 | 36 | osm elements can be: 37 | 38 | @code 39 | & attributes() {return m_attributes;} 74 | const std::map attributes() const { 75 | return m_attributes; 76 | } 77 | 78 | 79 | bool has_tag(const std::string&) const; 80 | std::string get_tag(const std::string&) const; 81 | 82 | bool has_tags() const {return !m_tags.empty();} 83 | std::map& tags() {return m_tags;} 84 | const std::map tags() const {return m_tags;} 85 | 86 | std::vector values( 87 | const std::vector &columns, 88 | bool is_hstore) const; 89 | virtual std::string members_str() const {return std::string();}; 90 | 91 | protected: 92 | // ! OSM ID of the element 93 | // or id of a configuraton 94 | int64_t m_osm_id; 95 | bool m_visible; 96 | Tag m_tag_config; 97 | 98 | 99 | std::map m_tags; 100 | std::map m_attributes; 101 | }; 102 | 103 | 104 | } // namespace osm2pgr 105 | #endif // SRC_OSM_ELEMENT_H_ 106 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | cmake_minimum_required(VERSION 3.12 FATAL_ERROR) 3 | 4 | 5 | if ( ${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR} ) 6 | message(FATAL_ERROR "In-source builds not allowed. 7 | Please make a new directory (called a build directory) and run CMake from there. 8 | You may need to remove CMakeCache.txt." ) 9 | endif() 10 | 11 | PROJECT(osm2pgrouting VERSION 3.0.0 12 | LANGUAGES C CXX) 13 | 14 | LIST(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake") 15 | SET(SHARE_DIR "${CMAKE_INSTALL_PREFIX}/share/osm2pgrouting") 16 | 17 | find_package(PostgreSQL REQUIRED) 18 | find_package(PQXX REQUIRED) 19 | include_directories(${PQXX_INCLUDE_DIR}) 20 | find_package(EXPAT REQUIRED) 21 | 22 | 23 | FILE(GLOB osm2pgrouting_lib_SOURCES "${CMAKE_SOURCE_DIR}/src/*/*.cpp") 24 | 25 | #--------------------------------------------- 26 | # C++ Compiler requirements 27 | #--------------------------------------------- 28 | #--------------------------------------------- 29 | 30 | #--------------------------------------------- 31 | # Boost 32 | #--------------------------------------------- 33 | #--------------------------------------------- 34 | find_package(Boost ${BOOST_MINIMUM_VERSION} REQUIRED COMPONENTS program_options) 35 | if (NOT Boost_VERSION_MACRO) 36 | set(Boost_VERSION_MACRO ${Boost_VERSION}) 37 | endif() 38 | add_definitions(-DBoost_VERSION_MACRO=${Boost_VERSION_MACRO}) 39 | add_definitions(-DBOOST_ALLOW_DEPRECATED_HEADERS) 40 | include_directories(SYSTEM ${Boost_INCLUDE_DIRS}) 41 | 42 | 43 | message(STATUS "PQXX_VERSION=${PQXX_VERSION}") 44 | if (PQXX_VERSION VERSION_GREATER_EQUAL "7.0.0") 45 | set(CMAKE_CXX_STANDARD 17) 46 | else() 47 | add_definitions(-DPQXX_DISCONNECT) 48 | set(CMAKE_CXX_STANDARD 14) 49 | endif() 50 | 51 | set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_FILE_OFFSET_BITS=64") 52 | set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall -Wconversion -pedantic -Wextra -frounding-math -Wno-deprecated") 53 | 54 | if(WIN32 AND MSVC) 55 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_CRT_SECURE_NO_DEPRECATE") 56 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_SCL_SECURE_NO_DEPRECATE") 57 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_CRT_SECURE_NO_WARNINGS") 58 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_SCL_SECURE_NO_WARNINGS") 59 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_CRT_NONSTDC_NO_DEPRECATE") 60 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -EHsc") 61 | endif() 62 | 63 | #-------------------------------------------------------- 64 | 65 | set (OSM2PGROUTING_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/include") 66 | message(STATUS "PQXX_INCLUDE_DIR: ${PQXX_INCLUDE_DIR}") 67 | message(STATUS "POSTGRESQL_INCLUDE_DIR: ${POSTGRESQL_INCLUDE_DIR}") 68 | message(STATUS "EXPAT_INCLUDE_DIRS: ${EXPAT_INCLUDE_DIRS}") 69 | message(STATUS "Boost_INCLUDE_DIRS: ${Boost_INCLUDE_DIRS}") 70 | message(STATUS "POSTGRESQL_LIBRARIES: ${POSTGRESQL_LIBRARIES}") 71 | message(STATUS "Boost_LIBRARIES: ${boost_LIBRARIES}") 72 | message(STATUS "PQXX_LIBRARIES: ${PQXX_LIBRARIES}") 73 | 74 | INCLUDE_DIRECTORIES(src 75 | ${POSTGRESQL_INCLUDE_DIR} 76 | ${EXPAT_INCLUDE_DIRS} 77 | ${OSM2PGROUTING_INCLUDE_DIRS} 78 | ) 79 | 80 | ADD_EXECUTABLE(osm2pgrouting ${osm2pgrouting_lib_SOURCES}) 81 | 82 | TARGET_LINK_LIBRARIES(osm2pgrouting 83 | ${PQXX_LIBRARIES} 84 | ${POSTGRESQL_LIBRARIES} 85 | ${EXPAT_LIBRARIES} 86 | ${Boost_LIBRARIES} 87 | ) 88 | 89 | INSTALL(TARGETS osm2pgrouting 90 | RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}/bin" 91 | ) 92 | 93 | if(WIN32) 94 | target_link_libraries(osm2pgrouting wsock32 ws2_32) 95 | endif() 96 | 97 | INSTALL(FILES 98 | "${CMAKE_SOURCE_DIR}/COPYING" 99 | "${CMAKE_SOURCE_DIR}/README.md" 100 | "${CMAKE_SOURCE_DIR}/mapconfig.xml" 101 | "${CMAKE_SOURCE_DIR}/mapconfig_for_cars.xml" 102 | "${CMAKE_SOURCE_DIR}/mapconfig_for_bicycles.xml" 103 | "${CMAKE_SOURCE_DIR}/mapconfig_for_pedestrian.xml" 104 | DESTINATION "${SHARE_DIR}") 105 | 106 | 107 | #INCLUDE_DIRECTORIES( ${Boost_INCLUDE_DIR} ) 108 | #TARGET_LINK_LIBRARIES( osm2pgrouting ${Boost_LIBRARIES} ) 109 | -------------------------------------------------------------------------------- /include/osm_elements/Node.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (C) 2016 by pgRouting developers * 3 | * project@pgrouting.org * 4 | * * 5 | * This program is free software; you can redistribute it and/or modify * 6 | * it under the terms of the GNU General Public License as published by * 7 | * the Free Software Foundation; either version 2 of the License, or * 8 | * (at your option) any later version. * 9 | * * 10 | * This program is distributed in the hope that it will be useful, * 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 13 | * GNU General Public License t &or more details. * 14 | * * 15 | * You should have received a copy of the GNU General Public License * 16 | * along with this program; if not, write to the * 17 | * Free Software Foundation, Inc., * 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 19 | ***************************************************************************/ 20 | 21 | 22 | #ifndef SRC_NODE_H_ 23 | #define SRC_NODE_H_ 24 | #pragma once 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include "./osm_element.h" 31 | 32 | namespace osm2pgr { 33 | 34 | class Tag; 35 | /** 36 | @code 37 | 39 | 40 | 41 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | @endcode 59 | */ 60 | 61 | class Node : public Element { 62 | public: 63 | Node() = default; 64 | Node(const Node&) = default; 65 | /** 66 | * @param atts attributes read py the parser 67 | */ 68 | explicit Node(const char **atts); 69 | ~Node() {}; 70 | 71 | inline std::string geom_str(const std::string separator) const { 72 | return get_attribute("lon") + separator + get_attribute("lat"); 73 | } 74 | inline std::string lat() {return get_attribute("lat");} 75 | inline std::string lon() {return get_attribute("lon");} 76 | 77 | void tag_config(const Tag &tag); 78 | 79 | 80 | std::string get_geometry() const { 81 | return 82 | std::string("srid=4326; POINT(") 83 | + geom_str(" ") + ")"; 84 | } 85 | 86 | inline std::string osm_id_str() { 87 | return boost::lexical_cast(m_osm_id); 88 | } 89 | double getLength(const Node &previous) const; 90 | 91 | 92 | inline uint16_t incrementUse() {return ++m_numsOfUse;} 93 | inline uint16_t numsOfUse() const {return m_numsOfUse;} 94 | inline void numsOfUse(uint16_t val) {m_numsOfUse = val;} 95 | 96 | private: 97 | /** 98 | * counts the rate, how much this node is used in different ways 99 | */ 100 | uint16_t m_numsOfUse; 101 | }; 102 | 103 | 104 | } // end namespace osm2pgr 105 | #endif // SRC_NODE_H_ 106 | -------------------------------------------------------------------------------- /src/database/edges_config.cpp: -------------------------------------------------------------------------------- 1 | /*PGR-GNU***************************************************************** 2 | 3 | Copyright (c) 2017 pgRouting developers 4 | Mail: project@pgrouting.org 5 | 6 | ------ 7 | This program is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation; either version 2 of the License, or 10 | (at your option) any later version. 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | ********************************************************************PGR-GNU*/ 19 | 20 | #include 21 | 22 | #include "boost/lexical_cast.hpp" 23 | #include "database/table_management.h" 24 | #include "utilities/utilities.h" 25 | 26 | namespace osm2pgr { 27 | 28 | 29 | /* 30 | * configuring TABLE edges_pgr 31 | */ 32 | 33 | 34 | Table 35 | Tables::ways_config() const { 36 | Table table( 37 | /* name */ 38 | "ways", 39 | 40 | /* schema */ 41 | m_vm["schema"].as(), 42 | 43 | /* full name */ 44 | std::string( 45 | m_vm["prefix"].as() 46 | + "ways" 47 | + m_vm["suffix"].as()), 48 | 49 | /* standard column creation string */ 50 | std::string( 51 | " id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY" 52 | ", osm_id BIGINT" 53 | ", tag_id integer" 54 | 55 | ", length double precision" 56 | ", length_m double precision" 57 | ", name text" 58 | ", source bigint" 59 | ", target bigint" 60 | ", source_osm bigint" 61 | ", target_osm bigint" 62 | 63 | ", cost double precision" 64 | ", reverse_cost double precision" 65 | ", cost_s double precision " 66 | ", reverse_cost_s double precision" 67 | ", rule text" 68 | ", one_way int " 69 | ", oneway TEXT " 70 | 71 | ", x1 double precision" 72 | ", y1 double precision" 73 | ", x2 double precision" 74 | ", y2 double precision" 75 | 76 | ", maxspeed_forward double precision" 77 | ", maxspeed_backward double precision" 78 | ", priority double precision DEFAULT 1" 79 | ", geom GEOMETRY(LINESTRING, 4326)" 80 | #if 0 81 | + (m_vm.count("attributes") ? 82 | (std::string(", attributes ") + (m_vm.count("hstore") ? "hstore" : "json")) 83 | : "") 84 | + (m_vm.count("tags") ? 85 | (std::string(", tags ") + (m_vm.count("hstore") ? "hstore" : "json")) 86 | : "") 87 | #endif 88 | ), 89 | 90 | /* other columns */ 91 | "", 92 | 93 | /* geometry */ 94 | ""); 95 | 96 | std::vector columns; 97 | columns.push_back("tag_id"); 98 | columns.push_back("osm_id"); 99 | columns.push_back("maxspeed_forward"); 100 | columns.push_back("maxspeed_backward"); 101 | columns.push_back("one_way"); 102 | columns.push_back("oneway"); 103 | columns.push_back("priority"); 104 | 105 | columns.push_back("length"); 106 | columns.push_back("x1"); columns.push_back("y1"); 107 | columns.push_back("x2"); columns.push_back("y2"); 108 | columns.push_back("source_osm"); 109 | columns.push_back("target_osm"); 110 | columns.push_back("geom"); 111 | columns.push_back("cost"); 112 | columns.push_back("reverse_cost"); 113 | columns.push_back("name"); 114 | 115 | 116 | #if 0 117 | // TODO get from the configuration 118 | columns.push_back("tag_name"); 119 | columns.push_back("tag_value"); 120 | 121 | // end todo 122 | if (m_vm.count("attributes")) columns.push_back("attributes"); 123 | if (m_vm.count("tags")) columns.push_back("tags"); 124 | #endif 125 | table.set_columns(columns); 126 | 127 | return table; 128 | } 129 | 130 | 131 | } //namespace osm2pgr 132 | -------------------------------------------------------------------------------- /tools/osmium/src/getrestrictions.cpp: -------------------------------------------------------------------------------- 1 | /*PGR-GNU***************************************************************** 2 | * File: getrestrictions.cpp 3 | * 4 | Copyright (c) 2017 pgRouting developers 5 | * 6 | * File developer: Celia Virginia Vergara Castillo (2017) 7 | * 8 | * 9 | * ------ 10 | * This program is free software; you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation; either version 2 of the License, or 13 | * (at your option) any later version. 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 21 | * ********************************************************************PGR-GNU*/ 22 | 23 | /*! @file */ 24 | 25 | 26 | #include 27 | #include // for std::cout, std::cerr 28 | 29 | #include "utilities/quotes_handling.h" 30 | #include "collectors/turn_restrictions.h" 31 | 32 | // For the DynamicHandler class 33 | #include 34 | 35 | 36 | // For the NodeLocationForWays handler 37 | #include 38 | 39 | // Allow any format of input files (XML, PBF, ...) 40 | #include 41 | 42 | 43 | 44 | 45 | 46 | main(int argc, char *argv[]) { 47 | using index_type = osmium::index::map::SparseMemArray; 48 | using location_handler_type = osmium::handler::NodeLocationsForWays; 49 | 50 | if (argc != 2) { 51 | std::cerr << "file to process missing\n"; 52 | exit(1); 53 | } 54 | /* 55 | * the input file 56 | */ 57 | std::string in_file_name = argv[1]; 58 | std::string out_file_name = 59 | std::string(in_file_name, 0, in_file_name.size()-4) + "_restrictions.sql"; 60 | 61 | std::cout << "processing: " << in_file_name << "\n"; 62 | std::cout << "results at: " << out_file_name << "\n"; 63 | 64 | /* 65 | * The output file 66 | */ 67 | std::ofstream of(out_file_name); 68 | 69 | /* 70 | * Reading the create table query 71 | */ 72 | std::ifstream f("../restrictions.sql"); 73 | std::stringstream buffer; 74 | 75 | /* 76 | * output of the create tables 77 | */ 78 | of << f.rdbuf(); 79 | 80 | f.close(); 81 | 82 | std::string str = buffer.str(); 83 | std::cout << str << "\n"; 84 | 85 | osmium::handler::DynamicHandler handler; 86 | osmium::relations::RelationMeta relation_meta; 87 | 88 | MyRelCollector collector(of); 89 | std::cerr << "Pass 1...\n"; 90 | osmium::io::Reader reader1{in_file_name, osmium::osm_entity_bits::relation}; 91 | collector.read_relations(reader1); 92 | reader1.close(); 93 | std::cerr << "Pass 1 done\n"; 94 | 95 | 96 | // Output the amount of main memory used so far. All multipolygon relations 97 | // are in memory now. 98 | std::cerr << "Memory:\n"; 99 | collector.used_memory(); 100 | 101 | // The index storing all node locations. 102 | index_type index; 103 | 104 | // The handler that stores all node locations in the index and adds them 105 | // to the ways. 106 | location_handler_type location_handler{index}; 107 | 108 | // If a location is not available in the index, we ignore it. It might 109 | // not be needed (if it is not part of a multipolygon relation), so why 110 | // create an error? 111 | location_handler.ignore_errors(); 112 | 113 | // On the second pass we read all objects and run them first through the 114 | // node location handler and then the multipolygon collector. The collector 115 | // will put the areas it has created into the "buffer" which are then 116 | // fed through our "handler". 117 | std::cerr << "Pass 2...\n"; 118 | osmium::io::Reader reader2{in_file_name}; 119 | osmium::apply(reader2, location_handler, collector.handler([&handler](osmium::memory::Buffer&& buffer) { 120 | osmium::apply(buffer, handler); 121 | })); 122 | of << "\\."; 123 | std::cerr << "Pass 2 done\n"; 124 | 125 | std::ifstream l("../restrictions_end.sql"); 126 | of << l.rdbuf(); 127 | l.close(); 128 | 129 | of.close(); 130 | 131 | reader2.close(); 132 | // Output the amount of main memory used so far. All complete multipolygon 133 | // relations have been cleaned up. 134 | std::cerr << "Memory:\n"; 135 | collector.used_memory(); 136 | } 137 | -------------------------------------------------------------------------------- /include/osm_elements/Way.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (C) 2016 by pgRouting developers * 3 | * project@pgrouting.org * 4 | * * 5 | * This program is free software; you can redistribute it and/or modify * 6 | * it under the terms of the GNU General Public License as published by * 7 | * the Free Software Foundation; either version 2 of the License, or * 8 | * (at your option) any later version. * 9 | * * 10 | * This program is distributed in the hope that it will be useful, * 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 13 | * GNU General Public License t &or more details. * 14 | * * 15 | * You should have received a copy of the GNU General Public License * 16 | * along with this program; if not, write to the * 17 | * Free Software Foundation, Inc., * 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 19 | ***************************************************************************/ 20 | 21 | #ifndef SRC_WAY_H_ 22 | #define SRC_WAY_H_ 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include "./osm_element.h" 29 | #include "./Node.h" 30 | 31 | namespace osm2pgr { 32 | 33 | 34 | /** 35 | \code 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | \endcode 53 | */ 54 | class Way : public Element { 55 | public: 56 | Way() = default; 57 | ~Way() {}; 58 | 59 | /** 60 | * @param atts attributes read py the parser 61 | */ 62 | explicit Way(const char **atts); 63 | Tag add_tag(const Tag &tag); 64 | void add_node(Node* node); 65 | void add_node(int64_t node_id); 66 | 67 | std::vector& nodeRefs() {return m_NodeRefs;} 68 | const std::vector nodeRefs() const {return m_NodeRefs;} 69 | 70 | 71 | std::string members_str() const; 72 | 73 | public: 74 | inline void maxspeed_forward(double p_max) {m_maxspeed_forward = p_max;} 75 | inline void maxspeed_backward(double p_max) {m_maxspeed_backward = p_max;} 76 | 77 | inline std::string name() const {return has_tag("name")? get_tag("name") : "";} 78 | 79 | 80 | std::string oneWay() const; 81 | std::string oneWayType_str() const; 82 | inline bool is_oneway() const { return m_oneWay == "YES";} 83 | inline bool is_reversed() const { return m_oneWay == "REVERSED";} 84 | 85 | inline double maxspeed_forward() const {return m_maxspeed_forward;} 86 | inline double maxspeed_backward() const { return m_maxspeed_backward;} 87 | 88 | std::string get_geometry() const; 89 | std::string length_str() const; 90 | 91 | 92 | inline std::string maxspeed_forward_str() const { 93 | return boost::lexical_cast(m_maxspeed_forward); 94 | } 95 | inline std::string maxspeed_backward_str() const { 96 | return boost::lexical_cast(m_maxspeed_backward); 97 | } 98 | 99 | 100 | //! splits the way 101 | std::vector> split_me(); 102 | std::string geometry_str(const std::vector &) const; 103 | std::string length_str(const std::vector &) const; 104 | 105 | /** 106 | * to insert the relations tags 107 | */ 108 | void insert_tags(const std::map &tags); 109 | 110 | #ifndef NDEBUG 111 | friend 112 | std::ostream& operator<<(std::ostream &, const Way &); 113 | #endif 114 | 115 | 116 | private: 117 | bool is_number(const std::string& s) const; 118 | double get_kph(const std::string &value) const; 119 | void max_speed(const Tag& tag); 120 | void oneWay(const Tag& tag); 121 | void implied_oneWay(const Tag& tag); 122 | 123 | 124 | private: 125 | /** references to node that its on the file */ 126 | std::vector m_NodeRefs; 127 | 128 | /** node identifiers found as part of the way */ 129 | std::vector m_node_ids; 130 | 131 | double m_maxspeed_forward; 132 | double m_maxspeed_backward; 133 | std::string m_oneWay; 134 | }; 135 | 136 | 137 | } // end namespace osm2pgr 138 | #endif // SRC_WAY_H_ 139 | -------------------------------------------------------------------------------- /include/database/table_management.h: -------------------------------------------------------------------------------- 1 | /*PGR-GNU***************************************************************** 2 | 3 | Copyright (c) 2017 pgRouting developers 4 | Mail: project@pgrouting.org 5 | 6 | ------ 7 | This program is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation; either version 2 of the License, or 10 | (at your option) any later version. 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | ********************************************************************PGR-GNU*/ 19 | 20 | /** @file **/ 21 | #pragma once 22 | #include 23 | #include "utilities/prog_options.h" 24 | 25 | namespace osm2pgr { 26 | 27 | class Table { 28 | public: 29 | Table() = default; 30 | Table(const Table &) = default; 31 | Table( 32 | const std::string &schema, 33 | const std::string &name, 34 | const std::string &full_name, 35 | 36 | const std::string &create_str, 37 | const std::string &other_columns, 38 | const std::string &geometry 39 | ); 40 | 41 | void set_columns(const std::vector &columns); 42 | 43 | /** @brief prefixNameSufix */ 44 | inline std::string table_name() const { 45 | return m_full_name; 46 | } 47 | 48 | 49 | /** @brief schema.prefixNameSufix 50 | * 51 | * schema.prefixNameSufix 52 | * OR 53 | * prefixNameSufix 54 | * 55 | */ 56 | std::string addSchema() const; 57 | std::string temp_name() const; 58 | std::string name() const {return m_name;}; 59 | std::string full_name() const {return m_full_name;}; 60 | 61 | /** sql queries 62 | */ 63 | std::string primary_key(const std::string &column) const; 64 | std::string unique(const std::string &column) const; 65 | std::string foreign_key( 66 | const std::string &column, 67 | const Table &table, 68 | const std::string &table_column) const; 69 | std::string gist_index() const; 70 | 71 | inline std::vector columns() const { 72 | return m_columns; 73 | } 74 | std::string sql(size_t i) const {return m_sql[i];} 75 | 76 | 77 | std::string tmp_create() const; 78 | std::string create() const; 79 | std::string drop() const; 80 | 81 | /* modifier */ 82 | void add_sql(const string& sql) { 83 | m_sql.push_back(sql); 84 | } 85 | 86 | private: 87 | std::string m_name; 88 | std::string m_schema; 89 | std::string m_full_name; 90 | 91 | std::string m_create; 92 | std::string m_other_columns; 93 | std::string m_constraint; 94 | std::string m_geometry; 95 | std::vector m_columns; 96 | 97 | /** aditional sqls (for pois) to keep code clean*/ 98 | std::vector m_sql; 99 | }; 100 | 101 | 102 | 103 | 104 | class Tables { 105 | public: 106 | Tables(const po::variables_map &vm); 107 | 108 | const Table& get_table(const std::string &name) const { 109 | if (name == "osm_nodes") return osm_nodes(); 110 | else if (name == "osm_ways") return osm_ways(); 111 | else if (name == "osm_relations") return osm_relations(); 112 | else if (name == "configuration") return configuration(); 113 | else if (name == "pointsofinterest") return pois(); 114 | else if (name == "ways") return ways(); 115 | else return vertices(); 116 | } 117 | 118 | std::string post_process(const Table &table) const; 119 | 120 | 121 | 122 | po::variables_map m_vm; 123 | 124 | private: 125 | /* 126 | * Conpulsory tables 127 | */ 128 | Table m_ways; 129 | Table m_ways_vertices_pgr; 130 | Table m_points_of_interest; 131 | Table m_configuration; 132 | 133 | /* 134 | * Optional tables 135 | */ 136 | Table m_osm_nodes; 137 | Table m_osm_ways; 138 | Table m_osm_relations; 139 | 140 | public: 141 | const Table& ways() const {return m_ways;} 142 | const Table& vertices() const {return m_ways_vertices_pgr;} 143 | const Table& pois() const {return m_points_of_interest;} 144 | const Table& configuration() const {return m_configuration;} 145 | const Table& osm_nodes() const {return m_osm_nodes;} 146 | const Table& osm_ways() const {return m_osm_ways;} 147 | const Table& osm_relations() const {return m_osm_relations;} 148 | 149 | private: 150 | Table osm_nodes_config() const; 151 | Table pois_config() const; 152 | Table osm_ways_config() const; 153 | Table osm_relations_config() const; 154 | Table configuration_config() const; 155 | Table ways_config() const; 156 | Table ways_vertices_pgr_config() const; 157 | }; 158 | 159 | } 160 | 161 | 162 | -------------------------------------------------------------------------------- /include/osm_elements/OSMDocument.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (C) 2016 by pgRouting developers * 3 | * project@pgrouting.org * 4 | * * 5 | * This program is free software; you can redistribute it and/or modify * 6 | * it under the terms of the GNU General Public License as published by * 7 | * the Free Software Foundation; either version 2 of the License, or * 8 | * (at your option) any later version. * 9 | * * 10 | * This program is distributed in the hope that it will be useful, * 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 13 | * GNU General Public License t &or more details. * 14 | * * 15 | * You should have received a copy of the GNU General Public License * 16 | * along with this program; if not, write to the * 17 | * Free Software Foundation, Inc., * 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 19 | ***************************************************************************/ 20 | 21 | 22 | #ifndef SRC_OSMDOCUMENT_H_ 23 | #define SRC_OSMDOCUMENT_H_ 24 | 25 | #include 26 | #include 27 | #include 28 | #include "utilities/utilities.h" 29 | #include "configuration/configuration.h" 30 | #include "utilities/prog_options.h" 31 | #include "database/Export2DB.h" 32 | 33 | namespace osm2pgr { 34 | 35 | 36 | class Node; 37 | class Way; 38 | class Relation; 39 | 40 | /** 41 | An osm-document. 42 | */ 43 | class OSMDocument { 44 | public: 45 | typedef std::vector Nodes; 46 | typedef std::vector Ways; 47 | typedef std::vector Relations; 48 | 49 | //! Constructor 50 | OSMDocument( 51 | const Configuration& config, 52 | const po::variables_map &vm, 53 | const Export2DB &db_conn, 54 | size_t lines); 55 | 56 | inline size_t lines() const {return m_lines;} 57 | 58 | //! Do the configuration has the @b tag ? 59 | inline bool config_has_tag(const Tag &tag) const { 60 | return m_rConfig.has_tag(tag); 61 | } 62 | 63 | inline double priority(const Tag &tag) const { 64 | return m_rConfig.priority(tag); 65 | } 66 | 67 | inline double maxspeed(const Tag &tag) const { 68 | return m_rConfig.maxspeed(tag); 69 | } 70 | 71 | const Nodes& nodes() const {return m_nodes;} 72 | const Ways& ways() const {return m_ways;} 73 | const Relations& relations() const {return m_relations;} 74 | 75 | void AddNode(const Node &n); 76 | void AddWay(const Way &w); 77 | void AddRelation(const Relation &r); 78 | void endOfFile(); 79 | 80 | //! find node by using an ID 81 | bool has_node(int64_t nodeRefId) const; 82 | Node* FindNode(int64_t nodeRefId); 83 | 84 | bool has_way(int64_t way_id) const; 85 | Way* FindWay(int64_t way_id); 86 | 87 | 88 | void add_node(Way &way, const char **atts); 89 | 90 | /** 91 | * add the configuration tag used for the speeds 92 | */ 93 | void add_config(Element *osm_element, const Tag &tag) const; 94 | 95 | inline uint16_t nodeErrs() const {return m_nodeErrs;} 96 | 97 | private: 98 | template 99 | bool 100 | do_export_osm(const T &container) { 101 | return m_vm.count("addnodes") && (container.size() % m_chunk_size) == 0; 102 | } 103 | 104 | 105 | void wait_child() const; 106 | 107 | template 108 | void 109 | osm_table_export(const T &osm_items, const std::string &table) const { 110 | if (osm_items.empty()) return; 111 | 112 | if (m_vm.count("addnodes")) { 113 | #if 0 114 | auto pid = fork(); 115 | if (pid < 0) { 116 | std::cerr << "Failed to fork" << endl; 117 | exit(1); 118 | } 119 | if (pid > 0) return; 120 | #endif 121 | } 122 | auto residue = osm_items.size() % m_chunk_size; 123 | auto start = residue? osm_items.size() - residue : osm_items.size() - m_chunk_size; 124 | T export_items = T(osm_items.begin() + static_cast(start), osm_items.end()); 125 | 126 | m_db_conn.export_osm(export_items, table); 127 | 128 | if (m_vm.count("addnodes")) { 129 | #if 0 130 | /* 131 | * finish the child process 132 | */ 133 | _exit(0); 134 | #endif 135 | } 136 | } 137 | 138 | void export_pois() const; 139 | 140 | 141 | private: 142 | // ! parsed nodes TODO change to sorted vector 143 | Nodes m_nodes; 144 | //! parsed ways 145 | Ways m_ways; 146 | //! parsed relations 147 | Relations m_relations; 148 | bool m_relPending; 149 | bool m_waysPending; 150 | 151 | const Configuration& m_rConfig; 152 | po::variables_map m_vm; 153 | const Export2DB &m_db_conn; 154 | 155 | size_t m_chunk_size; 156 | uint16_t m_nodeErrs; 157 | size_t m_lines; 158 | }; 159 | 160 | } // end namespace osm2pgr 161 | #endif // SRC_OSMDOCUMENT_H_ 162 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # osm2pgrouting 2 | 3 | [![Join the chat at https://gitter.im/pgRouting/osm2pgrouting](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/pgRouting/osm2pgrouting?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) 4 | 5 | # Table of Contents 6 | 7 | * [Requirements](#requirements) 8 | * [Documentation](#documentation) 9 | * [Installation](#installation) 10 | * [How to use](#how-to-use) 11 | * [Tips](#tips) 12 | 13 | 14 | ## Requirements 15 | 16 | Before you can use this tool for importing Openstreetmap data you need to install: 17 | 18 | 1. postgresql 19 | 2. postgis 20 | 3. pgrouting 21 | 4. boost 22 | 5. expat 23 | 5. libpqxx 24 | 6. cmake 25 | 26 | and to prepare a database. 27 | 28 | ## Documentation 29 | 30 | See in the documentation of the pgrouting website for more information: http://pgrouting.org 31 | 32 | ## Installation 33 | 34 | For compiling this tool, you will need boost, libpqxx, expat and cmake: 35 | Then just type the following in the root directory: 36 | 37 | ``` 38 | cmake -H. -Bbuild 39 | cd build/ 40 | make 41 | make install 42 | ``` 43 | 44 | Install some prerequisites: 45 | 46 | ``` 47 | sudo apt-get install expat 48 | sudo apt-get install libexpat1-dev 49 | sudo apt-get install libboost-dev 50 | sudo apt-get install libboost-program-options-dev 51 | sudo apt install libpqxx-dev 52 | ``` 53 | 54 | **Note:** FindLibPQXX.cmake does not find the version of libpqxx, but its documentation says C++11 is needed for the latests versions. 55 | 56 | 57 | If you have libraries installed in non-standard locations, you might need to pass in parameters to cmake. Commonly useful parameters are 58 | 59 | CMAKE options: 60 | 61 | -DBOOST_ROOT:PATH=/path/to/boost folder that contains include, lib, bin directories for boost 62 | 63 | -DEXPATH_INCLUDE_DIR:PATH=/path/to/expat/include the include folder for where your expat is installed 64 | 65 | -DPOSTGRESQL_INCLUDE_DIR:PATH=/path/to/postgresql/include the include folder for postgresql development headers 66 | 67 | 68 | A cmake with custom options might look something like 69 | 70 | ``` 71 | cmake -DBOOST_ROOT:PATH=/local/projects/rel-boost-1.58.0 \ 72 | -DPOSTGRESQL_INCLUDE_DIR:PATH=/local/projects/rel-pg94/include -Bbuild 73 | ``` 74 | 75 | ## How to use 76 | 77 | Prepare the database: 78 | 79 | ``` 80 | createdb routing 81 | psql --dbname routing -c 'CREATE EXTENSION postgis' 82 | psql --dbname routing -c 'CREATE EXTENSION pgRouting' 83 | ``` 84 | 85 | Start the program like this: 86 | 87 | ``` 88 | osm2pgrouting --f your-OSM-XML-File.osm --conf mapconfig.xml --dbname routing --username postgres --clean 89 | ``` 90 | 91 | Do incremental adition of data without using --clean 92 | 93 | ``` 94 | osm2pgrouting --f next-OSM-XML-File.osm --conf mapconfig.xml --dbname routing --username postgres 95 | ``` 96 | 97 | 98 | A complete list of arguments are: 99 | 100 | ``` 101 | osm2pgrouting --help 102 | Allowed options: 103 | 104 | Help: 105 | --help Produce help message for this version. 106 | -v [ --version ] Print version string 107 | 108 | General: 109 | -f [ --file ] arg REQUIRED: Name of the osm file. 110 | -c [ --conf ] arg (=/usr/share/osm2pgrouting/mapconfig.xml) 111 | Name of the configuration xml file. 112 | --schema arg Database schema to put tables. 113 | blank: defaults to default schema 114 | dictated by PostgreSQL 115 | search_path. 116 | --prefix arg Prefix added at the beginning of the 117 | table names. 118 | --suffix arg Suffix added at the end of the table 119 | names. 120 | --addnodes Import the osm_nodes, osm_ways & 121 | osm_relations tables. 122 | --attributes Include attributes information. 123 | --tags Include tag information. 124 | --chunk arg (=20000) Exporting chunk size. 125 | --clean Drop previously created tables. 126 | --no-index Do not create indexes (Use when indexes 127 | are already created) 128 | 129 | Database options: 130 | -d [ --dbname ] arg Name of your database (Required). 131 | -U [ --username ] arg Name of the user, which have write access to 132 | the database. 133 | -h [ --host ] arg (=localhost) Host of your postgresql database. 134 | -p [ --port ] arg (=5432) db_port of your database. 135 | -W [ --password ] arg Password for database access. 136 | 137 | ``` 138 | 139 | ## Tips 140 | 141 | Open Street Map (OSM) files contains tags not used at all for routing operations by PgRouting (i.e. author, version, timestamps, etc.). You can reduce a lot the size of your OSM file to import removing this metadata tags from original file (you can get around half size of original file). 142 | 143 | The best tool to remove tags is [osmconvert](https://wiki.openstreetmap.org/wiki/Osmconvert). 144 | There are another tools but osmconvert is the fastest parsing osm files. 145 | 146 | Example: 147 | ``` 148 | $ osmconvert output_data.osm.pbf --drop-author --drop-version --out-osm -o=output_data_reduc.osm 149 | ``` 150 | 151 | You can download OSM data as PBF (protobuffer) format. This is a binary format and it has a lower size than OSM raw files (better for downloading operations). 152 | -------------------------------------------------------------------------------- /include/database/Export2DB.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (C) 2016 by pgRouting developers * 3 | * project@pgrouting.org * 4 | * * 5 | * This program is free software; you can redistribute it and/or modify * 6 | * it under the terms of the GNU General Public License as published by * 7 | * the Free Software Foundation; either version 2 of the License, or * 8 | * (at your option) any later version. * 9 | * * 10 | * This program is distributed in the hope that it will be useful, * 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 13 | * GNU General Public License t &or more details. * 14 | * * 15 | * You should have received a copy of the GNU General Public License * 16 | * along with this program; if not, write to the * 17 | * Free Software Foundation, Inc., * 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 19 | ***************************************************************************/ 20 | 21 | 22 | #ifndef SRC_EXPORT2DB_H_ 23 | #define SRC_EXPORT2DB_H_ 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | #include "osm_elements/Node.h" 32 | #include "osm_elements/Way.h" 33 | #include "osm_elements/Relation.h" 34 | #include "configuration/configuration.h" 35 | #include "utilities/prog_options.h" 36 | #include "database/table_management.h" 37 | 38 | namespace osm2pgr { 39 | 40 | /** 41 | * This class connects to a postgresql database. For using this class, 42 | * you also need to install postgis and pgrouting 43 | */ 44 | 45 | class Export2DB { 46 | public: 47 | typedef std::vector Nodes; 48 | typedef std::vector Ways; 49 | typedef std::vector Relations; 50 | 51 | /** 52 | * Constructor 53 | * @param vm variable map holding the configuration 54 | * @param db_conn conection string 55 | * 56 | */ 57 | explicit Export2DB(const po::variables_map &vm, const std::string &db_conn); 58 | 59 | /** 60 | * Destructor 61 | * closes the connection to the database 62 | */ 63 | ~Export2DB(); 64 | 65 | #if 1 66 | //! connects to database 67 | int connect(); 68 | #endif 69 | 70 | bool has_extension(const std::string &name) const; 71 | #ifndef NDBEUG 72 | bool install_postGIS() const; 73 | #endif 74 | 75 | //! creates needed tables and geometries 76 | void createTables() const; 77 | 78 | 79 | /** @brief export values to osm_* table 80 | * 81 | * T must have: 82 | * T.values 83 | * 84 | * @param[in] items vector of values to be inserted into 85 | * @param[in] table 86 | */ 87 | template 88 | void export_osm ( 89 | std::vector &items, 90 | const std::string &table) const { 91 | auto osm_table = m_tables.get_table(table); 92 | std::vector values(items.size(), ""); 93 | 94 | size_t i(0); 95 | for (auto it = items.begin(); it != items.end(); ++it, ++i) { 96 | auto item = *it; 97 | values[i] = tab_separated(item.values(osm_table.columns(), true)); 98 | } 99 | 100 | export_osm(values, osm_table); 101 | } 102 | 103 | void export_configuration( 104 | const std::map& items) const; 105 | 106 | void exportWays( 107 | const Ways &ways, 108 | const Configuration &config) const; 109 | 110 | void dropTables() const; 111 | void createFKeys() const; 112 | void process_pois() const; 113 | bool exists(const std::string &table) const; 114 | 115 | private: 116 | 117 | void export_osm( 118 | const std::vector &values, 119 | const Table &table) const; 120 | 121 | void process_section(const std::string &ways_columns, pqxx::work &Xaction) const; 122 | 123 | void fill_adjacent_edges( 124 | const std::string &table, 125 | const std::string &vertices_tab, 126 | pqxx::work &Xaction) const; 127 | 128 | void fill_vertices_table( 129 | const std::string &table, 130 | const std::string &vertices_tab, 131 | pqxx::work &Xaction) const; 132 | 133 | void fill_source_target( 134 | const std::string &table, 135 | const std::string &vertices_tab, 136 | pqxx::work &Xaction) const; 137 | 138 | int64_t get_val(const std::string sql) const; 139 | void execute(const std::string sql) const; 140 | 141 | Table configuration() const {return m_tables.configuration();} 142 | Table vertices() const {return m_tables.vertices();} 143 | Table ways() const {return m_tables.ways();} 144 | Table pois() const {return m_tables.pois();} 145 | Table osm_ways() const {return m_tables.osm_ways();} 146 | Table osm_nodes() const {return m_tables.osm_nodes();} 147 | Table osm_relations() const {return m_tables.osm_relations();} 148 | 149 | private: 150 | po::variables_map m_vm; 151 | 152 | std::string conninf; 153 | 154 | Tables m_tables; 155 | 156 | }; 157 | } // namespace osm2pgr 158 | 159 | #endif // SRC_EXPORT2DB_H_ 160 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | Contributors to pgRouting are expected to act respectfully toward others in accordance with the http://www.osgeo.org/code_of_conduct. 2 | 3 | Full transcription: 4 | 5 | 6 | # OSGeo Code of Conduct 7 | 8 | Version: 1.0 9 | 10 | Date: May 2015 11 | 12 | ## Introduction 13 | 14 | This code of conduct governs how we behave in any OSGeo forum or event and whenever we will be judged by our actions. We expect it to be honored by everyone who participates in the OSGeo community formally or informally, or claims any affiliation with the OSGeo Foundation. 15 | 16 | It applies to in-person events (such as conferences and related social events), IRC, public and private mailing lists, the issue tracker, the wiki, blogs, Twitter, and any other forums which the community uses for communication and interactions. 17 | 18 | This code is not exhaustive or complete. It serves to distill our common understanding of a collaborative, shared environment and goals. We expect it to be followed in spirit as much as in the letter, so that it can enrich all of us and the technical communities in which we participate. 19 | 20 | ## Diversity Statement 21 | 22 | OSGeo welcomes and encourages participation by everyone. We are committed to being a community that everyone feels good about joining, and we will always work to treat everyone well. No matter how you identify yourself or how others perceive you: we welcome you. 23 | Specific Guidelines 24 | 25 | We strive to: 26 | 27 | - Be open. 28 | We invite anyone to participate in our community. We preferably use public methods of communication for project-related messages, unless discussing something sensitive. This applies to messages for help or project-related support, too; not only is a public support request much more likely to result in an answer to a question, it also makes sure that any inadvertent mistakes made by people answering will be more easily detected and corrected. 29 | 30 | - Be empathetic, welcoming, friendly, and patient. 31 | We work together to resolve conflict, assume good intentions, and do our best to act in an empathetic fashion. We may all experience some frustration from time to time, but we do not allow frustration to turn into a personal attack. A community where people feel uncomfortable or threatened is not a productive one. Note that we have a multi-cultural, multi-lingual community and some of us are non-native speakers. We should be respectful when dealing with other community members as well as with people outside our community. 32 | 33 | - Be collaborative. 34 | Our work will be used by other people, and in turn we will depend on the work of others. When we make something for the benefit of OSGeo, we are willing to explain to others how it works, so that they can build on the work to make it even better. Any decision we make will affect users and colleagues, and we take those consequences seriously when making decisions. 35 | 36 | - Be inquisitive. 37 | Nobody knows everything! Asking questions early avoids many problems later, so questions are encouraged, though they may be directed to the appropriate forum. Those who are asked should be responsive and helpful, within the context of our shared goal of improving OSGeo. 38 | 39 | - Be careful in the words that we choose. 40 | Whether we are participating as professionals or volunteers, we value professionalism in all interactions, and take responsibility for our own speech. Be kind to others. Do not insult or put down other participants. 41 | 42 | - Be concise 43 | Keep in mind that what you write once will be read by hundreds of persons. Writing a short email means people can understand the conversation as efficiently as possible. Short emails should always strive to be empathetic, welcoming, friendly and patient. When a long explanation is necessary, consider adding a summary. 44 | 45 | Try to bring new ideas to a conversation so that each mail adds something unique to the thread, keeping in mind that the rest of the thread still contains the other messages with arguments that have already been made. 46 | 47 | Try to stay on topic, especially in discussions that are already fairly large. 48 | 49 | - Step down considerately. 50 | Members of every project come and go. When somebody leaves or disengages from the project they should tell people they are leaving and take the proper steps to ensure that others can pick up where they left off. In doing so, they should remain respectful of those who continue to participate in the project and should not misrepresent the project's goals or achievements. Likewise, community members should respect any individual's choice to leave the project. 51 | 52 | ## Anti-Harassment 53 | 54 | Harassment and other exclusionary behaviour are not acceptable. This includes, but is not limited to: 55 | 56 | - Personal insults or discriminatory jokes and language, especially those using racist or sexist terms. 57 | - Offensive comments, excessive or unnecessary profanity. 58 | - Intimidation, violent threats or demands. 59 | - Sustained disruption of sessions or events. 60 | - Stalking, harassing photography or recording. 61 | - Unwelcome physical contact or sexual attention. 62 | - Repeated harassment of others. In general, if someone asks you to stop, then stop. 63 | - Posting (or threatening to post) other people's personally identifying information ("doxing"). 64 | - Sharing private content, such as emails sent privately or non-publicly, or unlogged forums such as IRC channel history. 65 | - Advocating for, or encouraging, any of the above behaviour. 66 | 67 | ## Reporting Guidelines 68 | 69 | If you believe someone is breaking this code of conduct, you may reply to them, and point to this code of conduct. Such messages may be in public or in private, whatever is most appropriate. Assume good faith; it is more likely that participants are unaware of their bad behaviour than that they intentionally try to degrade the quality of the discussion. Should there be difficulties in dealing with the situation, you may report your concerns to event staff, a forum leader or the OSGeo Board. Serious or persistent offenders may be expelled from the event or forum by event organizers or forum leaders. 70 | -------------------------------------------------------------------------------- /src/utilities/prog_options.cpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (C) 2016 by pgRouting developers * 3 | * project@pgrouting.org * 4 | * * 5 | * This program is free software; you can redistribute it and/or modify * 6 | * it under the terms of the GNU General Public License as published by * 7 | * the Free Software Foundation; either version 2 of the License, or * 8 | * (at your option) any later version. * 9 | * * 10 | * This program is distributed in the hope that it will be useful, * 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 13 | * GNU General Public License t &or more details. * 14 | * * 15 | * You should have received a copy of the GNU General Public License * 16 | * along with this program; if not, write to the * 17 | * Free Software Foundation, Inc., * 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 19 | ***************************************************************************/ 20 | 21 | 22 | #include 23 | #include 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | namespace po = boost::program_options; 30 | 31 | 32 | void get_option_description(po::options_description &od_desc) { 33 | /* po::options_description help_od_desc("Help"), 34 | required_od_desc("Required options"), 35 | optional_od_desc("Optional options"); 36 | */ 37 | po::options_description help_od_desc("Help"), 38 | general_od_desc("General"), 39 | db_options_od_desc("Database options"), 40 | not_used_od_desc("Not used currently"); 41 | 42 | help_od_desc.add_options() 43 | // help 44 | ("help", "Produce help message for this version.") 45 | ("version,v", "Print version string"); 46 | 47 | general_od_desc.add_options() 48 | // general 49 | ("file,f", po::value()->required(), "REQUIRED: Name of the osm file.") 50 | ("conf,c", po::value()->default_value("/usr/share/osm2pgrouting/mapconfig.xml"), "Name of the configuration xml file.") 51 | ("schema", po::value()->default_value(""), "Database schema to put tables.\n blank:\t defaults to default schema dictated by PostgreSQL search_path.") 52 | ("prefix", po::value()->default_value(""), "Prefix added at the beginning of the table names.") 53 | ("suffix", po::value()->default_value(""), "Suffix added at the end of the table names.") 54 | #if 0 55 | ("postgis", "Install postgis if not found.") // TODO(vicky) remove before realesing 56 | #endif 57 | ("addnodes", "Import the osm_nodes, osm_ways & osm_relations tables.") 58 | ("attributes", "Include attributes information.") 59 | ("tags", "Include tag information.") 60 | ("chunk", po::value()->default_value(20000), "Exporting chunk size.") 61 | ("clean", "Drop previously created tables.") 62 | ("no-index", "Do not create indexes (Use when indexes are already created)"); 63 | #if 0 64 | ("addways", "Import the osm_ways table.") 65 | ("addrelations", "Import the osm_relations table.") 66 | ("fork", "Use fork (works on small files)."); 67 | ("hstore", "Use hstore for attributes and/or tags. (not indicating will use json)") 68 | #endif 69 | 70 | db_options_od_desc.add_options() 71 | // database options 72 | ("dbname,d", po::value()->required(), "Name of your database (Required).") 73 | ("username,U", po::value()->default_value(""), "Name of the user, which have write access to the database.") 74 | ("host,h", po::value()->default_value("localhost"), "Host of your postgresql database.") 75 | ("port,p", po::value()->default_value("5432"), "db_port of your database.") 76 | ("password,W", po::value()->default_value(""), "Password for database access."); 77 | 78 | not_used_od_desc.add_options() 79 | ("threads,t", po::value()->default_value(false), "threads.") 80 | ("multimodal,m", po::value()->default_value(false), "multimodal.") 81 | ("multilevel,l", po::value()->default_value(false), "multilevel."); 82 | 83 | od_desc.add(help_od_desc).add(general_od_desc).add(db_options_od_desc); // .add(not_used_od_desc); 84 | 85 | return; 86 | } 87 | 88 | 89 | 90 | void 91 | process_command_line(po::variables_map &vm) { 92 | std::cout << "***************************************************\n"; 93 | std::cout << " COMMAND LINE CONFIGURATION *\n"; 94 | std::cout << "***************************************************\n"; 95 | std::cout << "Filename = " << vm["file"].as() << "\n"; 96 | std::cout << "Configuration file = " << vm["conf"].as() << "\n"; 97 | std::cout << "host = " << vm["host"].as() << "\n"; 98 | std::cout << "port = " << vm["port"].as() << "\n"; 99 | std::cout << "dbname = " << vm["dbname"].as() << "\n"; 100 | std::cout << "username = " << vm["username"].as() << "\n"; 101 | std::cout << "schema= " << vm["schema"].as() << "\n"; 102 | std::cout << "prefix = " << vm["prefix"].as() << "\n"; 103 | std::cout << "suffix = " << vm["suffix"].as() << "\n"; 104 | #if 0 105 | std::cout << (vm.count("postgis")? "I" : "Don't I") << "nstall postgis if not found\n"; 106 | #endif 107 | std::cout << (vm.count("clean")? "D" : "Don't d") << "rop tables\n"; 108 | std::cout << (vm.count("no-index")? "D" : "Don't c") << "reate indexes\n"; 109 | std::cout << (vm.count("addnodes")? "A" : "Don't a") << "dd OSM nodes\n"; 110 | #if 0 111 | std::cout << (vm.count("addways")? "A" : "Don't a") << "dd OSM ways\n"; 112 | std::cout << (vm.count("addrelations")? "A" : "Don't a") << "dd OSM relations\n"; 113 | std::cout << (vm.count("fork")? "F" : "Don't f") << "ork\n"; 114 | #endif 115 | std::cout << "***************************************************\n"; 116 | } 117 | -------------------------------------------------------------------------------- /tools/doxygen/DoxygenLayout.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | -------------------------------------------------------------------------------- /NEWS: -------------------------------------------------------------------------------- 1 | osm2pgRouting 3.0.0 2 | 3 | * cmake >= 3.12 4 | * geometry column name: `geom` 5 | 6 | New "ways" table structure 7 | Column | Type | Modifications | Default 8 | -------------------+---------------------------+--------------------+----------- 9 | id | bigint | previously was gid | generated always as identity 10 | osm_id | bigint | 11 | tag_id | integer | 12 | length | double precision | 13 | length_m | double precision | 14 | name | text | 15 | source | bigint | 16 | target | bigint | 17 | source_osm | bigint | 18 | target_osm | bigint | 19 | cost | double precision | 20 | reverse_cost | double precision | 21 | cost_s | double precision | 22 | reverse_cost_s | double precision | 23 | rule | text | 24 | one_way | integer | 25 | oneway | text | 26 | x1 | double precision | 27 | y1 | double precision | 28 | x2 | double precision | 29 | y2 | double precision | 30 | maxspeed_forward | double precision | 31 | maxspeed_backward | double precision | 32 | priority | double precision | 33 | geom | geometry(LineString,4326) | previously was the_geom 34 | 35 | New "ways_vertices_pgr" table structure 36 | 37 | Column | Type | Default 38 | -----------+----------------------+------------------------------------------- 39 | id | bigint | Default: generated always as identity 40 | in_edges | bigint[] | New column 41 | out_edges | bigint[] | New column 42 | x | numeric(11,8) | Default: generated always as (st_x(geom)) stored 43 | y | numeric(11,8) | Default: generated always as (st_y(geom)) stored 44 | osm_id | bigint | 45 | geom | geometry(Point,4326) 46 | 47 | osm2pgRouting 2.3.9 48 | 49 | * Homebrew: Add algorithm for std::transform 50 | 51 | osm2pgRouting 2.3.8 52 | 53 | * Removing travis tests 54 | * Updated FindPQXX to get the version 55 | * Adding github actions for compilation: 56 | * Postgres 9.6 to 13 57 | * libpqxx 6 & 7 58 | * Minimum Version Postgres 9.6 (supported version at this time) 59 | * Minimum Version libpqxx 6 60 | * C++ minimum standard depends on libpqxx 61 | * For version libpqxx 6: C++14 62 | * For version libpqxx 7: C++17 63 | 64 | osm2pgRouting 2.3.7 65 | 66 | * fix: Way - fixed bug handling oneway false conditions 67 | * fix: fixed CMakeLists 68 | * fix: adjustments to FindPostgreSQL.cmake. 69 | * Improvements on mapconfig XML files. 70 | * New docs: "Code of Conduct" and "Contributing". 71 | * Docs improvements. 72 | 73 | osm2pgRouting 2.3.6 74 | 75 | * Fix: Incorrect classification of one-ways. 76 | * Fix: command line configuration in print outputs (db password removed). 77 | * Other minor fixes. 78 | 79 | osm2pgRouting 2.3.5 80 | 81 | * Fix: zero division error when max_speed = 0. 82 | * Fix: fixed osm_ways parsing - OSMDocument. 83 | * Fix: switch to a more inclusive check for nullptr definition (fixes compilation on macOS 10.13 using Xcode 9.3) 84 | * Docs improvements: How to release doc. 85 | 86 | osm2pgRouting 2.3.4 87 | 88 | * Fix: osm_elements - fixed boolean assignment with boost::lexical_cast. 89 | * Use ${CMAKE_INSTALL_PREFIX} in CMakeLists.txt. 90 | * Readme doc improvements: Tips section and Table of contents. 91 | 92 | osm2pgRouting 2.3.3 93 | 94 | * Fix: wrong assumption in implied_oneWay() function 95 | * Fix: regression on 2.3.2: fixed hstore refs handling 96 | 97 | osm2pgRouting 2.3.2 98 | 99 | * Fix: Only on linux: use the wc command to count lines 100 | * Fix: the `osm_` are created only when addnodes flag is on 101 | * Fix: removed unused flag of the command line 102 | 103 | osm2pgRouting 2.3.1 104 | 105 | * Fix: When keys have spaces 106 | * Fix: Generating relations 107 | 108 | osm2pgRouting 2.3.0 109 | 110 | * Cost should not return the same value 111 | * Added a points of Interest table 112 | * Some default one_way values are taken into consideration 113 | * Relations are also condsidered 114 | * New mapconfig_for_pedestrian.xml 115 | 116 | 117 | osm2pgRouting 2.2.0 118 | 119 | * Adding foreign keys to the tables. 120 | * Added a progress bar. 121 | * New mapconfig_for_bicycles.xml 122 | * Improved the C++ code. 123 | * remove the use of pointers to avoid leaks. 124 | * Table `osm_ways_tags` because information is redundant. 125 | 126 | 127 | 128 | osm2pgRouting 2.1.0 129 | 130 | New "ways" table structure: 131 | Column | Type | Modifications 132 | -------------------+---------------------------+---------------- 133 | gid | bigint | 134 | class_id | integer | 135 | length | double precision | 136 | length_m | double precision | new column 137 | name | text | 138 | source | bigint | 139 | target | bigint | 140 | x1 | double precision | 141 | y1 | double precision | 142 | x2 | double precision | 143 | y2 | double precision | 144 | cost | double precision | name changed from 'to_cost' 145 | reverse_cost | double precision | 146 | cost_s | double precision | new column 147 | reverse_cost_s | double precision | new column 148 | rule | text | 149 | one_way | integer | new column 150 | maxspeed_forward | integer | 151 | maxspeed_backward | integer | 152 | osm_id | bigint | 153 | source_osm | bigint | new column 154 | target_osm | bigint | new column 155 | priority | double precision | 156 | the_geom | geometry(LineString,4326) | 157 | 158 | New "ways_vertices_pgr" table structure 159 | Column | Type | Modifications 160 | ----------+----------------------+---------------------------------------------------------------- 161 | id | bigint | 162 | osm_id | bigint | new column 163 | cnt | integer | 164 | chk | integer | 165 | ein | integer | 166 | eout | integer | 167 | lon | numeric(11,8) | new column 168 | lat | numeric(11,8) | new column 169 | the_geom | geometry(Point,4326) | 170 | Indexes: 171 | "ways_vertices_pgr_pkey" PRIMARY KEY, btree (id) 172 | "vertex_id" UNIQUE CONSTRAINT, btree (osm_id) 173 | "ways_vertices_pgr_gdx" gist (the_geom) 174 | "ways_vertices_pgr_osm_id_idx" btree (osm_id) 175 | -------------------------------------------------------------------------------- /src/osm_elements/osm_element.cpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (C) 2016 by pgRouting developers * 3 | * project@pgrouting.org * 4 | * * 5 | * This program is free software; you can redistribute it and/or modify * 6 | * it under the terms of the GNU General Public License as published by * 7 | * the Free Software Foundation; either version 2 of the License, or * 8 | * (at your option) any later version. * 9 | * * 10 | * This program is distributed in the hope that it will be useful, * 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 13 | * GNU General Public License t &or more details. * 14 | * * 15 | * You should have received a copy of the GNU General Public License * 16 | * along with this program; if not, write to the * 17 | * Free Software Foundation, Inc., * 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 19 | ***************************************************************************/ 20 | 21 | 22 | #include 23 | #include 24 | #include 25 | #include "osm_elements/osm_tag.h" 26 | #include "osm_elements/osm_element.h" 27 | 28 | namespace osm2pgr { 29 | 30 | 31 | Element::Element(const char **atts) : 32 | m_visible(true) { 33 | auto **attribut = atts; 34 | while (*attribut != NULL) { 35 | std::string name = *attribut++; 36 | std::string value = *attribut++; 37 | if (name == "id") { 38 | m_osm_id = boost::lexical_cast(value); 39 | } 40 | if (name == "visible") { 41 | m_visible = (value == "true")? true : false; 42 | } 43 | m_attributes[name] = value; 44 | } 45 | } 46 | 47 | void 48 | Element::tag_config(const Tag &tag) { 49 | m_tag_config = tag; 50 | } 51 | 52 | 53 | Tag 54 | Element::add_tag(const Tag &tag) { 55 | m_tags[tag.key()] = tag.value(); 56 | return tag; 57 | } 58 | 59 | bool 60 | Element::has_tag(const std::string& key) const { 61 | return m_tags.find(key) != m_tags.end(); 62 | } 63 | 64 | std::string 65 | Element::get_tag(const std::string& key) const { 66 | return m_tags.find(key)->second; 67 | } 68 | 69 | 70 | bool 71 | Element::is_tag_configured() const { 72 | return (m_tag_config.key() != "" && m_tag_config.value() != ""); 73 | } 74 | 75 | 76 | bool 77 | Element::has_attribute(const std::string& key) const { 78 | return m_attributes.find(key) != m_attributes.end(); 79 | } 80 | 81 | std::string 82 | Element::get_attribute(const std::string& key) const { 83 | return m_attributes.find(key)->second; 84 | } 85 | 86 | std::string 87 | Element::attributes_str() const { 88 | if (m_tags.empty()) return "\"\""; 89 | std::string str("\""); 90 | for (auto it = m_attributes.begin(); it != m_attributes.end(); ++it) { 91 | auto attribute = *it; 92 | str += attribute.first + "=>" + attribute.second + ","; 93 | } 94 | str[str.size()-1] = '\"'; 95 | return str; 96 | } 97 | 98 | std::string 99 | Element::tags_str() const { 100 | if (m_tags.empty()) return ""; 101 | std::string str("\""); 102 | for (auto it = m_tags.begin(); it != m_tags.end(); ++it) { 103 | auto tag = *it; 104 | str += tag.first + "=>" + tag.second + ","; 105 | } 106 | str[str.size()-1] = '\"'; 107 | return str; 108 | } 109 | 110 | static 111 | std::string 112 | addquotes(const std::string str, bool force) { 113 | std::string result(""); 114 | 115 | for (auto c : str) { 116 | if ( c == '"' ) { 117 | /* 118 | * To avoid problems with json & hstore 119 | * all quotes are converted to single quotes 120 | */ 121 | result += "\'\'"; 122 | continue; 123 | } else if ( c == '\\' ) { 124 | result += '\\'; 125 | } else if (c == '\'') { 126 | result += '\''; 127 | } else if (c == '\n') { 128 | result += "\\n"; 129 | continue; 130 | } else if (c == '\r') { 131 | result += "\\r"; 132 | continue; 133 | } else if (c == '\t') { 134 | result += "\\t"; 135 | continue; 136 | } 137 | result += c; 138 | } 139 | if (!force) { 140 | for (auto c : result) { 141 | if (c == ' ' || c == ',' || c == '=' || c == '>' || c == ':') { 142 | return std::string("\"") + result + "\""; 143 | } 144 | } 145 | return result; 146 | } 147 | return std::string("\"") + result + "\""; 148 | } 149 | 150 | 151 | static 152 | std::string 153 | getHstore(const std::map &values) { 154 | std::string hstore; 155 | if (values.empty()) return std::string(); 156 | 157 | for (const auto &item : values) { 158 | hstore += 159 | addquotes(item.first, true) 160 | + " => " 161 | + addquotes(item.second, true) + ","; 162 | } 163 | hstore[hstore.size() - 1] = ' '; 164 | hstore += ""; 165 | return hstore; 166 | } 167 | 168 | #if 0 169 | static 170 | std::string 171 | getJSON(const std::map &values) { 172 | if (values.empty()) return std::string("{}"); 173 | std::string json("{"); 174 | for (const auto item : values) { 175 | json += addquotes(item.first, true) 176 | + ":" 177 | + addquotes(item.second, true) + ","; 178 | } 179 | json[json.size() - 1] = '}'; 180 | json += ""; 181 | return json; 182 | } 183 | #endif 184 | 185 | std::vector 186 | Element::values(const std::vector &columns, bool is_hstore) const { 187 | std::vector values; 188 | for (const auto &column : columns) { 189 | if (column == "osm_id" || column == "tag_id") { 190 | values.push_back(boost::lexical_cast(osm_id())); 191 | continue; 192 | } 193 | if (column == "tag_name") { 194 | values.push_back(m_tag_config.key()); 195 | continue; 196 | } 197 | if (column == "tag_value") { 198 | values.push_back(m_tag_config.value()); 199 | continue; 200 | } 201 | if (column == "geom") { 202 | values.push_back(get_geometry()); 203 | continue; 204 | } 205 | 206 | if (column == "members") { 207 | values.push_back(members_str()); 208 | continue; 209 | } 210 | 211 | if (column == "attributes") { 212 | values.push_back(getHstore(m_attributes)); 213 | continue; 214 | } 215 | if (column == "tags") { 216 | values.push_back(getHstore(m_tags)); 217 | if (is_hstore) {}; 218 | 219 | continue; 220 | } 221 | if (has_attribute(column)) { 222 | values.push_back(get_attribute(column)); 223 | continue; 224 | } 225 | if (has_tag(column)) { 226 | values.push_back(get_tag(column)); 227 | continue; 228 | } 229 | values.push_back(std::string("")); 230 | } 231 | return values; 232 | } 233 | 234 | } // namespace osm2pgr 235 | -------------------------------------------------------------------------------- /src/parser/OSMDocumentParserCallback.cpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (C) 2016 by pgRouting developers * 3 | * project@pgrouting.org * 4 | * * 5 | * This program is free software; you can redistribute it and/or modify * 6 | * it under the terms of the GNU General Public License as published by * 7 | * the Free Software Foundation; either version 2 of the License, or * 8 | * (at your option) any later version. * 9 | * * 10 | * This program is distributed in the hope that it will be useful, * 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 13 | * GNU General Public License t &or more details. * 14 | * * 15 | * You should have received a copy of the GNU General Public License * 16 | * along with this program; if not, write to the * 17 | * Free Software Foundation, Inc., * 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 19 | ***************************************************************************/ 20 | 21 | 22 | 23 | #include "parser/OSMDocumentParserCallback.h" 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include "osm_elements/OSMDocument.h" 31 | #include "osm_elements/Relation.h" 32 | #include "osm_elements/osm_tag.h" 33 | #include "osm_elements/Way.h" 34 | #include "osm_elements/Node.h" 35 | #include "utilities/print_progress.h" 36 | 37 | 38 | namespace osm2pgr { 39 | 40 | /* 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | */ 56 | 57 | void 58 | OSMDocumentParserCallback::show_progress() { 59 | #if 0 60 | try { 61 | if (m_line == 0) return; 62 | assert(m_rDocument.lines()); 63 | if (m_rDocument.lines() == 0) return; 64 | if (((++m_line) % (m_rDocument.lines() / 100)) == 0) { 65 | print_progress(m_rDocument.lines(), m_line); 66 | } 67 | } catch(...) { 68 | m_line = 1; 69 | } 70 | #endif 71 | } 72 | 73 | 74 | /** 75 | Parser callback for OSMDocument files 76 | */ 77 | void 78 | OSMDocumentParserCallback::StartElement( 79 | const char *name, 80 | const char** atts) { 81 | show_progress(); 82 | 83 | if (strcmp(name, "osm") == 0) { 84 | m_section = 1; 85 | } 86 | 87 | if ((m_section == 1 && (strcmp(name, "way") == 0)) 88 | || (m_section == 2 && (strcmp(name, "relation") == 0))) { 89 | ++m_section; 90 | } 91 | 92 | 93 | if (m_section == 1) { 94 | if (strcmp(name, "node") == 0) { 95 | last_node = new Node(atts); 96 | } 97 | if (strcmp(name, "tag") == 0) { 98 | auto tag = last_node->add_tag(Tag(atts)); 99 | m_rDocument.add_config(last_node, tag); 100 | } 101 | return; 102 | } 103 | 104 | if (m_section == 2) { 105 | if (strcmp(name, "way") == 0) { 106 | last_way = new Way(atts); 107 | } 108 | if (strcmp(name, "tag") == 0) { 109 | auto tag = last_way->add_tag(Tag(atts)); 110 | m_rDocument.add_config(last_way, tag); 111 | } 112 | 113 | if (strcmp(name, "nd") == 0) { 114 | m_rDocument.add_node(*last_way, atts); 115 | } 116 | return; 117 | } 118 | 119 | if (m_section == 3) { 120 | /* 121 | * START RELATIONS CODE 122 | */ 123 | if (strcmp(name, "relation") == 0) { 124 | last_relation = new Relation(atts); 125 | return; 126 | } 127 | 128 | if (strcmp(name, "member") == 0) { 129 | /* 130 | 131 | 132 | 133 | */ 134 | auto way_id = last_relation->add_member(atts); 135 | if (way_id == -1) return; 136 | assert(!last_relation->way_refs().empty()); 137 | if (m_rDocument.has_way(way_id)) { 138 | Way* way_ptr = m_rDocument.FindWay(way_id); 139 | way_ptr->insert_tags(last_relation->tags()); 140 | } else { 141 | assert(!last_relation->way_refs().empty()); 142 | last_relation->way_refs().pop_back(); 143 | } 144 | 145 | return; 146 | } 147 | if (strcmp(name, "tag") == 0) { 148 | auto tag = last_relation->add_tag(Tag(atts)); 149 | m_rDocument.add_config(last_relation, tag); 150 | } 151 | } 152 | if (strcmp(name, "osm") == 0) { 153 | } 154 | } 155 | 156 | void OSMDocumentParserCallback::EndElement(const char* name) { 157 | if (strcmp(name, "osm") == 0) { 158 | m_rDocument.endOfFile(); 159 | show_progress(); 160 | return; 161 | } 162 | 163 | if (strcmp(name, "node") == 0) { 164 | m_rDocument.AddNode(*last_node); 165 | delete last_node; 166 | return; 167 | } 168 | if (strcmp(name, "way") == 0) { 169 | m_rDocument.AddWay(*last_way); 170 | if (m_rDocument.config_has_tag(last_way->tag_config())) { 171 | 172 | auto maxspeed = m_rDocument.maxspeed(last_way->tag_config()); 173 | if (last_way->maxspeed_forward() <= 0) { 174 | last_way->maxspeed_forward(maxspeed); 175 | } 176 | if (last_way->maxspeed_backward() <= 0) { 177 | last_way->maxspeed_backward(maxspeed); 178 | } 179 | } 180 | delete last_way; 181 | return; 182 | } 183 | 184 | if (strcmp(name, "relation") == 0) { 185 | if (m_rDocument.config_has_tag(last_relation->tag_config())) { 186 | for (auto it = last_relation->way_refs().begin(); it != last_relation->way_refs().end(); ++it) { 187 | auto way_id = *it; 188 | assert(m_rDocument.has_way(way_id)); 189 | if (m_rDocument.has_way(way_id)) { 190 | Way* way_ptr = m_rDocument.FindWay(way_id); 191 | way_ptr->tag_config(last_relation->tag_config()); 192 | auto newValue = m_rDocument.maxspeed( 193 | last_relation->tag_config()); 194 | if (way_ptr->maxspeed_forward() <= 0) { 195 | way_ptr->maxspeed_forward(newValue); 196 | } 197 | if (way_ptr->maxspeed_backward() <= 0) { 198 | way_ptr->maxspeed_backward(newValue); 199 | } 200 | } 201 | } 202 | m_rDocument.AddRelation(*last_relation); 203 | } 204 | // TODO add all other relations 205 | delete last_relation; 206 | return; 207 | } 208 | } 209 | 210 | } // end namespace osm2pgr 211 | --------------------------------------------------------------------------------