public void TestGeocentricCoordinateSystem() { var fac = new CoordinateSystemFactory(); GeocentricCoordinateSystem fcs = null; const string wkt = "GEOCCS[\"TUREF\", " + "DATUM[\"Turkish_National_Reference_Frame\", " + "SPHEROID[\"GRS 1980\", 6378137, 298.257222101, AUTHORITY[\"EPSG\", \"7019\"]], " + "AUTHORITY[\"EPSG\", \"1057\"]], " + "PRIMEM[\"Greenwich\", 0, AUTHORITY[\"EPSG\", \"8901\"]], " + "UNIT[\"metre\", 1, AUTHORITY[\"EPSG\", \"9001\"]], " + "AXIS[\"Geocentric X\", OTHER], AXIS[\"Geocentric Y\", OTHER], AXIS[\"Geocentric Z\", NORTH], " + "AUTHORITY[\"EPSG\", \"5250\"]]"; try { fcs = fac.CreateFromWkt(wkt) as GeocentricCoordinateSystem; } catch (Exception ex) { Assert.Fail("Could not create geocentric coordinate system from:\r\n" + wkt + "\r\n" + ex.Message); } Assert.That(fcs, Is.Not.Null); Assert.That(CheckInfo(fcs, "TUREF", "EPSG", 5250L)); Assert.That(CheckDatum(fcs.HorizontalDatum, "Turkish_National_Reference_Frame", "EPSG", 1057L), Is.True); Assert.That(CheckEllipsoid(fcs.HorizontalDatum.Ellipsoid, "GRS 1980", 6378137, 298.257222101, "EPSG", 7019), Is.True); Assert.That(CheckPrimem(fcs.PrimeMeridian, "Greenwich", 0, "EPSG", 8901L), Is.True); Assert.That(CheckUnit(fcs.PrimeMeridian.AngularUnit, "degree", null, null, null), Is.True); Assert.That(CheckUnit(fcs.LinearUnit, "metre", 1, "EPSG", 9001L), Is.True); Assert.That(fcs.Authority, Is.EqualTo("EPSG")); Assert.That(fcs.AuthorityCode, Is.EqualTo(5250L)); }
private static CoordinateTransformation Geoc2Geog(GeocentricCoordinateSystem source, GeographicCoordinateSystem target) { var geocMathTransform = CreateCoordinateOperation(source).Inverse(); if (source.PrimeMeridian.EqualParams(target.PrimeMeridian)) { return(new CoordinateTransformation(source, target, TransformType.Conversion, geocMathTransform, string.Empty, string.Empty, -1, string.Empty, string.Empty)); } var ct = new ConcatenatedTransform(); ct.CoordinateTransformationList.Add(new CoordinateTransformation(source, target, TransformType.Conversion, geocMathTransform, string.Empty, string.Empty, -1, string.Empty, string.Empty)); ct.CoordinateTransformationList.Add(new CoordinateTransformation(source, target, TransformType.Transformation, new PrimeMeridianTransform(source.PrimeMeridian, target.PrimeMeridian), string.Empty, string.Empty, -1, string.Empty, string.Empty)); return(new CoordinateTransformation(source, target, TransformType.Conversion, ct, string.Empty, string.Empty, -1, string.Empty, string.Empty)); }
private static MathTransform CreateCoordinateOperation(GeocentricCoordinateSystem geo) { var parameterList = new List <ProjectionParameter>(2); var ellipsoid = geo.HorizontalDatum.Ellipsoid; //var toMeter = ellipsoid.AxisUnit.MetersPerUnit; if (parameterList.Find((p) => p.Name.ToLowerInvariant().Replace(' ', '_').Equals("semi_major")) == null) { parameterList.Add(new ProjectionParameter("semi_major", /*toMeter * */ ellipsoid.SemiMajorAxis)); } if (parameterList.Find((p) => p.Name.ToLowerInvariant().Replace(' ', '_').Equals("semi_minor")) == null) { parameterList.Add(new ProjectionParameter("semi_minor", /*toMeter * */ ellipsoid.SemiMinorAxis)); } return(new GeocentricTransform(parameterList)); }
/// <summary> /// Geocentric to Geocentric transformation /// </summary> /// <param name="source"></param> /// <param name="target"></param> /// <returns></returns> private static CoordinateTransformation CreateGeoc2Geoc(GeocentricCoordinateSystem source, GeocentricCoordinateSystem target) { var ct = new ConcatenatedTransform(); //Does source has a datum different from WGS84 and is there a shift specified? if (source.HorizontalDatum.Wgs84Parameters != null && !source.HorizontalDatum.Wgs84Parameters.HasZeroValuesOnly) { ct.CoordinateTransformationList.Add( new CoordinateTransformation( ((target.HorizontalDatum.Wgs84Parameters == null || target.HorizontalDatum.Wgs84Parameters.HasZeroValuesOnly) ? target : GeocentricCoordinateSystem.WGS84), source, TransformType.Transformation, new DatumTransform(source.HorizontalDatum.Wgs84Parameters) , "", "", -1, "", "")); } //Does target has a datum different from WGS84 and is there a shift specified? if (target.HorizontalDatum.Wgs84Parameters != null && !target.HorizontalDatum.Wgs84Parameters.HasZeroValuesOnly) { ct.CoordinateTransformationList.Add( new CoordinateTransformation( ((source.HorizontalDatum.Wgs84Parameters == null || source.HorizontalDatum.Wgs84Parameters.HasZeroValuesOnly) ? source : GeocentricCoordinateSystem.WGS84), target, TransformType.Transformation, new DatumTransform(target.HorizontalDatum.Wgs84Parameters).Inverse() , "", "", -1, "", "")); } //If we don't have a transformation in this list, return null if (ct.CoordinateTransformationList.Count == 0) { return(null); } //If we only have one shift, lets just return the datumshift from/to wgs84 if (ct.CoordinateTransformationList.Count == 1) { return(new CoordinateTransformation(source, target, TransformType.ConversionAndTransformation, ((ICoordinateTransformation)ct.CoordinateTransformationList[0]).MathTransform, "", "", -1, "", "")); } return(new CoordinateTransformation(source, target, TransformType.ConversionAndTransformation, ct, "", "", -1, "", "")); }