示例#1
0
 /// <summary>
 /// Adds a relation.
 /// </summary>
 public override void AddRelation(Osm.Relation relation)
 {
     _currentEntities.Add(relation);
     if (_currentEntities.Count > 8000)
     {
         this.FlushBlock();
     }
 }
示例#2
0
        /// <summary>
        /// Encodes an OsmSharp-relation into a PBF-relation.
        /// </summary>
        /// <returns></returns>
        public static OsmSharp.Osm.PBF.Relation EncodeRelation(PrimitiveBlock block, Dictionary <string, int> reverseStringTable, Osm.Relation relation)
        {
            var pbfRelation = new OsmSharp.Osm.PBF.Relation();

            pbfRelation.id   = relation.Id.Value;
            pbfRelation.info = new Info();
            if (relation.ChangeSetId.HasValue)
            {
                pbfRelation.info.changeset = relation.ChangeSetId.Value;
            }
            if (relation.TimeStamp.HasValue)
            {
                pbfRelation.info.timestamp = Encoder.EncodeTimestamp(relation.TimeStamp.Value, block.date_granularity);
            }
            if (relation.UserId.HasValue)
            {
                pbfRelation.info.uid = (int)relation.UserId.Value;
            }
            pbfRelation.info.user_sid = Encoder.EncodeString(block, reverseStringTable, relation.UserName);
            pbfRelation.info.version  = 0;
            if (relation.Version.HasValue)
            {
                pbfRelation.info.version = (int)relation.Version.Value;
            }

            if (relation.Tags != null)
            {
                foreach (var tag in relation.Tags)
                {
                    pbfRelation.keys.Add((uint)Encoder.EncodeString(block, reverseStringTable, tag.Key));
                    pbfRelation.vals.Add((uint)Encoder.EncodeString(block, reverseStringTable, tag.Value));
                }
            }

            if (relation.Members != null &&
                relation.Members.Count > 0)
            {
                pbfRelation.memids.Add(relation.Members[0].MemberId.Value);
                pbfRelation.roles_sid.Add(Encoder.EncodeString(block, reverseStringTable, relation.Members[0].MemberRole));
                switch (relation.Members[0].MemberType.Value)
                {
                case OsmGeoType.Node:
                    pbfRelation.types.Add(Relation.MemberType.NODE);
                    break;

                case OsmGeoType.Way:
                    pbfRelation.types.Add(Relation.MemberType.WAY);
                    break;

                case OsmGeoType.Relation:
                    pbfRelation.types.Add(Relation.MemberType.RELATION);
                    break;
                }
                for (var i = 1; i < relation.Members.Count; i++)
                {
                    pbfRelation.memids.Add(relation.Members[i].MemberId.Value -
                                           relation.Members[i - 1].MemberId.Value);
                    pbfRelation.roles_sid.Add(Encoder.EncodeString(block, reverseStringTable, relation.Members[i].MemberRole));
                    switch (relation.Members[i].MemberType.Value)
                    {
                    case OsmGeoType.Node:
                        pbfRelation.types.Add(Relation.MemberType.NODE);
                        break;

                    case OsmGeoType.Way:
                        pbfRelation.types.Add(Relation.MemberType.WAY);
                        break;

                    case OsmGeoType.Relation:
                        pbfRelation.types.Add(Relation.MemberType.RELATION);
                        break;
                    }
                }
            }
            return(pbfRelation);
        }