public static IEnumerable <OsmWay> DecodeWays(PrimitiveBlock data) { if (data == null || data.PrimitiveGroup == null) { yield break; } foreach (var way in data.PrimitiveGroup.SelectMany(x => x.Ways)) { var ids = DecodeDeltaItems(way.Refs); var tags = DecodeTags(way.Keys, way.Values, data.Strings); yield return(new OsmWay { Id = way.Id, NodeIds = ids, Tags = tags }); } }
public PrimitiveBlock ReadData() { reader.BeginReadMessage(length); var result = new PrimitiveBlock(); result.PrimitiveGroup = new List <PrimitiveGroup>(); while (reader.State == ProtobufReaderState.Field) { switch (reader.FieldNumber) { case 1: result.Strings = ReadStringTable(); break; case 2: result.PrimitiveGroup.Add(ReadPrimitiveGroup()); break; case 17: result.Granularity = (int)reader.ReadInt64(); break; case 19: result.LatOffset = reader.ReadInt64(); break; case 20: result.LonOffset = reader.ReadInt64(); break; case 18: result.DateGranularity = (int)reader.ReadInt64(); break; default: reader.Skip(); break; } } reader.EndReadMessage(); return(result); }
public static IEnumerable <OsmNode> DecodeDenseNodes(PrimitiveBlock data) { if (data == null || data.PrimitiveGroup == null) { yield break; } foreach (var denseNodes in data.PrimitiveGroup.Select(group => group.DenseNodes) .Where(denseNodes => denseNodes != null)) { var ids = denseNodes.Ids; var latitudes = denseNodes.Latitudes; var longitudes = denseNodes.Longitudes; long prevId = 0; long prevLat = 0; long prevLon = 0; if (ids.Count != latitudes.Count || ids.Count != longitudes.Count) { throw new InvalidOperationException( "Dense node should have equal couont of Ids, Longitudes and Latitudes"); } for (var i = 0; i < ids.Count; i++) { prevId += ids[i]; prevLon += longitudes[i]; prevLat += latitudes[i]; var lon = 0.000000001 * (data.LonOffset + data.Granularity * prevLon); var lat = 0.000000001 * (data.LatOffset + data.Granularity * prevLat); var node = new OsmNode(prevId, lon, lat); yield return(node); } } }