private static IFittedCoordinateSystem ReadFittedCoordinateSystem(WktStreamTokenizer tokenizer) { /* * FITTED_CS[ * "Local coordinate system MNAU (based on Gauss-Krueger)", * PARAM_MT[ * "Affine", * PARAMETER["num_row",3], * PARAMETER["num_col",3], * PARAMETER["elt_0_0", 0.883485346527455], * PARAMETER["elt_0_1", -0.468458794848877], * PARAMETER["elt_0_2", 3455869.17937689], * PARAMETER["elt_1_0", 0.468458794848877], * PARAMETER["elt_1_1", 0.883485346527455], * PARAMETER["elt_1_2", 5478710.88035753], * PARAMETER["elt_2_2", 1], * ], * PROJCS["DHDN / Gauss-Kruger zone 3", GEOGCS["DHDN", DATUM["Deutsches_Hauptdreiecksnetz", SPHEROID["Bessel 1841", 6377397.155, 299.1528128, AUTHORITY["EPSG", "7004"]], TOWGS84[612.4, 77, 440.2, -0.054, 0.057, -2.797, 0.525975255930096], AUTHORITY["EPSG", "6314"]], PRIMEM["Greenwich", 0, AUTHORITY["EPSG", "8901"]], UNIT["degree", 0.0174532925199433, AUTHORITY["EPSG", "9122"]], AUTHORITY["EPSG", "4314"]], UNIT["metre", 1, AUTHORITY["EPSG", "9001"]], PROJECTION["Transverse_Mercator"], PARAMETER["latitude_of_origin", 0], PARAMETER["central_meridian", 9], PARAMETER["scale_factor", 1], PARAMETER["false_easting", 3500000], PARAMETER["false_northing", 0], AUTHORITY["EPSG", "31467"]] * AUTHORITY["CUSTOM","12345"] * ] */ tokenizer.ReadToken("["); string name = tokenizer.ReadDoubleQuotedWord(); tokenizer.ReadToken(","); tokenizer.ReadToken("PARAM_MT"); IMathTransform toBaseTransform = MathTransformWktReader.ReadMathTransform(tokenizer); tokenizer.ReadToken(","); tokenizer.NextToken(); ICoordinateSystem baseCS = ReadCoordinateSystem(null, tokenizer); string authority = String.Empty; long authorityCode = -1; TokenType ct = tokenizer.NextToken(); while (ct != TokenType.Eol && ct != TokenType.Eof) { switch (tokenizer.GetStringValue()) { case ",": case "]": break; case "AUTHORITY": tokenizer.ReadAuthority(ref authority, ref authorityCode); //tokenizer.ReadToken("]"); break; } ct = tokenizer.NextToken(); } IFittedCoordinateSystem fittedCS = new FittedCoordinateSystem(baseCS, toBaseTransform, name, authority, authorityCode, string.Empty, string.Empty, string.Empty); return(fittedCS); }
private static MathTransform CreateFittedTransform(FittedCoordinateSystem fittedSystem) { //create transform From fitted to base and inverts it return(fittedSystem.ToBaseTransform); //MathTransformFactory mtFac = new MathTransformFactory (); ////create transform From fitted to base and inverts it //return mtFac.CreateFromWKT (fittedSystem.ToBase ()); throw new NotImplementedException(); }
public void TestFittedCoordinateSystemWkt() { var fac = new CoordinateSystemFactory(); FittedCoordinateSystem fcs = null; string wkt = "FITTED_CS[\"Local coordinate system MNAU (based on Gauss-Krueger)\"," + "PARAM_MT[\"Affine\"," + "PARAMETER[\"num_row\",3],PARAMETER[\"num_col\",3],PARAMETER[\"elt_0_0\", 0.883485346527455],PARAMETER[\"elt_0_1\", -0.468458794848877],PARAMETER[\"elt_0_2\", 3455869.17937689],PARAMETER[\"elt_1_0\", 0.468458794848877],PARAMETER[\"elt_1_1\", 0.883485346527455],PARAMETER[\"elt_1_2\", 5478710.88035753],PARAMETER[\"elt_2_2\", 1]]," + "PROJCS[\"DHDN / Gauss-Kruger zone 3\"," + "GEOGCS[\"DHDN\"," + "DATUM[\"Deutsches_Hauptdreiecksnetz\"," + "SPHEROID[\"Bessel 1841\", 6377397.155, 299.1528128, AUTHORITY[\"EPSG\", \"7004\"]]," + "TOWGS84[612.4, 77, 440.2, -0.054, 0.057, -2.797, 0.525975255930096]," + "AUTHORITY[\"EPSG\", \"6314\"]]," + "PRIMEM[\"Greenwich\", 0, AUTHORITY[\"EPSG\", \"8901\"]]," + "UNIT[\"degree\", 0.0174532925199433, AUTHORITY[\"EPSG\", \"9122\"]]," + "AUTHORITY[\"EPSG\", \"4314\"]]," + "UNIT[\"metre\", 1, AUTHORITY[\"EPSG\", \"9001\"]]," + "PROJECTION[\"Transverse_Mercator\"]," + "PARAMETER[\"latitude_of_origin\", 0]," + "PARAMETER[\"central_meridian\", 9]," + "PARAMETER[\"scale_factor\", 1]," + "PARAMETER[\"false_easting\", 3500000]," + "PARAMETER[\"false_northing\", 0]," + "AUTHORITY[\"EPSG\", \"31467\"]]" + "]"; try { fcs = fac.CreateFromWkt(wkt) as FittedCoordinateSystem; } catch (Exception ex) { Assert.Fail("Could not create fitted coordinate system from:\r\n" + wkt + "\r\n" + ex.Message); } Assert.That(fcs, Is.Not.Null); Assert.That(fcs.ToBase(), Is.Not.Null.Or.Empty); Assert.That(fcs.BaseCoordinateSystem, Is.Not.Null); Assert.AreEqual("Local coordinate system MNAU (based on Gauss-Krueger)", fcs.Name); //Assert.AreEqual ("CUSTOM", fcs.Authority); //Assert.AreEqual (123456, fcs.AuthorityCode); Assert.AreEqual("EPSG", fcs.BaseCoordinateSystem.Authority); Assert.AreEqual(31467, fcs.BaseCoordinateSystem.AuthorityCode); }
/// <summary> /// Creates transformation from source coordinate system to specified target system which is the fitted one /// </summary> /// <param name="source"></param> /// <param name="target"></param> /// <returns></returns> private static CoordinateTransformation Any2Fitt(CoordinateSystem source, FittedCoordinateSystem target) { //Transform form base system of fitted to target coordinate system - use invered math transform var invMt = CreateFittedTransform(target).Inverse(); //case when source system is equal to base system of the fitted if (target.BaseCoordinateSystem.EqualParams(source)) { //Transform form base system of fitted to target coordinate system return(CreateTransform(source, target, TransformType.Transformation, invMt)); } var ct = new ConcatenatedTransform(); //First transform from source to base system of fitted var ctFac = new CoordinateTransformationFactory(); ct.CoordinateTransformationList.Add(ctFac.CreateFromCoordinateSystems(source, target.BaseCoordinateSystem)); //Transform form base system of fitted to target coordinate system - use invered math transform ct.CoordinateTransformationList.Add(CreateTransform(target.BaseCoordinateSystem, target, TransformType.Transformation, invMt)); return(CreateTransform(source, target, TransformType.Transformation, ct)); }
/// <summary> /// Creates transformation from fitted coordinate system to the target one /// </summary> /// <param name="source"></param> /// <param name="target"></param> /// <returns></returns> private static CoordinateTransformation Fitt2Any(FittedCoordinateSystem source, CoordinateSystem target) { //transform from fitted to base system of fitted (which is equal to target) var mt = CreateFittedTransform(source); //case when target system is equal to base system of the fitted if (source.BaseCoordinateSystem.EqualParams(target)) { //Transform form base system of fitted to target coordinate system return(CreateTransform(source, target, TransformType.Transformation, mt)); } //Transform form base system of fitted to target coordinate system var ct = new ConcatenatedTransform(); ct.CoordinateTransformationList.Add(CreateTransform(source, source.BaseCoordinateSystem, TransformType.Transformation, mt)); //Transform form base system of fitted to target coordinate system var ctFac = new CoordinateTransformationFactory(); ct.CoordinateTransformationList.Add(ctFac.CreateFromCoordinateSystems(source.BaseCoordinateSystem, target)); return(CreateTransform(source, target, TransformType.Transformation, ct)); }