Hi
I am trying to apply a categorized style to a shapefile layer.
The file could be any shapefile, I wish to choose a column, define a color ramp, and then automatically classify the style.
Basically I want the same behaviour as you can easily achieve in Quantum GIS with the following steps.
- load shapefile
- choose properties
- style tab
- choose categorized
- set column
click classify.
I have not been able to find any samples in the wiki, is there any there?
If not if you can point me in the right direction to achieve this I would be grateful
Thanks
Murray
Categorized Style
Hi Murray,
I have download a Quantum GIS and see what you want.
It looks we don’t have a sample for all the steps, but I think all of they can be implemented.
I think you can do that follow this:
1. Load shapefile then read columns and value from it.
shapeFileFeatureLayer.FeatureSource.GetColumns(); // Read columns
// Read value for “name” column
Collection<Feature> myFeatures = shapeFileFeatureLayer.FeatureSource.GetAllFeatures(ReturningColumnsType.AllColumns);
foreach (Feature feature in myFeatures)
{
string columnValue = feature.ColumnValues[“name”].ToString();
}
2. Change the code and render the layer by new ValueStyle or ClassBreakStyle.
wiki.thinkgeo.com/wiki/Map_Suite_Desktop_Edition_All_Samples#ValueStyle_with_Countries
wiki.thinkgeo.com/wiki/Map_Suite_Desktop_Edition_All_Samples#Labeling_based_on_size
3. Refresh Map.
I think that’s the logic for render different styles follow column value in our map control.
You can write some logic like their classify based this.
Any question please let me know.
Regards,
Don
Thanks Don
I worked it out between those examples
For anyone else here is the code
// set style categories
var sql = String.Format("Select distinct {0} from {1}",CategoryColumn, name);
var columns = layer.QueryTools.ExecuteQuery(sql);
var items = columns.Rows.OfType<DataRow>().Select(dr => dr.Field<String>(CategoryColumn)).ToList();
//Create a series of colors from blue to red that we will use for the breaks
Collection<GeoColor> colors = GeoColor.GetColorsInQualityFamily(GeoColor.StandardColors.Blue, GeoColor.StandardColors.Red, items.Count, ColorWheelDirection.Clockwise);
ValueStyle valueStyle = new ValueStyle();
valueStyle.ColumnName = CategoryColumn;
for (int i = 0; i < items.Count; i++)
{
valueStyle.ValueItems.Add(new ValueItem(items[i], AreaStyles.CreateSimpleAreaStyle(colors[i], GeoColor.StandardColors.Black)));
}
layer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(valueStyle); ;
}
layer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
Thanks Murray,
Your share should be very helpful if someone else met the same problem!
Regards,
Don