Пример #1
0
        private static void ModifyFeaturesInDataset()
        {
            // -- copy test dataset, to avoid modification of test data.
            var path        = Path.Combine(RunExamples.GetDataDir(), "ThreeLayers.gdb");
            var datasetPath = RunExamples.GetDataDir() + "ModifyFeaturesInDataset_out.gdb";

            RunExamples.CopyDirectory(path, datasetPath);
            // --

            //ExStart: ModifyFeaturesInDataset
            using (Dataset dataset = Dataset.Open(datasetPath, Drivers.FileGdb))
            {
                using (var source = dataset.OpenLayer("layer2"))
                    using (var result = dataset.CreateLayer("modified", source.SpatialReferenceSystem))
                    {
                        result.CopyAttributes(source);

                        foreach (var feature in source)
                        {
                            // modify the geometry
                            var modifiedGeometry = feature.Geometry.GetBuffer(2.0);
                            feature.Geometry = modifiedGeometry;

                            // modify a feature attribute
                            var attributeValue         = feature.GetValue <double>("Value");
                            var modifiedAttributeValue = attributeValue * 2;
                            feature.SetValue("Value", modifiedAttributeValue);

                            result.Add(feature);
                        }
                    }

                // optional: remove the source layer from the dataset
                dataset.RemoveLayer("layer2");
            }
            //ExEnd: ModifyFeaturesInDataset
        }