parse diff metadata
parent
c5993ecb81
commit
3fae4c34ca
|
@ -5,6 +5,7 @@ import (
|
||||||
"encoding/xml"
|
"encoding/xml"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/omniscale/imposm3/element"
|
"github.com/omniscale/imposm3/element"
|
||||||
"github.com/omniscale/imposm3/logging"
|
"github.com/omniscale/imposm3/logging"
|
||||||
|
@ -24,11 +25,18 @@ type DiffElem struct {
|
||||||
func Parse(diff string) (chan DiffElem, chan error) {
|
func Parse(diff string) (chan DiffElem, chan error) {
|
||||||
elems := make(chan DiffElem)
|
elems := make(chan DiffElem)
|
||||||
errc := make(chan error)
|
errc := make(chan error)
|
||||||
go parse(diff, elems, errc)
|
go parse(diff, elems, errc, false)
|
||||||
return elems, errc
|
return elems, errc
|
||||||
}
|
}
|
||||||
|
|
||||||
func parse(diff string, elems chan DiffElem, errc chan error) {
|
func ParseFull(diff string) (chan DiffElem, chan error) {
|
||||||
|
elems := make(chan DiffElem)
|
||||||
|
errc := make(chan error)
|
||||||
|
go parse(diff, elems, errc, true)
|
||||||
|
return elems, errc
|
||||||
|
}
|
||||||
|
|
||||||
|
func parse(diff string, elems chan DiffElem, errc chan error, metadata bool) {
|
||||||
defer close(elems)
|
defer close(elems)
|
||||||
defer close(errc)
|
defer close(errc)
|
||||||
|
|
||||||
|
@ -91,18 +99,27 @@ NextToken:
|
||||||
node.Long, _ = strconv.ParseFloat(attr.Value, 64)
|
node.Long, _ = strconv.ParseFloat(attr.Value, 64)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if metadata {
|
||||||
|
setElemMetadata(tok.Attr, &node.OSMElem)
|
||||||
|
}
|
||||||
case "way":
|
case "way":
|
||||||
for _, attr := range tok.Attr {
|
for _, attr := range tok.Attr {
|
||||||
if attr.Name.Local == "id" {
|
if attr.Name.Local == "id" {
|
||||||
way.Id, _ = strconv.ParseInt(attr.Value, 10, 64)
|
way.Id, _ = strconv.ParseInt(attr.Value, 10, 64)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if metadata {
|
||||||
|
setElemMetadata(tok.Attr, &way.OSMElem)
|
||||||
|
}
|
||||||
case "relation":
|
case "relation":
|
||||||
for _, attr := range tok.Attr {
|
for _, attr := range tok.Attr {
|
||||||
if attr.Name.Local == "id" {
|
if attr.Name.Local == "id" {
|
||||||
rel.Id, _ = strconv.ParseInt(attr.Value, 10, 64)
|
rel.Id, _ = strconv.ParseInt(attr.Value, 10, 64)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if metadata {
|
||||||
|
setElemMetadata(tok.Attr, &rel.OSMElem)
|
||||||
|
}
|
||||||
case "nd":
|
case "nd":
|
||||||
for _, attr := range tok.Attr {
|
for _, attr := range tok.Attr {
|
||||||
if attr.Name.Local == "ref" {
|
if attr.Name.Local == "ref" {
|
||||||
|
@ -188,5 +205,25 @@ NextToken:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func setElemMetadata(attrs []xml.Attr, elem *element.OSMElem) {
|
||||||
|
elem.Metadata = &element.Metadata{}
|
||||||
|
for _, attr := range attrs {
|
||||||
|
switch attr.Name.Local {
|
||||||
|
case "version":
|
||||||
|
v, _ := strconv.ParseInt(attr.Value, 10, 64)
|
||||||
|
elem.Metadata.Version = int(v)
|
||||||
|
case "uid":
|
||||||
|
v, _ := strconv.ParseInt(attr.Value, 10, 64)
|
||||||
|
elem.Metadata.UserId = int(v)
|
||||||
|
case "user":
|
||||||
|
elem.Metadata.UserName = attr.Value
|
||||||
|
case "changeset":
|
||||||
|
v, _ := strconv.ParseInt(attr.Value, 10, 64)
|
||||||
|
elem.Metadata.Changeset = int(v)
|
||||||
|
case "timestamp":
|
||||||
|
elem.Metadata.Timestamp, _ = time.Parse(time.RFC3339, attr.Value)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
"sort"
|
"sort"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Tags map[string]string
|
type Tags map[string]string
|
||||||
|
@ -15,6 +16,7 @@ func (t *Tags) String() string {
|
||||||
type OSMElem struct {
|
type OSMElem struct {
|
||||||
Id int64 `json:"-"`
|
Id int64 `json:"-"`
|
||||||
Tags Tags `json:"tags,omitempty"`
|
Tags Tags `json:"tags,omitempty"`
|
||||||
|
Metadata *Metadata `json:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Node struct {
|
type Node struct {
|
||||||
|
@ -81,6 +83,14 @@ type Relation struct {
|
||||||
Members []Member `json:"members"`
|
Members []Member `json:"members"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Metadata struct {
|
||||||
|
UserId int
|
||||||
|
UserName string
|
||||||
|
Version int
|
||||||
|
Timestamp time.Time
|
||||||
|
Changeset int
|
||||||
|
}
|
||||||
|
|
||||||
type IdRefs struct {
|
type IdRefs struct {
|
||||||
Id int64
|
Id int64
|
||||||
Refs []int64
|
Refs []int64
|
||||||
|
|
Loading…
Reference in New Issue