Coordinate Conversion and CF Version

Topics: CompactFramework, SharpMap Project, SharpMap v0.9 / v1.x
May 21, 2010 at 2:45 AM

Hi,

I have the need to convert some coordinates from New Zealand Map Grid into New Zealand Transverse Mercator projection. I am having some trouble getting the coordinate conversion to work using SharpMap 0.9.

I have the following code

        private static string nzmg_wkt = "PROJCS[\"NZGD49 / New Zealand Map Grid\",GEOGCS[\"NZGD49\",DATUM[\"New_Zealand_Geodetic_Datum_1949\",SPHEROID[\"International 1924\",6378388,297,AUTHORITY[\"EPSG\",\"7022\"]],TOWGS84[59.47,-5.04,187.44,0.47,-0.1,1.024,-4.5993],AUTHORITY[\"EPSG\",\"6272\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.01745329251994328,AUTHORITY[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4272\"]],PROJECTION[\"New_Zealand_Map_Grid\"],PARAMETER[\"latitude_of_origin\",-41],PARAMETER[\"central_meridian\",173],PARAMETER[\"false_easting\",2510000],PARAMETER[\"false_northing\",6023150],UNIT[\"metre\",1,AUTHORITY[\"EPSG\",\"9001\"]],AUTHORITY[\"EPSG\",\"27200\"]]";
        private static string nzgd49gc_wkt = "GEOGCS[\"NZGD49\",DATUM[\"New_Zealand_Geodetic_Datum_1949\",SPHEROID[\"International 1924\",6378388,297,AUTHORITY[\"EPSG\",\"7022\"]],TOWGS84[59.47,-5.04,187.44,0.47,-0.1,1.024,-4.5993],AUTHORITY[\"EPSG\",\"6272\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.01745329251994328,AUTHORITY[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4272\"]]";
        private static string nzgd2000gc_wkt = "GEOGCS[\"NZGD2000\",DATUM[\"New_Zealand_Geodetic_Datum_2000\",SPHEROID[\"GRS 1980\",6378137,298.257222101,AUTHORITY[\"EPSG\",\"7019\"]],TOWGS84[0,0,0,0,0,0,0],AUTHORITY[\"EPSG\",\"6167\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.01745329251994328,AUTHORITY[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4167\"]]";
        private static string nzgd2000tm_wkt = "PROJCS[\"NZGD2000 / New Zealand Transverse Mercator\",GEOGCS[\"NZGD2000\",DATUM[\"New_Zealand_Geodetic_Datum_2000\",SPHEROID[\"GRS 1980\",6378137,298.257222101,AUTHORITY[\"EPSG\",\"7019\"]],TOWGS84[0,0,0,0,0,0,0],AUTHORITY[\"EPSG\",\"6167\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.01745329251994328,AUTHORITY[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4167\"]],PROJECTION[\"Transverse_Mercator\"],PARAMETER[\"latitude_of_origin\",0],PARAMETER[\"central_meridian\",173],PARAMETER[\"scale_factor\",0.9996],PARAMETER[\"false_easting\",1600000],PARAMETER[\"false_northing\",10000000],UNIT[\"metre\",1,AUTHORITY[\"EPSG\",\"9001\"]],AUTHORITY[\"EPSG\",\"2193\"]]";

        private static double[] NZMGToNZGD49(double[] coord)
        {
            CoordinateSystemFactory factory = new CoordinateSystemFactory();
            ICoordinateSystem sourceCS = factory.CreateFromWkt(nzmg_wkt);
            ICoordinateSystem targetCS = factory.CreateFromWkt(nzgd49gc_wkt);

            ICoordinateTransformationFactory factory2 = new CoordinateTransformationFactory();
            return factory2.CreateFromCoordinateSystems(sourceCS, targetCS).MathTransform.Transform(coord);
        }


The WKT strings are taken from the SRID.csv file in the test project for SharpMap. I keep getting an exception that "Projection New Zealand Map Grid is not supported" when it tries to execute the return statement.

I am doing this conversion wrong?
Do you also know whether SharpLib supports the use of a grid for tranverse mercator projections.

I have also tried to download the CF version of SharpMap since I need to do something similar on a mobile device, but I do not seem to be able to checkout using the url provided.
Is there a zip available?

Regards
Alan

Coordinator
May 21, 2010 at 10:27 AM

 Hi Alan, try getting a more recent version of projnet from http://projnet.codeplex.com (note that there are interface changes between the version of projnet used by sharpmap 0.9 and the  projnet trunk)
or you could try FObermaiers latest work hot off the press @  http://proj4net.codeplex.com/ 

hth jd