ThinkGeo.com    |     Documentation    |     Premium Support

Slow rendering of ValueStyle items

Hi,


I have a requiremetn to colorcode zipcode areas based on information contained in a mysql database. I aslo have a shapefile that contains the information for zipcode areas (zipcodes.shp)


1. From the mysql database, I retrieve the zipcodes I am interested in, along with the coloding information.


2. I create  ShapefileFeatureLayer from the .shp file.


 


ShapeFileFeatureLayer areaShapeLayer = new ShapeFileFeatureLayer(layerPath); 


3. Define a new ValueStyle to added to the ShapefileFeatureLayer.


ValueStyle valueStyle = new ValueStyle(); 


4. Create a ValueItem for each of the zipcode areas, referencing the appropriate column in the zipcode.shp file and the supplying the relevant coloring.


 


valueStyle.ColumnName = idColName; foreach(KeyValuePair keyValuePair in uidToArea) { valueStyle.ValueItems.Add(new ValueItem(keyValuePair.Key, new AreaStyle(new GeoPen(GeoColor.SimpleColors.Black), new GeoSolidBrush(MapManager.alignAreas[keyValuePair.Value].GetGeoColor(MapManager.viewLevelIndex))))); } areaShapeLayer.ZoomLevelSet.ZoomLevel05.CustomStyles.Add(valueStyle); 


Although this works, it renders very slooow. I initialy added this layer to the DynamicOverlay set since I need to interact with the features. Since it was so slow, I then tried addign it to the StaticOverlay set which sped it up a tad.


Any suggestions how to do this better/more efficient?


Thanks,


Chris



Chris,  


Thanks for joining the forum, hope you enjoy learning and sharing here!
 
First, I am wondering if you have the spatial index for the shape file. You can use shapefileFeatureLayer’s static method to generate it.
 
ValueStyle checks every feature and decide how to render, if you have too many options for every feature, it might slow. You can cache them to speed it up.  Here David have 2 posts showing how to improve the performance for ValueStyle, this one I think is for your case. 
gis.thinkgeo.com/Support/DiscussionForums/tabid/143/aff/16/aft/5265/afv/topic/Default.aspx
 
Also please have a look at this one maybe you can get some insights.
gis.thinkgeo.com/Support/DiscussionForums/tabid/143/aff/16/aft/5263/afv/topic/Default.aspx
 
Thanks,
 
Ben

Ben, 
  
 Thank you so much for your speedy response! 
  
 The solutions you provided seems to be the way to go. 
  
 Since I’m very new to ThinkGeo (1 week!) and need to deliver a working prototype by Friday - can you please provide me a sample/example of how I would use the class instead of the way I use the ValueStyle as explained in my code snippet in my initial post? 
  
 Thanks very much 
 Chris

Chris, 


I made a sample for you, it compiles and as I didn’t have the data, it cannot run. Anyway you can get the idea how to use the cachedValueStyle from the codes.
 
Let me know if you have any queries.
 
Thanks,
 
Ben

388-CachedValueStyleForChris.zip (13 KB)

Ben,


Thanks for the excellent support.


I cannot get the features to display. I'm sure I'm doing something stupid.

The included zipfile  contains my edits to the code in an effort to make it work.


The shapefile is rather big so it does not make sense to include. The important columns in the shapefile are ZPR_ID which is a duplicate of the RECID column, and the ZIP which is the zipcodes. Please refer to my comments in the code.


You help is greatly appreciated!


Thanks,

Chris



Chris, 


Here is a new sample for you. I created a shape file with only “ZPR_ID” and “ZIP” for this sample and also I cleared up the codes (remove the previous comments from you and me) to make it clear. Hope you can make your app before the deadline and any comments just let me know.
 
 


 
Thanks,
 
Ben

394-CachedValueStyleForChris2.zip (95 KB)

Ben,


 


You are an absolute star! This works like a charm.


Althought the initial loading time is a little longer (to be expected by building the cache) the draw times are about 7 times faster!!!


Thank you for putting me in a position to shine :)


Chris



Great it helps, Chris, and it’s always my pleasure. 
  
 Ben