1
Vote

CoordinateSystemWktReader fails in Silverlight

description

CoordinateSystemWktReader fails in Silverlight when trying to parse WKT to a coordinate system. It seems to be related to the fact that in Silverlight, you must using Unicode encoding, which is 2 bytes per character instead of 1.
 
The following code throws an exception:
 
string charlotteCSWKT = "PROJCS[\"NAD83 / North Carolina (ftUS)\",GEOGCS[\"NAD83\",DATUM[\"North_American_Datum_1983\",SPHEROID[\"GRS 1980\",6378137,298.257222101,AUTHORITY[\"EPSG\",\"7019\"]],AUTHORITY[\"EPSG\",\"6269\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.01745329251994328,AUTHORITY[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4269\"]],PROJECTION[\"Lambert_Conformal_Conic_2SP\"],PARAMETER[\"standard_parallel_1\",36.16666666666666],PARAMETER[\"standard_parallel_2\",34.33333333333334],PARAMETER[\"latitude_of_origin\",33.75],PARAMETER[\"central_meridian\",-79],PARAMETER[\"false_easting\",2000000],PARAMETER[\"false_northing\",0],UNIT[\"US survey foot\",0.3048006096012192,AUTHORITY[\"EPSG\",\"9003\"]],AUTHORITY[\"EPSG\",\"2264\"]]";
ICoordinateSystem charlotteCS = (ICoordinateSystem)CoordinateSystemWktReader.Parse(charlotteCSWKT);
 
The following update to StreamTokenizer seems to fix the problem. Replace
 
ascii = AE.GetChars(ba);
 
With:
if (AE.GetByteCount("a") == 2)
{
// handle unicode appropriately
ascii = AE.GetChars(new byte[2] { ba[0], 0 });
}
else
{
ascii = AE.GetChars(ba);
}

comments