public static void Run() { //ExStart: CreateFileGdbDatasetWithSingleLayer var path = RunExamples.GetDataDir() + "CreateFileGdbDatasetWithSingleLayer_out.gdb"; var options = new FileGdbOptions(); using (var layer = VectorLayer.Create(path, Drivers.FileGdb, options, SpatialReferenceSystem.Wgs84)) // this 'using' is equivalent to // using (var dataset = Dataset.Create(path, Drivers.FileGdb)) // using (var layer = Dataset.CreateLayer("layer")) { var feature = layer.ConstructFeature(); feature.Geometry = new LineString(new[] { new Point(1, 2), new Point(3, 4), }); layer.Add(feature); } using (var dataset = Dataset.Open(path, Drivers.FileGdb)) using (var layer = dataset.OpenLayer("layer")) { Console.WriteLine("Features count: {0}", layer.Count); // 1 } //ExEnd: CreateFileGdbDatasetWithSingleLayer }
public static void Run() { //ExStart: SpecifyNamesOfObjectIdAndGeometryFields var path = RunExamples.GetDataDir() + "NamesOfObjectIdAndGeometryFields_out.gdb"; using (var dataset = Dataset.Create(path, Drivers.FileGdb)) { var options = new FileGdbOptions { // name object ID field 'OID' rather than the default 'OBJECTID'. ObjectIdFieldName = "OID", // name geometry field 'POINT' rather than the default 'SHAPE'. GeometryFieldName = "POINT", }; using (var layer = dataset.CreateLayer("layer_name", options, SpatialReferenceSystem.Wgs84)) { var feature = layer.ConstructFeature(); feature.Geometry = new Point(12.32, 34.21); layer.Add(feature); } using (var layer = dataset.OpenLayer("layer_name")) { var feature = layer[0]; Console.WriteLine(feature.GetValue <int>("OID")); // 1 } } //ExEnd: SpecifyNamesOfObjectIdAndGeometryFields }
public static void Run() { //ExStart: SpecifyPrecisionGridForFileGdbLayer var path = RunExamples.GetDataDir() + "PrecisionGrid_out.gdb"; using (var dataset = Dataset.Create(path, Drivers.FileGdb)) { var options = new FileGdbOptions { // specify coordinate precision grid parameters (origins and scales for coordinates) CoordinatePrecisionGrid = new FileGdbCoordinatePrecisionGrid { // all our coordinates must be more than (-400, -400) point XOrigin = -400, YOrigin = -400, // the write precision is 10 digits after the decimal point XYScale = 1e10, // M values are started at 0 and precision is 4 digits after the decimal point MOrigin = 0, MScale = 1e4, }, // throw whenever an attempt to write coordinate that does not fit precision grid is detected EnsureValidCoordinatesRange = true, }; using (var layer = dataset.CreateLayer("layer_name", options, SpatialReferenceSystem.Wgs84)) { var feature = layer.ConstructFeature(); feature.Geometry = new Point(10, 20) { M = 10.1282 }; layer.Add(feature); feature = layer.ConstructFeature(); // X == -410 is less than XOrigin, so an exception is thrown feature.Geometry = new Point(-410, 0) { M = 20.2343 }; try { layer.Add(feature); } catch (GisException e) { Console.WriteLine(e.Message); // X value -410 is out of valid range. } } } //ExEnd: SpecifyPrecisionGridForFileGdbLayer }
public static void Run() { //ExStart: SpecifyTolerancesForFileGdbLayer var path = RunExamples.GetDataDir() + "TolerancesForFileGdbLayer_out.gdb"; using (var dataset = Dataset.Create(path, Drivers.FileGdb)) { var options = new FileGdbOptions { XYTolerance = 0.001, ZTolerance = 0.1, MTolerance = 0.1, }; using (var layer = dataset.CreateLayer("layer_name", options)) { // layer is created with the provided tolerances and some ArcGIS features/tools will use it } } //ExEnd: SpecifyTolerancesForFileGdbLayer }