Reputation: 7524
A combination of abstract programming, poor/incomplete documentation, and cryptic errors have left me scratching my head to figure out what is causing this error:
Simply using EntityFramework to load models from a table that has a geometry column. The value of the column was set by:
var example = DbGeometry.FromText(string.Format("POINT({0} {1})", 51.5 /* Lat /*, -1.28 /* LON * /), 4326)
Reading the value back generates the exception:
24114: The label SRID=4326;POINT(51.5 in the input well-known text (WKT) is not valid. Valid labels are POINT, LINESTRING, POLYGON, MULTIPOINT, MULTILINESTRING, MULTIPOLYGON, GEOMETRYCOLLECTION, CIRCULARSTRING, COMPOUNDCURVE, CURVEPOLYGON and FULLGLOBE (geography Data Type only).
With a stacktrace:
[FormatException: 24114: The label SRID=4326;POINT(51.5 in the input well-known text (WKT) is not valid. Valid labels are POINT, LINESTRING, POLYGON, MULTIPOINT, MULTILINESTRING, MULTIPOLYGON, GEOMETRYCOLLECTION, CIRCULARSTRING, COMPOUNDCURVE, CURVEPOLYGON and FULLGLOBE (geography Data Type only).]
Microsoft.SqlServer.Types.OpenGisTypes.ParseLabel(String input) +326
Microsoft.SqlServer.Types.WellKnownTextReader.ParseTaggedText(OpenGisType type) +99
Microsoft.SqlServer.Types.WellKnownTextReader.Read(OpenGisType type, Int32 srid) +47
Microsoft.SqlServer.Types.SqlGeometry.GeometryFromText(OpenGisType type, SqlChars text, Int32 srid) +485
Microsoft.SqlServer.Types.SqlGeometry.Parse(SqlString s) +222
My first observation is the use of Microsoft.SqlServer namespace which seems inconsistent since I'm using the MySQL provider.
Does the MySQL .NET Connector not support SRIDs? Has it not registered properly? (Basically I'm trying to work out what units the .Distance()
method on a DbGeometry
object is returning, so far it seems to be a random decimal.
Upvotes: 3
Views: 6358
Reputation: 3373
This isn't a complete answer to your question and i'm not entirely sure why you're getting the error, but I had some advice and it was too long for comments.
You need to specify Longitude before Latitude when creating the point. Your coordinates are technically valid either way given their values, but of course you will experience issues in other regions and if you ever mapped it, that coordinate would not be in the UK where you'd expect with the sample coordinates.
Additionally, if you know it's a point, use the DbGeometry.PointFromText(WKT, SRID) method - it's just easier to read.
double lng = -1.28;
double lat = 51.5;
var wkt = String.Format("POINT({0} {1})", lng, lat);
var geometry = DbGeometry.PointFromText(wkt, 4326);
I'd also recommend using Geography rather than Geometry if you're using a latitude / longitude system - or is there a specific reason for using Geometry? The methods above are available in DbGeography.
Edit: The unit (or random decimal as you put it) for STDistance() is in metres.
Good luck in finding the source of the error.
Upvotes: 2