public static void Run() { //ExStart: LimitPrecisionWhenReadingGeometries string path = RunExamples.GetDataDir() + "LimitPrecisionWhenReadingGeometries_out.shp"; using (VectorLayer layer = VectorLayer.Create(path, Drivers.Shapefile)) { var feature = layer.ConstructFeature(); feature.Geometry = new Point(1.10234, 2.09743); layer.Add(feature); } var options = new ShapefileOptions(); // read data as-is. options.XYPrecisionModel = PrecisionModel.Exact; using (VectorLayer layer = VectorLayer.Open(path, Drivers.Shapefile, options)) { var point = (IPoint)layer[0].Geometry; // 1.10234, 2.09743 Console.WriteLine("{0}, {1}", point.X, point.Y); } // truncate all X and Y, so only two fractional digits are left. options.XYPrecisionModel = PrecisionModel.Rounding(2); using (VectorLayer layer = VectorLayer.Open(path, Drivers.Shapefile, options)) { var point = (IPoint)layer[0].Geometry; // 1.1, 2.1 Console.WriteLine("{0}, {1}", point.X, point.Y); } //ExEnd: LimitPrecisionWhenReadingGeometries }
public static void Run() { //ExStart: LimitPrecisionWhenWritingGeometries var options = new GeoJsonOptions { // write only 3 fractional digits of X and Y coordinates. XYPrecisionModel = PrecisionModel.Rounding(3), // write all fractional digits of Z coordinate (the default, you don't have to specify it) ZPrecisionModel = PrecisionModel.Exact }; var path = RunExamples.GetDataDir() + "LimitPrecisionWhenWritingGeometries_out.json"; using (VectorLayer layer = VectorLayer.Create(path, Drivers.GeoJson, options)) { var point = new Point(); point.X = 1.8888888; point.Y = 1.00123; point.Z = 1.123456789; Feature feature = layer.ConstructFeature(); feature.Geometry = point; layer.Add(feature); } using (VectorLayer layer = VectorLayer.Open(path, Drivers.GeoJson)) { var point = (IPoint)layer[0].Geometry; // 1.889, 1.001, 1.123456789 Console.WriteLine("{0}, {1}, {2}", point.X, point.Y, point.Z); } //ExEnd: LimitPrecisionWhenWritingGeometries }