osmpbfparser

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2020 License: MIT Imports: 19 Imported by: 0

README

OSM PBF Parser

  • Parse pbf file to osm element(Node, Way and Relation)

  • Iterator pattern. Easy to get.

  • Progress bar for parsing process.

  • Control memory usage by using levelDB.

  • Convert Element to GeoJSON

    • Support type: Node, Way, Relation(polygon, multipolygon)

Install

go get -u https://github.com/jneo8/osmpbfparser-go

Quick start

# This will run the example code in ./cmd/example/main.go
make run-example

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Args

type Args struct {
	PBFFile     string // pbf file path.
	LevelDBPath string // levelDB init path.
	BatchSize   int    // levelDB batch size, it depends on how many memory you have.
}

Args is inpute arguments struct.

type Element

type Element struct {
	Type     int // 0=Node, 1=Way. 2=Relation
	Node     gosmparse.Node
	Way      gosmparse.Way
	Relation gosmparse.Relation
	Elements []Element
	Role     int // 0=outer, 1=inner
}

Element is an osm data element group set.

func BytesToElement

func BytesToElement(b []byte) (Element, error)

BytesToElement convert bytes to Element struct.

func (*Element) GetID

func (e *Element) GetID() int64

GetID return ID.

func (*Element) GetName added in v1.2.0

func (e *Element) GetName() (string, error)

GetName from tags.

func (*Element) GetRelationAsGeometries

func (e *Element) GetRelationAsGeometries() *geojson.Feature

GetRelationAsGeometries return relation as geojson geometries. Sometimes relation will missing type tag, so defualt we use collect feature.

func (*Element) GetRelationAsMultipolygon

func (e *Element) GetRelationAsMultipolygon() *geojson.Feature

GetRelationAsMultipolygon return relation as geosjon multipolygon.

func (*Element) GetTags added in v1.1.0

func (e *Element) GetTags() map[string]string

GetTags ...

func (*Element) IsArea

func (e *Element) IsArea() bool

IsArea return if element is area or not. https://wiki.openstreetmap.org/wiki/Key:area

func (*Element) IsMultiPolygon

func (e *Element) IsMultiPolygon() bool

IsMultiPolygon check if element is multi-polygon or not.

func (*Element) NodeToFeature

func (e *Element) NodeToFeature() *geojson.Feature

NodeToFeature convert node element to geojson feature.

func (*Element) RelationToFeature

func (e *Element) RelationToFeature() *geojson.Feature

RelationToFeature convert relation element to geojson feature.

func (*Element) ToBytes

func (e *Element) ToBytes() ([]byte, error)

ToBytes convert element struct to bytes.

func (*Element) ToGeoJSON

func (e *Element) ToGeoJSON() ([]byte, error)

ToGeoJSON convery element to JSON bytes.

func (*Element) ToGeoJSONFeature

func (e *Element) ToGeoJSONFeature() *geojson.Feature

ToGeoJSONFeature ...

func (*Element) WayToFeature

func (e *Element) WayToFeature() *geojson.Feature

WayToFeature convert way element to geojson feature.

type PBFCounter

type PBFCounter struct {
	PBFFile       string
	NodeCount     int
	WayCount      int
	RelationCount int
	// contains filtered or unexported fields
}

PBFCounter count the number of each type data element and return the number.

func (*PBFCounter) ReadNode

func (p *PBFCounter) ReadNode(node gosmparse.Node)

ReadNode for gosmparse OSMReader interface.

func (*PBFCounter) ReadRelation

func (p *PBFCounter) ReadRelation(relation gosmparse.Relation)

ReadRelation for gosmparse OSMReader interface.

func (*PBFCounter) ReadWay

func (p *PBFCounter) ReadWay(way gosmparse.Way)

ReadWay for gosmparse OSMReader interface.

func (*PBFCounter) Run

func (p *PBFCounter) Run() (int, int, int, error)

Run exec func for PBFCounter.

type PBFIndexer

type PBFIndexer struct {
	PBFFile     string
	PBFMasks    *bitmask.PBFMasks
	NodeBar     *mpb.Bar
	WayBar      *mpb.Bar
	RelationBar *mpb.Bar
}

PBFIndexer parser pbffile and mark if this element is needed, save to PBFMasks.

func (*PBFIndexer) ReadNode

func (p *PBFIndexer) ReadNode(node gosmparse.Node)

ReadNode for gosmparse OSMReader interface.

func (*PBFIndexer) ReadRelation

func (p *PBFIndexer) ReadRelation(relation gosmparse.Relation)

ReadRelation for gosmparse OSMReader interface.

func (*PBFIndexer) ReadWay

func (p *PBFIndexer) ReadWay(way gosmparse.Way)

ReadWay for gosmparse OSMReader interface.

func (*PBFIndexer) Run

func (p *PBFIndexer) Run() error

Run exec func.

type PBFParser

type PBFParser interface {
	Iterator() <-chan Element
	SetLogger(*log.Logger)
	Err() error
	Close() error
}

PBFParser is a item parse pbf file, iterator return.

func New

func New(
	args Args,
) PBFParser

New return new PBFParser.

type PBFRelationMemberIndexer

type PBFRelationMemberIndexer struct {
	PBFFile     string
	PBFMasks    *bitmask.PBFMasks
	NodeBar     *mpb.Bar
	WayBar      *mpb.Bar
	RelationBar *mpb.Bar
}

PBFRelationMemberIndexer same as PBFIndexer but run after PBFIndxeer. Mark relation's member element to mask.

func (*PBFRelationMemberIndexer) ReadNode

func (p *PBFRelationMemberIndexer) ReadNode(node gosmparse.Node)

ReadNode for gosmparse OSMReader interface.

func (*PBFRelationMemberIndexer) ReadRelation

func (p *PBFRelationMemberIndexer) ReadRelation(relation gosmparse.Relation)

ReadRelation for gosmparse OSMReader interface.

func (*PBFRelationMemberIndexer) ReadWay

func (p *PBFRelationMemberIndexer) ReadWay(way gosmparse.Way)

ReadWay for gosmparse OSMReader interface.

func (*PBFRelationMemberIndexer) Run

Run exec func.

type Report

type Report struct {
	PBFFile           string
	Fizesize          int64
	SpendTime         time.Duration
	ProcessedRelation int
	ProcessedWay      int
	ProcessedNode     int
	FatalRelation     int
	FatalWay          int
}

Report recor the information duration the runtime.

func (*Report) GetReport

func (r *Report) GetReport() string

GetReport return report string.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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