Example #1
0
        public void ImportData(osm osmData)
        {
            foreach (osmNode originalNode in osmData.Node)
            {
                OsmObjectAction objectAction = ParseOsmObjectAction(originalNode.Action);
                if (objectAction == OsmObjectAction.Delete)
                {
                    continue;
                }

                OsmNode node = new OsmNode(originalNode.Id, originalNode.Lat, originalNode.Lon);
                if (originalNode.Timestamp != null)
                {
                    node.Timestamp = DateTime.Parse(originalNode.Timestamp, CultureInfo.InvariantCulture);
                }
                node.User        = OsmUser.Fetch(originalNode.User, originalNode.Uid);
                node.ChangesetId = originalNode.Changeset;
                node.Visible     = originalNode.Visible;
                node.Action      = objectAction;

                foreach (tag tag in originalNode.Tag)
                {
                    node.SetTag(tag.K, tag.V);
                }

                AddNode(node);
            }

            foreach (osmWay originalWay in osmData.Way)
            {
                OsmObjectAction objectAction = ParseOsmObjectAction(originalWay.Action);
                if (objectAction == OsmObjectAction.Delete)
                {
                    continue;
                }

                OsmWay way = new OsmWay(originalWay.Id);
                if (originalWay.Timestamp != null)
                {
                    way.Timestamp = DateTime.Parse(originalWay.Timestamp, CultureInfo.InvariantCulture);
                }
                way.User        = OsmUser.Fetch(originalWay.User, originalWay.Uid);
                way.ChangesetId = originalWay.Changeset;
                way.Visible     = originalWay.Visible;
                way.Action      = objectAction;

                foreach (osmWayND nd in originalWay.Nd)
                {
                    way.AddNode(nd.Ref);
                }

                foreach (tag tag in originalWay.Tag)
                {
                    way.SetTag(tag.K, tag.V);
                }

                AddWay(way);
            }

            foreach (osmRelation originalRelation in osmData.Relation)
            {
                OsmObjectAction objectAction = ParseOsmObjectAction(originalRelation.Action);
                if (objectAction == OsmObjectAction.Delete)
                {
                    continue;
                }

                if (originalRelation.Action == "delete")
                {
                    continue;
                }

                OsmRelation relation = new OsmRelation(originalRelation.Id);
                if (originalRelation.Timestamp != null)
                {
                    relation.Timestamp = DateTime.Parse(originalRelation.Timestamp, CultureInfo.InvariantCulture);
                }
                relation.User        = OsmUser.Fetch(originalRelation.User, originalRelation.Uid);
                relation.ChangesetId = originalRelation.Changeset;
                relation.Visible     = originalRelation.Visible;
                relation.Action      = objectAction;

                foreach (osmRelationMember member in originalRelation.Member)
                {
                    OsmReferenceType referenceType = ParseOsmReferenceType(member.Type);
                    relation.AddMember(referenceType, member.Ref, member.Role);
                }

                foreach (tag tag in originalRelation.Tag)
                {
                    relation.SetTag(tag.K, tag.V);
                }

                AddRelation(relation);
            }
        }
Example #2
0
 /// <summary>
 /// Formats a specified value of <see cref="OsmReferenceType"/> into a string.
 /// </summary>
 /// <param name="action">The OSM reference type value.</param>
 /// <returns>The OSM reference type value in a string form.</returns>
 static public string FormatOsmReferenceType(OsmReferenceType osmReferenceType)
 {
     return(osmReferenceTypeStringConstants [(int)osmReferenceType]);
 }
Example #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="OsmRelationMemberReference"/> class
 /// using a specified type of the OSM object to be referenced and its ID.
 /// </summary>
 /// <param name="referenceType">Type of the referenced OSM object.</param>
 /// <param name="referenceId">The ID of the referenced OSM object.</param>
 public OsmRelationMemberReference(OsmReferenceType referenceType, long referenceId)
 {
     this.referenceType = referenceType;
     this.referenceId   = referenceId;
 }
Example #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="OsmRelationMember"/> class
 /// using a specified type of the OSM object to be referenced, its ID and its role.
 /// </summary>
 /// <param name="referenceType">Type of the referenced OSM object.</param>
 /// <param name="referenceId">The ID of the referenced OSM object.</param>
 /// <param name="role">The role of the relation's member.</param>
 public OsmRelationMember(OsmReferenceType referenceType,
                          long referenceId,
                          string role)
     : this(new OsmRelationMemberReference(referenceType, referenceId), role)
 {
 }
Example #5
0
        /// <summary>
        /// Adds a new member to the relation.
        /// </summary>
        /// <param name="referenceType">Type of the referenced OSM object.</param>
        /// <param name="referenceId">The ID of the referenced OSM object.</param>
        /// <param name="role">The role of the relation's member.</param>
        /// <exception cref="ArgumentException">A member with the same key already exists in the relation.</exception>
        public void AddMember(OsmReferenceType referenceType, long referenceId, string role)
        {
            OsmRelationMember member = new OsmRelationMember(referenceType, referenceId, role);

            members.Add(member.MemberReference, member);
        }