Work with Curved Geometries using GIS C# Library
Contents
[
Hide
]
Aspose.GIS C# Library supports working with non-linear geometries, like CircularString and CurvePolygon. You may read and write curved geometries to FileGDB, WKT, WKB, and GML files.
Create a Circular String
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-gis/Aspose.GIS-for-.NET | |
string path = RunExamples.GetDataDir() + "CreateCircularString_out.shp"; | |
using (VectorLayer layer = VectorLayer.Create(path, Drivers.Shapefile)) | |
{ | |
var feature = layer.ConstructFeature(); | |
// create a circle with center at (1,0) and radius 1. | |
var circularString = new CircularString(); | |
circularString.AddPoint(0, 0); | |
circularString.AddPoint(1, 1); | |
circularString.AddPoint(2, 0); | |
circularString.AddPoint(1, -1); | |
circularString.AddPoint(0, 0); | |
feature.Geometry = circularString; | |
layer.Add(feature); | |
} |
Create a Compound Curve
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-gis/Aspose.GIS-for-.NET | |
string path = RunExamples.GetDataDir() + "CreateCompoundCurve_out.shp"; | |
using (VectorLayer layer = VectorLayer.Create(path, Drivers.Shapefile)) | |
{ | |
var feature = layer.ConstructFeature(); | |
// create an 'S' letter (starts at bottom left end) | |
var compoundCurve = new CompoundCurve(); | |
var bottom = (ILineString)Geometry.FromText("LineString (0 0, 3 0)"); | |
var firstArc = (ICircularString)Geometry.FromText("CircularString (3 0, 4 1, 3 2)"); | |
var middle = (ILineString)Geometry.FromText("LineString (3 2, 1 2)"); | |
var secondArc = (ICircularString)Geometry.FromText("CircularString (1 2, 0 3, 1 4)"); | |
var top = (ILineString)Geometry.FromText("LineString (1 4, 4 4)"); | |
compoundCurve.AddCurve(bottom); | |
compoundCurve.AddCurve(firstArc); | |
compoundCurve.AddCurve(middle); | |
compoundCurve.AddCurve(secondArc); | |
compoundCurve.AddCurve(top); | |
feature.Geometry = compoundCurve; | |
layer.Add(feature); | |
} |
Create a Curved Polygon
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-gis/Aspose.GIS-for-.NET | |
string path = RunExamples.GetDataDir() + "CreateCurvePolygon_out.shp"; | |
using (VectorLayer layer = VectorLayer.Create(path, Drivers.Shapefile)) | |
{ | |
var feature = layer.ConstructFeature(); | |
// create a torus with center at (0,0), radius equal to 2 and hole radius equal to 1 | |
var curvePolygon = new CurvePolygon(); | |
var exterior = new CircularString(); | |
exterior.AddPoint(-2, 0); | |
exterior.AddPoint(0, 2); | |
exterior.AddPoint(2, 0); | |
exterior.AddPoint(0, -2); | |
exterior.AddPoint(-2, 0); | |
curvePolygon.ExteriorRing = exterior; | |
var interior = new CircularString(); | |
interior.AddPoint(-1, 0); | |
interior.AddPoint(0, 1); | |
interior.AddPoint(1, 0); | |
interior.AddPoint(0, -1); | |
interior.AddPoint(-1, 0); | |
curvePolygon.AddInteriorRing(interior); | |
feature.Geometry = curvePolygon; | |
layer.Add(feature); | |
} |
Create Multi-Curve
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-gis/Aspose.GIS-for-.NET | |
string path = RunExamples.GetDataDir() + "CreateMultiCurve_out.shp"; | |
using (VectorLayer layer = VectorLayer.Create(path, Drivers.Shapefile)) | |
{ | |
var feature = layer.ConstructFeature(); | |
var multiCurve = new MultiCurve(); | |
multiCurve.Add(Geometry.FromText("LineString (0 0, 1 0)")); | |
multiCurve.Add(Geometry.FromText("CircularString (2 2, 3 3, 4 2)")); | |
multiCurve.Add(Geometry.FromText("CompoundCurve ((0 1, 0 0), CircularString (0 0, 3 3, 6 0))")); | |
feature.Geometry = multiCurve; | |
layer.Add(feature); | |
} |
Create Multi-Surface
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-gis/Aspose.GIS-for-.NET | |
string path = RunExamples.GetDataDir() + "CreateMultiSurface_out.json"; | |
using (VectorLayer layer = VectorLayer.Create(path, Drivers.GeoJson)) | |
{ | |
var feature = layer.ConstructFeature(); | |
var multiSurface = new MultiSurface(); | |
var polygon = Geometry.FromText("Polygon ((0 0, 0 1, 1 1, 1 0, 0 0))"); | |
multiSurface.Add(polygon); | |
var curvePolygon = Geometry.FromText("CurvePolygon (CircularString (-2 0, 0 2, 2 0, 0 -2, -2 0))"); | |
multiSurface.Add(curvePolygon); | |
feature.Geometry = multiSurface; | |
layer.Add(feature); | |
} |
Determine If Geometry Has Curves
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-gis/Aspose.GIS-for-.NET | |
var geometryWithoutCurves = Geometry.FromText(@"GeometryCollection (LineString (0 0, 1 1, 2 0),CompoundCurve ((4 0, 5 1), (5 1, 6 2, 7 1)))"); | |
// geometry does not contain circular string, so HasCurveGeometry returns false. | |
Console.WriteLine(geometryWithoutCurves.HasCurveGeometry); // False | |
var geometry = Geometry.FromText(@"GeometryCollection (LineString (0 0, 1 1, 2 0),CompoundCurve ((4 0, 5 1), CircularString (5 1, 6 2, 7 1)))"); | |
// geometry contains circular string, so HasCurveGeometry returns true. | |
Console.WriteLine(geometry.HasCurveGeometry); // True |
Linearize Geometry
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-gis/Aspose.GIS-for-.NET | |
string path = RunExamples.GetDataDir() + "LinearizeGeometry_out.kml"; | |
using (var layer = Drivers.Kml.CreateLayer(path)) | |
{ | |
var feature = layer.ConstructFeature(); | |
var geometry = Geometry.FromText(@"GeometryCollection (LineString (0 0, 1 1, 2 0),CompoundCurve ((4 0, 5 1), CircularString (5 1, 6 2, 7 1)))"); | |
// creates linear geometry that approximates input geometry | |
var linear = geometry.ToLinearGeometry(); | |
feature.Geometry = linear; | |
layer.Add(feature); | |
} |
Specify Linearization Tolerance
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-gis/Aspose.GIS-for-.NET | |
// If file format does not support curve geometries, we linearize them on write. | |
// This example shows how to specify tolerance of the linearization. | |
var options = new GeoJsonOptions | |
{ | |
// linearized geometry must be within 1e-4 from curve geometry | |
LinearizationTolerance = 1e-4, | |
}; | |
string path = RunExamples.GetDataDir() + "SpecifyLinearizationTolerance_out.json"; | |
using (VectorLayer layer = VectorLayer.Create(path, Drivers.GeoJson, options)) | |
{ | |
var curveGeometry = Geometry.FromText("CircularString (0 0, 1 1, 2 0)"); | |
var feature = layer.ConstructFeature(); | |
feature.Geometry = curveGeometry; | |
// geometry is linearized with tolerance 1e-4 | |
layer.Add(feature); | |
} |