Map server layer with help of sharpmap

Topics: SharpMap Project, SharpMap v0.9 / v1.x, SharpMap v2.0, WinForms Controls
Nov 24, 2010 at 8:06 AM

Hi Felix,

Is it possible to have map server layer with help of shapefile.

 var osmLayer = new TileLayer(new OsmTileSource(), "OSM");
                map.Layers.Add(osmLayer);

now I want to have map server layer,using shapefile. and I want to show both layer together.

please let me know some exmaple.

thanks for the help.

Nov 24, 2010 at 9:27 AM

Hi FObermaier ,

could you please help me out form this!

 

thanks

Coordinator
Nov 24, 2010 at 9:34 AM
Edited Jun 22, 2011 at 1:14 PM

hello vivekkumar,

It is possible and works similar to the Excel example. you simply have to replace the OleDbPointPrivider with the ShapeFile provider:

private static SharpMap.Map InitializeMapOsmWithShapeFile(string shapeFilePath)
{
SharpMap.Map map = new SharpMap.Map();

SharpMap.Layers.TileLayer tileLayer = new SharpMap.Layers.TileLayer(new BruTile.Web.OsmTileSource(), "TileLayer - OSM with ShapeFile");
map.Layers.Add(tileLayer);
//Set up provider
var shpProvider = new SharpMap.Data.Providers.ShapeFile(shapeFilePath, true);

#if !DotSpatialProjections //The SRS for this datasource is EPSG:4326, therefore we need to transfrom it to OSM projection var ctf = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory(); var cf = new ProjNet.CoordinateSystems.CoordinateSystemFactory(); var epsgSHP = shpProvider.CoordinateSystem; var epsg3857 = cf.CreateFromWkt("PROJCS[\"Popular Visualisation CRS / Mercator\", GEOGCS[\"Popular Visualisation CRS\", DATUM[\"Popular Visualisation Datum\", SPHEROID[\"Popular Visualisation Sphere\", 6378137, 0, AUTHORITY[\"EPSG\",\"7059\"]], TOWGS84[0, 0, 0, 0, 0, 0, 0], AUTHORITY[\"EPSG\",\"6055\"]],PRIMEM[\"Greenwich\", 0, AUTHORITY[\"EPSG\", \"8901\"]], UNIT[\"degree\", 0.0174532925199433, AUTHORITY[\"EPSG\", \"9102\"]], AXIS[\"E\", EAST], AXIS[\"N\", NORTH], AUTHORITY[\"EPSG\",\"4055\"]], PROJECTION[\"Mercator\"], PARAMETER[\"False_Easting\", 0], PARAMETER[\"False_Northing\", 0], PARAMETER[\"Central_Meridian\", 0], PARAMETER[\"Latitude_of_origin\", 0], UNIT[\"metre\", 1, AUTHORITY[\"EPSG\", \"9001\"]], AXIS[\"East\", EAST], AXIS[\"North\", NORTH], AUTHORITY[\"EPSG\",\"3857\"]]"); var ct = ctf.CreateFromCoordinateSystems(epsgSHP, epsg3857); #else var epsgSHP = shpProvider.CoordinateSystem; var epsg3857 = new DotSpatial.Projections.ProjectionInfo(); epsg3857.ReadEsriString("PROJCS[\"Popular Visualisation CRS / Mercator\", GEOGCS[\"Popular Visualisation CRS\", DATUM[\"Popular Visualisation Datum\", SPHEROID[\"Popular Visualisation Sphere\", 6378137, 0, AUTHORITY[\"EPSG\",\"7059\"]], TOWGS84[0, 0, 0, 0, 0, 0, 0], AUTHORITY[\"EPSG\",\"6055\"]],PRIMEM[\"Greenwich\", 0, AUTHORITY[\"EPSG\", \"8901\"]], UNIT[\"degree\", 0.0174532925199433, AUTHORITY[\"EPSG\", \"9102\"]], AXIS[\"E\", EAST], AXIS[\"N\", NORTH], AUTHORITY[\"EPSG\",\"4055\"]], PROJECTION[\"Mercator\"], PARAMETER[\"False_Easting\", 0], PARAMETER[\"False_Northing\", 0], PARAMETER[\"Central_Meridian\", 0], PARAMETER[\"Latitude_of_origin\", 0], UNIT[\"metre\", 1, AUTHORITY[\"EPSG\", \"9001\"]], AXIS[\"East\", EAST], AXIS[\"North\", NORTH], AUTHORITY[\"EPSG\",\"3857\"]]"); var ct = new DotSpatial.Projections.CoordinateTransformation { Source = epsgSHP, Target = epsg3857 };
#endif var shpLayer = new SharpMap.Layers.VectorLayer("SHP", shpProvider); shpLayer.CoordinateTransformation = ct;

//Add layer to map map.Layers.Add(shpLayer); map.ZoomToBox(shpLayer.Envelope); return map; }

I suggest you use the [Debug|Release]DSProjection configuration, since the on-the-fly reprojection is -in my experience- more accurate.
The other choice would be to make sure your shapefiles are already transformed to google mercator.

Hth FObermaier

Nov 24, 2010 at 9:56 AM

Hi Hth FObermaier,

Actually I am trying to create map server map but I want background map as well . the background map will be OSM layer and in front I want Map server map to be loaded.

it it possible? I want to use shapefile to create map server map.

Thanks for the help. 

Coordinator
Nov 24, 2010 at 11:29 AM

I don't know if you can setup a MapServer layer with  Brutile (->ask at brutile.codeplex.com), but there is also wmslayer.

Look at the winformsamples project to see if it is useful for you.

Hth FObermaier

Nov 30, 2010 at 5:04 PM

Hi Felix,

I am using map server URL with help of WMS layer .

 

 
                ////Map Server URL 
                string wmsUrl = "http://localhost/cgi-bin/mapserv.exe?map=/ms4w/apps/tutorial/htdocs/example1-1-map.map&layer=states&mode=map";
                WmsLayer layWms = new WmsLayer("states", wmsUrl);

                layWms.AddLayer("states");
                layWms.SetImageFormat(layWms.OutputFormats[3]);

                //Map Server Transparancy 
                layWms.Transparancy = true;           
                layWms.SetImageFormat("image/png");
                layWms.ContinueOnError = true;
                layWms.BgColor = System.Drawing.Color.Transparent;
                //Set timeout to 5 seconds
                layWms.TimeOut = 5000;

                //Map Server Projection ID
                layWms.SRID = 4326;

                map.Layers.Add(layWms);

I am getting this error Could not download capabilities  in this line 

 

WmsLayer layWms = new WmsLayer("states", wmsUrl); 
I can run this http://localhost/cgi-bin/mapserv.exe?map=/ms4w/apps/tutorial/htdocs/ms4tutorial.map&layer=states&mode=map
in my browser and i am getting map. but not with help of sharp map.
please let me know whether this is possible in sharp map or not?
if it is please guide me .

thanks for the help.