### Install osm2pgsql on Ubuntu Source: https://osm2pgsql.org/doc/install/linux Installs the osm2pgsql package on Ubuntu using the apt package manager. This is a straightforward installation process for Ubuntu users. ```bash apt install osm2pgsql ``` -------------------------------- ### osm2pgsql-replication init Source: https://osm2pgsql.org/doc/man/osm2pgsql-replication-2.2.0 Initializes replication by specifying the source of replication data, either from a file or a server, and an optional start time. ```APIDOC ## osm2pgsql-replication init ### Description Initializes replication by specifying the source of replication data and an optional start time. ### Method `osm2pgsql-replication init` ### Parameters #### Path Parameters None #### Query Parameters None #### Arguments - **--osm-file** _FILE_ - Get replication information from the given file. - **--server** _URL_ - Use replication server at the given URL. - **--start-at** _TIME_ - Time when to start replication. When an absolute timestamp (in ISO format) is given, it will be used. If a number is given, then replication starts the number of minutes before the known date of the database. ### Request Example ```bash osm2pgsql-replication init --osm-file data.osm --start-at 2023-10-27T10:00:00Z ``` ### Response #### Success Response (0) Replication initialized successfully. #### Response Example (No specific response body defined, indicates success via exit code) ``` -------------------------------- ### Build osm2pgsql from AUR on Arch Linux Source: https://osm2pgsql.org/doc/install/linux Instructions for installing osm2pgsql on Arch Linux by building the osm2pgsql-git package from the AUR. This typically involves downloading a tarball and using `makepkg` or an AUR helper. ```bash # Download the tarball and compile/install with `makepkg`, or use an AUR helper such as `yaourt`. ``` -------------------------------- ### osm2pgsql-replication init Source: https://osm2pgsql.org/doc/man/osm2pgsql-replication-2.2.0 Initializes the replication process for updating the osm2pgsql database. This command sets up the replication service and determines the starting point for applying updates. It can be run multiple times to change replication servers or rollback the update process. ```APIDOC ## osm2pgsql-replication init ### Description Initializes the replication process for updating the osm2pgsql database. This command sets up the replication service and determines the starting point for applying updates. It can be run multiple times to change replication servers or rollback the update process. ### Method `osm2pgsql-replication` ### Endpoint N/A (Command-line tool) ### Parameters #### Command Arguments * **init** - Required - Initializes the replication process. * **update** - Required - Downloads and applies new data. * **status** - Required - Prints replication status information. #### Options * **-h, --help** - Display help message and exit. * **-q, --quiet** - Print only error messages. * **-v, --verbose** - Increase verbosity of output. #### Initialization Specific Arguments * **--osm-file FILE** - Use replication information from a local OSM file. * **--server URL** - Specify the replication server URL. * **--start-at TIME** - Specify an absolute ISO timestamp or rollback period in minutes. #### Database Arguments * **-d DB, --database DB** - Name of the PostgreSQL database or connection string. * **-U NAME, --username NAME, --user NAME** - PostgreSQL user name. * **-H HOST, --host HOST** - Database server host name or socket location. * **-P PORT, --port PORT** - Database server port. * **-p PREFIX, --prefix PREFIX** - Prefix for table names (default: 'planet_osm'). * **--middle-schema SCHEMA** - Schema for the replication state table. * **--schema SCHEMA** - Schema for the database tables. ### Request Example ```bash osm2pgsql-replication init --database gis --user postgres --host localhost --osm-file planet-latest.osm.pbf --start-at 2023-01-01T10:00:00Z ``` ### Response #### Success Response (Exit Code 0) Indicates successful initialization. Output may include status messages about the process. #### Response Example ``` Replication initialized successfully. ``` ``` -------------------------------- ### Lint Lua Scripts with luacheck Source: https://osm2pgsql.org/doc/manual Employ the 'luacheck' linter for more extensive analysis of Lua scripts beyond basic syntax. It can identify potential issues and enforce coding standards. Installation is available via LuaRocks or system package managers. ```bash luarocks install luacheck luacheck SCRIPT.lua ``` ```bash # Debian/Ubuntu apt-get install lua-checks luacheck SCRIPT.lua ``` -------------------------------- ### Calculating Polygon Area with Real Type in osm2pgsql Source: https://osm2pgsql.org/doc/tutorials/switching-from-add-row-to-insert This example demonstrates how to calculate the area of a polygon and store it in a column of type 'real'. It uses `as_polygon():transform(3857)` to get the geometry in WebMercator coordinates before calculating the area. ```lua local forests = osm2pgsql.define_way_table('forests', { { column = 'geom', type = 'polygon' }, { column = 'area', type = 'real' } }) function osm2pgsql.process_way(object) if object.is_closed and object.tags.natural == 'wood' then forests:add_row({ geom = { create = 'area' } }) local poly = object:as_polygon():transform(3857) forests:insert({ geom = poly, area = poly:area() }) end end ``` -------------------------------- ### Osm2pgsql Help and Version Commands Source: https://osm2pgsql.org/doc/manual-v1 Illustrates the command-line options to retrieve help information or check the version of the osm2pgsql executable. The '--help' option can be augmented with '--verbose' for more detailed output, while '--version' also displays the versions of linked libraries. ```bash osm2pgsql -h osm2pgsql --help osm2pgsql -h -v osm2pgsql --help --verbose osm2pgsql -V osm2pgsql --version ``` -------------------------------- ### Osm2pgsql Import and Update Command Line Options Source: https://osm2pgsql.org/doc/manual-v1 Shows the command-line options for setting up an initial import with the capability for subsequent updates using OSM change files. This mode requires the '--slim' option for initial creation and '--append' with '--slim' for update operations. It necessitates more disk space for storing update-related information. ```bash osm2pgsql -c -s OSMFILE osm2pgsql --create --slim OSMFILE osm2pgsql --slim OSMFILE osm2pgsql -a -s OSMFILE osm2pgsql --append --slim OSMFILE ``` -------------------------------- ### Install osm2pgsql on Fedora Source: https://osm2pgsql.org/doc/install/linux Installs the osm2pgsql package on Fedora using the dnf package manager. This command directly installs the available package for Fedora. ```bash dnf install osm2pgsql ``` -------------------------------- ### Add Geo repository and install osm2pgsql on openSUSE Source: https://osm2pgsql.org/doc/install/linux Adds the 'Geo' package repository and refreshes it, then installs osm2pgsql on openSUSE using the zypper package manager. Ensure the repository URL matches your openSUSE version. ```bash zypper ar https://download.opensuse.org/repositories/Application:/Geo/openSUSE_Leap_15.6/ "Geo" zypper refresh zypper install osm2pgsql ``` -------------------------------- ### Initialize osm2pgsql Replication (Version < 1.9.0 with Extract) Source: https://osm2pgsql.org/doc/manual-v1 Initializes the osm2pgsql replication process using an existing OSM extract file. This method requires the database name and the path to the PBF extract. It sets up the necessary replication status table and connection details based on the provided extract. ```shell osm2pgsql-replication init -d --osm-file your-extract.pbf ``` -------------------------------- ### Manage systemd Services and Timers Source: https://osm2pgsql.org/doc/manual-v1 Commands to reload the systemd daemon to recognize new service and timer files, enable a timer to start on boot, and manually start a timer. ```bash sudo systemctl daemon-reload sudo systemctl enable osm2pgsql-update.timer sudo systemctl start osm2pgsql-update.timer ``` -------------------------------- ### Example Usage of Memory Reporter (Lua) Source: https://osm2pgsql.org/doc/manual Provides an example of how to use the `create_memory_reporter` function within an osm2pgsql Lua script. It shows the creation of a memory reporter instance and its subsequent invocation within the `process_node` callback to log memory usage periodically. ```lua local mr = create_memory_reporter('/tmp/osm2pgsql-lua-memlog.csv', 10000) function osm2pgsql.process_node(object) mr() ... end ``` -------------------------------- ### Command Line Options Source: https://osm2pgsql.org/doc/manual-v1 This section provides an overview of the command-line options available for the osm2pgsql tool. ```APIDOC ## Command Line Options ### Main Options | Option | Description | | --------------- | --------------------------------------------------------- | | `-a`, `--append` | Run in append mode. | | `-c`, `--create` | Run in create mode (this is the default if `-a` is not used). | ### Help/Version Options | Option | Description | | ----------- | ------------------------------------------------------------------------- | | `-h`, `--help` | Print help. Add `-v, --verbose` for more verbose help. | | `-V`, `--version` | Print osm2pgsql version. Also prints versions of some libraries used. | ``` -------------------------------- ### Create PostgreSQL Database and Extensions Source: https://osm2pgsql.org/doc/manual Commands to create a new PostgreSQL database user, create a database owned by that user, and enable the PostGIS and hstore extensions. These steps are necessary before importing OSM data with osm2pgsql. ```shell sudo -u postgres createuser osmuser sudo -u postgres createdb --encoding=UTF8 --owner=osmuser osm sudo -u postgres psql osm --command='CREATE EXTENSION postgis;' sudo -u postgres psql osm --command='CREATE EXTENSION hstore;' ``` -------------------------------- ### Manage systemd Service and Timer Source: https://osm2pgsql.org/doc/manual Commands to reload systemd after creating new service and timer files, and to enable and start the scheduled update timer. ```bash sudo systemctl daemon-reload sudo systemctl enable osm2pgsql-update.timer sudo systemctl start osm2pgsql-update.timer ``` -------------------------------- ### Output Options Source: https://osm2pgsql.org/doc/man/osm2pgsql-1-4-1 Specifies the output back-end and style file for osm2pgsql imports. ```APIDOC ## OUTPUT OPTIONS -O, --output=OUTPUT Specifies the output back-end to use. Currently osm2pgsql supports **pgsql**, **flex**, **gazetteer** and **null**. **pgsql** is the default output back-end and is optimized for rendering with Mapnik. **gazetteer** is intended for geocoding with Nominatim. The experimental **flex** backend allows more flexible configuration. **null** does not write any output and is only useful for testing or with **--slim** for creating slim tables. There is also a **multi** backend. This is now deprecated and will be removed in future versions of osm2pgsql. -S, --style=FILE The style file. This specifies how the data is imported into the database, its format depends on the output. (For the **pgsql** output, the default is `/usr/share/osm2pgsql/default.style`, for other outputs there is no default.) ``` -------------------------------- ### Lua: Iterate Over Multi-Geometry Members Source: https://osm2pgsql.org/doc/manual This example shows how to iterate through the individual geometries within a multi-geometry object using the `:geometries()` function. Each member geometry can then be processed or inserted into a database. ```lua local geom = object:as_multipolygon() for g in geom:geometries() do landuse.insert({ geom = g, ... }) end ``` -------------------------------- ### Pull osm2pgsql Docker Image Source: https://osm2pgsql.org/doc/install/docker This command pulls the latest stable version of the osm2pgsql Docker image from Dockerhub. This is the first step to running osm2pgsql within a Docker environment. ```docker docker pull iboates/osm2pgsql:latest ``` -------------------------------- ### osm2pgsql Command Line Options Source: https://osm2pgsql.org/doc/manual This section provides an overview of the available command-line options for the osm2pgsql utility. ```APIDOC ## Command Line Options This appendix contains an overview of all command line options. ### Main Options | Option | Description | |---------------|-----------------------------------------| | -a, --append | Run in append mode. | | -c, --create | Run in create mode (default if not -a). | ### Help/Version Options | Option | Description | |-------------|-----------------------------------------------------------------------------| | -h, --help | Print help message. | | -V, --version | Print osm2pgsql version. Also prints versions of some libraries used. | ``` -------------------------------- ### Example Usage of Lua Memory Reporter Source: https://osm2pgsql.org/doc/manual-v1 This Lua code demonstrates how to use the `create_memory_reporter` function within an `osm2pgsql.process_node` callback. It initializes a memory reporter to log to '/tmp/osm2pgsql-lua-memlog.csv' every 10,000 processing cycles. ```lua local mr = create_memory_reporter('/tmp/osm2pgsql-lua-memlog.csv', 10000) function osm2pgsql.process_node(object) mr() ... end ``` -------------------------------- ### Osm2pgsql Data Processing Overview Source: https://osm2pgsql.org/doc/manual-v1 Provides a high-level overview of the three main steps involved in osm2pgsql data processing: Input, Middle, and Output. This helps in understanding how OSM data is read, processed, and loaded into the database. ```APIDOC ## Osm2pgsql Data Processing Overview ### Description Provides a high-level overview of the three main steps involved in osm2pgsql data processing: Input, Middle, and Output. This helps in understanding how OSM data is read, processed, and loaded into the database. ### Processing Steps 1. **Input**: Reads the OSM data from the source file. 2. **Middle**: Stores all objects and manages relationships between them. 3. **Output**: Transforms the processed data and loads it into the target database. ### Usage This section provides a conceptual understanding of the osm2pgsql workflow. ```