I know how to compose a SqlGeometry
using SqlGeometryBuilder
, for example:
// using Microsoft.SqlServer.Types;
SqlGeometryBuilder geometryBuilder = new SqlGeometryBuilder();
geometryBuilder.SetSrid(…);
geometryBuilder.BeginGeometry(OpenGisGeometryType.Polygon);
geometryBuilder.BeginFigure(0, 0);
geometryBuilder.AddLine(…);
…
geometryBuilder.EndFigure();
geometryBuilder.EndGeometry();
SqlGeometry geometry = geometryBuilder.ConstructedGeometry;
Once a SqlGeometry
is built, it's pretty much an opaque object, and inspecting its constituent parts (e.g. the line segments its boundary is made up from, and those lines' end points) using the ST…
methods methods (STNumPoints
, STPointN
, STNumCurves
, STCurveN
, STBoundary
, etc.) feels a little cumbersome to me.
Is there something in Microsoft.SqlServer.Types
or the .NET Framework Class Library that is the logical opposite of SqlGeometryBuilder
, i.e. something that I could use to decompose a SqlGeometry
into its constituent parts? I imagine that what I am looking for might possibly make use of the visitor pattern.
The
Microsoft.SqlServer.Types
API does offer functionality opposite toSqlGeometryBuilder
, in the form of theSqlGeometry.Populate(IGeometrySink110)
method.This method accepts an object implementing the
IGeometrySink110
interface, whose definition very closely mirrors that ofSqlGeometryBuilder
. The method will "replay" the method calls that were used on aSqlGeometryBuilder
in order to construct theSqlGeometry
.For example, given the
SqlGeometry geometry
as shown in the question above, as well as the followingIGeometrySink110
implementation:Calling
geometry.Populate(new ConsoleGeometrySink())
would output the following:which mirrors exactly the original steps performed to build the
SqlGeometry
.