Example #1
0
        /// <summary>
        /// Added Osm primitive
        /// </summary>
        /// <param name="osmPrimitive">Node, Way or Relation</param>
        /// <param name="changesType">Created, Updated or Deleted</param>
        public void AddOsmPrimitive(OsmPrimitive osmPrimitive, ChangesType changesType)
        {
            Type type = osmPrimitive.GetType();

            if (osmPrimitive is Node)
            {
                switch (changesType)
                {
                case ChangesType.Created:
                    NodesCreated.Add((Node)osmPrimitive);
                    return;

                    break;

                case ChangesType.Updated:
                    NodesUpdated.Add((Node)osmPrimitive);
                    return;

                    break;

                case ChangesType.Deleted:
                    NodesDeleted.Add((Node)osmPrimitive);
                    return;

                    break;
                }
            }

            if (osmPrimitive is Way)
            {
                switch (changesType)
                {
                case ChangesType.Created:
                    WaysCreated.Add((Way)osmPrimitive);
                    return;

                    break;

                case ChangesType.Updated:
                    WaysUpdated.Add((Way)osmPrimitive);
                    return;

                    break;

                case ChangesType.Deleted:
                    WaysDeleted.Add((Way)osmPrimitive);
                    return;

                    break;
                }
            }
        }
Example #2
0
        private static byte[] ConstructLineString(List<Node> nodes, OsmPrimitive osmPrimitive)
        {
            if (nodes != null)
            {
                try
                {
                    SqlGeometry line;
                    SqlGeometryBuilder lineBuilder = new SqlGeometryBuilder();
                    lineBuilder.SetSrid(4326);
                    lineBuilder.BeginGeometry(OpenGisGeometryType.LineString);
                    lineBuilder.BeginFigure(nodes.First().Latitude, nodes.First().Longtitude);
                    for (int i = 1; i < nodes.Count; i++)
                    {
                        lineBuilder.AddLine(nodes[i].Latitude, nodes[i].Longtitude);
                    }

                    lineBuilder.EndFigure();
                    lineBuilder.EndGeometry();
                    line = lineBuilder.ConstructedGeometry;

                    if (line.STIsValid())
                    {
                        return line.STAsBinary().Buffer;
                    }
                    else
                    {
                        Log.Log.Write(osmPrimitive.GetType() + " " + osmPrimitive.Id + " not valid");
                        return null;
                    }
                }
                catch (Exception e)
                {
                    Log.Log.Write(osmPrimitive.GetType() + " " + osmPrimitive.Id + " Error constructed Geometry LINE STRING: " + e.Message);
                    return null;
                }
            }
            else
            {
                throw new NullReferenceException("Construct polygon failed. Nodes not found.");
            }
        }
Example #3
0
        /// <summary>
        /// Added Osm primitive
        /// </summary>
        /// <param name="osmPrimitive">Node, Way or Relation</param>
        /// <param name="changesType">Created, Updated or Deleted</param>
        public void AddOsmPrimitive(OsmPrimitive osmPrimitive, ChangesType changesType)
        {
            Type type = osmPrimitive.GetType();
            if (osmPrimitive is Node)
            {
                switch (changesType)
                {
                    case ChangesType.Created:
                        NodesCreated.Add((Node)osmPrimitive);
                        return;
                        break;
                    case ChangesType.Updated:
                        NodesUpdated.Add((Node)osmPrimitive);
                        return;
                        break;
                    case ChangesType.Deleted:
                        NodesDeleted.Add((Node)osmPrimitive);
                        return;
                        break;
                }
            }

            if (osmPrimitive is Way)
            {
                switch (changesType)
                {
                    case ChangesType.Created:
                        WaysCreated.Add((Way)osmPrimitive);
                        return;
                        break;
                    case ChangesType.Updated:
                        WaysUpdated.Add((Way)osmPrimitive);
                        return;
                        break;
                    case ChangesType.Deleted:
                        WaysDeleted.Add((Way)osmPrimitive);
                        return;
                        break;
                }
            }
        }
Example #4
0
        private static byte[] ConstructPolygon(List <Node> nodes, OsmPrimitive osmPrimitive)
        {
            if (nodes != null)
            {
                try
                {
                    SqlGeometry        polygon;
                    SqlGeometryBuilder polygonBuilder = new SqlGeometryBuilder();
                    polygonBuilder.SetSrid(4326);
                    polygonBuilder.BeginGeometry(OpenGisGeometryType.Polygon);
                    polygonBuilder.BeginFigure(nodes.First().Latitude, nodes.First().Longtitude);
                    for (int i = 1; i < nodes.Count; i++)
                    {
                        polygonBuilder.AddLine(nodes[i].Latitude, nodes[i].Longtitude);
                    }

                    polygonBuilder.EndFigure();
                    polygonBuilder.EndGeometry();

                    polygon = polygonBuilder.ConstructedGeometry;
                    if (polygon.STIsValid())
                    {
                        return(polygon.STAsBinary().Buffer);
                    }
                    else
                    {
                        Log.Log.Write(osmPrimitive.GetType() + " " + osmPrimitive.Id + " not valid");
                        return(null);
                    }
                }
                catch (Exception e)
                {
                    Log.Log.Write(osmPrimitive.GetType() + " " + osmPrimitive.Id + " Error constructed Geometry POLYGON: " + e.Message);
                    return(null);
                }
            }
            else
            {
                throw new NullReferenceException("Construct polygon failed. Nodes not found.");
            }
        }