aboutsummaryrefslogtreecommitdiff
path: root/reader.go
diff options
context:
space:
mode:
authorAlexander NeonXP Kiryukhin <a.kiryukhin@mail.ru>2019-06-03 13:59:49 +0300
committerAlexander NeonXP Kiryukhin <a.kiryukhin@mail.ru>2019-06-03 13:59:49 +0300
commitc36227104708bf48c95d2b61ba9176370eb0baf5 (patch)
tree47e0a0373956556955f1dcfb8f00421a6c714025 /reader.go
parent2f4b6e90597784a8a7c01027e0ff5c6b69634a96 (diff)
Store objects on single collections (overpass like json)HEADmaster
Filter deleted objects
Diffstat (limited to 'reader.go')
-rw-r--r--reader.go39
1 files changed, 16 insertions, 23 deletions
diff --git a/reader.go b/reader.go
index 5ab603c..c273d3f 100644
--- a/reader.go
+++ b/reader.go
@@ -9,7 +9,7 @@ import (
"github.com/paulmach/osm/osmpbf"
)
-func read(ctx context.Context, file string, nodesCh chan Node, waysCh chan Way, relationsCh chan Relation, concurrency int, layers []string) error {
+func read(ctx context.Context, file string, insertCh chan Object, concurrency int, layers []string) error {
f, err := os.Open(file)
if err != nil {
return err
@@ -35,7 +35,7 @@ func read(ctx context.Context, file string, nodesCh chan Node, waysCh chan Way,
o := scanner.Object()
switch o := o.(type) {
case *osm.Way:
- if !layersToImport["ways"] {
+ if !layersToImport["ways"] || !o.Visible {
continue
}
nodes := make([]int64, 0, len(o.Nodes))
@@ -43,35 +43,31 @@ func read(ctx context.Context, file string, nodesCh chan Node, waysCh chan Way,
nodes = append(nodes, int64(v.ID))
}
- w := Way{
- OsmID: int64(o.ID),
+ w := Object{
+ ID: ID{ID: int64(o.ID), Type: WayType, Version: o.Version},
Tags: convertTags(o.Tags),
- Nodes: nodes,
Timestamp: o.Timestamp,
- Version: o.Version,
- Visible: o.Visible,
+ Nodes: nodes,
}
- waysCh <- w
+ insertCh <- w
case *osm.Node:
- if !layersToImport["nodes"] {
+ if !layersToImport["nodes"] || !o.Visible {
continue
}
- n := Node{
- OsmID: int64(o.ID),
+ w := Object{
+ ID: ID{ID: int64(o.ID), Type: NodeType, Version: o.Version},
+ Tags: convertTags(o.Tags),
+ Timestamp: o.Timestamp,
Location: Coords{
Type: "Point",
Coordinates: []float64{
o.Lon,
o.Lat,
}},
- Tags: convertTags(o.Tags),
- Version: o.Version,
- Timestamp: o.Timestamp,
- Visible: o.Visible,
}
- nodesCh <- n
+ insertCh <- w
case *osm.Relation:
- if !layersToImport["relations"] {
+ if !layersToImport["relations"] || !o.Visible {
continue
}
members := make([]Member, 0, len(o.Members))
@@ -87,22 +83,19 @@ func read(ctx context.Context, file string, nodesCh chan Node, waysCh chan Way,
}
members = append(members, Member{
Type: v.Type,
- Version: v.Version,
Orientation: v.Orientation,
Ref: v.Ref,
Role: v.Role,
Location: location,
})
}
- r := Relation{
- OsmID: int64(o.ID),
+ w := Object{
+ ID: ID{ID: int64(o.ID), Type: RelationType, Version: o.Version},
Tags: convertTags(o.Tags),
- Version: o.Version,
Timestamp: o.Timestamp,
- Visible: o.Visible,
Members: members,
}
- relationsCh <- r
+ insertCh <- w
}
}
log.Println("Read done")