Exemplo n.º 1
0
        public override void ProcessIsohypse(Isohypse isohypse, NextIdCallback nodeCallback, NextIdCallback wayCallback)
        {
            if (writer == null)
            {
                throw new InvalidOperationException("The Begin method must be called before calling ProcessIsohypse.");
            }
            if (isohypse == null)
            {
                throw new ArgumentNullException("isohypse");
            }

            foreach (Polyline polyline in isohypse.Segments)
            {
                OsmUtils.OsmSchema.osmWay way = new osmWay();

                settings.ContourMarker.MarkContour(way, isohypse);

                way.Id        = wayCallback();
                way.Nd        = new List <osmWayND> ();
                way.Timestamp = DateTime.UtcNow.ToString("o", System.Globalization.CultureInfo.InvariantCulture);
                way.Version   = 1;
                way.User      = settings.UserName;
                way.Uid       = settings.UserId;
                way.Changeset = settings.ChangesetId;

                long firstWayNodeId = 0;

                for (int i = 0; i < polyline.Vertices.Count; i++)
                {
                    Point3 <double> point = polyline.Vertices[i];

                    OsmUtils.OsmSchema.osmNode node = new osmNode();
                    node.Id        = nodeCallback();
                    node.Lat       = point.Y + settings.LatitudeCorrection;
                    node.Lon       = point.X + settings.LongitudeCorrection;
                    node.Timestamp = DateTime.UtcNow.ToString("o", System.Globalization.CultureInfo.InvariantCulture);
                    node.Version   = 1;
                    node.User      = settings.UserName;
                    node.Uid       = settings.UserId;
                    node.Changeset = settings.ChangesetId;

                    // Do explicity set the Lat- / LonSpecified properties.
                    // Otherwise the lat / lon XML attributes would not get written, if the node has
                    // a latitude or longitude of exactly 0°.
                    node.LatSpecified = true;
                    node.LonSpecified = true;

                    if (i == 0)
                    {
                        firstWayNodeId = node.Id;
                    }

                    nodeSerializer.Serialize(writer, node, ns);

                    way.Nd.Add(new osmWayND(node.Id, true));

                    // Split the way if the maximum node count per way is reached.
                    if (way.Nd.Count == settings.MaxWayNodes && polyline.VerticesCount > settings.MaxWayNodes)
                    {
                        // Don't create a new way if already at the end of the *unclosed* polyline
                        if (i == polyline.VerticesCount - 1 && !polyline.IsClosed)
                        {
                            continue;
                        }

                        // first, serialize old way
                        waySerializer.Serialize(writer, way, ns);

                        way           = new osmWay();
                        way.Id        = wayCallback();
                        way.Nd        = new List <osmWayND> ();
                        way.Timestamp = DateTime.UtcNow.ToString("o", System.Globalization.CultureInfo.InvariantCulture);
                        way.Version   = 1;
                        way.User      = settings.UserName;
                        way.Uid       = settings.UserId;
                        way.Changeset = settings.ChangesetId;

                        settings.ContourMarker.MarkContour(way, isohypse);
                        way.Nd.Add(new osmWayND(node.Id, true));
                    }
                }

                // if the isohypse segment is closed, add the first node as the final node of the way
                if (polyline.IsClosed)
                {
                    way.Nd.Add(new osmWayND(firstWayNodeId, true));
                }

                waySerializer.Serialize(writer, way, ns);
            }
        }
Exemplo n.º 2
0
 abstract public void ProcessIsohypse(Isohypse isohypse, NextIdCallback nodeCallback, NextIdCallback wayCallback);
Exemplo n.º 3
0
        public override void ProcessIsohypse(Isohypse isohypse, NextIdCallback nodeCallback, NextIdCallback wayCallback)
        {
            foreach (Polyline polyline in isohypse.Segments)
            {
                OsmWay isohypseWay = new OsmWay(wayCallback());
                isohypseWay.Visible     = true;
                isohypseWay.Timestamp   = DateTime.UtcNow;
                isohypseWay.User        = this.user;
                isohypseWay.ChangesetId = settings.ChangesetId;

                settings.ContourMarker.MarkContour(isohypseWay, isohypse);
                osmDb.AddWay(isohypseWay);

                long firstWayNodeId = 0;

                for (int i = 0; i < polyline.VerticesCount; i++)
                {
                    Point3 <double> point = polyline.Vertices[i];

                    OsmNode node = new OsmNode(nodeCallback(), point.Y + settings.LongitudeCorrection, point.X + settings.LatitudeCorrection);
                    node.Visible     = true;
                    node.Timestamp   = DateTime.UtcNow;
                    node.User        = this.user;
                    node.ChangesetId = settings.ChangesetId;
                    osmDb.AddNode(node);

                    if (i == 0)
                    {
                        firstWayNodeId = node.ObjectId;
                    }

                    isohypseWay.AddNode(node.ObjectId);

                    // Split the polyline if the maximum node count per way is reached.
                    if (isohypseWay.NodesList.Count == settings.MaxWayNodes && polyline.VerticesCount > settings.MaxWayNodes)
                    {
                        // Don't create a new way if already at the end of the *unclosed* polyline
                        if (i == polyline.VerticesCount - 1 && !polyline.IsClosed)
                        {
                            continue;
                        }

                        isohypseWay             = new OsmWay(wayCallback());
                        isohypseWay.Visible     = true;
                        isohypseWay.Timestamp   = DateTime.UtcNow;
                        isohypseWay.User        = this.user;
                        isohypseWay.ChangesetId = settings.ChangesetId;

                        settings.ContourMarker.MarkContour(isohypseWay, isohypse);
                        osmDb.AddWay(isohypseWay);
                        isohypseWay.AddNode(node.ObjectId);
                    }
                }

                // if the isohypse segment is closed, add the first node as the final node of the way
                if (polyline.IsClosed)
                {
                    isohypseWay.AddNode(firstWayNodeId);
                }
            }
        }