### Install Imposm using Go
Source: https://github.com/omniscale/imposm3/blob/master/README.md
Installs Imposm to your local go/bin directory. Ensure your GOBIN environment variable is set if you want to change the installation location.
```bash
go install github.com/omniscale/imposm3/cmd/imposm@latest
```
--------------------------------
### Build Imposm from Source
Source: https://github.com/omniscale/imposm3/blob/master/README.md
Builds Imposm into your local path and includes version information. This is the recommended installation method from source.
```bash
git clone https://github.com/omniscale/imposm3.git
cd imposm3
make build
```
--------------------------------
### Install Levigo with Snappy Support and Custom Paths
Source: https://github.com/omniscale/imposm3/blob/master/vendor/github.com/jmhodges/levigo/README.md
Install levigo with support for Snappy compression, specifying custom paths for both LevelDB and Snappy. Ensure the Snappy library flag (-lsnappy) appears after its library path.
```bash
CGO_CFLAGS="-I/path/to/leveldb/include -I/path/to/snappy/include"
CGO_LDFLAGS="-L/path/to/leveldb/lib -L/path/to/snappy/lib -lsnappy" go get github.com/jmhodges/levigo
```
--------------------------------
### Verify PostGIS Installation
Source: https://github.com/omniscale/imposm3/blob/master/docs/tutorial.md
Connect to the 'osm' database using psql to confirm the PostGIS extension is installed and accessible by printing its version.
```bash
PGPASSWORD=osm psql -h 127.0.0.1 -d osm -U osm -c 'select postgis_version();'
```
--------------------------------
### Install Levigo with Custom Paths
Source: https://github.com/omniscale/imposm3/blob/master/vendor/github.com/jmhodges/levigo/README.md
Install the levigo Go package when LevelDB shared libraries and headers are located in non-standard directories. This requires setting CGO_CFLAGS and CGO_LDFLAGS environment variables.
```bash
CGO_CFLAGS="-I/path/to/leveldb/include" CGO_LDFLAGS="-L/path/to/leveldb/lib" go get github.com/jmhodges/levigo
```
--------------------------------
### Run PostgreSQL Container with Docker
Source: https://github.com/omniscale/imposm3/blob/master/vendor/github.com/lib/pq/TESTS.md
Starts a PostgreSQL container, exposing the default port.
```bash
docker run --expose 5432:5432 postgres
```
--------------------------------
### Install fsnotify Dependency
Source: https://github.com/omniscale/imposm3/blob/master/vendor/gopkg.in/fsnotify.v1/README.md
Ensure you have the latest version of the golang.org/x/sys package installed, which fsnotify utilizes.
```console
go get -u golang.org/x/sys/...
```
--------------------------------
### Imposm3 Configuration Options
Source: https://github.com/omniscale/imposm3/blob/master/README.md
Example JSON configuration file for Imposm3. This allows you to specify options like cache directory, mapping file, and database connection details in a structured format.
```json
{
"cachedir": "/var/local/imposm",
"mapping": "mapping.json",
"connection": "postgis://user:password@localhost:port/database"
}
```
--------------------------------
### Run Imposm for Continuous Updates
Source: https://github.com/omniscale/imposm3/blob/master/docs/tutorial.md
Start the Imposm update process to automatically fetch and import diff files. Ensure a configuration file is specified.
```bash
imposm run -config config.json
```
--------------------------------
### Example Relation Data (Bus Route)
Source: https://github.com/omniscale/imposm3/blob/master/docs/relations.md
This is an example of an XML representation of a bus route relation, including its members and tags. This data can be imported using the 'route_members' mapping.
```xml
```
--------------------------------
### Building Import with Filters
Source: https://github.com/omniscale/imposm3/blob/master/docs/mapping.md
This example demonstrates how to import buildings into a table, applying filters to include only those with a 'name' tag, and excluding buildings tagged with 'building=no' or 'building=none'. It also rejects buildings where the 'level' tag is not purely numeric.
```yaml
tables:
buildings:
type: polygon
filters:
require:
name: [__any__]
reject:
building: ['no', none]
reject_regexp:
level: '^\D+.*$'
mapping:
building: [__any__]
columns:
...
```
--------------------------------
### Polygon Mapping Example
Source: https://github.com/omniscale/imposm3/blob/master/docs/mapping.md
This example shows how to map OSM polygons with specific 'natural' or 'tourism' tags into the 'landusages' table. It demonstrates the basic structure of table type, mapping, and column definitions.
```yaml
tables:
landusages:
type: polygon
mapping:
natural: [wood, land]
tourism: [zoo]
…
```
--------------------------------
### Build Imposm3 with LevelDB Support
Source: https://github.com/omniscale/imposm3/blob/master/README.md
Use this flag to build Imposm3 with support for LevelDB versions prior to 1.21. This is useful for compatibility with older LevelDB installations.
```bash
go build -tags="ldbpre121"
```
```bash
LEVELDB_PRE_121=1 make build
```
--------------------------------
### Print Imposm Version
Source: https://github.com/omniscale/imposm3/blob/master/docs/tutorial.md
Call the version sub-command to display the installed imposm version number.
```bash
$ imposm version
master-20180507-7ddba33
```
--------------------------------
### Example Way Element with Building Tag
Source: https://github.com/omniscale/imposm3/blob/master/docs/relations.md
This is an example of an OpenStreetMap way element that has a 'building' tag. Imposm3 will insert such closed ways if they are part of a multipolygon relation or have the 'building' tag themselves.
```xml
...
```
--------------------------------
### Define an 'enumerate' column type for landuse
Source: https://github.com/omniscale/imposm3/blob/master/docs/mapping.md
Example of an 'enumerate' column type that maps specific 'landuse' tag values to integers (e.g., 'forest' to 1, 'grass' to 4). Undefined values are set to 0.
```yaml
columns:
- name: enum
type: enumerate
key: landuse
args:
values:
- forest
- park
- cemetery
- grass
```
--------------------------------
### Get Property of Intersected Feature
Source: https://github.com/omniscale/imposm3/blob/master/docs/mapping.md
Use 'geojson_intersects_feature' to retrieve a specific property from a feature in a GeoJSON file that intersects with the element's geometry.
```default
- args:
geojson: special_interest_areas.geojson
property: area
name: special_interest_area_name
type: geojson_intersects_feature
```
--------------------------------
### Example Relation Element for Multipolygon
Source: https://github.com/omniscale/imposm3/blob/master/docs/relations.md
This XML snippet shows an OpenStreetMap relation of type 'multipolygon' with a 'building' tag. Imposm3 automatically handles these for complex polygon geometries and holes, ignoring member roles and using geometry operations for hole detection.
```xml
```
--------------------------------
### Create PostgreSQL User and Database
Source: https://github.com/omniscale/imposm3/blob/master/docs/tutorial.md
These commands set up a PostgreSQL user named 'osm' and a database also named 'osm', enabling the PostGIS and hstore extensions. Ensure the user has password authentication enabled from localhost.
```bash
sudo su postgres
createuser --no-superuser --no-createrole --createdb osm
createdb -E UTF8 -O osm osm
psql -d osm -c "CREATE EXTENSION postgis;"
psql -d osm -c "CREATE EXTENSION hstore;" # only required for hstore support
echo "ALTER USER osm WITH PASSWORD 'osm';" |psql -d osm
```
--------------------------------
### Combined Import, Write, and Optimize
Source: https://github.com/omniscale/imposm3/blob/master/docs/tutorial.md
Execute Imposm import, write data to the database, and optimize tables in a single command using a configuration file.
```bash
imposm import -config config.json -read hamburg.osm.pbf -write -optimize
```
--------------------------------
### Import using Configuration File
Source: https://github.com/omniscale/imposm3/blob/master/docs/tutorial.md
Run Imposm import by referencing a JSON configuration file using the -config option.
```bash
imposm import -config config.json -read hamburg.osm.pbf -write
```
--------------------------------
### Run Benchmarks
Source: https://github.com/omniscale/imposm3/blob/master/vendor/github.com/lib/pq/TESTS.md
Executes the benchmark suite as part of the test process.
```bash
go test -bench .
```
--------------------------------
### Use Imposm3 Configuration File
Source: https://github.com/omniscale/imposm3/blob/master/README.md
Import OSM data using options defined in a JSON configuration file. This simplifies command-line usage by externalizing configuration parameters.
```bash
imposm import -config config.json [args...]
```
--------------------------------
### Combine Read and Write Steps
Source: https://github.com/omniscale/imposm3/blob/master/docs/tutorial.md
A convenience command that combines the reading of OSM data and writing it to the database in a single operation. This is useful for smaller imports or when disk space for the cache is not a concern.
```bash
imposm import -mapping mapping.yml -read hamburg.osm.pbf -write -connection postgis://osm:osm@localhost/osm
```
--------------------------------
### Configure PostgreSQL pg_hba.conf
Source: https://github.com/omniscale/imposm3/blob/master/docs/tutorial.md
Ensure your PostgreSQL pg_hba.conf file allows database access from localhost using MD5 password authentication.
```text
host all all 127.0.0.1/32 md5
```
--------------------------------
### Run All System Tests
Source: https://github.com/omniscale/imposm3/blob/master/README.md
Execute system tests for Imposm3, which involve importing and updating OSM data and verifying database content. This requires `osmosis` and a local PostgreSQL database.
```bash
make test
```
```bash
make test-system
```
--------------------------------
### Run Tests with Dockerized PostgreSQL
Source: https://github.com/omniscale/imposm3/blob/master/vendor/github.com/lib/pq/TESTS.md
Configures environment variables to connect to a Dockerized PostgreSQL instance for running tests.
```bash
PGHOST=localhost PGPORT=5432 PGUSER=postgres PGSSLMODE=disable PGDATABASE=postgres go test
```
--------------------------------
### Unmarshal and Marshal YAML Data in Go
Source: https://github.com/omniscale/imposm3/blob/master/vendor/gopkg.in/yaml.v2/README.md
Demonstrates how to unmarshal YAML data into a Go struct and a map, and then marshal them back into YAML format. Ensure struct fields are public for correct unmarshalling.
```Go
package main
import (
"fmt"
"log"
"gopkg.in/yaml.v2"
)
var data = `
a: Easy!
b:
c: 2
d: [3, 4]
`
// Note: struct fields must be public in order for unmarshal to
// correctly populate the data.
type T struct {
A string
B struct {
RenamedC int `yaml:"c"`
D []int `yaml:",flow"`
}
}
func main() {
t := T{}
err := yaml.Unmarshal([]byte(data), &t)
if err != nil {
log.Fatalf("error: %v", err)
}
fmt.Printf("--- t:\n%v\n\n", t)
d, err := yaml.Marshal(&t)
if err != nil {
log.Fatalf("error: %v", err)
}
fmt.Printf("--- t dump:\n%s\n\n", string(d))
m := make(map[interface{}]interface{})
err = yaml.Unmarshal([]byte(data), &m)
if err != nil {
log.Fatalf("error: %v", err)
}
fmt.Printf("--- m:\n%v\n\n", m)
d, err = yaml.Marshal(&m)
if err != nil {
log.Fatalf("error: %v", err)
}
fmt.Printf("--- m dump:\n%s\n\n", string(d))
}
```
--------------------------------
### Perform One-time Update with Changes Files
Source: https://github.com/omniscale/imposm3/blob/master/docs/tutorial.md
Manually update an existing database by importing OSM changes files. Pass one or more .osc.gz files to the diff command.
```bash
imposm diff -config config.json changes-1.osc.gz changes-2.osc.gz changes-3.osc.gz
```
--------------------------------
### System Call Entry Points
Source: https://github.com/omniscale/imposm3/blob/master/vendor/golang.org/x/sys/unix/README.md
Defines the entry points for system call dispatch in the hand-written assembly file.
```go
func Syscall(trap, a1, a2, a3 uintptr) (r1, r2, err uintptr)
func Syscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2, err uintptr)
func RawSyscall(trap, a1, a2, a3 uintptr) (r1, r2, err uintptr)
```
--------------------------------
### Basic Imposm3 Import
Source: https://github.com/omniscale/imposm3/blob/master/README.md
Perform a basic import of OSM data using a specified connection string, mapping file, and input data file. This command creates tables within the 'import' schema by default.
```bash
imposm import -connection postgis://user:password@host/database \
-mapping mapping.json -read /path/to/osm.pbf -write
```
--------------------------------
### Build Imposm Directly with Go
Source: https://github.com/omniscale/imposm3/blob/master/README.md
Builds Imposm directly using the Go toolchain without adding version information. This method is an alternative to 'make build'.
```bash
go build ./cmd/imposm
```
--------------------------------
### Run Tests with Custom PostgreSQL Host
Source: https://github.com/omniscale/imposm3/blob/master/vendor/github.com/lib/pq/TESTS.md
Overrides the default PostgreSQL host for running tests using environment variables.
```bash
PGHOST=/run/postgresql go test
```
--------------------------------
### Deploy Production Tables
Source: https://github.com/omniscale/imposm3/blob/master/docs/tutorial.md
Move imported tables from the 'import' schema to the default 'public' schema for production use. This also backs up existing public tables.
```bash
imposm import -mapping mapping.yml -connection postgis://osm:osm@localhost/osm -deployproduction
```
--------------------------------
### Standard Go Error Handling
Source: https://github.com/omniscale/imposm3/blob/master/vendor/github.com/pkg/errors/README.md
Illustrates the traditional error handling idiom in Go, which can lead to error reports without context.
```go
if err != nil {
return err
}
```
--------------------------------
### Run All Unit Tests
Source: https://github.com/omniscale/imposm3/blob/master/README.md
Execute all unit tests for Imposm3. This command is part of the build and testing process to ensure code quality and correctness.
```bash
make test-unit
```
--------------------------------
### Write OSM Data to Database
Source: https://github.com/omniscale/imposm3/blob/master/docs/tutorial.md
Executes the second step of the import process, reading data from the cache, building geometries, and inserting features into the PostgreSQL database. Requires database connection parameters.
```bash
imposm import -mapping mapping.yml -write -connection postgis://osm:osm@localhost/osm
```
--------------------------------
### Read OSM Data into Cache
Source: https://github.com/omniscale/imposm3/blob/master/docs/tutorial.md
Initiates the first step of the import process by reading OpenStreetMap data from a PBF file into an on-disk LevelDB cache. This step requires a mapping file to define which OSM elements to process.
```bash
imposm import -mapping mapping.yml -read germany.osm.pbf
```
--------------------------------
### Deploy Imposm3 Import to Production Schema
Source: https://github.com/omniscale/imposm3/blob/master/README.md
This command deploys the imported data to the production schema, typically 'public', after a successful import. Ensure your mapping and connection details are correct for production.
```bash
imposm import -connection postgis://user:passwd@host/database \
-mapping mapping.json -deployproduction
```
--------------------------------
### Enable Diff Updates
Source: https://github.com/omniscale/imposm3/blob/master/docs/tutorial.md
Configure Imposm for updating OSM data from diff files by enabling the -diff option during initial import. Specify cache and diff directories.
```bash
imposm import -config config.json -read hamburg.osm.pbf -write -diff -cachedir ./cache -diffdir ./diff
```
--------------------------------
### Load Specific Tags for HSTORE
Source: https://github.com/omniscale/imposm3/blob/master/docs/mapping.md
Include only a predefined list of tags for import, typically used when populating an hstore_tags column with specific key-value pairs.
```yaml
tags:
include: [operator, opening_hours, wheelchair, website, phone, cuisine]
```
--------------------------------
### Adding Context to an Error
Source: https://github.com/omniscale/imposm3/blob/master/vendor/github.com/pkg/errors/README.md
Demonstrates how to use errors.Wrap to add context to an existing error, creating a new error with additional information.
```go
_, err := ioutil.ReadAll(r)
if err != nil {
return errors.Wrap(err, "read failed")
}
```
--------------------------------
### Optimize Imported Tables
Source: https://github.com/omniscale/imposm3/blob/master/docs/tutorial.md
Perform optional optimizations on imported tables, including spatial clustering and vacuum analyze. This applies only to import tables.
```bash
imposm import -config config.json -optimize
```
--------------------------------
### Enable TLS/SSL for PostgreSQL Connection
Source: https://github.com/omniscale/imposm3/blob/master/README.md
Configure TLS/SSL encryption for the PostgreSQL connection by setting the `sslmode` option. This enhances security when connecting to the database.
```bash
-connect postgis://host/dbname?sslmode=require
```
--------------------------------
### Importing Relation Metadata (e.g., Route Details)
Source: https://github.com/omniscale/imposm3/blob/master/docs/relations.md
This mapping configuration imports relation metadata, specifically for 'route' types with a 'bus' mapping. It creates a table with essential route details like ID, reference, and network, without including geometry.
```default
routes:
type: relation
columns:
- name: osm_id
type: id
- key: ref
name: ref
type: string
- name: network
key: network
type: string
relation_types: [route]
mapping:
route: [bus]
```
--------------------------------
### Define 'geometry' table with type_mappings for points, linestrings, and polygons
Source: https://github.com/omniscale/imposm3/blob/master/docs/mapping.md
Configures a 'geometry' table to handle multiple geometry types using `type_mappings`, specifying distinct mappings for points, linestrings, and polygons based on OSM tags.
```yaml
tables:
all:
columns:
- name: osm_id
type: id
- name: geometry
type: geometry
- name: tags
type: hstore_tags
type: geometry
type_mappings:
points:
amenity: [__any__]
poi: [__any__]
shop: [__any__]
linestrings:
highway: [__any__]
polygons:
landuse: [__any__]
poi: [__any__]
shop: [__any__]
```
--------------------------------
### Revert Production Table Deployment
Source: https://github.com/omniscale/imposm3/blob/master/docs/tutorial.md
Revert the deployment of production tables, moving tables from 'public' back to 'import' and from 'backup' to 'public'.
```bash
imposm import -mapping mapping.yml -connection postgis://osm:osm@localhost/osm -revertdeploy
```
--------------------------------
### Define Generalized Tables
Source: https://github.com/omniscale/imposm3/blob/master/docs/mapping.md
Create simplified geometries for rendering at lower map scales. Specify the source table, tolerance for simplification, and an optional SQL filter to exclude small geometries.
```yaml
generalized_tables:
waterareas_gen_50:
source: waterareas
sql_filter: ST_Area(geometry)>50000.000000
tolerance: 50.0
```
--------------------------------
### Retrieving the Cause of an Error
Source: https://github.com/omniscale/imposm3/blob/master/vendor/github.com/pkg/errors/README.md
Shows how to inspect an error stack created by errors.Wrap to retrieve the original error using errors.Cause. This is useful for specific error handling or debugging.
```go
type causer interface {
Cause() error
}
```
```go
switch err := errors.Cause(err).(type) {
case *MyError:
// handle specifically
default:
// unknown error
}
```
--------------------------------
### Importing Relation Members (e.g., Bus Routes)
Source: https://github.com/omniscale/imposm3/blob/master/docs/relations.md
This mapping configuration imports relation members, specifically for 'route' types with a 'bus' mapping. It extracts various details about the relation and its members, including IDs, roles, types, and associated tags.
```default
route_members:
type: relation_member
columns:
- name: osm_id
type: id
- name: member
type: member_id
- name: index
type: member_index
- name: role
type: member_role
- name: type
type: member_type
- name: geometry
type: geometry
- name: relname
key: name
type: string
- name: name
key: name
type: string
from_member: true
- key: ref
name: ref
type: string
relation_types: [route]
mapping:
route: [bus]
```
--------------------------------
### Load All Tags with Exclusions
Source: https://github.com/omniscale/imposm3/blob/master/docs/mapping.md
Configure Imposm to load all tags from OSM data, excluding specific tags using shell-style patterns. This is useful when you need to import most tags but want to omit certain ones.
```yaml
tags:
load_all: true,
exclude: [created_by, source, "tiger:*"]
```
--------------------------------
### Categorize Integer Values
Source: https://github.com/omniscale/imposm3/blob/master/docs/mapping.md
Use 'categorize_int' to assign integer values based on specific keys. Multiple keys can be searched, and multiple values can map to the same integer.
```default
- args:
default: 0
values: {
FR: 10, NL: 8, LU: 3,
}
keys:
- country_code_iso3166_1_alpha_2
- ISO3166-1:alpha2
- ISO3166-1
name: scalerank
type: categorize_int
```
--------------------------------
### Limit Import to Geometries
Source: https://github.com/omniscale/imposm3/blob/master/docs/tutorial.md
Use the -limitto option to restrict imported geometries to specified polygon boundaries from a GeoJSON file. Ensure the GeoJSON is in EPSG:4326.
```bash
imposm import -mapping mapping.yml -connection postgis://osm:osm@localhost/osm -read europe.osm.pbf -write -limitto germany.geojson
```
--------------------------------
### Define a 'wayzorder' column with custom ranks and default
Source: https://github.com/omniscale/imposm3/blob/master/docs/mapping.md
Demonstrates the 'wayzorder' column type with custom ranks for highway importance and a default value. It also shows how 'bridge', 'tunnel', and 'layer' modify the calculated z-order.
```yaml
columns:
- name: zorder
type: wayzorder
args:
default: 5
ranks:
- footway
- path
- residential
- primary
- motorway
```
--------------------------------
### Remove Backup Schema
Source: https://github.com/omniscale/imposm3/blob/master/docs/tutorial.md
Remove the backup schema containing previously deployed production tables.
```bash
imposm import -mapping mapping.yml -connection postgis://osm:osm@localhost/osm -removebackup
```
--------------------------------
### Disable Table Prefixing
Source: https://github.com/omniscale/imposm3/blob/master/docs/tutorial.md
Configures Imposm to not add a prefix to the database tables it creates. By default, tables are prefixed with 'osm_'. Use 'NONE' to disable this behavior.
```bash
imposm import -mapping mapping.yml -write -connection postgis://osm:osm@localhost/osm?prefix=NONE
```
--------------------------------
### Polygon Table Mapping for Buildings
Source: https://github.com/omniscale/imposm3/blob/master/docs/relations.md
This configuration defines a 'buildings' table of type 'polygon' and maps any 'building' tag to it. It ensures that closed ways with a 'building' tag are inserted.
```yaml
tables:
buildings:
type: polygon
mapping:
building: [__any__]
```
--------------------------------
### Define 'tracks' table with linestring mapping
Source: https://github.com/omniscale/imposm3/blob/master/docs/mapping.md
This mapping creates a 'tracks' table for linestrings, extracting specific OSM tags like 'name', 'bridge', and 'highway' type.
```yaml
tables:
tracks:
type: linestring
mapping:
highway: [path, track, unclassified]
columns:
- {name: osm_id, type: id}
- {name: the_geom, type: geometry}
- {key: name, name: street_name, type: string}
- {key: bridge, name: is_bridge, type: bool}
- {name: highway_type, type: mapping_value}
```
--------------------------------
### Relation Type Filtering for Routes
Source: https://github.com/omniscale/imposm3/blob/master/docs/mapping.md
This snippet illustrates how to configure a table of type 'relation' to import only relations with the 'route' type. It specifies the relation_types and a mapping for the 'route' tag.
```yaml
tables:
routes:
type: relation
relation_types: [route]
mapping:
route: [bus]
```
--------------------------------
### Configure Area Feature Interpretation
Source: https://github.com/omniscale/imposm3/blob/master/docs/mapping.md
Define which OSM tags should be interpreted as areas (polygons) and which as linear features. This allows customization of how Imposm handles closed ways based on tags.
```yaml
areas:
area_tags: [building, landuse, leisure, natural, aeroway]
linear_tags: [highway, barrier]
```
--------------------------------
### Define multiple sub-mappings for 'transport' table
Source: https://github.com/omniscale/imposm3/blob/master/docs/mapping.md
Uses `mappings` to define separate sub-mappings for different OSM features (rail, roads) within a single table, allowing elements to be inserted multiple times if they match different criteria.
```yaml
tables:
transport:
type: linestring
mappings:
rail:
mapping:
rail: [__any__]
roads:
mapping:
highway: [__any__]
…
```
--------------------------------
### Check Geometry Intersection
Source: https://github.com/omniscale/imposm3/blob/master/docs/mapping.md
Use 'geojson_intersects' to determine if an element's geometry intersects with any geometry in a specified GeoJSON file.
```default
- args:
geojson: special_interest_areas.geojson
name: in_special_interest_area
type: geojson_intersects
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.