Example #1
0
func (dec *dataDecoder) parseWays(pb *osmpbf.PrimitiveBlock, ways []*osmpbf.Way) {
	st := pb.GetStringtable().GetS()
	dateGranularity := int64(pb.GetDateGranularity())

	for _, way := range ways {
		var (
			prev    int64
			nodeIDs []osm.WayNode
		)

		info := extractInfo(st, way.Info, dateGranularity)
		if refs := way.GetRefs(); len(refs) > 0 {
			nodeIDs = make([]osm.WayNode, len(refs))
			for i, r := range refs {
				prev = r + prev // delta encoding
				nodeIDs[i].ID = osm.NodeID(prev)
			}
		}

		dec.q = append(dec.q, osm.Element{
			Way: &osm.Way{
				ID:          osm.WayID(way.Id),
				User:        info.User,
				UserID:      osm.UserID(info.UID),
				Visible:     info.Visible,
				Version:     int(info.Version),
				ChangesetID: osm.ChangesetID(info.Changeset),
				Timestamp:   info.Timestamp,
				Nodes:       nodeIDs,
				Tags:        extractTags(st, way.Keys, way.Vals),
			},
		})
	}
}
Example #2
0
func (dec *dataDecoder) parseDenseNodes(pb *osmpbf.PrimitiveBlock, dn *osmpbf.DenseNodes) {
	st := pb.GetStringtable().GetS()
	granularity := int64(pb.GetGranularity())

	latOffset := pb.GetLatOffset()
	lonOffset := pb.GetLonOffset()
	ids := dn.GetId()
	lats := dn.GetLat()
	lons := dn.GetLon()
	di := dn.GetDenseinfo()

	tu := tagUnpacker{st, dn.GetKeysVals(), 0}
	state := &denseInfoState{
		DenseInfo:       di,
		StringTable:     st,
		DateGranularity: int64(pb.GetDateGranularity()),
	}

	var id, lat, lon int64
	for index := range ids {
		id = ids[index] + id
		lat = lats[index] + lat
		lon = lons[index] + lon
		info := state.Next()

		dec.q = append(dec.q, osm.Element{
			Node: &osm.Node{
				ID:          osm.NodeID(id),
				Lat:         1e-9 * float64((latOffset + (granularity * lat))),
				Lon:         1e-9 * float64((lonOffset + (granularity * lon))),
				User:        info.User,
				UserID:      osm.UserID(info.UID),
				Visible:     info.Visible,
				Version:     int(info.Version),
				ChangesetID: osm.ChangesetID(info.Changeset),
				Timestamp:   info.Timestamp,
				Tags:        tu.Next(),
			},
		})
	}
}
Example #3
0
func (dec *dataDecoder) parseRelations(pb *osmpbf.PrimitiveBlock, relations []*osmpbf.Relation) {
	st := pb.GetStringtable().GetS()
	dateGranularity := int64(pb.GetDateGranularity())

	for _, rel := range relations {
		members := extractMembers(st, rel)
		info := extractInfo(st, rel.GetInfo(), dateGranularity)

		dec.q = append(dec.q, osm.Element{
			Relation: &osm.Relation{
				ID:          osm.RelationID(rel.Id),
				User:        info.User,
				UserID:      osm.UserID(info.UID),
				Visible:     info.Visible,
				Version:     int(info.Version),
				ChangesetID: osm.ChangesetID(info.Changeset),
				Timestamp:   info.Timestamp,
				Tags:        extractTags(st, rel.GetKeys(), rel.GetVals()),
				Members:     members,
			},
		})
	}
}
Example #4
0
func (dec *dataDecoder) parsePrimitiveBlock(pb *osmpbf.PrimitiveBlock) {
	for _, pg := range pb.GetPrimitivegroup() {
		dec.parsePrimitiveGroup(pb, pg)
	}
}