0

I am calling a web service in my C# code. The service returns Geometry in WKT (well known text).

When printing out the returned WKT in a message box, it looks as follows:

POINT(-9206304.681343028 5363253.767605823)

However when I attempt to create an SQLChar from this string and invoke STGeomFromText to create a point, I get the following error

{"24114: The label ???POINT(-9206304.68 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)."}

I am not sure why the entire string till the coordinate separator is perceived as the label in this case instead of the actual "POINT" label.

Here is my C# code:

// Call the webservice.
byte[] responseBody = webClient.UploadData(uri, requestMethod, requestBodyBytes);

string ProjectedWKTString = Encoding.ASCII.GetString(responseBody);

SqlString anSQLString = new SqlString(ProjectedWKTString);
SqlChars anSQLChar = new SqlChars(anSQLString);

SqlGeometry projectedPoint = SqlGeometry.STGeomFromText(anSQLChar, 3857);

I have been investigating this for a while. Any help is very much appreciated

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Ihab
  • 1
  • It works if the SRID is 0, `select geometry::STGeomFromText('POINT(-9206304.681343028 5363253.767605823)', 0)` so what's SRID 3857? – AlwaysLearning Nov 12 '19 at 21:42
  • Your select statement works too for srid 3857. SRID 3857 is web mercator auxillary sphere https://epsg.io/3857. This does not explain why the C# code above does not parse the point string correctly. – Ihab Nov 12 '19 at 23:55
  • These question marks ??? in the error message are suspicious. Are they part of WKT string? Make sure the bytes you get are really ASCII and don't have UTF8 prefix or something like this in front. – Michael Entin Nov 13 '19 at 03:45
  • Thanks Michael. I changed the code to retrieve the response in UTF8: string ProjectedWKTString = Encoding.UTF8.GetString(responseBody); The question marks disappeared from the error message but i still get error. 24114: The label POINT (-9206304.681 in the input well-known text (WKT) is not valid.... – Ihab Nov 13 '19 at 17:21

0 Answers0