osm2ch

package module
v1.5.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 25, 2023 License: Apache-2.0 Imports: 11 Imported by: 1

README

GoDoc Build Status Sourcegraph Go Report Card GitHub tag

osm2ch

Convert *.osm.pbf files to CSV for contraction hierarchies library

About

With this CLI tool you can convert *.osm.pbf (Compressed Open Street Map) file to CSV (Comma-Separated Values) file, which is used in our contraction hierarchies library. What it does:

  • Edge expansion (single edge == single vertex);
  • Handles some kind and types of restrictions:
    • Supported kind of restrictions:
      • EdgeFrom - NodeVia - EdgeTo.
    • Supported types of restrictions:
      • only_left_turn;
      • only_right_turn;
      • only_straight_on;
      • no_left_turn;
      • no_right_turn;
      • no_straight_on.
  • Saves CSV file with geom in WKT format;
  • Currently supports tags for 'highway' OSM entity only.

PRs are welcome!

Installation

Note: There is zlib support in OSM-pbf parser. If you do not want use it then disable CGO:

export CGO_ENABLED=0
# Then build osm2ch from source

Usage

osm2ch -h

Output:

Usage of osm2ch:
  -file string
        Filename of *.osm.pbf file (it has to be compressed) (default "my_graph.osm.pbf")
  -geomf string
        Format of output geometry. Expected values: wkt / geojson (default "wkt")
  -out string
        Filename of 'Comma-Separated Values' (CSV) formatted file (default "my_graph.csv")
        E.g.: if file name is 'map.csv' then 3 files will be produced: 'map.csv' (edges), 'map_vertices.csv', 'map_shortcuts.csv'
  -tags string
        Set of needed tags (separated by commas) (default "motorway,primary,primary_link,road,secondary,secondary_link,residential,tertiary,tertiary_link,unclassified,trunk,trunk_link,motorway_link")
  -units string
        Units of output weights. Expected values: km for kilometers / m for meters (default "km")
  -contract
        Prepare contraction hierarchies? (default true)

The default list of tags is this, since usually these tags are used for routing for personal cars.

Example

You can find example file of *.osm.pbf file in nested child /example_data.

If you want WKT format for output geometry:

osm2ch --file example_data/moscow_center_reduced.osm.pbf --out graph.csv --geomf wkt --units m --tags motorway,primary,primary_link,road,secondary,secondary_link,residential,tertiary,tertiary_link,unclassified,trunk,trunk_link,motorway_link --contract=true

If you want GeoJSON format for output geometry:

osm2ch --file example_data/moscow_center_reduced.osm.pbf --out graph.csv --geomf geojson --units m --tags motorway,primary,primary_link,road,secondary,secondary_link,residential,tertiary,tertiary_link,unclassified,trunk,trunk_link,motorway_link --contract=true

If you dont want to prepare contraction hierarchies then:

osm2ch --file example_data/moscow_center_reduced.osm.pbf --out graph.csv --geomf wkt --units m --tags motorway,primary,primary_link,road,secondary,secondary_link,residential,tertiary,tertiary_link,unclassified,trunk,trunk_link,motorway_link --contract=false

After that files 'graph.csv', 'graph_vertices.csv', 'graph_shortcuts.csv' will be created (or only 'graph.csv' and 'graph_vertices' if 'contract' flag is set to False).

Header of edges CSV-file is: from_vertex_id;to_vertex_id;weight;geom;was_one_way;edge_id;osm_way_from;osm_way_to;osm_way_from_source_node;osm_way_from_target_node;osm_way_to_source_node;osm_way_to_target_node

  • from_vertex_id - Generated source vertex;
  • to_vertex_id - Generated target vertex;
  • weight - Traveling cost from source to target (actually length of an edge in kilometers/meters);
  • geom - Geometry of edge (Linestring) in WKT or GeoJSON format.
  • was_one_way - Boolean value. When source OSM way was "one way" then it's true, otherwise it's false. Might be helpfull for ignore edges with WasOneWay=true when offesting overlapping two-way geometries in some GIS viewer
  • edge_id - ID of generated edge
  • osm_way_from - ID of source OSM Way
  • osm_way_to - ID of target OSM Way
  • osm_way_from_source_node - ID of first OSM Node in source OSM Way
  • osm_way_from_target_node - ID of last OSM Node in source OSM Way
  • osm_way_to_source_node - ID of first OSM Node in target OSM Way
  • osm_way_to_target_node - ID of last OSM Node in target OSM Way

Header of vertices CSV-file is: vertex_id;order_pos;importance;geom

  • vertex_id - Vertex;
  • order_pos - Order position in contraction hierarchies;
  • importance - Importance of vertex with respect to contraction hierarchies
  • geom - Geometry of vertex (Point) in WKT or GeoJSON format.

[Optional] Header of shortcuts CSV-file is: from_vertex_id;to_vertex_id;weight;via_vertex_id

  • from_vertex_id - Source vertex;
  • to_vertex_id - Target vertex;
  • weight - Traveling cost from source to target (actually length of the shortcut in kilometers/meters);
  • via_vertex_id - ID of vertex through which the shortcut exists

Now you can use this graph in contraction hierarchies library.

Dependencies

Thanks to paulmach for his OSM-parser written in Go.

Paulmach's license is here (it's MIT)

License

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PrepareGeoJSONLinestring

func PrepareGeoJSONLinestring(pts []GeoPoint) string

PrepareGeoJSONLinestring returns GeoJSON representation of LineString

func PrepareGeoJSONPoint added in v1.3.0

func PrepareGeoJSONPoint(pt GeoPoint) string

PrepareGeoJSONPoint returns GeoJSON representation of Point

func PrepareWKTLinestring

func PrepareWKTLinestring(pts []GeoPoint) string

PrepareWKTLinestring returns WKT representation of LineString

func PrepareWKTPoint added in v1.3.0

func PrepareWKTPoint(pt GeoPoint) string

PrepareWKTPoint returns WKT representation of Point

Types

type Edge added in v1.5.0

type Edge struct {
	ID           EdgeID
	WayID        osm.WayID
	SourceNodeID osm.NodeID
	TargetNodeID osm.NodeID
	WasOneway    bool
	CostMeters   float64
	/* CostSeconds  float64 */ //@todo: consider cost customization
	Geom                       []GeoPoint
}

type EdgeID added in v1.5.0

type EdgeID int64

type ExpandedEdge added in v1.5.0

type ExpandedEdge struct {
	ID              int64
	Source          EdgeID
	Target          EdgeID
	SourceOSMWayID  osm.WayID
	TargetOSMWayID  osm.WayID
	SourceComponent expandedEdgeComponent
	TargeComponent  expandedEdgeComponent
	WasOneway       bool
	CostMeters      float64
	/* CostSeconds  float64 */ //@todo: consider cost customization
	Geom                       []GeoPoint
}

ExpandedGraph represents an edge in expanded graph

func ImportFromOSMFile

func ImportFromOSMFile(fileName string, cfg *OsmConfiguration) ([]ExpandedEdge, error)

ImportFromOSMFile Imports graph from file of PBF-format (in OSM terms)

File should have PBF (Protocolbuffer Binary Format) extension according to https://github.com/paulmach/osm

type GeoPoint added in v1.3.0

type GeoPoint struct {
	Lat float64
	Lon float64
}

GeoPoint representation of point on Earth

func (GeoPoint) String added in v1.3.0

func (gp GeoPoint) String() string

String returns pretty printed value for for GeoPoint

type Node added in v1.5.0

type Node struct {
	ID osm.NodeID
	// contains filtered or unexported fields
}

type OsmConfiguration

type OsmConfiguration struct {
	EntityName string // Currrently we support 'highway' only
	Tags       []string
}

OsmConfiguration Allows to filter ways by certain tags from OSM data

func (*OsmConfiguration) CheckTag

func (cfg *OsmConfiguration) CheckTag(tag string) bool

CheckTag Checks if incoming tag is represented in configuration

type Way added in v1.5.0

type Way struct {
	ID     osm.WayID
	Oneway bool
	Nodes  osm.WayNodes
	TagMap osm.Tags
}

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL