public static void Run() { //ExStart: RemoveLayersFromFileGdbDataset // -- copy test dataset, to avoid modification of test data. //var datasetPath = GetOutputPath(".gdb"); var path = RunExamples.GetDataDir() + "ThreeLayers.gdb"; var datasetPath = RunExamples.GetDataDir() + "RemoveLayersFromFileGdbDataset_out.gdb"; RunExamples.CopyDirectory(path, datasetPath); // -- using (var dataset = Dataset.Open(datasetPath, Drivers.FileGdb)) { Console.WriteLine(dataset.CanRemoveLayers); // True Console.WriteLine(dataset.LayersCount); // 3 // remove layer by index dataset.RemoveLayerAt(2); Console.WriteLine(dataset.LayersCount); // 2 // remove layer by name dataset.RemoveLayer("layer1"); Console.WriteLine(dataset.LayersCount); // 1 } //ExEnd: RemoveLayersFromFileGdbDataset }
public static void Run() { //ExStart: AddLayerToFileGdbDataset // -- copy test dataset, to avoid modification of test data. var path = RunExamples.GetDataDir() + "ThreeLayers.gdb"; var datasetPath = RunExamples.GetDataDir() + "AddLayerToFileGdbDataset_out.gdb"; RunExamples.CopyDirectory(path, datasetPath); // -- using (var dataset = Dataset.Open(datasetPath, Drivers.FileGdb)) { Console.WriteLine(dataset.CanCreateLayers); // True using (var layer = dataset.CreateLayer("data", SpatialReferenceSystem.Wgs84)) { layer.Attributes.Add(new FeatureAttribute("Name", AttributeDataType.String)); var feature = layer.ConstructFeature(); feature.SetValue("Name", "Name_1"); feature.Geometry = new Point(12.21, 23.123, 20, -200); layer.Add(feature); } using (var layer = dataset.OpenLayer("data")) { Console.WriteLine(layer.Count); // 1 Console.WriteLine(layer[0].GetValue <string>("Name")); // "Name_1" } } //ExEnd: AddLayerToFileGdbDataset }
public static void Run() { //ExStart: ConvertGeoJsonLayerToLayerInFileGdbDataset var geoJsonPath = RunExamples.GetDataDir() + "ConvertGeoJsonLayerToLayerInFileGdbDataset_out.json"; using (VectorLayer layer = VectorLayer.Create(geoJsonPath, Drivers.GeoJson)) { layer.Attributes.Add(new FeatureAttribute("name", AttributeDataType.String)); layer.Attributes.Add(new FeatureAttribute("age", AttributeDataType.Integer)); Feature firstFeature = layer.ConstructFeature(); firstFeature.Geometry = new Point(33.97, -118.25); firstFeature.SetValue("name", "John"); firstFeature.SetValue("age", 23); layer.Add(firstFeature); Feature secondFeature = layer.ConstructFeature(); secondFeature.Geometry = new Point(35.81, -96.28); secondFeature.SetValue("name", "Mary"); secondFeature.SetValue("age", 54); layer.Add(secondFeature); } // -- // -- copy test dataset, to avoid modification of test data. var sourceFile = RunExamples.GetDataDir() + "ThreeLayers.gdb"; var destinationFile = RunExamples.GetDataDir() + "ThreeLayersCopy_out.gdb"; RunExamples.CopyDirectory(sourceFile, destinationFile); // -- using (var geoJsonLayer = VectorLayer.Open(geoJsonPath, Drivers.GeoJson)) { using (var fileGdbDataset = Dataset.Open(destinationFile, Drivers.FileGdb)) using (var fileGdbLayer = fileGdbDataset.CreateLayer("new_layer", SpatialReferenceSystem.Wgs84)) { fileGdbLayer.CopyAttributes(geoJsonLayer); foreach (var feature in geoJsonLayer) { fileGdbLayer.Add(feature); } } } //ExEnd: ConvertGeoJsonLayerToLayerInFileGdbDataset }
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 }