Select to view content in your preferred language

data collection WPF

573
1
04-21-2011 07:17 AM
olivierdev
Deactivated User
How does the data collection work using WPF?
I had a look at the Windows forms example, but it seems to be a little different with WPF.
I've got an error running my code.
Any example or sample is welcome.
thanks
0 Kudos
1 Reply
MelindaFrost
Frequent Contributor
I assume you asking how to edit in general. I am not sure about the sample you are talking about but here is a code snippet of taking the map click and making a map point and saving to feature layer

private void map1_MouseDown(object sender, MouseButtonEventArgs e)
        {
            if (createPoint)
            {
                System.Windows.Point clickPoint = e.GetPosition(map1);
                getMapClick(clickPoint);
                createPoint = false;
            }
        }
        private void getMapClick(System.Windows.Point clickPoint)
        {
            try
            {
                Envelope env = map1.GetRotatedExtent();
                Coordinate coord;
                //GeoTransformation geoTransform = new GeoTransformation(SpatialReference.Create(3857)); // WGS 1984 Web Mecrator Auxiliary Sphere transformer
                //SpatialReferenceConverter src = new SpatialReferenceConverter(SpatialReference.CreateWgs84SpatialReference(), SpatialReference.Create(3857), geoTransform);
                System.Drawing.Point point = new System.Drawing.Point(Convert.ToInt32(clickPoint.X), Convert.ToInt32(clickPoint.Y));
                    coord = map1.ToMap(point); 
                    //System.Windows.MessageBox.Show("map coord" + coord.X.ToString() + " " + coord.Y.ToString());
             
                saveNewObservation(new ESRI.ArcGIS.Mobile.Geometries.Point(coord));

            }
            catch (Exception ex)
            {
                System.Windows.MessageBox.Show(ex.Message.ToString(), "Map Click Error");
            }
        }

        private void saveNewObservation(ESRI.ArcGIS.Mobile.Geometries.Point point)
        {
            try
            {

                //get feature layer
                FeatureLayer featureLayer = getFeatureLayer("Observations", mobileCache);
                //if still null
                if (featureLayer == null)
                {
                    System.Windows.MessageBox.Show("Could not find feature layer 'Observations' in map cache", "Search Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }
                //create datareader
                FeatureDataTable featDataTable = featureLayer.GetDataTable(new QueryFilter());

                DataRow newFeatDataRow = featDataTable.NewRow();
                newFeatDataRow[featDataTable.GeometryColumnIndex] = point;
                //populate new row with some defatul data values
                newFeatDataRow["OBSERVATIONID"] = "1";
                newFeatDataRow["TYPEID"] = 1;                
                newFeatDataRow["STATUS"] = "Active";                
                newFeatDataRow["CREATEDATE"] = DateTime.Now;
                featDataTable.Rows.Add(newFeatDataRow);

                //now save edits
                 featureLayer.SaveEdits(featDataTable);
                
                featDataTable.Dispose();
                featureLayer = null;
            }
            catch (Exception e)
            {
                System.Windows.MessageBox.Show(e.Message.ToString(), "saveNewObservation");
            }
        }
0 Kudos