This is 10.0 code but it won't need much modification for 3.x. If you are using 3.1 and have a hard time figuring out what to convert post again and I will send a 3.1 snippet.
You have a feature you want to buffer, such as a point you have collected. As you collect the point set the following
string m_featureName = featureDataRow.FeatureLayer.Name;
Then call
CreateBuffer (feature);
protected double FeetToMeters(int feet)
{
return feet / 3.2808399;
}
protected void CreateBuffer(Feature feature)
{
try
{
// Load the Feature Layer
FeatureLayer layer = null;
if (m_featureName == "Nest Site")
layer = MobileApplication.Current.Project.FindFeatureLayer("Nest Buffer");
if (layer == null)
{
MessageBox.Show(string.Format("Can't find the required buffer layer!"));
return;
}
// Create the polygon based on the current point center, buffer size and shape.
Polygon newPolygon = new Polygon();
Point currentPoint = feature.Geometry as Point;
// Transform coordinate from WGS84 to coordinate based on this spatial reference
SpatialReference spatialReference = layer.MobileCache.SpatialReference;
// See if we need a square or circle.
string shapeType = "Circle"
int bufferSizeInt = 300;
CoordinateCollection shell = null;
if (shapeType == "Circle")
{
shell = GetCircle(currentPoint, FeetToMeters(bufferSizeInt)); // new CoordinateCollection();
}
if (shell == null)
{
return;
}
newPolygon.AddShell(shell);
FeatureDataTable t = layer.GetDataTable();
FeatureDataRow dr = t.NewRow();
dr.BeginEdit();
dr.Geometry = newPolygon;
// copy the data from the Site feature
try
{
AutoPopulateHelper autoPopulator = new AutoPopulateHelper(dr);
autoPopulator.AutoPopulateColumnValue("Version",FeatureDataReaderHelper.GetStringValueOrNull("Version",feature.FeatureDataRow));
autoPopulator.AutoPopulateColumnValue("DisplayKey", FeatureDataReaderHelper.GetStringValueOrNull("DisplayKey", feature.FeatureDataRow));
autoPopulator.AutoPopulateColumnValue("UserID", FeatureDataReaderHelper.GetStringValueOrNull("UserID", feature.FeatureDataRow));
autoPopulator.AutoPopulateColumnValue("TimeStamp", FeatureDataReaderHelper.GetStringValueOrNull("TimeStamp", feature.FeatureDataRow));
autoPopulator.AutoPopulateColumnValue("DeviceID", FeatureDataReaderHelper.GetStringValueOrNull("DeviceID", feature.FeatureDataRow));
autoPopulator.AutoPopulateColumnValue("Lat", FeatureDataReaderHelper.GetStringValueOrNull("Lat", feature.FeatureDataRow));
autoPopulator.AutoPopulateColumnValue("Lon", FeatureDataReaderHelper.GetStringValueOrNull("Lon", feature.FeatureDataRow));
autoPopulator.AutoPopulateColumnValue("Active", "Y");
}
catch (SystemException ex)
{
MessageBox.Show(string.Format("Error pulling data from Site: {0}", ex.Message));
Logger.AddError(ex);
}
dr.EndEdit();
t.Rows.Add(dr);
layer.SaveEdits(t);
}
catch (SystemException ex)
{
MessageBox.Show("Error creating the requested buffer. See log for details");
Logger.AddError(ex);
}
}