1
Vote

Incorrect parsing of wkt projection system

description

In the CoordinateSystemWktReader, the ReadProjection method does not include support for the optional authority parameter specified in the wkt standard, and will fail with an exception if such as parameter is provided. It should include a check for it.

comments

pcttechnical wrote Feb 9, 2012 at 12:33 AM

had same problem. This is my fix:

private static IProjection ReadProjection(WktStreamTokenizer tokenizer)
    {
        //tokenizer.NextToken();// PROJECTION
        tokenizer.ReadToken("PROJECTION");
        tokenizer.ReadToken("[");//[
        string projectionName = tokenizer.ReadDoubleQuotedWord();
        tokenizer.NextToken();

        string authority = String.Empty;
        long authorityCode = -1;

        /* below section altered to allow an authority to be read within the projection token. 
         * This seems to be valid in WKT as per http://www.geoapi.org/3.0/javadoc/org/opengis/referencing/doc-files/WKT.html
         */
        if (tokenizer.GetStringValue() == ",") //Read authority
        {
            tokenizer.ReadAuthority(ref authority, ref authorityCode);
            tokenizer.ReadToken("]");//]
        }

        tokenizer.ReadToken(","); //,
        tokenizer.ReadToken("PARAMETER");
        List<ProjectionParameter> paramList = new List<ProjectionParameter>();
        while (tokenizer.GetStringValue() == "PARAMETER")
        {
            tokenizer.ReadToken("[");
            string paramName = tokenizer.ReadDoubleQuotedWord();
            tokenizer.ReadToken(",");
            tokenizer.NextToken();
            double paramValue = tokenizer.GetNumericValue();
            tokenizer.ReadToken("]");
            tokenizer.ReadToken(",");
            paramList.Add(new ProjectionParameter(paramName, paramValue));
            tokenizer.NextToken();
        }
        IProjection projection = new Projection(projectionName, paramList, projectionName, authority, authorityCode, String.Empty, String.Empty, string.Empty);
        return projection;
    }

wrote Feb 21, 2013 at 11:06 PM