Adding points in VirtualEarth through sharpMap

Topics: Algorithms
Sep 25, 2008 at 2:15 PM
Hi everyone!

I have this code that adds polyline and would like to know what is needed to be changed to add points.

C# code:


public class ShapefileReader
{
    /// <summary>
    /// This method parses an ESRI shapefile and returns a list of simple Shape objects
    /// </summary>
    /// <param name="filePath">Path to the ESRI shapefile (.shp)</param>
    /// <returns>A list of Shape object, where each Shape is a Shapefiles's part</returns>
    public List<Shape> LoadShapefileLayer(string filePath)
    {
        Random random = new Random((int)DateTime.Now.Ticks);
        // SharpMap's Shapefile reader / writer
        ShapeFileProvider sf = null;
        try
        {
            sf = new ShapeFileProvider(filePath);
            sf.Open(false);

            if (sf.ShapeType != ShapeType.PolyLine)
                return null;

            // Initializing the list of Shapes to be returned
            List<Shape> layer = new List<Shape>();
           
            // Retrieving all the geometries in the Shapefile
            BoundingBox ext = sf.GetExtents();
            IEnumerable<Geometry> geometries = sf.ExecuteGeometryIntersectionQuery(ext);
            // Iterating through all the geometries in the shapefile, converting them
            // to Shape objects and adding them to the output list
            foreach (Geometry geometry in geometries)
            {
           
                List<PointF> points = new List<PointF>();
                LineString polyline = geometry as SharpMap.Geometries.LineString;
                //Verify that the geometry is actually a polyline. If it is not, just skip it.
                if (polyline != null)
                {
                    foreach (var vertex in polyline.Vertices)
                    {
                        points.Add(new PointF((float)vertex.X, (float)vertex.Y));
                    }
                    Color randomColour = Color.Orange;
                    layer.Add(new Shape(points, randomColour));
                }
}
            return layer;
        }
        finally
        {
            if (sf != null)
                sf.Close();
        }
    }



Thank you a lot!!

Sep 30, 2008 at 5:00 PM
Edited Oct 1, 2008 at 9:32 AM
I have until now, this code for load the points.

// Initializing the list of Shapes to be returned
                List<Shape> layer = new List<Shape>();
                // Retrieving all the geometries in the Shapefile
                BoundingBox ext = sf.GetExtents();
                IEnumerable<Geometry> geometries = sf.ExecuteGeometryIntersectionQuery(ext);
                // Iterating through all the geometries in the shapefile, converting them
                // to Shape objects and adding them to the output list
                foreach (Geometry geometry in geometries)
                {
                    List<PointF> points = new List<PointF>();
                    SharpMap.Geometries.MultiPoint point = geometry as SharpMap.Geometries.MultiPoint;
                    // Verify that the geometry is actually a point. If it is not, just skip it.
                    if (point != null)
                    {
                        foreach (var vertex in point.Points)
                        {
                            points.Add(new PointF((float)vertex.X, (float)vertex.Y));
                        }
                        Color randomColour = Color.Orange;
                        layer.Add(new Shape(points, randomColour, 2));
                    }
                }
                return layer;
Aug 2, 2009 at 1:30 PM

Hi,

see the link

http://www.solutionwindow.com/sharpmap/addpoint.asp

Regards