This project has moved and is read-only. For the latest updates, please go here.

Layer from different sources

Topics: Data Access, SharpMap v0.9 / v1.x, Web Controls
Jul 5, 2011 at 3:07 AM

I need to create a single layer from 3 different shape files. Is this possible?

Jul 5, 2011 at 7:44 AM

you would need to create a custom IProvider, that

  • iterates through
  • aggregates
  • does whatever else with

all the features of all datasources.

A LayerGroup is not an option?

Hth FObermaier

Jul 6, 2011 at 10:01 AM
Edited Jul 6, 2011 at 10:09 AM

I am collecting information from each state. Some states have all the info in 1 shapefiles & some in 2 sahpefiles & some in 1.
Then I allow the user to query this information & highligt a district. The highlighted district is then added to a database.
So it would be easier to combine all 3 layers into one,  to do the query.

SharpMap - version 0.9 & ASP.NET

1. What  is a LayerGroup? Can you elaborate on how to create one? Any sample code?

2. Is there a restriction on how many layers I can load?

3. Will there be a performance improvement if I load all my layers, but only enable those that are required?

4. Will performace improve if I can trim down the feature set to only those I need? i. e. trim the associated DBF file?

5. Any tool that I can use to trim shapefiles - cut down feature set?


Jul 6, 2011 at 1:51 PM
  1. A LayerGroup has a Collection<Layer>. Every function call is passed to the underlying Layer function and the results are being aggregated.
    var l = new LayerGroup("manyShapes");
    l.Layers.Add( new VectorLayer("Layer1", new Shapefile( ..., ... ));
    l.Layers.Add( new VectorLayer("Layer2", new Shapefile( ..., ... ));
  2. No, at least I didn't find one
  3. Yes
  4. Probably
  5. Use ogr2ogr to read shapefile, select fields wanted and save to new shapefile

Hth FObermaier

Jul 8, 2011 at 8:06 AM
Edited Jul 8, 2011 at 8:20 AM

Thanks. I will follow your directions.

I added the LayerGroup - Now how do I set the style of each layer?  Default Fill is Black.

I tried this

LayerGroup layerGroup = new LayerGroup("myGroup"); //var layerGroup = new LayerGroup("myGroup"); won't compile on .net 3.5 
foreach (SharpMap.Layers.Layer layerI in layerGroup.Layers)
//Set fill-style to Transparent with a black outline
//layerI.Style.Fill = new SolidBrush(Color.Transparent);
//layerI.Style.Outline = Pens.Black;
//layerI.Style.EnableOutline = true;
layerI.SRID = 4326;
Jul 8, 2011 at 10:26 AM
Edited Jul 8, 2011 at 10:27 AM

You should create your layers as ususal, defining the style you want, and when you are done add them to the layergroup.
You should be able to set the layerstyle afterwards, too.

Hth FObermaier