Data collection in ArcGIS for Windows Mobile
Data collection development involves a feature source to edit the datatable that receives the new feature, and a sketch to draw the new feature on the map display. The code below shows how to set a feature source, change the MapAction to addVertexSketchTool, and create an empty geometry based on the feature source type.
// Sets map action to add vertex sketch
map1.MapAction = addVertexSketchTool1;
// Selects the inspecton feature source to add features
valveInspectionsLayer = mobileCache1.FeatureSources["Inspections"] as FeatureSource;
if (valveInspectionsLayer == null)
{
throw new NullReferenceException("Could not find the specified featuresource");
}
switch (valveInspectionsLayer.GeometryType)
{
case GeometryType.Polygon:
sketchGraphicLayer1.Geometry = new Polygon();
break;
case GeometryType.Polyline:
sketchGraphicLayer1.Geometry = new Polyline();
break;
case GeometryType.Point:
sketchGraphicLayer1.Geometry = new ESRI.ArcGIS.Mobile.Geometries.Point();
break;
case GeometryType.Multipoint:
sketchGraphicLayer1.Geometry = new Multipoint();
break;
}
When the above code is executed, the mouse cursor can be used on the display to create a new feature.
The code below is used to signal that the data collection of the feature's geometry is completed. The process involves creating a new row for the feature data table, adding it to the table, assigning the geometry, and saving the table changes.
//Used to signal geometry has been created for new feature
private void map1_DoubleClick(object sender, EventArgs e)
{
try
{
if (map1.MapAction != addVertexSketchTool1)
return;
FeatureDataTable fTable = valveInspectionsLayer.GetDataTable();
// Creates a new row
FeatureDataRow newFeature = fTable.NewRow();
//Sets the new geometry to the feature layer data table
fTable.Rows.Add(editedFeature);
//Sets the new geometry to the geometry field
editedFeature[valveInspectionsLayer.GeometryColumnIndex] = sketchGraphicLayer1.Geometry;
// Updates the feature layer data table
fTable.SaveInFeatureSource();
// Cleans the sketch
sketchGraphicLayer1.Geometry = null;
//Now use selection to select new feature and modify
map1.MapAction = selectionMapAction1;
}
catch (Exception ex)
{
MessageBox.Show("Invalid geometry. " + ex.ToString());
// Cleans the invalid geometry
sketchGraphicLayer1.Geometry = null;
}
}
To add attributes to a new feature, use the feature data table the same way as when adding the geometry; it involves different columns or fields in the row.
Where to get the sample
Download the sample from ArcGIS.com DataCollection with ArcGIS for Windows Mobile.