Class WKTReader
Converts a Well-Known Text string to a Geometry
.
The WKTReader
allows
extracting Geometry
objects from either input streams or
internal strings. This allows it to function as a parser to read Geometry
objects from text blocks embedded in other data formats (e.g. XML).
The Well-known Text format is defined in the OpenGIS Simple Features Specification for SQL .
As of version 2.0, NTS can read WKT syntax
which specifies coordinate dimension Z, M or ZM as modifiers(e.g.POINT Z)
or in the name of the geometry type(e.g.LINESTRINGZM).
If the coordinate dimension is specified it will be set in the created geometry.
If the coordinate dimension is not specified, the default behaviour is to
create XYZ geometry(this is backwards compatible with older JTS versions).
This can be altered to create XY geometry by
setting IsOldNtsCoordinateSyntaxAllowed to false
.
A reader can be set to ensure the input is structurally valid
by setting FixStructure to true
.
This ensures that geometry can be constructed without errors due to missing coordinates.
The created geometry may still be topologically invalid.
NOTE: There is an inconsistency in the SFS.
The WKT grammar states that MultiPoints
are represented by
MULTIPOINT ( ( x y), (x y) )
,
but the examples show MultiPoint
s as MULTIPOINT ( x y, x y )
.
Other implementations follow the latter syntax, so NTS will adopt it as well.
A WKTReader
is parameterized by a GeometryFactory
,
to allow it to create Geometry
objects of the appropriate
implementation. In particular, the GeometryFactory
will
determine the PrecisionModel
and SRID
that is used.
The WKTReader
will convert the input numbers to the precise
internal representation.
Inherited Members
Namespace: NetTopologySuite.IO
Assembly: NetTopologySuite.dll
Syntax
public class WKTReader
Constructors
| Improve this Doc View SourceWKTReader()
Creates a WKTReader
that creates objects using a basic GeometryFactory.
Declaration
public WKTReader()
WKTReader(GeometryFactory)
Creates a WKTReader
that creates objects using the given
GeometryFactory
.
Declaration
[Obsolete("Use a constructor with a configured NtsGeometryServices instance.")]
public WKTReader(GeometryFactory factory)
Parameters
Type | Name | Description |
---|---|---|
GeometryFactory | factory | The factory used to create |
WKTReader(NtsGeometryServices)
Creates a WKTReader
that creates objects using a basic GeometryFactory.
Declaration
public WKTReader(NtsGeometryServices ntsGeometryServices)
Parameters
Type | Name | Description |
---|---|---|
NtsGeometryServices | ntsGeometryServices |
Properties
| Improve this Doc View SourceDefaultSRID
Gets or sets the default SRID
Declaration
[Obsolete("Supply an appropriate NtsGeometryServices instance to the constructor instead. The ability to set this value after an instance is created may be removed in a future release.")]
public int DefaultSRID { get; set; }
Property Value
Type | Description |
---|---|
Int32 |
Factory
Gets or sets the factory to create geometries
Declaration
[Obsolete("Supply an appropriate NtsGeometryServices instance to the constructor instead. The ability to set this value after an instance is created may be removed in a future release.")]
public GeometryFactory Factory { get; set; }
Property Value
Type | Description |
---|---|
GeometryFactory |
FixStructure
Gets or sets a flag indicating that the structure of input geometry should be fixed
so that the geometry can be constructed without error.
This involves adding coordinates if the input coordinate sequence is shorter than required.
Declaration
public bool FixStructure { get; set; }
Property Value
Type | Description |
---|---|
Boolean |
See Also
| Improve this Doc View SourceIsOldNtsCoordinateSyntaxAllowed
Gets or sets a value indicating whether or not coordinates may have 3 ordinate values even though no Z or M ordinate indicator is present. The default value is true.
Declaration
public bool IsOldNtsCoordinateSyntaxAllowed { get; set; }
Property Value
Type | Description |
---|---|
Boolean |
IsOldNtsMultiPointSyntaxAllowed
Gets or sets a value indicating whether or not point coordinates in a MultiPoint geometry must not be enclosed in paren. The default value is true.
Declaration
public bool IsOldNtsMultiPointSyntaxAllowed { get; set; }
Property Value
Type | Description |
---|---|
Boolean |
IsStrict
Gets or sets a value indicating if the reader should attempt to repair malformed input.
Declaration
public bool IsStrict { get; set; }
Property Value
Type | Description |
---|---|
Boolean |
Remarks
Malformed in this case means the ring has too few points (4), or is not closed.
Methods
| Improve this Doc View SourceRead(Stream)
Converts a Well-known Text representation to a Geometry
.
Declaration
public Geometry Read(Stream stream)
Parameters
Type | Name | Description |
---|---|---|
Stream | stream | one or more Geometry Tagged Text strings (see the OpenGIS Simple Features Specification) separated by whitespace. |
Returns
Type | Description |
---|---|
Geometry | A |
Read(TextReader)
Converts a Well-known Text representation to a Geometry
.
Declaration
public Geometry Read(TextReader reader)
Parameters
Type | Name | Description |
---|---|---|
TextReader | reader | A Reader which will return a "Geometry Tagged Text" string (see the OpenGIS Simple Features Specification). |
Returns
Type | Description |
---|---|
Geometry | A |
Read(String)
Converts a Well-known Text representation to a Geometry
.
Declaration
public Geometry Read(string wellKnownText)
Parameters
Type | Name | Description |
---|---|---|
String | wellKnownText | one or more Geometry Tagged Text strings (see the OpenGIS Simple Features Specification) separated by whitespace. |
Returns
Type | Description |
---|---|
Geometry | A |