Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions src/NetTopologySuite/IO/WKTConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,37 @@ public class WKTConstants
/// </summary>
public const string TIN = "TIN";

/// <summary>
/// Token text for ISO/IEC 13249-3 §4.2.7 ST_Circle. Instantiable;
/// NTS has no carrier yet — the reader names the type and refuses.
/// </summary>
public const string CIRCLE = "CIRCLE";
/// <summary>
/// Token text for ISO/IEC 13249-3 §4.2.8 ST_GeodesicString.
/// Instantiable; named refuse until a carrier exists.
/// </summary>
public const string GEODESICSTRING = "GEODESICSTRING";
/// <summary>
/// Token text for ISO/IEC 13249-3 §4.2.9 ST_EllipticalCurve.
/// Instantiable; named refuse until a carrier exists.
/// </summary>
public const string ELLIPTICALCURVE = "ELLIPTICALCURVE";
/// <summary>
/// Token text for ISO/IEC 13249-3 §4.2.10 ST_NURBSCurve.
/// Instantiable; named refuse until a carrier exists.
/// </summary>
public const string NURBSCURVE = "NURBSCURVE";
/// <summary>
/// Token text for ISO/IEC 13249-3 §4.2.11 ST_Clothoid.
/// Instantiable; named refuse until a carrier exists.
/// </summary>
public const string CLOTHOID = "CLOTHOID";
/// <summary>
/// Token text for ISO/IEC 13249-3 §4.2.12 ST_SpiralCurve.
/// Instantiable; named refuse until a carrier exists.
/// </summary>
public const string SPIRALCURVE = "SPIRALCURVE";

/// <summary>
/// Token text for empty geometries
/// </summary>
Expand Down
42 changes: 42 additions & 0 deletions src/NetTopologySuite/IO/WKTReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,8 @@ internal Geometry ReadGeometryTaggedText(TokenStream tokens)
returned = ReadTriangleText(tokens, factory, ordinateFlags);
else if (IsTypeName(tokens, type, WKTConstants.TIN))
returned = ReadTinText(tokens, factory, ordinateFlags);
else if (IsUnimplementedSqlMmCurve(type))
throw SqlMmUnimplemented(type);
else throw new ParseException("Unknown type: " + type);

if (returned == null)
Expand Down Expand Up @@ -802,6 +804,43 @@ private static bool IsTypeName(TokenStream tokens, string type, string typeName)
return true;
}

/// <summary>
/// True when <paramref name="type"/> is <paramref name="typeName"/>
/// with an optional Z / M / ZM suffix. Unlike <see cref="IsTypeName"/>,
/// a longer leftover (CIRCULARSTRING vs CIRCLE) is not an error — it
/// is simply not a match.
/// </summary>
private static bool HasTypeNameWithDimSuffix(string type, string typeName)
{
if (!type.StartsWith(typeName, StringComparison.OrdinalIgnoreCase))
return false;
string modifiers = type.Substring(typeName.Length);
return modifiers.Length == 0
|| modifiers.Equals(WKTConstants.Z, StringComparison.OrdinalIgnoreCase)
|| modifiers.Equals(WKTConstants.M, StringComparison.OrdinalIgnoreCase)
|| modifiers.Equals(WKTConstants.ZM, StringComparison.OrdinalIgnoreCase);
}

/// <summary>
/// Instantiable ST_Curve subtypes in ISO/IEC 13249-3 §4.2.1 that NTS
/// does not yet carry. Not optional extras. Do not call them unknown.
/// </summary>
private static bool IsUnimplementedSqlMmCurve(string type)
{
return HasTypeNameWithDimSuffix(type, WKTConstants.CLOTHOID)
|| HasTypeNameWithDimSuffix(type, WKTConstants.CIRCLE)
|| HasTypeNameWithDimSuffix(type, WKTConstants.GEODESICSTRING)
|| HasTypeNameWithDimSuffix(type, WKTConstants.ELLIPTICALCURVE)
|| HasTypeNameWithDimSuffix(type, WKTConstants.NURBSCURVE)
|| HasTypeNameWithDimSuffix(type, WKTConstants.SPIRALCURVE);
}

private static ParseException SqlMmUnimplemented(string type)
{
return new ParseException(
"SQL/MM type is not optional (ISO/IEC 13249-3 §4.2.1) and is not implemented: " + type);
}

/// <summary>
/// Creates a <c>Point</c> using the next token in the stream.
/// </summary>
Expand Down Expand Up @@ -1078,6 +1117,9 @@ private Curve ReadCurveText(TokenStream tokens, GeometryFactory factory, Ordinat
return ReadCompoundCurveText(tokens, factory, ordinateFlags);
}

if (IsUnimplementedSqlMmCurve(current))
throw SqlMmUnimplemented(current);

throw new ParseException("Unexpected token: " + current);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,30 @@ public void ReadRejectsNonContiguousCompoundCurve()
Assert.Throws<ArgumentException>(() =>
new WKTReader().Read("COMPOUNDCURVE ((0 0, 1 0), (2 0, 3 0))"));
}

[TestCase("CLOTHOID EMPTY")]
[TestCase("CIRCLE EMPTY")]
[TestCase("GEODESICSTRING EMPTY")]
[TestCase("NURBSCURVE EMPTY")]
[TestCase("SPIRALCURVE EMPTY")]
[TestCase("ELLIPTICALCURVE EMPTY")]
[TestCase("CLOTHOID Z EMPTY")]
[TestCase("COMPOUNDCURVE (CLOTHOID EMPTY)")]
public void SqlMmSection421TypesAreNamedRefusesNotUnknown(string wkt)
{
var ex = Assert.Throws<ParseException>(() => new WKTReader().Read(wkt));
Assert.That(ex.Message, Does.Contain("not optional"));
Assert.That(ex.Message, Does.Contain("13249-3"));
Assert.That(ex.Message, Does.Not.Contain("Unknown type"));
Assert.That(ex.Message, Does.Not.Contain("Unexpected token"));
}

[Test]
public void GenuineUnknownTypeStaysUnknown()
{
var ex = Assert.Throws<ParseException>(() => new WKTReader().Read("NOTATYPE (0 0)"));
Assert.That(ex.Message, Does.Contain("Unknown type"));
Assert.That(ex.Message, Does.Not.Contain("not optional"));
}
}
}
Loading