Define Precision Grid for File GDB Layer in Aspose.GIS

Introduction

In this tutorial, we will explore how to define a precision grid for a File Geodatabase (GDB) layer using Aspose.GIS for .NET. Aspose.GIS is a powerful .NET library that provides comprehensive geospatial functionality to work with various GIS file formats.

Prerequisites

Before we begin, ensure you have the following prerequisites installed:

  1. Visual Studio: Ensure you have Visual Studio installed on your system.
  2. Aspose.GIS for .NET Library: Download and install the Aspose.GIS for .NET library from the website.
  3. Basic Knowledge of C#: Familiarity with C# programming language will be beneficial for understanding the code examples.

Import Namespaces

First, let’s import the necessary namespaces to work with Aspose.GIS:

using Aspose.Gis;
using Aspose.Gis.Formats.FileGdb;
using Aspose.Gis.Geometries;
using Aspose.Gis.SpatialReferencing;
using System;
using System.Text;

Now, let’s break down each step of defining a precision grid for a File GDB layer.

Step 1: Create a Dataset

var path = "Your Document Directory" + "PrecisionGrid_out.gdb";
using (var dataset = Dataset.Create(path, Drivers.FileGdb))
{

Here, we create a new dataset in a File Geodatabase format by specifying the path and using the Dataset.Create method.

Step 2: Define Precision Grid Options

var options = new FileGdbOptions
{
    CoordinatePrecisionGrid = new FileGdbCoordinatePrecisionGrid
    {
        XOrigin = -400,
        YOrigin = -400,
        XYScale = 1e10,
        MOrigin = 0,
        MScale = 1e4,
    },
    EnsureValidCoordinatesRange = true,
};

In this step, we define precision grid options for the File GDB layer. We specify the X and Y origins, XY scale, M origin, M scale, and ensure that valid coordinate ranges are enforced.

Step 3: Create a Layer

using (var layer = dataset.CreateLayer("layer_name", options, SpatialReferenceSystem.Wgs84))
{

Here, we create a new layer within the dataset with the specified name and options. We use the WGS84 spatial reference system.

Step 4: Add Features to the Layer

var feature = layer.ConstructFeature();
feature.Geometry = new Point(10, 20) { M = 10.1282 };
layer.Add(feature);
feature = layer.ConstructFeature();
feature.Geometry = new Point(-410, 0) { M = 20.2343 };

In this step, we construct features with point geometries and add them to the layer. Note that adding a feature with coordinates outside the defined precision grid will throw an exception.

Step 5: Handle Exceptions

try
{
    layer.Add(feature);
}
catch (GisException e)
{
    Console.WriteLine(e.Message); // X value -410 is out of valid range.
}

Here, we handle exceptions that may occur when adding features to the layer outside the valid coordinate range.

Conclusion

In this tutorial, we learned how to define a precision grid for a File GDB layer using Aspose.GIS for .NET. By following the step-by-step guide, you can efficiently work with geospatial data in your .NET applications.

FAQ’s

Can I use Aspose.GIS for .NET with other GIS file formats?

Yes, Aspose.GIS for .NET supports various GIS file formats, including Shapefile, GeoJSON, KML, and more.

Is Aspose.GIS for .NET compatible with .NET Core?

Yes, Aspose.GIS for .NET is compatible with both .NET Framework and .NET Core.

Can I perform spatial operations using Aspose.GIS for .NET?

Yes, you can perform spatial operations such as buffering, intersection, and distance calculation using Aspose.GIS for .NET.

Does Aspose.GIS for .NET provide support for coordinate transformations?

Yes, Aspose.GIS for .NET provides support for coordinate transformations between different spatial reference systems.

Is there a trial version available for Aspose.GIS for .NET?

Yes, you can download a free trial version of Aspose.GIS for .NET from the website.