Foreword: This article is the extension of <<Enjoy Mobile GIS(1) Using C# to create a GIS program of mobile phone>>. It will show how to using C# edit the .shp map file of ESRI based on HiMap.
Some download for this article: code: myHiMapAdvanced.zip , map file: maps.zip , demo animation: myHiMapVideo2.gif .
I. System requirements.
Development Environment:: Windows XP, .NET Compact Framework 2.0, Windows Mobile 5 SDK, HiMap Beta1 runtime
Run-time Environment: DOPOD D600 mobile phone(ARM CPU) (Windows Mobile 5.0)
II.Function List:
1. Draw Geometry
2. Edit Geometry
3. Delete Geometry
4. Edit Property



III.About the realization:
First, we will have a brief introduction of these basic function. For more description of functions, please consult <<HiMap Help>>
//1.Create a new feature
//Get a layer
IFeatureLayer lyr = (IFeatureLayer)mapControl1.Map.GetLayer(0);
//Get a featureClass of the layer
IFeatureClass cls = (IFeatureClass)lyr.Class;
//Create a feature for this featureClass
IFeature feat = cls.CreateFeature();
//Save the change
feat.Save();
//2.Delete a feature
//Get a layer
IFeatureLayer lyr = (IFeatureLayer)mapControl1.Map.GetLayer(0);
//Get a featureClass of layer
IFeatureClass cls = (IFeatureClass)lyr.Class;
//Create a query filter of featureClass
IQueryFilter qf=new QueryFilterClass();
//Setup query condition
qf.WhereClause="id =1";
//Query data
IFeatureCursor cur = cls.Search(qf);
//Get the feature of query result
IFeature feat = cur.Next();
//Delete a feature
if (feat != null)
{
cls.DeleteFeature(feat);
}
//3.Update the value of a feature
//First of all, get a layer
IFeatureLayer lyr = (IFeatureLayer)mapControl1.Map.GetLayer(0);
//Get a featureClass
IFeatureClass cls = (IFeatureClass)lyr.Class;
//Create a filter of query
IQueryFilter qf=new QueryFilterClass();
//Setup the condition of query
qf.WhereClause="id =1";
//Query data
IFeatureCursor cur = cls.Search(qf);
//Get the feature of query result
IFeature feat = cur.Next();
if (feat != null)
{
//update the value "test data" to the field "name"
feat.SetValue(cls.Fields.FindField("name"), "test data");
//save change
feat.Save();
}
//4.Update the geometry of a feature

//Get a layer first
IFeatureLayer lyr = (IFeatureLayer)mapControl1.Map.GetLayer(0);
//Get a featureClass
IFeatureClass cls = (IFeatureClass)lyr.Class;
//Create a query filter
IQueryFilter qf=new QueryFilterClass();
//Setup query condition
qf.WhereClause="id =1";
//Query data
IFeatureCursor cur = cls.Search(qf);
//Get the feature of query result
IFeature feat = cur.Next();
if (feat != null)
{
//Because the layer is a line type layer, so we use the IPolyling to get the geometry
HiMap.Geometry.IPolyline line = (HiMap.Geometry.IPolyline)feat.Shape;
IPointCollection chline = (IPointCollection)line;
//Create some points(the LGT and LTT are for test only)
IPoint pt1 = new PointClass();
pt1.X = "111.2345556";
pt1.Y = "23.2345556";
IPoint pt2 = new PointClass();
pt2.X = "112.2345556";
pt2.Y = "23.3345556";
//Add points to the line
chline.AddPoint(pt1);
chline.AddPoint(pt2);
//Give the shape value of updated to the feature
feat.Shape = (IGeometry)line;
//Save change
feat.Save();
}
//5.Add parts to ployline and polygon

//Get a layer
IFeatureLayer lyr = (IFeatureLayer)mapControl1.Map.GetLayer(0);
//Get a featureClass
IFeatureClass cls = (IFeatureClass)lyr.Class;
//Create a query filter
IQueryFilter qf=new QueryFilterClass();
//Setup condition of query filter
qf.WhereClause="id =1";
//Query data
IFeatureCursor cur = cls.Search(qf);
//Get a feature by query
IFeature feat = cur.Next();
if (feat != null)
{
//Because the layer is a line type layer, so we use the IPolyling to get the geometry
HiMap.Geometry.IPolyline line = (HiMap.Geometry.IPolyline)feat.Shape;
//Create a new line
IPointCollection chline = new PolylineClass();
//Create points for new the line(test data too)
IPoint pt1 = new PointClass();
pt1.X = "111.2345556";
pt1.Y = "23.2345556";
IPoint pt2 = new PointClass();
pt2.X = "112.2345556";
pt2.Y = "23.3345556";
//Add points to the new line
chline.AddPoint(pt1);
chline.AddPoint(pt2);
HiMap.Geometry.IGeometryCollection geoColl = (HiMap.Geometry.IGeometryCollection)line;
//Add the new line to original line
geoColl.AddGeometry((IGeometry)chline);
//Give the value of geometry to feature
feat.Shape = (IGeometry)line;
//Save change
feat.Save();
}
IV.Sample animation and code:
Download the demo animation: myHiMapVideo2.gif
Download the sample code: myHiMapAdvanced.zip