Select to view content in your preferred language

PointPaintOperation (Coloring the points using my color scheme)

768
6
11-10-2010 04:42 AM
AkhilParujanwala
Regular Contributor
I am trying to render the map using my own coloring scheme.
1) I am using a Query Filter to select the features that meet a certain criteria.
2) I want to take the selected features and add them to a geometry collection.
3) Assign a new symbol with my own color for the point.
4) render the map (using invalidate or refresh).

Can someone help me out in terms of this please.

Here are the links I am using:
http://forums.esri.com/Thread.asp?c=206&f=2295&t=284884
http://translate.google.ca/translate?hl=en&sl=zh-CN&u=http://blog.163.com/zhr-jerry/blog/static/2588...

Here is the code:

void Apply_Colors()
        {
            // find the Radiation Devices feature layer
            FeatureLayer featureLayer = MobileApplication.Current.Project.FindFeatureLayer("Dose Rates");

            // get the current team that is using the application            
            string whereClause = "VALUE_USV < 1";

            // creates a new queryfilter and where clause
            QueryFilter pQFilter = new QueryFilter();
            pQFilter.WhereClause = whereClause;

            // queries the feature layer and selects the rows from the datatable
            FeatureDataTable fDataTable = featureLayer.GetDataTable(pQFilter);
            fDataTable = featureLayer.GetDataTable();
            
            //**Missing how to add the selected feature to geometry collection


            //creates a new symbol with different colors
            PointPaintOperation ppo = new PointPaintOperation(Color.AliceBlue,2,1,Color.Beige,1,4,PointPaintStyle.Circle);
            Symbol symbol = new Symbol(ppo as PaintOperation);

            //**Missing how to add this new color scheme to a graphic layer and render on map
        }



Hopefully my logic is correct, please help me if you can.

Thanks,

Akhil P.
0 Kudos
6 Replies
MelindaFrost
Frequent Contributor
Is this WPF or WinForms?
If WPF- here is what I did

          
 glSelected = new GraphicLayer();
            //create brush for fill
            System.Windows.Media.SolidColorBrush myBrush = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.Aqua);
            // Create a Pen to add to the GeometryDrawing created above.
            System.Windows.Media.Pen myPen = new System.Windows.Media.Pen();
           myPen.Brush = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.Aquamarine);

            glSelected.Fill = myBrush;
            glSelected.DrawingPen = myPen;
            
            _map.MapGraphicLayers.Add(glSelected);

            //.....get geometry

          glSelected.GeometryBag.Add(m_geometry);
0 Kudos
AkhilParujanwala
Regular Contributor
I am using the WPF version of the out-of-the-box-solution.

I am almost done writing up the code however, when I made reference to:
using ESRI.ArcGIS.Mobile.WPF;

Map _map = new Map();

does not work.

How do I create and instance of the WPF map?? This may also be my problem with my Download_Data procedure because I must be making reference to the Windows Forms version of the Map instead of the WPF version of the Map.

Please advise.

Thanks,

Akhil P.
0 Kudos
AkhilParujanwala
Regular Contributor
Ok this is what I got so far, hopefully it make sense, except the part where I put ?????.

I understand I need to put the geometries into the collectionbag, but I am unable to figure out how to get the feature from the selected rows in the FeatureDataTable.

void Apply_Colors2()
        {
            // find the Radiation Devices feature layer
            FeatureLayer featureLayer = MobileApplication.Current.Project.FindFeatureLayer("Dose Rates");
            
            
            // get the current team that is using the application            
            string whereClause = "VALUE_USV < '1'";

            // creates a new queryfilter and where clause
            QueryFilter pQFilter = new QueryFilter();
            pQFilter.WhereClause = whereClause;

            // queries the feature layer and selects the rows from the datatable
            FeatureDataTable fDataTable = featureLayer.GetDataTable(pQFilter);
            fDataTable = featureLayer.GetDataTable();

            
            Feature feature;
            Geometry geometry;
            

            GraphicLayer glSelected = new GraphicLayer();
            System.Windows.Media.SolidColorBrush myBrush = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.Aqua);

            System.Windows.Media.Pen myPen = new System.Windows.Media.Pen();
            myPen.Brush = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.Aquamarine);

            glSelected.Fill = myBrush;
            glSelected.DrawingPen = myPen;

            using (FeatureDataReader fDataReader = featureLayer.GetDataReader(pQFilter))
            {
                while (fDataReader.Read())
                {
                    feature = ?????;
                    geometry = feature.Geometry;   
                    glSelected.GeometryBag.Add(geometry);
                }
            }

            ESRI.ArcGIS.Mobile.WPF.Map mMap = MobileApplication.Current.Map;
            mMap.MapGraphicLayers.Add(glSelected);
        }


Kindly advise, thanks,

Akhil P.
0 Kudos
StephenDickinson
Esri Contributor
Have you tried:

feature = new Feature(fDataReader)
geometry = feature.Geometry;

or

geometry = fDataReader[fDataReader.GeometryColumnIndex] as Geometry

Steve
0 Kudos
AkhilParujanwala
Regular Contributor
Have you tried:

feature = new Feature(fDataReader)
geometry = feature.Geometry;

or

geometry = fDataReader[fDataReader.GeometryColumnIndex] as Geometry

Steve


I have tried both of those as you suggested and this
Geometry geometry = fDataTable.Rows[0][fDataTable.GeometryColumnIndex] as Geometry;

But when the code gets to
glSelected.GeometryBag.Add(geometry);

it gives me an error:
"SystemNullReferenceException: Object reference not set to an isntance of object. at ESRI.ArcGISMobile.WPF.GeometryCollection.UpdateGeometry(Int32 index) at ESRI.ArcGIS.Mobile.WPF.GeometryCollection.UpdateGeometry(Geometry geometry) at ESRI.ArcGIS.Mobile.WPF.GeometryCollection.RaiseGeometryUpdated(Geometry item) at ESRI.ArcGIS.Mobile.WPF.GeometryCollection.Add(Geometry item) at NEPRDMobile.Colour_Class.Apply_Colors3()"

I have even checked if the geometry IsValid (True) and IsEmpty (False) and both results are good. But it still won't add it to the GeometryBag.

Please shed some light onto this.

Thanks,

Akhil P.
0 Kudos
AkhilParujanwala
Regular Contributor
Ok I figured this out. I am just going to outline roughly what I did.

Mind you the above suggestions by stephendickinson may work, but I used some different code to do so.

Firstly you must add the graphic layer to the map, then add geometries to the graphiclayer's geometrybag. I had this backwards so that's why it didn't work.

I am querying the feature layer's data table, reading the table, getting a value from a specific field, getting the geometry of the record | Geometry geometry = fDataReader.GetGeometry(); | then assigning the geometry to a specific graphic layer based on the value previously received.

Do better understand what the code is doing, it is essentially the same as selecting the features, for example you have a map of dots in ArcMap, you take a select tool and you select a few of them, the dots now appear selected in a teal color and a square shape.

This is exactly the same thing, except we can control the color of the selected feature.

My only question is can we change the shape of the selected feature, right now it is a square, I would like to try a circle instead if possible. Can anyone suggest how to do this? Do I need to do this through WPF, meaning use a style? Dynamic Static Resource? Create my own style? etc?


Thanks,

Akhil P.
0 Kudos