Select to view content in your preferred language

HowTo create a Feature? new ESRI.ArcGIS.Mobile.Client.Feature(featureDataReader);

3371
4
03-13-2013 09:51 PM
AndrewHughes
Deactivated User
Hi All,

I'm trying to embed ArcGIS for Mobile in a C# Application. The first (basic) stumbling block is how I can create instances of ESRI.ArcGIS.Mobile.Client.Feature. The unit test below will execute (so long as ./MapCache exists), however it will throw a NullReferenceException every time I try and create a new Feature from the FeatureDataReader.

using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.IO;

namespace ArcGISForMobileTest
{
    [TestClass]
    public class CreateFeatureUnitTest
    {
        [TestMethod]
        public void TestCreateFeature()
        {
            //Create the mobile cache...
            ESRI.ArcGIS.Mobile.FeatureCaching.FeatureDataReader featureDataReader = Setup();
            //Assert Input....
            Assert.IsNotNull(featureDataReader);

            while (featureDataReader.Read())
            {
                Assert.IsNotNull(featureDataReader.GetGlobalId());
                //////////////////////////////////////////////////////////
                // START: Why does this always throw NullReferenceException????
                //////////////////////////////////////////////////////////
                ESRI.ArcGIS.Mobile.Client.Feature feature = new ESRI.ArcGIS.Mobile.Client.Feature(featureDataReader);
                //////////////////////////////////////////////////////////
                // END: Why does this always throw NullReferenceException????
                //////////////////////////////////////////////////////////
                Assert.IsNotNull(feature);
                Assert.IsNotNull(feature.ObjectId);
            }

        }

        private ESRI.ArcGIS.Mobile.FeatureCaching.FeatureDataReader Setup()
        {
            //create the mobile cache
            var mobileCache = new ESRI.ArcGIS.Mobile.FeatureCaching.MobileCache();
            mobileCache.StoragePath = Directory.GetParent(Directory.GetParent(Directory.GetCurrentDirectory()).ToString()) + @"\Mapcache";
            mobileCache.Open();
            //get the first FeatureSource
            ESRI.ArcGIS.Mobile.FeatureCaching.FeatureSource featureSource = mobileCache.FeatureSources.ToArray()[0];
            //get the a FeatureDataReader
            return featureSource.GetDataReader(new ESRI.ArcGIS.Mobile.FeatureCaching.QueryFilter("ObjectId > -1"),null);
        }

    }
}



Can anyone tell me where I am going wrong?

Thanks in advance.
0 Kudos
4 Replies
KierenTinning1
Deactivated User
I'm not specifically sure where your code is going wrong from what you have posted. I am guessing you have a featureclass already specified.

Anyways, this is how I have mine setup and it works, you may want to compare.

fLayer = MobileApplication.Current.Project.FindFeatureLayer("Landbase");
FeatureDataTable fTable = fLayer.GetDataTable();
            FeatureDataRow fRow = fTable.NewRow();
            Feature feat = new Feature(fRow);
            Geometry geom = new ESRI.ArcGIS.Mobile.Geometries.Point();
            m_gpsAveragingSettings = feat.FeatureLayerInfo.CurrentGpsAveragingSettings;
            m_gpsAveragingTool = new GpsAveragingTool(feat.FeatureLayerInfo.CurrentGpsQualityFilter, gps, geom, MobileApplication.Current.Project.SpatialReference);
            m_gpsAveragingTool.GoodPositionAcquired += new EventHandler(m_gpsAveragingTool_GoodPositionAcquired);
            m_gpsAveragingTool.Start();

etc, so on and so forth.

You can then call the edit attributes dialog after.  Or you can call the dialog first and then you the GPS tools to get your location after
0 Kudos
AndrewHughes
Deactivated User
Hi entombedtrader,

I really appreciate your response...




However, the code you have posted has completely different goals 🙂 Thus, I need to continue looking for an answer. The code I have posted is verbatim to what I am running. It has no mobile project defined and does not try and add a new feature - it's goal is to open an existing Feature from a FeatureSource in the mobile cache.

What do you mean, when you say "featureclass already specified"...
I am guessing you have a featureclass already specified....

... I am simply trying to read from the mobile cache's first FeatureSource. Problem?

Of course, help would be most appreciated 🙂
0 Kudos
KierenTinning1
Deactivated User
Hmm, good question and good luck. I've not tried to do that. My work with Mobile anyways has always been about creating new features and the closest I've come to working with 'existing' is with the creating feature action items and reconfiguring those

protected override void Initialize()
        {
            MobileApplication.Current.Project.CreatingFeatureActionItems += new EventHandler<FeatureActionEventArgs>(Project_CreatingFeatureActionItems);
           
        }

and

  void Project_CreatingFeatureActionItems(object sender, FeatureActionEventArgs e)
        {

            //Test batch number and remove 'delete option'
            string str= null;
            ESRI.ArcGIS.Mobile.Client.Feature feat = e.SelectedFeature;
           

            if (feat.CanEdit)
            {
                feat.StartEditing();
                FeatureDataRow fdr = feat.FeatureDataRow;
               

                if (e.Context is FeatureListPage ||
                        e.Context is IdentifyResultsPage ||
                        e.Context is SearchResultsPage)
                {

                    foreach (DataColumn dc in fdr.FeatureLayer.Columns)
                    {
                        if (dc.ColumnName.Equals(strConfig))
                        {
                            str = fdr[dc.ColumnName].ToString();
                        }
                    }


                    if (str.Length > 0)
                    {
                        e.ActionItems.RemoveAt(2);
                    }
                }

                feat.StopEditing();
               // m_viewAttributePage = new ViewAttributesPage(feat, false);
               
            }
        }

Please do post your answer if you find it, would be interesting to know what you find
0 Kudos
AndrewHughes
Deactivated User
Answer, do not create "Feature" objects, instead create a new FeatureDataRow from a FeatureDataTable, then edit the new Row, add it to the table and save changes. Sorry I don't have code with me to post right now.

Thanks for the help.
0 Kudos