how to buffer a point in Windows Mobile application

2079
2
03-08-2012 04:08 AM
MichelleMa
New Contributor
Has anyone done any customization work to buffer a point in a Windows Mobile platform?
To adress this problem, how to trigger a Map paint event to draw a graphic layer on top of map layers on Windows Mobile?
How to get hold of Map instance in Windows Mobile in a customization environment?
Thanks,
0 Kudos
2 Replies
KarenPinkerton
New Contributor II
Hi!

Any replies to this?
I'm trying to do the same thing but as a relatively new user I am having difficulty.
0 Kudos
LeeGraham
New Contributor III
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);
            }
        }
0 Kudos