Aspose.GIS for .NET 24.8 (MSI) brings exciting enhancements for developers working with geospatial data. This release simplifies layer manipulation within datasets and allows you to edit and rename layers directly.
Simplified Layer Editing
Effortlessly edit layers within a dataset using the newly added EditLayerAt
and EditLayer
methods in this release of the .NET geospatial data manipulation API. This update allows you to make direct changes to existing feature data or geometries.
Code example:
public void EditLayerInDatasetByName()
{
string path = ".gdbtable";
using (var dataset = Dataset.Create(path, Drivers.FileGdb))
{
using (var layer = dataset.CreateLayer("l1"))
{
layer.Attributes.Add(new FeatureAttribute("attribute", AttributeDataType.String));
var feature = layer.ConstructFeature();
feature.SetValue("attribute", "value");
layer.Add(feature);
}
}
using (var dataset = Dataset.Open(path, Drivers.FileGdb))
{
Assert.AreEqual(1, dataset.LayersCount);
using (var layer = dataset.EditLayer("l1"))
{
AddFeature(layer, "attribute", "value_2");
}
}
using (var dataset = Dataset.Open(path, Drivers.FileGdb))
{
Assert.AreEqual(1, dataset.LayersCount);
using (var layer = dataset.OpenLayerAt(0))
{
Assert.AreEqual(2, layer.Count);
var feature_1 = layer[0];
Assert.AreEqual("value", feature_1.GetValue<string>("attribute"));
var feature_2 = layer[1];
Assert.AreEqual("value_2", feature_2.GetValue<string>("attribute"));
}
}
}
public void EditLayerInDatasetByIndex()
{
string path = ".gdbtable";
using (var dataset = Dataset.Create(path, Drivers.FileGdb))
{
using (var layer = dataset.CreateLayer())
{
layer.Attributes.Add(new FeatureAttribute("attribute", AttributeDataType.String));
var feature = layer.ConstructFeature();
feature.SetValue("attribute", "value");
layer.Add(feature);
}
}
using (var dataset = Dataset.Open(path, Drivers.FileGdb))
{
Assert.AreEqual(1, dataset.LayersCount);
using (var layer = dataset.EditLayerAt(0))
{
var feature = layer.ConstructFeature();
feature.SetValue("attribute", "value_1");
feature.Geometry = new Point(7, 7);
layer.ReplaceAt(0, feature);
AddFeature(layer, "attribute", "value_2");
}
}
using (var dataset = Dataset.Open(path, Drivers.FileGdb))
{
Assert.AreEqual(1, dataset.LayersCount);
using (var resultLayer = dataset.OpenLayerAt(0))
{
Assert.AreEqual(2, resultLayer.Count);
var feature_1 = resultLayer[0];
Assert.AreEqual("value_1", feature_1.GetValue<string>("attribute"));
var feature_2 = resultLayer[1];
Assert.AreEqual("value_2", feature_2.GetValue<string>("attribute"));
Assert.AreEqual(new Point(7, 7), resultLayer[0].Geometry);
}
}
}
Source*
Layer Renaming
You can now rename layers and enhance code clarity and organization within datasets using the new RenameLayer
method.
Code example:
public void RenameLayerInDataset()
{
string path = ".gdbtable";
using (var dataset = Dataset.Create(path, Drivers.FileGdb))
{
using (var layer = dataset.CreateLayer("l1"))
{
layer.Attributes.Add(new FeatureAttribute("attribute", AttributeDataType.String));
AddFeature(layer, "attribute", "value");
}
using (var layer = dataset.CreateLayer("l2"))
{
layer.Attributes.Add(new FeatureAttribute("attribute", AttributeDataType.String));
AddFeature(layer, "attribute", "value");
}
using (var layer = dataset.CreateLayer("l3"))
{
layer.Attributes.Add(new FeatureAttribute("attribute", AttributeDataType.String));
AddFeature(layer, "attribute", "value");
}
}
using (var dataset = Dataset.Open(path, Drivers.FileGdb))
{
Assert.AreEqual(3, dataset.LayersCount);
using (var layer = dataset.EditLayer("l3"))
{
AddFeature(layer, "attribute", "value_2");
}
dataset.RenameLayer("l3", "new_l3");
}
using (var dataset = Dataset.Open(path, Drivers.FileGdb))
{
Assert.AreEqual(3, dataset.LayersCount);
using (var layer = dataset.OpenLayerAt(2))
{
Assert.AreEqual(2, layer.Count);
var feature_1 = layer[0];
Assert.AreEqual("value", feature_1.GetValue<string>("attribute"));
var feature_2 = layer[1];
Assert.AreEqual("value_2", feature_2.GetValue<string>("attribute"));
Assert.AreEqual(true, dataset.HasLayerWithName("l1"));
Assert.AreEqual(true, dataset.HasLayerWithName("l2"));
Assert.AreEqual(true, dataset.HasLayerWithName("new_l3"));
Assert.AreEqual(false, dataset.HasLayerWithName("l3"));
}
}
}
Source*
Improved GDB Geometry Handling
Aspose.GIS for .NET v24.8 includes the ability to correctly identify geometry types in layers with empty geometries within GDB files.
Code example:
public void CheckGeometryType()
{
string outputPath = "somepath.gdb";
CopyDirectory(GetPath("ThreeLayers.gdb"), outputPath);
using (var dataset = Dataset.Open(outputPath, Drivers.FileGdb))
{
using (dataset.CreateLayer("unnamed_layer_1")) { }
using (dataset.CreateLayer()) { }
using (var layer = dataset.CreateLayer("new_layer", new FileGdbOptions(), SpatialReferenceSystem.Wgs72))
{
layer.Attributes.Add(new FeatureAttribute("color", AttributeDataType.String));
var feature = layer.ConstructFeature();
feature.SetValue("color", "red");
feature.Geometry = new Point(1, 2);
layer.Add(feature);
}
Assert.AreEqual(6, dataset.LayersCount);
}
using (var dataset = Dataset.Open(outputPath, Drivers.FileGdb))
{
Assert.AreEqual(6, dataset.LayersCount);
Assert.AreEqual(GeometryType.Point, dataset.OpenLayerAt(0).GeometryType);
Assert.AreEqual(GeometryType.MultiPoint, dataset.OpenLayerAt(1).GeometryType);
Assert.AreEqual(GeometryType.Null, dataset.OpenLayerAt(2).GeometryType);
Assert.AreEqual(GeometryType.Null, dataset.OpenLayerAt(3).GeometryType);
Assert.AreEqual(GeometryType.Null, dataset.OpenLayerAt(4).GeometryType);
Assert.AreEqual(GeometryType.Point, dataset.OpenLayerAt(5).GeometryType);
using (var layer = dataset.OpenLayer("new_layer"))
{
Assert.IsTrue(SpatialReferenceSystem.Wgs72.IsEquivalent(layer.SpatialReferenceSystem));
Assert.AreEqual(1, layer.Count);
Assert.AreEqual("red", layer[0].GetValue<string>("color"));
Assert.AreEqual(new Point(1, 2) { SpatialReferenceSystem = SpatialReferenceSystem.Wgs72 }, layer[0].Geometry);
Assert.AreEqual(GeometryType.Point, layer.GeometryType);
}
}
}
Source*
Bug Fix
We have addressed a potential OutOfMemory
exception encountered while working with GeoTIFF files to ensure a more stable development experience.
Public API and Backward Incompatible Changes
Added API Members
- Method:Aspose.Gis.Dataset.EditLayerAt(System.Int32,Aspose.Gis.DriverOptions,Aspose.Gis.SpatialReferencing.SpatialReferenceSystem)
- Method:Aspose.Gis.Dataset.EditLayerAt(System.Int32,Aspose.Gis.DriverOptions,Aspose.Gis.SpatialReferencing.SpatialReferenceSystem)
- Method:Aspose.Gis.Dataset.HasLayerWithName(System.String)
- Method:Aspose.Gis.Dataset.RenameLayer(System.String,System.String)
You can view the list of all new features, enhancements, and bug fixes introduced in this release by visiting Aspose.GIS for .NET 24.8 Release Notes.