PopulateRowBufferWithAttributes() public method

public PopulateRowBufferWithAttributes ( RowBuffer &rowBuffer ) : void
rowBuffer RowBuffer
return void
Ejemplo n.º 1
0
        public async void CreateNewFeatureAsync(object parameter)
        {
            string message        = String.Empty;
            bool   creationResult = false;

            //Generate geometry if polygon or polyline, if adding new feature is from using coordinates and not the map tool
            if (Convert.ToBoolean(parameter) == true)
            {
                if (GeometryType == GeometryType.Polyline || GeometryType == GeometryType.Polygon)
                {
                    GeneratePolyGeometry();
                }
            }

            IEnumerable <GDBProjectItem> gdbProjectItems = Project.Current.GetItems <GDBProjectItem>();
            await QueuedTask.Run(() =>
            {
                foreach (GDBProjectItem gdbProjectItem in gdbProjectItems)
                {
                    using (Datastore datastore = gdbProjectItem.GetDatastore())
                    {
                        //Unsupported datastores (non File GDB and non Enterprise GDB) will be of type UnknownDatastore
                        if (datastore is UnknownDatastore)
                        {
                            continue;
                        }
                        Geodatabase geodatabase = datastore as Geodatabase;
                        // Use the geodatabase.

                        string geodatabasePath = geodatabase.GetPath();
                        if (geodatabasePath.Contains(ProSymbolEditorModule.WorkspaceString))
                        {
                            //Correct GDB, open the current selected feature class
                            FeatureClass featureClass = geodatabase.OpenDataset <FeatureClass>(_currentFeatureClassName);
                            using (featureClass)
                                using (FeatureClassDefinition facilitySiteDefinition = featureClass.GetDefinition())
                                {
                                    EditOperation editOperation = new EditOperation();
                                    editOperation.Name          = "Military Symbol Insert";
                                    editOperation.Callback(context =>
                                    {
                                        try
                                        {
                                            RowBuffer rowBuffer = featureClass.CreateRowBuffer();
                                            _symbolAttributeSet.PopulateRowBufferWithAttributes(ref rowBuffer);
                                            rowBuffer["Shape"] = GeometryEngine.Project(MapGeometry, facilitySiteDefinition.GetSpatialReference());

                                            Feature feature = featureClass.CreateRow(rowBuffer);
                                            feature.Store();

                                            //To Indicate that the attribute table has to be updated
                                            context.Invalidate(feature);
                                        }
                                        catch (GeodatabaseException geodatabaseException)
                                        {
                                            message = geodatabaseException.Message;
                                        }
                                    }, featureClass);

                                    var task       = editOperation.ExecuteAsync();
                                    creationResult = task.Result;
                                    if (!creationResult)
                                    {
                                        message = editOperation.ErrorMessage;
                                    }

                                    break;
                                }
                        }
                    }
                }
            });

            if (!creationResult)
            {
                MessageBox.Show(message);
            }
        }