Total beginner struggles

Topics: General Topics
Mar 31, 2013 at 12:16 AM
Edited Mar 31, 2013 at 12:22 AM
Hello everyone,

I have lots of coordinates I want to plot on a map to look at their distribution. I was going to use System.Drawing and download an image of the world, but then I bumped into SharpMap!

It looks excellent, but I'm struggling to do anything with it. I'm using VS2012 and none of the code examples seem to work.

I have fixed up some things and got a mapbox displaying a map, and I am adding layers but nothing really seems to change.

Does anyone know for a working project/solution I can download to use as a guide please? Most things seem to be geared towards pulling points from a database but mine are in a list object.

Currently this is the rubbish I've cobbled together :)
        SharpMap.Layers.VectorLayer vlay = new SharpMap.Layers.VectorLayer("States");
        vlay.DataSource = new SharpMap.Data.Providers.ShapeFile(@"Packages\states_ugl.shp", true);

        //Create the style for Land
        VectorStyle landStyle = new VectorStyle();
        landStyle.Fill = new SolidBrush(Color.FromArgb(232, 232, 232));

        //Create the style for Water
        VectorStyle waterStyle = new VectorStyle();
        waterStyle.Fill = new SolidBrush(Color.FromArgb(198, 198, 255));

        //Create the map
        Dictionary<string, SharpMap.Styles.IStyle> styles = new Dictionary<string, IStyle>();
        styles.Add("land", landStyle);
        styles.Add("water", waterStyle);

        //Assign the theme
        vlay.Theme = new SharpMap.Rendering.Thematics.UniqueValuesTheme<string>("class", styles, landStyle);

        mapBox1.Map.Layers.Add(vlay);

        SharpMap.Layers.VectorLayer vectorLayer = new VectorLayer("GeometryLayer");

        Collection<GeoAPI.Geometries.IGeometry> geomColl = new Collection<GeoAPI.Geometries.IGeometry>();

        //Get the default geometry factory
        GeoAPI.GeometryServiceProvider.Instance = new NetTopologySuite.NtsGeometryServices();
        GeoAPI.Geometries.IGeometryFactory gf = GeoAPI.GeometryServiceProvider.Instance.CreateGeometryFactory();

        //Add a single Point
        geomColl.Add(gf.CreatePoint(new GeoAPI.Geometries.Coordinate(10, 10)));

        //Add a LineString with 2 Points
        GeoAPI.Geometries.Coordinate[] points = new GeoAPI.Geometries.Coordinate[2];

        points[0] = new GeoAPI.Geometries.Coordinate(10, 10);
        points[1] = new GeoAPI.Geometries.Coordinate(200, 200);

        geomColl.Add(gf.CreateLineString(points));

        GeoAPI.Geometries.Coordinate[] points2 = new GeoAPI.Geometries.Coordinate[100000];

        for (var i = 0; i < 100000; i++)
        {
            points2[i] = new GeoAPI.Geometries.Coordinate(i, i);
        }

        geomColl.Add(gf.CreateLineString(points2));

        vectorLayer.Style.Line.StartCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor;
        vectorLayer.Style.Line.EndCap = System.Drawing.Drawing2D.LineCap.Round;

        vectorLayer.DataSource = new SharpMap.Data.Providers.GeometryProvider(geomColl);

        mapBox1.Map.BackgroundLayer.Add(new SharpMap.Layers.TileAsyncLayer(new BruTile.Web.OsmTileSource(), "OSM"));

        mapBox1.Map.Layers.Add(vectorLayer);

        mapBox1.Map.ZoomToExtents();
        mapBox1.Refresh();
        mapBox1.ActiveTool = SharpMap.Forms.MapBox.Tools.Pan;

The map displays and is controllable, but I'm not sure my code is right. The points I'm trying to plot are probably nonsense, I cannot see anywhere if they've appeared so it's difficult to carry on. I'm sure my coordinate scale is a bit wacky and I need to set up a style. I might just have gotten it completely wrong :)

Thank you for your time :)
Coordinator
Mar 31, 2013 at 9:55 PM
Hi,
Check the SharpMap Tutorial
http://sharpmap.codeplex.com/wikipage?title=SharpMap%20Tutorial&referringTitle=Home

If you use OSM as background and your data is in another projection that Global Mercator (Google / OSM coodinates) you need to set the CoordinateProjection on your VectorLayer