From 9c6ed68acd34e3817f4a784c7259da337de08579 Mon Sep 17 00:00:00 2001 From: Jochen Topf Date: Thu, 10 Aug 2023 21:46:25 +0200 Subject: [PATCH 1/2] Store -O/--output setting in properties and use for append --- src/command-line-parser.cpp | 1 + src/options.hpp | 2 ++ src/osm2pgsql.cpp | 21 ++++++++++++++++++ tests/bdd/regression/properties.feature | 29 +++++++++++++++++++++++++ tests/bdd/regression/timestamps.feature | 24 +++++++++++++------- tests/bdd/regression/update.feature | 2 +- tests/bdd/steps/steps_execute.py | 7 ++++-- 7 files changed, 75 insertions(+), 11 deletions(-) diff --git a/src/command-line-parser.cpp b/src/command-line-parser.cpp index 3dffa8a72..d3ad4e258 100644 --- a/src/command-line-parser.cpp +++ b/src/command-line-parser.cpp @@ -652,6 +652,7 @@ options_t parse_command_line(int argc, char *argv[]) break; case 'O': // --output options.output_backend = optarg; + options.output_backend_set = true; break; case 'x': // --extra-attributes options.extra_attributes = true; diff --git a/src/options.hpp b/src/options.hpp index 0baa4aced..31302c4bd 100644 --- a/src/options.hpp +++ b/src/options.hpp @@ -184,6 +184,8 @@ struct options_t bool parallel_indexing = true; bool create = false; bool pass_prompt = false; + + bool output_backend_set = false; }; // struct options_t #endif // OSM2PGSQL_OPTIONS_HPP diff --git a/src/osm2pgsql.cpp b/src/osm2pgsql.cpp index 9e23852d9..beaa5d17c 100644 --- a/src/osm2pgsql.cpp +++ b/src/osm2pgsql.cpp @@ -113,6 +113,7 @@ static void store_properties(properties_t *properties, options_t const &options) properties->set_bool("updatable", options.slim && !options.droptemp); properties->set_string("version", get_osm2pgsql_short_version()); properties->set_int("db_format", options.middle_database_format); + properties->set_string("output", options.output_backend); properties->store(); } @@ -241,6 +242,25 @@ static void check_db_format(properties_t const &properties, options_t *options) options->middle_database_format = format; } +static void check_output(properties_t const &properties, options_t *options) +{ + auto const output = properties.get_string("output", "pgsql"); + + if (!options->output_backend_set) { + options->output_backend = output; + log_info("Using output '{}' (same as on import).", output); + return; + } + + if (options->output_backend == output) { + return; + } + + throw fmt_error("Different output specified on command line ('{}')" + " then used on import ('{}').", + options->output_backend, output); +} + // This is called in "append" mode to check that the command line options are // compatible with the properties stored in the database. static void check_and_update_properties(properties_t *properties, @@ -251,6 +271,7 @@ static void check_and_update_properties(properties_t *properties, check_and_update_flat_node_file(properties, options); check_prefix(*properties, options); check_db_format(*properties, options); + check_output(*properties, options); } // If we are in append mode and the middle nodes table isn't there, it probably diff --git a/tests/bdd/regression/properties.feature b/tests/bdd/regression/properties.feature index 3d754c7b3..64ff02ac0 100644 --- a/tests/bdd/regression/properties.feature +++ b/tests/bdd/regression/properties.feature @@ -26,6 +26,21 @@ Feature: Updates to the test database with properties check | --slim | --flat-nodes=x | Database was imported without flat node file | + Scenario: Append without output on null output + When running osm2pgsql null with parameters + | -c | + | --slim | + + Given the input file '000466354.osc.gz' + When running osm2pgsql nooutput with parameters + | -a | + | --slim | + Then the error output contains + """ + Using output 'null' (same as on import). + """ + + Scenario Outline: Create/append with various parameters When running osm2pgsql pgsql with parameters | --slim | @@ -50,3 +65,17 @@ Feature: Updates to the test database with properties check | --flat-nodes=x | --flat-nodes=y | Using the flat node file you specified | | --prefix=abc | | Using prefix 'abc' (same as on import). | + + Scenario: Create with different output than append + When running osm2pgsql pgsql with parameters + | --slim | + + Given the input file '000466354.osc.gz' + Then running osm2pgsql null with parameters fails + | -a | + | --slim | + And the error output contains + """ + Different output specified on command line + """ + diff --git a/tests/bdd/regression/timestamps.feature b/tests/bdd/regression/timestamps.feature index bc80c7fc7..99dd768d3 100644 --- a/tests/bdd/regression/timestamps.feature +++ b/tests/bdd/regression/timestamps.feature @@ -9,7 +9,7 @@ Feature: Timestamps in properties table should reflect timestamps in input file """ When running osm2pgsql pgsql - Then table osm2pgsql_properties has 8 rows + Then table osm2pgsql_properties has 9 rows And table osm2pgsql_properties contains | property | value | | attributes | false | @@ -19,6 +19,7 @@ Feature: Timestamps in properties table should reflect timestamps in input file | updatable | false | | import_timestamp | 2020-01-02T03:04:06Z | | current_timestamp | 2020-01-02T03:04:06Z | + | output | pgsql | Scenario: Create database without timestamps Given the OSM data @@ -29,7 +30,7 @@ Feature: Timestamps in properties table should reflect timestamps in input file """ When running osm2pgsql pgsql - Then table osm2pgsql_properties has 6 rows + Then table osm2pgsql_properties has 7 rows Then table osm2pgsql_properties contains | property | value | | attributes | false | @@ -37,6 +38,7 @@ Feature: Timestamps in properties table should reflect timestamps in input file | flat_node_file | | | prefix | planet_osm | | updatable | false | + | output | pgsql | Scenario: Create and update database with timestamps Given the OSM data @@ -49,7 +51,7 @@ Feature: Timestamps in properties table should reflect timestamps in input file When running osm2pgsql pgsql with parameters | --create | --slim | - Then table osm2pgsql_properties has 8 rows + Then table osm2pgsql_properties has 9 rows And table osm2pgsql_properties contains | property | value | | attributes | false | @@ -59,6 +61,7 @@ Feature: Timestamps in properties table should reflect timestamps in input file | updatable | true | | import_timestamp | 2020-01-02T03:04:06Z | | current_timestamp | 2020-01-02T03:04:06Z | + | output | pgsql | Given the OSM data """ @@ -69,7 +72,7 @@ Feature: Timestamps in properties table should reflect timestamps in input file When running osm2pgsql pgsql with parameters | --append | --slim | - Then table osm2pgsql_properties has 8 rows + Then table osm2pgsql_properties has 9 rows And table osm2pgsql_properties contains | property | value | | attributes | false | @@ -79,6 +82,7 @@ Feature: Timestamps in properties table should reflect timestamps in input file | updatable | true | | import_timestamp | 2020-01-02T03:04:06Z | | current_timestamp | 2020-01-02T03:06:05Z | + | output | pgsql | Scenario: Create database with timestamps and update without timestamps Given the OSM data @@ -91,7 +95,7 @@ Feature: Timestamps in properties table should reflect timestamps in input file When running osm2pgsql pgsql with parameters | --create | --slim | - Then table osm2pgsql_properties has 8 rows + Then table osm2pgsql_properties has 9 rows And table osm2pgsql_properties contains | property | value | | attributes | false | @@ -101,6 +105,7 @@ Feature: Timestamps in properties table should reflect timestamps in input file | updatable | true | | import_timestamp | 2020-01-02T03:04:06Z | | current_timestamp | 2020-01-02T03:04:06Z | + | output | pgsql | Given the OSM data """ @@ -111,7 +116,7 @@ Feature: Timestamps in properties table should reflect timestamps in input file When running osm2pgsql pgsql with parameters | --append | --slim | - Then table osm2pgsql_properties has 8 rows + Then table osm2pgsql_properties has 9 rows And table osm2pgsql_properties contains | property | value | | attributes | false | @@ -121,6 +126,7 @@ Feature: Timestamps in properties table should reflect timestamps in input file | updatable | true | | import_timestamp | 2020-01-02T03:04:06Z | | current_timestamp | 2020-01-02T03:04:06Z | + | output | pgsql | Scenario: Create database without timestamps and update with timestamps Given the OSM data @@ -133,7 +139,7 @@ Feature: Timestamps in properties table should reflect timestamps in input file When running osm2pgsql pgsql with parameters | --create | --slim | - Then table osm2pgsql_properties has 6 rows + Then table osm2pgsql_properties has 7 rows And table osm2pgsql_properties contains | property | value | | attributes | false | @@ -141,6 +147,7 @@ Feature: Timestamps in properties table should reflect timestamps in input file | flat_node_file | | | prefix | planet_osm | | updatable | true | + | output | pgsql | Given the OSM data """ @@ -151,7 +158,7 @@ Feature: Timestamps in properties table should reflect timestamps in input file When running osm2pgsql pgsql with parameters | --append | --slim | - Then table osm2pgsql_properties has 7 rows + Then table osm2pgsql_properties has 8 rows And table osm2pgsql_properties contains | property | value | | attributes | false | @@ -160,4 +167,5 @@ Feature: Timestamps in properties table should reflect timestamps in input file | prefix | planet_osm | | updatable | true | | current_timestamp | 2020-01-02T03:06:05Z | + | output | pgsql | diff --git a/tests/bdd/regression/update.feature b/tests/bdd/regression/update.feature index 8509b5b85..c25d740db 100644 --- a/tests/bdd/regression/update.feature +++ b/tests/bdd/regression/update.feature @@ -22,7 +22,7 @@ Feature: Updates to the test database And table planet_osm_line has 3274 rows And table planet_osm_roads has 380 rows And table planet_osm_polygon has 4277 rows - And table osm2pgsql_properties has 11 rows + And table osm2pgsql_properties has 12 rows Examples: | param1 | param2 | param3 | diff --git a/tests/bdd/steps/steps_execute.py b/tests/bdd/steps/steps_execute.py index 79638ba19..01a5bab7c 100644 --- a/tests/bdd/steps/steps_execute.py +++ b/tests/bdd/steps/steps_execute.py @@ -38,10 +38,13 @@ def get_import_file(context): def run_osm2pgsql(context, output): - assert output in ('flex', 'pgsql', 'gazetteer', 'none') + assert output in ('flex', 'pgsql', 'gazetteer', 'null', 'nooutput') cmdline = [str(Path(context.config.userdata['BINARY']).resolve())] - cmdline.extend(('-O', output)) + + if output != 'nooutput': + cmdline.extend(('-O', output)) + cmdline.extend(context.osm2pgsql_params) # convert table items to CLI arguments and inject constants to placeholders From ed0c0ef9a01f8140b8883380b42404b15a6ec125 Mon Sep 17 00:00:00 2001 From: Jochen Topf Date: Sat, 12 Aug 2023 12:03:59 +0200 Subject: [PATCH 2/2] Store -S/--style setting in properties and use for append --- docs/osm2pgsql-gen.md | 8 +- src/command-line-parser.cpp | 9 +- src/gen/osm2pgsql-gen.cpp | 15 +-- src/options.hpp | 3 +- src/osm2pgsql.cpp | 58 +++++++++++ tests/bdd/regression/properties.feature | 43 ++++++++ tests/bdd/regression/timestamps.feature | 16 +-- tests/bdd/regression/update.feature | 2 +- tests/data/test_output_flex_copy.lua | 133 ++++++++++++++++++++++++ 9 files changed, 262 insertions(+), 25 deletions(-) create mode 100644 tests/data/test_output_flex_copy.lua diff --git a/docs/osm2pgsql-gen.md b/docs/osm2pgsql-gen.md index ef361b679..eb81d8629 100644 --- a/docs/osm2pgsql-gen.md +++ b/docs/osm2pgsql-gen.md @@ -36,13 +36,19 @@ mandatory for short options too. specified. -S, \--style=FILE -: The Lua config file. Same as for **osm2pgsql**. +: The Lua config file. Same as for **osm2pgsql**. Usually not required + because it is read from the `osm2pgsql_properties` table. -j, \-jobs=NUM : Specifies the number of parallel threads used for certain operations. Setting this to the number of available CPU cores is a reasonable starting point. +\--middle-schema=SCHEMA +: Database schema where the `osm2pgsql_properties` table is to be found. + Default `public`. Set to the same value as on the `osm2pgsql` command + line. + # HELP/VERSION OPTIONS -h, \--help diff --git a/src/command-line-parser.cpp b/src/command-line-parser.cpp index d3ad4e258..cc23323ec 100644 --- a/src/command-line-parser.cpp +++ b/src/command-line-parser.cpp @@ -514,14 +514,6 @@ static void check_options(options_t *options) options->expire_tiles_zoom = 0; } - if (options->output_backend == "flex" || - options->output_backend == "gazetteer") { - if (options->style == DEFAULT_STYLE) { - throw std::runtime_error{ - "You have to set the config file with the -S|--style option."}; - } - } - if (options->output_backend == "gazetteer") { log_warn( "The 'gazetteer' output is deprecated and will soon be removed."); @@ -623,6 +615,7 @@ options_t parse_command_line(int argc, char *argv[]) break; case 'S': // --style options.style = optarg; + options.style_set = true; break; case 'i': // --tablespace-index options.tblsmain_index = optarg; diff --git a/src/gen/osm2pgsql-gen.cpp b/src/gen/osm2pgsql-gen.cpp index 41626287a..cba0e1b97 100644 --- a/src/gen/osm2pgsql-gen.cpp +++ b/src/gen/osm2pgsql-gen.cpp @@ -88,7 +88,7 @@ This program is EXPERIMENTAL and might change without notice. Main Options: -a|--append Run in append mode -c|--create Run in create mode (default) - -S|--style=FILE The Lua config file (required, same as for osm2pgsql) + -S|--style=FILE The Lua config file (same as for osm2pgsql) -j|--jobs=NUM Number of parallel jobs (default 1) --middle-schema=SCHEMA Database schema for middle tables @@ -667,11 +667,6 @@ int main(int argc, char *argv[]) return 2; } - if (style.empty()) { - log_error("Need --style/-S option"); - return 2; - } - if (jobs < 1 || jobs > 32) { log_error("The --jobs/-j parameter must be between 1 and 32."); return 2; @@ -710,6 +705,14 @@ int main(int argc, char *argv[]) properties_t properties{conninfo, schema}; properties.load(); + if (style.empty()) { + style = properties.get_string("style", ""); + if (style.empty()) { + log_error("Need --style/-S option"); + return 2; + } + } + bool const updatable = properties.get_bool("updatable", false); genproc_t gen{style, conninfo, append, updatable, jobs}; gen.run(); diff --git a/src/options.hpp b/src/options.hpp index 31302c4bd..b15964104 100644 --- a/src/options.hpp +++ b/src/options.hpp @@ -104,7 +104,7 @@ struct options_t /// Pg schema to store output tables in. std::string output_dbschema{"public"}; - std::string style{DEFAULT_STYLE}; ///< style file to use + std::string style{}; ///< style file to use /// Name of the flat node file used. Empty if flat node file is not enabled. std::string flat_node_file{}; @@ -186,6 +186,7 @@ struct options_t bool pass_prompt = false; bool output_backend_set = false; + bool style_set = false; }; // struct options_t #endif // OSM2PGSQL_OPTIONS_HPP diff --git a/src/osm2pgsql.cpp b/src/osm2pgsql.cpp index beaa5d17c..2a8661011 100644 --- a/src/osm2pgsql.cpp +++ b/src/osm2pgsql.cpp @@ -115,6 +115,15 @@ static void store_properties(properties_t *properties, options_t const &options) properties->set_int("db_format", options.middle_database_format); properties->set_string("output", options.output_backend); + if (options.style.empty()) { + properties->set_string("style", ""); + } else { + properties->set_string( + "style", + boost::filesystem::absolute(boost::filesystem::path{options.style}) + .string()); + } + properties->store(); } @@ -261,6 +270,38 @@ static void check_output(properties_t const &properties, options_t *options) options->output_backend, output); } +static void check_and_update_style_file(properties_t *properties, + options_t *options) +{ + auto const style_file_from_import = properties->get_string("style", ""); + + if (options->style.empty()) { + log_info("Using style file '{}' (same as on import).", + style_file_from_import); + options->style = style_file_from_import; + return; + } + + if (style_file_from_import.empty()) { + throw std::runtime_error{"Style file from import is empty!?"}; + } + + const auto absolute_path = + boost::filesystem::absolute(boost::filesystem::path{options->style}) + .string(); + + if (absolute_path == style_file_from_import) { + log_info("Using style file '{}' (same as on import).", + style_file_from_import); + return; + } + + log_info("Using the style file you specified on the command line" + " ('{}') instead of the one used on import ('{}').", + absolute_path, style_file_from_import); + properties->set_string("style", absolute_path, true); +} + // This is called in "append" mode to check that the command line options are // compatible with the properties stored in the database. static void check_and_update_properties(properties_t *properties, @@ -272,6 +313,7 @@ static void check_and_update_properties(properties_t *properties, check_prefix(*properties, options); check_db_format(*properties, options); check_output(*properties, options); + check_and_update_style_file(properties, options); } // If we are in append mode and the middle nodes table isn't there, it probably @@ -291,6 +333,20 @@ static void check_for_nodes_table(options_t const &options) } } +static void check_and_set_style(options_t *options) +{ + if (!options->style_set) { + if (options->output_backend == "flex" || + options->output_backend == "gazetteer") { + throw std::runtime_error{"You have to set the config file " + "with the -S|--style option."}; + } + if (options->output_backend == "pgsql") { + options->style = DEFAULT_STYLE; + } + } +} + int main(int argc, char *argv[]) { try { @@ -317,6 +373,7 @@ int main(int argc, char *argv[]) if (properties.load()) { check_and_update_properties(&properties, &options); } else { + check_and_set_style(&options); check_for_nodes_table(options); } @@ -334,6 +391,7 @@ int main(int argc, char *argv[]) } } } else { + check_and_set_style(&options); store_properties(&properties, options); auto const finfo = run(options); store_data_properties(&properties, finfo); diff --git a/tests/bdd/regression/properties.feature b/tests/bdd/regression/properties.feature index 64ff02ac0..2e25a6152 100644 --- a/tests/bdd/regression/properties.feature +++ b/tests/bdd/regression/properties.feature @@ -79,3 +79,46 @@ Feature: Updates to the test database with properties check Different output specified on command line """ + Scenario Outline: Create/append with with null output doesn't need style + When running osm2pgsql null with parameters + | --slim | + + Given the input file '000466354.osc.gz' + When running osm2pgsql null with parameters + | -a | + | --slim | + | | + Then the error output contains + """ + + """ + + Examples: + | param | message | + | | Using style file '' (same as on import). | + | --style= | Using style file '' (same as on import). | + + + @config.have_lua + Scenario Outline: Create/append with various style parameters with flex output + When running osm2pgsql flex with parameters + | --slim | + | | + + Given the input file '000466354.osc.gz' + When running osm2pgsql flex with parameters + | -a | + | --slim | + | | + Then the error output contains + """ + + """ + + Examples: + | param_create | param_append | message | + | --style={TEST_DATA_DIR}/test_output_flex.lua | | Using style file | + | --style={TEST_DATA_DIR}/test_output_flex.lua | --style={TEST_DATA_DIR}/test_output_flex.lua | Using style file | + | --style={TEST_DATA_DIR}/test_output_flex.lua | --style={TEST_DATA_DIR}/test_output_flex_copy.lua | Using the style file you specified | + + diff --git a/tests/bdd/regression/timestamps.feature b/tests/bdd/regression/timestamps.feature index 99dd768d3..56edb1631 100644 --- a/tests/bdd/regression/timestamps.feature +++ b/tests/bdd/regression/timestamps.feature @@ -9,7 +9,7 @@ Feature: Timestamps in properties table should reflect timestamps in input file """ When running osm2pgsql pgsql - Then table osm2pgsql_properties has 9 rows + Then table osm2pgsql_properties has 10 rows And table osm2pgsql_properties contains | property | value | | attributes | false | @@ -30,7 +30,7 @@ Feature: Timestamps in properties table should reflect timestamps in input file """ When running osm2pgsql pgsql - Then table osm2pgsql_properties has 7 rows + Then table osm2pgsql_properties has 8 rows Then table osm2pgsql_properties contains | property | value | | attributes | false | @@ -51,7 +51,7 @@ Feature: Timestamps in properties table should reflect timestamps in input file When running osm2pgsql pgsql with parameters | --create | --slim | - Then table osm2pgsql_properties has 9 rows + Then table osm2pgsql_properties has 10 rows And table osm2pgsql_properties contains | property | value | | attributes | false | @@ -72,7 +72,7 @@ Feature: Timestamps in properties table should reflect timestamps in input file When running osm2pgsql pgsql with parameters | --append | --slim | - Then table osm2pgsql_properties has 9 rows + Then table osm2pgsql_properties has 10 rows And table osm2pgsql_properties contains | property | value | | attributes | false | @@ -95,7 +95,7 @@ Feature: Timestamps in properties table should reflect timestamps in input file When running osm2pgsql pgsql with parameters | --create | --slim | - Then table osm2pgsql_properties has 9 rows + Then table osm2pgsql_properties has 10 rows And table osm2pgsql_properties contains | property | value | | attributes | false | @@ -116,7 +116,7 @@ Feature: Timestamps in properties table should reflect timestamps in input file When running osm2pgsql pgsql with parameters | --append | --slim | - Then table osm2pgsql_properties has 9 rows + Then table osm2pgsql_properties has 10 rows And table osm2pgsql_properties contains | property | value | | attributes | false | @@ -139,7 +139,7 @@ Feature: Timestamps in properties table should reflect timestamps in input file When running osm2pgsql pgsql with parameters | --create | --slim | - Then table osm2pgsql_properties has 7 rows + Then table osm2pgsql_properties has 8 rows And table osm2pgsql_properties contains | property | value | | attributes | false | @@ -158,7 +158,7 @@ Feature: Timestamps in properties table should reflect timestamps in input file When running osm2pgsql pgsql with parameters | --append | --slim | - Then table osm2pgsql_properties has 8 rows + Then table osm2pgsql_properties has 9 rows And table osm2pgsql_properties contains | property | value | | attributes | false | diff --git a/tests/bdd/regression/update.feature b/tests/bdd/regression/update.feature index c25d740db..57a9c5d39 100644 --- a/tests/bdd/regression/update.feature +++ b/tests/bdd/regression/update.feature @@ -22,7 +22,7 @@ Feature: Updates to the test database And table planet_osm_line has 3274 rows And table planet_osm_roads has 380 rows And table planet_osm_polygon has 4277 rows - And table osm2pgsql_properties has 12 rows + And table osm2pgsql_properties has 13 rows Examples: | param1 | param2 | param3 | diff --git a/tests/data/test_output_flex_copy.lua b/tests/data/test_output_flex_copy.lua new file mode 100644 index 000000000..c25469168 --- /dev/null +++ b/tests/data/test_output_flex_copy.lua @@ -0,0 +1,133 @@ + +local tables = {} + +tables.point = osm2pgsql.define_node_table('osm2pgsql_test_point', { + { column = 'tags', type = 'hstore' }, + { column = 'geom', type = 'point' }, +}) + +tables.line = osm2pgsql.define_table{ + name = 'osm2pgsql_test_line', + ids = { type = 'way', id_column = 'osm_id' }, + columns = { + { column = 'tags', type = 'hstore' }, + { column = 'name', type = 'text' }, + { column = 'geom', type = 'linestring' }, + }, + cluster = 'auto' +} + +tables.polygon = osm2pgsql.define_table{ + name = 'osm2pgsql_test_polygon', + ids = { type = 'area', id_column = 'osm_id' }, + columns = { + { column = 'tags', type = 'hstore' }, + { column = 'name', type = 'text' }, + { column = 'geom', type = 'geometry' }, + { column = 'area', type = 'area' }, + } +} + +tables.route = osm2pgsql.define_table{ + name = 'osm2pgsql_test_route', + ids = { type = 'relation', id_column = 'osm_id' }, + columns = { + { column = 'tags', type = 'hstore' }, + { column = 'geom', type = 'multilinestring' }, + } +} + +local function is_polygon(tags) + if tags.aeroway + or tags.amenity + or tags.area + or tags.building + or tags.harbour + or tags.historic + or tags.landuse + or tags.leisure + or tags.man_made + or tags.military + or tags.natural + or tags.office + or tags.place + or tags.power + or tags.public_transport + or tags.shop + or tags.sport + or tags.tourism + or tags.water + or tags.waterway + or tags.wetland + or tags['abandoned:aeroway'] + or tags['abandoned:amenity'] + or tags['abandoned:building'] + or tags['abandoned:landuse'] + or tags['abandoned:power'] + or tags['area:highway'] + then + return true + else + return false + end +end + +local delete_keys = { + 'odbl', + 'created_by', + 'source' +} + +local clean_tags = osm2pgsql.make_clean_tags_func(delete_keys) + +function osm2pgsql.process_node(object) + if clean_tags(object.tags) then + return + end + + tables.point:add_row({ + tags = object.tags + }) +end + +function osm2pgsql.process_way(object) + if clean_tags(object.tags) then + return + end + + if is_polygon(object.tags) then + tables.polygon:add_row({ + tags = object.tags, + name = object.tags.name, + geom = { create = 'area' } + }) + else + tables.line:add_row({ + tags = object.tags, + name = object.tags.name + }) + end +end + +function osm2pgsql.process_relation(object) + if clean_tags(object.tags) then + return + end + + if object.tags.type == 'multipolygon' or object.tags.type == 'boundary' then + tables.polygon:add_row({ + tags = object.tags, + name = object.tags.name, + geom = { create = 'area', split_at = 'multi' } + }) + return + end + + if object.tags.type == 'route' then + tables.route:add_row({ + tags = object.tags, + geom = { create = 'line' } + }) + end +end +