Select to view content in your preferred language

DrawObject returns null geometry

577
1
05-22-2012 07:10 PM
CraigPatterson
Regular Contributor
I'm creating a tool that allows users to create new features based on the graphic returned by a DrawObject.

I've added the following event handler for my DrawObject

        
        /// <summary>
        /// Rectangle_DrawObject DrawComplete event handler
        /// Adds user drawn rectangle to Projects FeatureLayer
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args">DrawEventArgs</param> 
        private void Rectangle_DrawObject_DrawComplete(object sender, DrawEventArgs args)
        {
            Rectangle_DrawObject.IsEnabled = false;

            //Ready the graphic 
            Graphic graphic = new Graphic()
            {
                Geometry = args.Geometry
            };

            // Input spatial reference for buffer operation defined by first feature of input geometry array
            graphic.Geometry.SpatialReference = Map.SpatialReference;

            AddProjectGraphic(graphic);

        }


The AddProjectGraphic method adds the attributes and adds the graphic to the feature layer

        /// <summary>
        /// AddProjectGraphic
        /// Adds graphic to Projects_Edit featurelayer
        /// </summary>
        /// <param name="graphic">Graphic to be added</param>
        private void AddProjectGraphic(Graphic graphic)
        {

            // Retrieve the Projects featurelayer from the application
            FeatureLayer projects = Map.Layers["Projects_Edit"] as FeatureLayer;

            // add attributes to the graphic
            // loop through the field list
            foreach (var field in projects.LayerInfo.Fields)
            {
                // only add fields that are editable and set to null
                if (field.Editable) {
                    graphic.Attributes[field.Name] = null;
                }
            } // end loop

            // Add the buffered line graphic to the featurelayer
            if (projects != null)
            {
                projects.Graphics.Add(graphic);

                // turn off datagrid/turn on dataform
                DocumentFeatureDataGrid.Visibility = Visibility.Collapsed;
                DocumentFeatureDataForm.Visibility = Visibility.Visible;
                
                // set the data forms source to new graphic
                DocumentFeatureDataForm.GraphicSource = graphic;
            }
        }


The problem is that when the DrawObject is in Rectangle mode, it returns a null geometry.  Here is the results from fiddler...
[{,"attributes":{"BARCODE":null,"BAR_IMAGE":null,"DELETE_POLY":null,"DOCHYPERLINK":null,"PROJECT_NAME":null,"PRINT_DATE":null,"FILENUMBER":null,"SHEET_NUMBER":null,"SHEET_TOTAL":null,"COMMUNITY":null,"AVAILABLE":null,"QC":null,"QCDATE":null,"QCUSER":null}}]

If the DrawObject is in Polygon mode, it works just fine.  Here are the polygon results from fiddler...
[{"geometry":{"spatialReference":{"wkt":"PROJCS[\"NAD_1983_StatePlane_Michigan_South_FIPS_2113_IntlFeet\",GEOGCS[\"GCS_North_American_1983\",DATUM[\"D_North_American_1983\",SPHEROID[\"GRS_1980\",6378137.0,298.257222101]],PRIMEM[\"Greenwich\",0.0],UNIT[\"Degree\",0.0174532925199433]],PROJECTION[\"Lambert_Conformal_Conic\"],PARAMETER[\"False_Easting\",13123359.58005249],PARAMETER[\"False_Northing\",0.0],PARAMETER[\"Central_Meridian\",-84.36666666666666],PARAMETER[\"Standard_Parallel_1\",42.1],PARAMETER[\"Standard_Parallel_2\",43.66666666666666],PARAMETER[\"Latitude_Of_Origin\",41.5],UNIT[\"Foot\",0.3048]]"},"rings":[[[12761546.5763327,543598.139940832],[12761922.406962,541437.113822478],[12759573.465529,541437.113822478],[12759479.5078716,544161.885884751],[12760419.0844448,542752.521024954],[12761546.5763327,543598.139940832]]]},"attributes":{"BARCODE":"testpolygonforfiddler","BAR_IMAGE":null,"DELETE_POLY":null,"DOCHYPERLINK":null,"PROJECT_NAME":null,"PRINT_DATE":null,"FILENUMBER":null,"SHEET_NUMBER":null,"SHEET_TOTAL":null,"COMMUNITY":null,"AVAILABLE":null,"QC":null,"QCDATE":null,"QCUSER":null}}]

Why doesn't the rectangle have a geometry when the polygon does?

Thanks,

Craig
0 Kudos
1 Reply
CraigPatterson
Regular Contributor
Mistakenly posted in the Silverlight Viewer forum.  Will report in the Silverlight forum.
0 Kudos