1

I have a Shapefile map of Maryland separated by zipcode. What I'd like to do is color each area based on a value I'm looking up in a database. Currently, I'm using ASP.NET with the SharpMap package. The basic questions are:

1) How do I associate a shape with its zipcode? I can generate the list of zipcodes using SharpMap's ExecuteIntersectionQuery with the BoundingBox set as the extent of the map, but I have no idea how to then connect each row of the resulting table with the shape it represents.

2) Once I have access to an individual shape and know what color I want, how do I assign the color to the shape? In SharpMap, I can color a VectorLayer, but a VectorLayer is generated from a source .shp file, not a shape.

I'm open to using other free map packages besides SharpMap (so no ArcGIS), but for legal reasons I can't use GoogleMaps.

I feel like this should be relatively simple, but trying to find any decent resource for SharpMap is pretty difficult.

EDIT: Alright, I've made a lot of process just by reading over what documentation there is. By setting the FilterDelegate of ShapeFile, I can make a layer consist of only the rows where the zip code matches a certain value. Now my only problem is making the delegate filter look for a different zip code each time. Can I pass another parameter besides the FeatureDataRow? Should I resort to a global variable?

Jodaka
  • 1,237
  • 8
  • 16
  • actually, ERSI IS free to use--including their public map servers for basic services etc. – Muad'Dib Jul 05 '11 at 17:20
  • Does what they offer for free allow me to easily accomplish this goal? And could you provide some specific links if so? – Jodaka Jul 05 '11 at 17:55
  • you want asp, flash, or silverlight? – Muad'Dib Jul 05 '11 at 17:57
  • http://www.esri.com/mapping-for-everyone/index.html – Muad'Dib Jul 05 '11 at 17:58
  • ASP.NET. Also, I'm sorry, but I don't think I understand the purpose of your link, because I'm still not seeing where I can assign colors to zip code areas based on my own data, not an information set ESRI provides. – Jodaka Jul 05 '11 at 18:30
  • link to esri's api--they have tons of sample code for whichever api you want to use. you might have to dig for it, tho. and i dont think they have built-in shapefile readers :( – Muad'Dib Jul 05 '11 at 18:34
  • Thanks for the suggestion, but I'm not sure that's going to help me. – Jodaka Jul 05 '11 at 19:28

1 Answers1

2

You'll need to use thematics to do this.

I'll assume you already have some code that configures your map and it's layers. Your shapefile is a VectorLayer.

VectorLayer shapefileLayer = GetMyShapefileLayer();
shapefileLayer.Theme = new SharpMap.Rendering.Thematics.CustomTheme(GetStyleForShape);

Then, method GetStyleForShape is called every time the map needs a style for rendering. It looks like this:-

private SharpMap.Styles.VectorStyle GetStyleForShape(SharpMap.Data.FeatureDataRow row, SharpMap.Layers.Layer layer)
    {
}

In the method, you create and return a VectorStyle. The table data associated with the feature it's trying to render is passed as a parameter to this method.

So you can use the row parameter to get your zip code, do whatever logic you need to do to calculate it's style, configure that style and return it.

This method (potentially) gets called a lot, so consider storing the styles and reusing them, rather than recreating them every time.

Hope this helps.

slippyr4
  • 862
  • 7
  • 18