Select to view content in your preferred language

unable to add/save new feature point to mobile cache on ArcMobile 10.

4943
10
Jump to solution
11-21-2012 01:06 PM
KarenPinkerton
Deactivated User
WHAT WE NEED
Guidance on how to identify the causes of the issues we are having adding a new point to the layer. Is it a process problem?  Is it a code problem?  If so, who can help us identify the failure points?

The full source code is available if it would be helpful for you to decipher the issue.

We have created our project in Visual Studio 2008 .net 2.0.
What we can do:
- Run the project in Debug mode through Windows Mobile 6 classic Emulator
- Load a MobileCache of 6 Feature Layers ??? 3 editable with existing feature points & 3 as background data
- ZoomIn, ZoomOut, Pan, IdentifyFeature on map using toolbar control
- Load Existing Feature Data to screens when using the IdentifyFeature toolbar function
What we can???t do (identified so far):
- Adding new Feature Point
- How we are attempting this:
- Click toolbar button
- Click map to add new feature
- Run code that we have sourced from multiple different online examples in an attempt to add a new point ??? we have had several different stages of errors thrown from the ???The geometry is empty???, to completely destroying the MobileCache

Example of current relevant code
private void toolBar1_ButtonClick(object sender, ToolBarButtonClickEventArgs e)
{
switch (toolBar1.Buttons.IndexOf(e.Button))
{
  case 0:
   MapMain.CurrentMapAction = zoomInMapAction1;
   break;
  case 1:
   MapMain.CurrentMapAction = zoomOutMapAction1;
   break;
  case 2:
   MapMain.CurrentMapAction = panMapAction1;
   break;
  case 3:
   MapMain.CurrentMapAction = null;
   break;
  case 4:
   MapMain.CurrentMapAction = addVertexSketchTool1;
   break;
  default:
   break;
}
}
private void MapMain_MouseDown(object sender, ESRI.ArcGIS.Mobile.MapMouseEventArgs e)
{
if (MapMain.CurrentMapAction == addVertexSketchTool1)
{
  AddNewFeaturePoint();
}
}
private void AddNewFeaturePoint()
{
sketchGraphicLayer1.Geometry = new ESRI.ArcGIS.Mobile.Geometries.Point();

FeatureLayer locationLayer = mobileCache1.Layers["Location"] as FeatureLayer;
using (FeatureDataTable locationTable = locationLayer.GetDataTable())
{
  DataRow locationRow = locationTable.NewRow();
  locationRow.BeginEdit();
  locationRow["LocationID"] = Guid.NewGuid();
  locationRow[locationLayer.GeometryColumnIndex] = sketchGraphicLayer1.Geometry;
  locationRow.EndEdit();
  locationTable.Rows.Add(locationRow);
  locationTable.SaveInFeatureLayer();

  DataRow[] errors = locationTable.GetErrors();
  for (int i = 0; i < errors.Length; i++)
  {
   if (errors.HasErrors)
   {
    DataColumn[] colArr = errors.GetColumnsInError();
    for (int j = 0; j < colArr.Length; j++)
    {
     MessageBox.Show(string.Format("Error '{0}' in column '{1}'.", errors.GetColumnError(colArr), colArr.ColumnName));
    }
   }
  }
}
}
0 Kudos
1 Solution

Accepted Solutions
Andréde_Mattos_Ferraz
Deactivated User
Solution for me:

//this im chaging position of first record
fdt.Rows[0][fdt.GeometryColumnIndex] = newPoint; //fdt - featureDataTable
fdt.SaveInFeatureSource();
fdt.AcceptChanges();

View solution in original post

0 Kudos
10 Replies
Jitendrudulacaraju
Emerging Contributor
It needs a FID- create it like this:

editRow[featureRTS.FidColumnIndex] = -1 * int.Parse(editRow["ObjectID"].ToString());


It will work.


WHAT WE NEED
Guidance on how to identify the causes of the issues we are having adding a new point to the layer. Is it a process problem?  Is it a code problem?  If so, who can help us identify the failure points?

The full source code is available if it would be helpful for you to decipher the issue.

We have created our project in Visual Studio 2008 .net 2.0.
What we can do:
-    Run the project in Debug mode through Windows Mobile 6 classic Emulator
-    Load a MobileCache of 6 Feature Layers �?? 3 editable with existing feature points & 3 as background data
-    ZoomIn, ZoomOut, Pan, IdentifyFeature on map using toolbar control
-    Load Existing Feature Data to screens when using the IdentifyFeature toolbar function
What we can�??t do (identified so far):
-    Adding new Feature Point
-    How we are attempting this:
-    Click toolbar button
-    Click map to add new feature
-    Run code that we have sourced from multiple different online examples in an attempt to add a new point �?? we have had several different stages of errors thrown from the �??The geometry is empty�??, to completely destroying the MobileCache

Example of current relevant code
private void toolBar1_ButtonClick(object sender, ToolBarButtonClickEventArgs e)
{
switch (toolBar1.Buttons.IndexOf(e.Button))
    {
        case 0:
            MapMain.CurrentMapAction = zoomInMapAction1;
            break;
        case 1:
            MapMain.CurrentMapAction = zoomOutMapAction1;
            break;
        case 2:
            MapMain.CurrentMapAction = panMapAction1;
            break;
        case 3:
            MapMain.CurrentMapAction = null;
            break;
        case 4:
            MapMain.CurrentMapAction = addVertexSketchTool1;
            break;
        default:
            break;
    }
}
private void MapMain_MouseDown(object sender, ESRI.ArcGIS.Mobile.MapMouseEventArgs e)
{
    if (MapMain.CurrentMapAction == addVertexSketchTool1)
    {
        AddNewFeaturePoint();
    }
}
private void AddNewFeaturePoint()
{
    sketchGraphicLayer1.Geometry = new ESRI.ArcGIS.Mobile.Geometries.Point();

    FeatureLayer locationLayer = mobileCache1.Layers["Location"] as FeatureLayer;
    using (FeatureDataTable locationTable = locationLayer.GetDataTable())
    {
        DataRow locationRow = locationTable.NewRow();
        locationRow.BeginEdit();
        locationRow["LocationID"] = Guid.NewGuid();
        locationRow[locationLayer.GeometryColumnIndex] = sketchGraphicLayer1.Geometry;
        locationRow.EndEdit();
        locationTable.Rows.Add(locationRow);
        locationTable.SaveInFeatureLayer();

        DataRow[] errors = locationTable.GetErrors();
        for (int i = 0; i < errors.Length; i++)
        {
            if (errors.HasErrors)
            {
                DataColumn[] colArr = errors.GetColumnsInError();
                for (int j = 0; j < colArr.Length; j++)
                {
                    MessageBox.Show(string.Format("Error '{0}' in column '{1}'.", errors.GetColumnError(colArr), colArr.ColumnName));
                }
            }
        }
    }
}
0 Kudos
KarenPinkerton
Deactivated User
Thanks for your comment, I�??m having trouble implementing it though.

In the case of a new feature row we are adding, there is no populated ObjectID to multiply and it appears that when you add or edit a feature, there must be a metadata table within the MobileCache that tracks the total number of features within that layer that have been changed, and then automatically increments and assigns that number in negative format to the ObjectID.

In the case of an edit, I attempted to set the ObjectID as per you code, and it fails as the field is ReadOnly.

I�??m a bit puzzled as it appears that there�??s no problem with the MobileCache as it works successfully in the Windows project.
However, when I use the same code that is implemented within the Windows application in our mobile application (which appears to be the same as all of the code examples that I�??ve seen for Mobile applications), it fails.

It�??s almost like there is a project specific ReadOnly setting on the MobileCache.

Could you help us with this please?
0 Kudos
ThadTilton
Esri Contributor
I came across this thread hoping to find a solution to a very similar problem. In my case, the geometry is Polyline and I'm working with code that has worked for a long time. In my case, the geometry looks fine (same simple line I've stored a million times), but the error identifies the SHAPE field as problematic. In my case, I suspect the mobile cache may be corrupt. I've tried rebuilding it without success. Any suggestions will be greatly appreciated!

I gave your code a quick look, and I wonder if the geometry you're attempting to store is the problem (a new, empty point). Maybe try modifying your code like the following and see if that works (?):

private void MapMain_MouseDown(object sender, ESRI.ArcGIS.Mobile.MapMouseEventArgs e)
{
   if (MapMain.CurrentMapAction == addVertexSketchTool1)
  {
     AddNewFeaturePoint(e.MapCoordinate); // pass the map click as the location to store
  }
} 

private void AddNewFeaturePoint(Coordinate mapCoord)
{
  var pointGeom = new ESRI.ArcGIS.Mobile.Geometries.Point(mapCoord);
  // ...
  locationRow[locationLayer.GeometryColumnIndex] = pointGeom;
  // ...
}


Hope that helps. -Thad
0 Kudos
KarenPinkerton
Deactivated User
Thanks for your reply Thad!

I did actually have the geometry being set that way, but I�??d removed it wondering if that was causing the problem then forgot to re-add it to the example code. Thanks for the reminder, frustratingly we are still having problems though.  The cache appears to be fine as we can load it onto a window application that we have and it works fine.

What would be really great would be to be able to find an example mobile application that adds/edits features.

Do you know of anyone who can provide this?
0 Kudos
JayChen
Esri Contributor
Thanks for your reply Thad!

I did actually have the geometry being set that way, but I�??d removed it wondering if that was causing the problem then forgot to re-add it to the example code. Thanks for the reminder, frustratingly we are still having problems though.  The cache appears to be fine as we can load it onto a window application that we have and it works fine.

What would be really great would be to be able to find an example mobile application that adds/edits features.

Do you know of anyone who can provide this?


There are a few things to check when a seemingly good feature fail to save in an SDK app:
1. make sure the feature is created within the full extent of your mobile cache.
2. make sure all required fields are set (those fields that don't allow null).
3. make sure GlobalID is available in your feature class.
4. if you have a map document referencing a file GDB and publish to 10.1 server, make sure you choose to copy data to server otherwise the layer will be read-only even it has GlobalID.

To add a new feature in SDK is something similar to the following code snippet:
            FeatureDataTable fTable = editlayer.GetDataTable();

            // creates a new row
            DataRow editedFeature = fTable.NewRow();

            //sets the new geometry to the geometry field
            editedFeature[editlayer.GeometryColumnIndex] = sketchGraphicLayer1.Geometry;

            //sets other required fields
            editedFeature["xxxxxx"] = "xxxxxx";

            //sets the new geometry to the feature layer data table
            fTable.Rows.Add(editedFeature);         

            // updates the feature layer data table
            fTable.SaveInFeatureLayer();

0 Kudos
ThadTilton
Esri Contributor
Thanks Jay, good list of things to troubleshoot.
For me, I found that my GPS simulator was using the wrong set of coordinates and therefore inputting coordinates that my app was unable to handle (outside my cache's extent, per your first item).
0 Kudos
KarenPinkerton
Deactivated User
Thanks everyone for all of your suggestions, we have now solved this thank to Shane Pienaar.

It turns out the issue was around the mobile cache being stored on the Storage Card not on the device or emulator itself.

Problem solved! 🙂
0 Kudos
TimDonoyou
Regular Contributor
Hi Karen,

Quick question - by solution do you just mean that you have saved the mobile cache to the device rather than the sd card and now it works?

We have had similar issues and can save to the device fine but not to the sd card which is ok but going forward when we have a range of projects with differing datasets we really need to use multiple sd cards...

I, personally, don't think this is a solution but really just a workaround... and it would be good if the saving to sd card functionality was made available.

Thanks

Tim
0 Kudos
IanBrown
New Contributor
Hi Tim

haha, just her girlie wording :). No we didn't actually solve the problem of being able to hold the data on the sd card we did just take the work around of storing it on the device, so I do agree with you, it's not a solution, but I guess for us, as we didn't know what was causing the problem initially, this is a fix.
Now that we know what is causing the problem, we've don't some searching and can't find an ideal solution, which is a bit annoying, especially for testing on the emulator which is limited to 32mb.

Regards,
Ian

Hi Karen,

Quick question - by solution do you just mean that you have saved the mobile cache to the device rather than the sd card and now it works?

We have had similar issues and can save to the device fine but not to the sd card which is ok but going forward when we have a range of projects with differing datasets we really need to use multiple sd cards...

I, personally, don't think this is a solution but really just a workaround... and it would be good if the saving to sd card functionality was made available.

Thanks

Tim
0 Kudos