ThinkGeo.com    |     Documentation    |     Premium Support

Valustyle to InmemoryFeatureLayer

Hi Ethan,
as per your recent solution,it did not work.
I am provoding my code here…

LayerOverlay staticOverlay = (LayerOverlay)Map1.CustomOverlays[“StaticOverLay”];
ShapeFileFeatureLayer shapeFileLayer = (ShapeFileFeatureLayer)staticOverlay.Layers[“ShapeLayer”];

        LayerOverlay dynamicOverlay = (LayerOverlay)Map1.CustomOverlays["DynamicOverlay"];
        InMemoryFeatureLayer highlightLayer = (InMemoryFeatureLayer)dynamicOverlay.Layers["HighlightLayer"];
        highlightLayer.Open();
        highlightLayer.Columns.Add(new FeatureSourceColumn("GovtLand_G"));

        shapeFileLayer.Open();
        SQLstr = "Select Gut_Number,GovtLand_G From ALL where Village_Na= '" + drpVillage.SelectedItem.Text + "' and (GovtLand_G='Forest' or GovtLand_G='Government')";              
        dtSQL = shapeFileLayer.QueryTools.ExecuteQuery(SQLstr);

        if (dtSQL.Rows.Count > 0)
        {
            int z = 0;
            highlightLayer.InternalFeatures.Clear();
            List<string> featureIds = new List<string>();
            for (int i = 0; i < dtSQL.Rows.Count; i++)
            {
                string gutNo = dtSQL.Rows[i]["Gut_Number"].ToString();
                bool isIntString = gutNo.All(char.IsDigit);
                if (isIntString == true)
                    featureIds.Add(dtSQL.Rows[i]["Gut_Number"].ToString());
                else
                {
                    featureIds.Add(GetNumberOnly(gutNo).ToString());
                }
            }
            Collection<Feature> features = shapeFileLayer.QueryTools.GetFeaturesByIds(featureIds, new string[] { "Village_Na" });
            Feature f = new Feature();
            f.ColumnValues.Add("GovtLand_G", "Forest");
            //feature.ColumnValues.Add("GovtLand_G", "Government");
            foreach (Feature feature in features)
            {
                f = feature;
                highlightLayer.InternalFeatures.Add(feature.Id+z, f);                         
                z++;                  
            }                
        }            
        shapeFileLayer.Close();
        ValueStyle valueStyle = new ValueStyle();
        valueStyle.ColumnName = "GovtLand_G";
        valueStyle.ValueItems.Add(new ValueItem("Forest", new AreaStyle(new GeoSolidBrush(GeoColor.FromArgb(130, 38, 153, 0)))));
        valueStyle.ValueItems.Add(new ValueItem("Government", new AreaStyle(new GeoSolidBrush(GeoColor.FromArgb(110, 245, 245, 122)))));
        highlightLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(valueStyle);

        if (highlightLayer.InternalFeatures.Count > 0)
        {
            highlightLayer.Open();
            Map1.CurrentExtent = highlightLayer.GetBoundingBox();
            highlightLayer.Close();
        }

Thank you,

Hi Mouni_M,

Thanks to let us know your question.

I found your code missed one important line:

highlightLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(valueStyle);
// you missed this line 
highlightLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;

It will apply the value style to all zoom levels.

If it still don’t works please let me know.

Regards,

Ethan

Still it did not work.

Regards,
Mouni_M

Hi Mouni_M,

Please wait, I will build a sample for you.

Regards,

Ethan

Hi Mouni_M,

Here is a sample based on your code.

9728.zip (1.6 MB)

Because I don’t have your data, so I just pick a sample data, you can modify the column and query logic to make it work in your project.

Any question please let me know.

Regards,

Ethan

Hi Ethan,
I checked ur solution still I’m not able to get my desired output.
here I am attaching my sample application please go through it and help me out.
Just add shape files in App_Data folder.
SampleWebApp.zip (2.6 MB)
ShapeFiles.zip (3.7 MB)
In following image the portion pointed with red arrow should affect by green and yellow color.

Regards,
Mouni_M

Hi Mouni_M,

Thanks for your sample and data.

I debug your project and found the reason why it don’t works is because you use Gut_Number as id to query feature but in fact it’s not the feature id, so the return features are not what you want and their GovtLand_G value is empty.

You can view that like this:
shapeFileLayer.QueryTools.GetAllFeatures(ReturningColumnsType.AllColumns)

Then compare the feature.id and feature.columnvalues[“Gut_Number”].

I think there are some solutions for that:

  1. Modify the shape file, insert a column equal feature id, then you can select that column as id and use your currently logic.

  2. Write custom value style, filter the feature in drawcore function.

  3. Get all features instead of GetFeaturesByIds, loop the features to find the features you want:
    Village_Na= ‘Gurholi’ and GovtLand_G=‘Forest’ or GovtLand_G=‘Government’

I suggest you choose the third solution, because maybe you don’t want to modify the file, and the custom style also require loop drawing features. So directly get all features and collect the feature group you want is the easiest solution, and if your requirement get changed, you can also modify it quickly.

Any question please feel free to let us know.

Regards,

Ethan

Hi Ethan,
My problem get resolved.Your suggested third solution get worked.
Thank you so much.

Regards,
Mouni_M

Hi Mouni_M,

I am glad to hear that’s helpful.

Any question please feel free to let us know.

Regards,

Ethan