Creates coordinate transformations.
Наследование: ICoordinateTransformationFactory
		public void TestAlbersProjection()
		{
			CoordinateSystemFactory cFac = new SharpMap.CoordinateSystems.CoordinateSystemFactory();

			IEllipsoid ellipsoid = cFac.CreateFlattenedSphere("Clarke 1866", 6378206.4, 294.9786982138982, LinearUnit.USSurveyFoot);

			IHorizontalDatum datum = cFac.CreateHorizontalDatum("Clarke 1866", DatumType.HD_Geocentric, ellipsoid, null);
			IGeographicCoordinateSystem gcs = cFac.CreateGeographicCoordinateSystem("Clarke 1866", AngularUnit.Degrees, datum,
				PrimeMeridian.Greenwich, new AxisInfo("Lon", AxisOrientationEnum.East),
				new AxisInfo("Lat", AxisOrientationEnum.North));
			System.Collections.Generic.List<ProjectionParameter> parameters = new System.Collections.Generic.List<ProjectionParameter>(5);
			parameters.Add(new ProjectionParameter("central_meridian", -96));
			parameters.Add(new ProjectionParameter("latitude_of_center", 23));
			parameters.Add(new ProjectionParameter("standard_parallel_1", 29.5));
			parameters.Add(new ProjectionParameter("standard_parallel_2", 45.5));
			parameters.Add(new ProjectionParameter("false_easting", 0));
			parameters.Add(new ProjectionParameter("false_northing", 0));
			IProjection projection = cFac.CreateProjection("Albers Conical Equal Area", "albers", parameters);

			IProjectedCoordinateSystem coordsys = cFac.CreateProjectedCoordinateSystem("Albers Conical Equal Area", gcs, projection, LinearUnit.Metre, new AxisInfo("East", AxisOrientationEnum.East), new AxisInfo("North", AxisOrientationEnum.North));

			ICoordinateTransformation trans = new CoordinateTransformationFactory().CreateFromCoordinateSystems(gcs, coordsys);

			double[] pGeo = new double[] { -75, 35 };
			double[] pUtm = trans.MathTransform.Transform(pGeo);
			double[] pGeo2 = trans.MathTransform.Inverse().Transform(pUtm);

			double[] expected = new double[] { 1885472.7, 1535925 };
			Assert.IsTrue(ToleranceLessThan(pUtm, expected, 0.05), String.Format("Albers forward transformation outside tolerance, Expected {0}, got {1}", expected.ToString(), pUtm.ToString()));
			Assert.IsTrue(ToleranceLessThan(pGeo, pGeo2, 0.0000001), String.Format("Albers reverse transformation outside tolerance, Expected {0}, got {1}", pGeo.ToString(), pGeo2.ToString()));
		}
		public void TestMercator_1SP_Projection()
		{
			CoordinateSystemFactory cFac = new SharpMap.CoordinateSystems.CoordinateSystemFactory();

			IEllipsoid ellipsoid = cFac.CreateFlattenedSphere("Bessel 1840", 6377397.155, 299.15281, LinearUnit.Metre);

			IHorizontalDatum datum = cFac.CreateHorizontalDatum("Bessel 1840", DatumType.HD_Geocentric, ellipsoid, null);
			IGeographicCoordinateSystem gcs = cFac.CreateGeographicCoordinateSystem("Bessel 1840", AngularUnit.Degrees, datum,
				PrimeMeridian.Greenwich, new AxisInfo("Lon", AxisOrientationEnum.East),
				new AxisInfo("Lat", AxisOrientationEnum.North));
			System.Collections.Generic.List<ProjectionParameter> parameters = new System.Collections.Generic.List<ProjectionParameter>(5);
			parameters.Add(new ProjectionParameter("latitude_of_origin", 0));
			parameters.Add(new ProjectionParameter("central_meridian", 110));
			parameters.Add(new ProjectionParameter("scale_factor", 0.997));
			parameters.Add(new ProjectionParameter("false_easting", 3900000));
			parameters.Add(new ProjectionParameter("false_northing", 900000));
			IProjection projection = cFac.CreateProjection("Mercator_1SP", "Mercator_1SP", parameters);

			IProjectedCoordinateSystem coordsys = cFac.CreateProjectedCoordinateSystem("Makassar / NEIEZ", gcs, projection, LinearUnit.Metre, new AxisInfo("East", AxisOrientationEnum.East), new AxisInfo("North", AxisOrientationEnum.North));

			ICoordinateTransformation trans = new CoordinateTransformationFactory().CreateFromCoordinateSystems(gcs, coordsys);

			double[] pGeo = new double[] { 120, -3 };
			double[] pUtm = trans.MathTransform.Transform(pGeo);
			double[] pGeo2 = trans.MathTransform.Inverse().Transform(pUtm);

			double[] expected = new double[] { 5009726.58, 569150.82 };
			Assert.IsTrue(ToleranceLessThan(pUtm, expected, 0.02), String.Format("Mercator_1SP forward transformation outside tolerance, Expected {0}, got {1}", expected.ToString(), pUtm.ToString()));
			Assert.IsTrue(ToleranceLessThan(pGeo, pGeo2, 0.0000001), String.Format("Mercator_1SP reverse transformation outside tolerance, Expected {0}, got {1}", pGeo.ToString(), pGeo2.ToString()));
		}
Пример #3
0
	private void TestMercator_2SP()
	{
		CoordinateSystemFactory cFac = new SharpMap.CoordinateSystems.CoordinateSystemFactory();

		IEllipsoid ellipsoid = cFac.CreateFlattenedSphere("Krassowski 1940", 6378245.0, 298.3, LinearUnit.Metre);

		IHorizontalDatum datum = cFac.CreateHorizontalDatum("Krassowski 1940", DatumType.HD_Geocentric, ellipsoid, null);
		IGeographicCoordinateSystem gcs = cFac.CreateGeographicCoordinateSystem("Krassowski 1940", AngularUnit.Degrees, datum, 
			PrimeMeridian.Greenwich, new AxisInfo("Lon", AxisOrientationEnum.East),
			new AxisInfo("Lat", AxisOrientationEnum.North));
        List<ProjectionParameter> parameters = new List<ProjectionParameter>();
		parameters.Add(new ProjectionParameter("latitude_of_origin", 42));
		parameters.Add(new ProjectionParameter("central_meridian", 51));
		parameters.Add(new ProjectionParameter("false_easting", 0));
		parameters.Add(new ProjectionParameter("false_northing", 0));
		IProjection projection = cFac.CreateProjection("Mercator_2SP", "Mercator_2SP", parameters);

		IProjectedCoordinateSystem coordsys = cFac.CreateProjectedCoordinateSystem("Pulkovo 1942 / Mercator Caspian Sea", gcs, projection, LinearUnit.Metre, new AxisInfo("East", AxisOrientationEnum.East), new AxisInfo("North", AxisOrientationEnum.North));

		ICoordinateTransformation trans = new CoordinateTransformationFactory().CreateFromCoordinateSystems(gcs, coordsys);

		SharpMap.Geometries.Point pGeo = new SharpMap.Geometries.Point(53,53);
		SharpMap.Geometries.Point pUtm = new Point(trans.MathTransform.Transform(pGeo.ToDoubleArray()));
        SharpMap.Geometries.Point pGeo2 = new Point(trans.MathTransform.Inverse().Transform(pUtm.ToDoubleArray()));

		result.Text += PrintResultTable(gcs, coordsys, pGeo, pUtm, new Point(165704.29, 5171848.07), pGeo2, "Mercator_2SP test");
	}
Пример #4
0
	private void TestMercator_1SP()
	{
		CoordinateSystemFactory cFac = new SharpMap.CoordinateSystems.CoordinateSystemFactory();

		IEllipsoid ellipsoid = cFac.CreateFlattenedSphere("Bessel 1840", 6377397.155, 299.15281, LinearUnit.Metre);

		IHorizontalDatum datum = cFac.CreateHorizontalDatum("Bessel 1840", DatumType.HD_Geocentric, ellipsoid, null);
		IGeographicCoordinateSystem gcs = cFac.CreateGeographicCoordinateSystem("Bessel 1840", AngularUnit.Degrees, datum,
			PrimeMeridian.Greenwich, new AxisInfo("Lon", AxisOrientationEnum.East),
			new AxisInfo("Lat", AxisOrientationEnum.North));
        List<ProjectionParameter> parameters = new List<ProjectionParameter>();
		parameters.Add(new ProjectionParameter("latitude_of_origin", 0));
		parameters.Add(new ProjectionParameter("central_meridian", 110));
		parameters.Add(new ProjectionParameter("scale_factor", 0.997));
		parameters.Add(new ProjectionParameter("false_easting", 3900000));
		parameters.Add(new ProjectionParameter("false_northing", 900000));
		IProjection projection = cFac.CreateProjection("Mercator_1SP", "Mercator_1SP", parameters);

		IProjectedCoordinateSystem coordsys = cFac.CreateProjectedCoordinateSystem("Makassar / NEIEZ", gcs, projection, LinearUnit.Metre, new AxisInfo("East", AxisOrientationEnum.East), new AxisInfo("North", AxisOrientationEnum.North));

		ICoordinateTransformation trans = new CoordinateTransformationFactory().CreateFromCoordinateSystems(gcs, coordsys);

		SharpMap.Geometries.Point pGeo = new SharpMap.Geometries.Point(120, -3);
		SharpMap.Geometries.Point pUtm = new Point(trans.MathTransform.Transform(pGeo.ToDoubleArray()));
		SharpMap.Geometries.Point pGeo2 = new Point(trans.MathTransform.Inverse().Transform(pUtm.ToDoubleArray()));

		result.Text += PrintResultTable(gcs, coordsys, pGeo, pUtm, new Point(5009726.58, 569150.82), pGeo2, "Mercator_1SP test");
	}
        private static ICoordinateTransformation Proj2Proj(IProjectedCoordinateSystem source, IProjectedCoordinateSystem target)
        {
            ConcatenatedTransform           ct    = new ConcatenatedTransform();
            CoordinateTransformationFactory ctFac = new CoordinateTransformationFactory();

            //First transform from projection to geographic
            ct.CoordinateTransformationList.Add(ctFac.CreateFromCoordinateSystems(source, source.GeographicCoordinateSystem));
            //Transform geographic to geographic:
            ct.CoordinateTransformationList.Add(ctFac.CreateFromCoordinateSystems(source.GeographicCoordinateSystem, target.GeographicCoordinateSystem));
            //Transform to new projection
            ct.CoordinateTransformationList.Add(ctFac.CreateFromCoordinateSystems(target.GeographicCoordinateSystem, target));

            return(new CoordinateTransformation(source,
                                                target, TransformType.Transformation, ct,
                                                String.Empty, String.Empty, -1, String.Empty, String.Empty));
        }
		public void TestDatumTransform()
		{
			CoordinateSystemFactory cFac = new CoordinateSystemFactory();
			//Define datums
			HorizontalDatum wgs72 = HorizontalDatum.WGS72;
			HorizontalDatum ed50 = HorizontalDatum.ED50;

			//Define geographic coordinate systems
			IGeographicCoordinateSystem gcsWGS72 = cFac.CreateGeographicCoordinateSystem("WGS72 Geographic", AngularUnit.Degrees, wgs72, PrimeMeridian.Greenwich,
				new AxisInfo("East", AxisOrientationEnum.East), new AxisInfo("North", AxisOrientationEnum.North));

			IGeographicCoordinateSystem gcsWGS84 = cFac.CreateGeographicCoordinateSystem("WGS84 Geographic", AngularUnit.Degrees, HorizontalDatum.WGS84, PrimeMeridian.Greenwich,
				new AxisInfo("East", AxisOrientationEnum.East), new AxisInfo("North", AxisOrientationEnum.North));

			IGeographicCoordinateSystem gcsED50 = cFac.CreateGeographicCoordinateSystem("ED50 Geographic", AngularUnit.Degrees, ed50, PrimeMeridian.Greenwich,
				new AxisInfo("East", AxisOrientationEnum.East), new AxisInfo("North", AxisOrientationEnum.North));

			//Define geocentric coordinate systems
			IGeocentricCoordinateSystem gcenCsWGS72 = cFac.CreateGeocentricCoordinateSystem("WGS72 Geocentric", wgs72, LinearUnit.Metre, PrimeMeridian.Greenwich);
			IGeocentricCoordinateSystem gcenCsWGS84 = cFac.CreateGeocentricCoordinateSystem("WGS84 Geocentric", HorizontalDatum.WGS84, LinearUnit.Metre, PrimeMeridian.Greenwich);
			IGeocentricCoordinateSystem gcenCsED50 = cFac.CreateGeocentricCoordinateSystem("ED50 Geocentric", ed50, LinearUnit.Metre, PrimeMeridian.Greenwich);

			//Define projections
			System.Collections.Generic.List<ProjectionParameter> parameters = new System.Collections.Generic.List<ProjectionParameter>(5);
			parameters.Add(new ProjectionParameter("latitude_of_origin", 0));
			parameters.Add(new ProjectionParameter("central_meridian", 9));
			parameters.Add(new ProjectionParameter("scale_factor", 0.9996));
			parameters.Add(new ProjectionParameter("false_easting", 500000));
			parameters.Add(new ProjectionParameter("false_northing", 0));
			IProjection projection = cFac.CreateProjection("Transverse Mercator", "Transverse_Mercator", parameters);
			IProjectedCoordinateSystem utmED50 = cFac.CreateProjectedCoordinateSystem("ED50 UTM Zone 32N", gcsED50, projection, LinearUnit.Metre, new AxisInfo("East", AxisOrientationEnum.East), new AxisInfo("North", AxisOrientationEnum.North));
			IProjectedCoordinateSystem utmWGS84 = cFac.CreateProjectedCoordinateSystem("WGS84 UTM Zone 32N", gcsWGS84, projection, LinearUnit.Metre, new AxisInfo("East", AxisOrientationEnum.East), new AxisInfo("North", AxisOrientationEnum.North));

			//Set TOWGS84 parameters
			wgs72.Wgs84Parameters = new Wgs84ConversionInfo(0, 0, 4.5, 0, 0, 0.554, 0.219);
			ed50.Wgs84Parameters = new Wgs84ConversionInfo(-81.0703, -89.3603, -115.7526,
														   -0.48488, -0.02436, -0.41321,
														   -0.540645); //Parameters for Denmark

			//Set up coordinate transformations
			CoordinateTransformationFactory ctFac = new CoordinateTransformationFactory();
			ICoordinateTransformation ctForw = ctFac.CreateFromCoordinateSystems(gcsWGS72, gcenCsWGS72); //Geographic->Geocentric (WGS72)
			ICoordinateTransformation ctWGS84_Gcen2Geo = ctFac.CreateFromCoordinateSystems(gcenCsWGS84, gcsWGS84);  //Geocentric->Geographic (WGS84)
			ICoordinateTransformation ctWGS84_Geo2UTM = ctFac.CreateFromCoordinateSystems(gcsWGS84, utmWGS84);  //UTM ->Geographic (WGS84)
			ICoordinateTransformation ctED50_UTM2Geo = ctFac.CreateFromCoordinateSystems(utmED50, gcsED50);  //UTM ->Geographic (ED50)
			ICoordinateTransformation ctED50_Geo2Gcen = ctFac.CreateFromCoordinateSystems(gcsED50, gcenCsED50); //Geographic->Geocentric (ED50)

			//Test datum-shift from WGS72 to WGS84
			//Point3D pGeoCenWGS72 = ctForw.MathTransform.Transform(pLongLatWGS72) as Point3D;
			double[] pGeoCenWGS72 = new double[] {3657660.66, 255768.55, 5201382.11};
			ICoordinateTransformation geocen_ed50_2_Wgs84 = ctFac.CreateFromCoordinateSystems(gcenCsWGS72, gcenCsWGS84);
			double[] pGeoCenWGS84 = geocen_ed50_2_Wgs84.MathTransform.Transform(pGeoCenWGS72);
			//Point3D pGeoCenWGS84 = wgs72.Wgs84Parameters.Apply(pGeoCenWGS72);

			Assert.IsTrue(ToleranceLessThan(new double[] { 3657660.78, 255778.43, 5201387.75 }, pGeoCenWGS84, 0.01));

			ICoordinateTransformation utm_ed50_2_Wgs84 = ctFac.CreateFromCoordinateSystems(utmED50, utmWGS84);
			double[] pUTMED50 = new double[] {600000, 6100000};
			double[] pUTMWGS84 = utm_ed50_2_Wgs84.MathTransform.Transform(pUTMED50);
			Assert.IsTrue(ToleranceLessThan(new double[] { 599928.6, 6099790.2 }, pUTMWGS84, 0.1));
			//Perform reverse
			ICoordinateTransformation utm_Wgs84_2_Ed50 = ctFac.CreateFromCoordinateSystems(utmWGS84, utmED50);
			pUTMED50 = utm_Wgs84_2_Ed50.MathTransform.Transform(pUTMWGS84);
			Assert.IsTrue(ToleranceLessThan(new double[] {600000, 6100000}, pUTMED50, 0.1));
			//Assert.IsTrue(Math.Abs((pUTMWGS84 as Point3D).Z - 36.35) < 0.5);
			//Point pExpected = Point.FromDMS(2, 7, 46.38, 53, 48, 33.82);
			//ED50_to_WGS84_Denmark: datum.Wgs84Parameters = new Wgs84ConversionInfo(-89.5, -93.8, 127.6, 0, 0, 4.5, 1.2);

		}
		public void TestGeocentric()
		{
			CoordinateSystemFactory cFac = new CoordinateSystemFactory();
			IGeographicCoordinateSystem gcs = cFac.CreateGeographicCoordinateSystem("ETRF89 Geographic", AngularUnit.Degrees, HorizontalDatum.ETRF89, PrimeMeridian.Greenwich,
				new AxisInfo("East", AxisOrientationEnum.East), new AxisInfo("North", AxisOrientationEnum.North));
			IGeocentricCoordinateSystem gcenCs = cFac.CreateGeocentricCoordinateSystem("ETRF89 Geocentric", HorizontalDatum.ETRF89, LinearUnit.Metre, PrimeMeridian.Greenwich);
			CoordinateTransformationFactory gtFac = new CoordinateTransformationFactory();
			ICoordinateTransformation ct = gtFac.CreateFromCoordinateSystems(gcs, gcenCs);
			double[] pExpected = new double[] { 2 + 7.0 / 60 + 46.38 / 3600, 53 + 48.0 / 60 + 33.82/3600 }; // Point.FromDMS(2, 7, 46.38, 53, 48, 33.82);
			double[] pExpected3D = new double[] { pExpected[0], pExpected[1], 73.0 };
			double[] p0 = new double[] { 3771793.97, 140253.34, 5124304.35 };
			double[] p1 = ct.MathTransform.Transform(pExpected3D) as double[];
			double[] p2 = ct.MathTransform.Inverse().Transform(p1) as double[];
			Assert.IsTrue(ToleranceLessThan(p1, p0, 0.01));
			Assert.IsTrue(ToleranceLessThan(p2, pExpected, 0.00001));
		}
		public void TestLambertConicConformal2SP_Projection()
		{
			CoordinateSystemFactory cFac = new SharpMap.CoordinateSystems.CoordinateSystemFactory();

			IEllipsoid ellipsoid = cFac.CreateFlattenedSphere("Clarke 1866", 20925832.16, 294.97470, LinearUnit.USSurveyFoot);

			IHorizontalDatum datum = cFac.CreateHorizontalDatum("Clarke 1866", DatumType.HD_Geocentric, ellipsoid, null);
			IGeographicCoordinateSystem gcs = cFac.CreateGeographicCoordinateSystem("Clarke 1866", AngularUnit.Degrees, datum,
				PrimeMeridian.Greenwich, new AxisInfo("Lon", AxisOrientationEnum.East),
				new AxisInfo("Lat", AxisOrientationEnum.North));
			System.Collections.Generic.List<ProjectionParameter> parameters = new System.Collections.Generic.List<ProjectionParameter>(5);
			parameters.Add(new ProjectionParameter("latitude_of_origin", 27.833333333));
			parameters.Add(new ProjectionParameter("central_meridian", -99));
			parameters.Add(new ProjectionParameter("standard_parallel_1", 28.3833333333));
			parameters.Add(new ProjectionParameter("standard_parallel_2", 30.2833333333));
			parameters.Add(new ProjectionParameter("false_easting", 2000000));
			parameters.Add(new ProjectionParameter("false_northing", 0));
			IProjection projection = cFac.CreateProjection("Lambert Conic Conformal (2SP)", "lambert_conformal_conic_2sp", parameters);

			IProjectedCoordinateSystem coordsys = cFac.CreateProjectedCoordinateSystem("NAD27 / Texas South Central", gcs, projection, LinearUnit.USSurveyFoot, new AxisInfo("East", AxisOrientationEnum.East), new AxisInfo("North", AxisOrientationEnum.North));

			ICoordinateTransformation trans = new CoordinateTransformationFactory().CreateFromCoordinateSystems(gcs, coordsys);

			double[] pGeo = new double[] { -96, 28.5 };
			double[] pUtm = trans.MathTransform.Transform(pGeo);
			double[] pGeo2 = trans.MathTransform.Inverse().Transform(pUtm);

			double[] expected = new double[] { 2963503.91, 254759.80 };
			Assert.IsTrue(ToleranceLessThan(pUtm, expected, 0.02), String.Format("LambertConicConformal2SP forward transformation outside tolerance, Expected {0}, got {1}", expected.ToString(), pUtm.ToString()));
			Assert.IsTrue(ToleranceLessThan(pGeo, pGeo2, 0.0000001), String.Format("LambertConicConformal2SP reverse transformation outside tolerance, Expected {0}, got {1}", pGeo.ToString(), pGeo2.ToString()));

		}
Пример #9
0
	private void TestLambertConicConformal_2SP()
	{
		CoordinateSystemFactory cFac = new SharpMap.CoordinateSystems.CoordinateSystemFactory();

		IEllipsoid ellipsoid = cFac.CreateFlattenedSphere("Clarke 1866", 20925832.16, 294.97470, LinearUnit.USSurveyFoot);

		IHorizontalDatum datum = cFac.CreateHorizontalDatum("Clarke 1866", DatumType.HD_Geocentric, ellipsoid, null);
		IGeographicCoordinateSystem gcs = cFac.CreateGeographicCoordinateSystem("Clarke 1866", AngularUnit.Degrees, datum,
			PrimeMeridian.Greenwich, new AxisInfo("Lon", AxisOrientationEnum.East),
			new AxisInfo("Lat", AxisOrientationEnum.North));
        List<ProjectionParameter> parameters = new List<ProjectionParameter>();
		parameters.Add(new ProjectionParameter("latitude_of_origin", 27.833333333));
		parameters.Add(new ProjectionParameter("central_meridian", -99));
		parameters.Add(new ProjectionParameter("standard_parallel_1", 28.3833333333));
		parameters.Add(new ProjectionParameter("standard_parallel_2", 30.2833333333));
		parameters.Add(new ProjectionParameter("false_easting", 2000000));
		parameters.Add(new ProjectionParameter("false_northing", 0));
		IProjection projection = cFac.CreateProjection("Lambert Conic Conformal (2SP)", "lambert_conformal_conic_2sp", parameters);

		IProjectedCoordinateSystem coordsys = cFac.CreateProjectedCoordinateSystem("NAD27 / Texas South Central", gcs, projection, LinearUnit.USSurveyFoot, new AxisInfo("East", AxisOrientationEnum.East), new AxisInfo("North", AxisOrientationEnum.North));

		ICoordinateTransformation trans = new CoordinateTransformationFactory().CreateFromCoordinateSystems(gcs, coordsys);

		SharpMap.Geometries.Point pGeo = new SharpMap.Geometries.Point(-96, 28.5);
		SharpMap.Geometries.Point pUtm = new Point(trans.MathTransform.Transform(pGeo.ToDoubleArray()));
        SharpMap.Geometries.Point pGeo2 = new Point(trans.MathTransform.Inverse().Transform(pUtm.ToDoubleArray()));

		result.Text += PrintResultTable(gcs, coordsys, pGeo, pUtm, new Point(2963503.91, 254759.80), pGeo2, "Lambert Conic Conformal 2SP test");
	}
 /// <summary>
 /// Geographic to geographic transformation
 /// </summary>
 /// <remarks>Adds a datum shift if nessesary</remarks>
 /// <param name="source"></param>
 /// <param name="target"></param>
 /// <returns></returns>
 private ICoordinateTransformation CreateGeog2Geog(IGeographicCoordinateSystem source, IGeographicCoordinateSystem target)
 {
     if (source.HorizontalDatum.EqualParams(target.HorizontalDatum))
     {
         //No datum shift needed
         return new CoordinateTransformation(source,
             target, TransformType.Conversion, new GeographicTransform(source, target),
             String.Empty, String.Empty, -1, String.Empty, String.Empty);
     }
     else
     {
         //Create datum shift
         //Convert to geocentric, perform shift and return to geographic
         CoordinateTransformationFactory ctFac = new CoordinateTransformationFactory();
         CoordinateSystemFactory cFac = new CoordinateSystemFactory();
         IGeocentricCoordinateSystem sourceCentric = cFac.CreateGeocentricCoordinateSystem(source.HorizontalDatum.Name + " Geocentric",
             source.HorizontalDatum, LinearUnit.Metre, source.PrimeMeridian);
         IGeocentricCoordinateSystem targetCentric = cFac.CreateGeocentricCoordinateSystem(target.HorizontalDatum.Name + " Geocentric",
             target.HorizontalDatum, LinearUnit.Metre, source.PrimeMeridian);
         ConcatenatedTransform ct = new ConcatenatedTransform();
         ct.CoordinateTransformationList.Add(ctFac.CreateFromCoordinateSystems(source, sourceCentric));
         ct.CoordinateTransformationList.Add(ctFac.CreateFromCoordinateSystems(sourceCentric, targetCentric));
         ct.CoordinateTransformationList.Add(ctFac.CreateFromCoordinateSystems(targetCentric, target));
         return new CoordinateTransformation(source,
             target, TransformType.Transformation, ct,
             String.Empty, String.Empty, -1, String.Empty, String.Empty);
     }
 }
        private static ICoordinateTransformation Geog2Proj(IGeographicCoordinateSystem source, IProjectedCoordinateSystem target)
        {
	        if (source.EqualParams(target.GeographicCoordinateSystem))
	        {
				IMathTransform mathTransform = CreateCoordinateOperation(target.Projection, target.GeographicCoordinateSystem.HorizontalDatum.Ellipsoid, target.LinearUnit);
		        return new CoordinateTransformation(source, target, TransformType.Transformation, mathTransform,
			        String.Empty, String.Empty, -1, String.Empty, String.Empty);
	        }
	        else
	        {
	        	// Geographic coordinatesystems differ - Create concatenated transform
		        ConcatenatedTransform ct = new ConcatenatedTransform();
		        CoordinateTransformationFactory ctFac = new CoordinateTransformationFactory();
		        ct.CoordinateTransformationList.Add(ctFac.CreateFromCoordinateSystems(source,target.GeographicCoordinateSystem));
		        ct.CoordinateTransformationList.Add(ctFac.CreateFromCoordinateSystems(target.GeographicCoordinateSystem, target));
		        return new CoordinateTransformation(source,
			        target, TransformType.Transformation, ct,
			        String.Empty, String.Empty, -1, String.Empty, String.Empty);
	        }
        }
Пример #12
0
	private void TestTransverseMercator()
	{
		CoordinateSystemFactory cFac = new SharpMap.CoordinateSystems.CoordinateSystemFactory();

		IEllipsoid ellipsoid = cFac.CreateFlattenedSphere("Airy 1830", 6377563.396, 299.32496, LinearUnit.Metre);

		IHorizontalDatum datum = cFac.CreateHorizontalDatum("Airy 1830", DatumType.HD_Geocentric, ellipsoid, null);
		IGeographicCoordinateSystem gcs = cFac.CreateGeographicCoordinateSystem("Airy 1830", AngularUnit.Degrees, datum,
			PrimeMeridian.Greenwich, new AxisInfo("Lon", AxisOrientationEnum.East),
			new AxisInfo("Lat", AxisOrientationEnum.North));
        List<ProjectionParameter> parameters = new List<ProjectionParameter>();
		parameters.Add(new ProjectionParameter("latitude_of_origin", 49));
		parameters.Add(new ProjectionParameter("central_meridian", -2));
		parameters.Add(new ProjectionParameter("scale_factor", 0.9996012717));
		parameters.Add(new ProjectionParameter("false_easting", 400000));
		parameters.Add(new ProjectionParameter("false_northing", -100000));
		IProjection projection = cFac.CreateProjection("Transverse Mercator", "Transverse_Mercator", parameters);

		IProjectedCoordinateSystem coordsys = cFac.CreateProjectedCoordinateSystem("OSGB 1936 / British National Grid", gcs, projection, LinearUnit.Metre, new AxisInfo("East", AxisOrientationEnum.East), new AxisInfo("North", AxisOrientationEnum.North));

		ICoordinateTransformation trans = new CoordinateTransformationFactory().CreateFromCoordinateSystems(gcs, coordsys);

		SharpMap.Geometries.Point pGeo = new SharpMap.Geometries.Point(0.5, 50.5);
		SharpMap.Geometries.Point pUtm = new Point(trans.MathTransform.Transform(pGeo.ToDoubleArray()));
		SharpMap.Geometries.Point pGeo2 = new Point(trans.MathTransform.Inverse().Transform(pUtm.ToDoubleArray()));

		result.Text += PrintResultTable(gcs, coordsys, pGeo, pUtm, new Point(577274.99, 69740.50), pGeo2, "Transverse Mercator test");
	}
Пример #13
0
	private void TestGeocentric()
	{
		CoordinateSystemFactory cFac = new SharpMap.CoordinateSystems.CoordinateSystemFactory();

		IGeographicCoordinateSystem gcs = cFac.CreateGeographicCoordinateSystem("WGS84", AngularUnit.Degrees, HorizontalDatum.WGS84,
			PrimeMeridian.Greenwich, new AxisInfo("Lon", AxisOrientationEnum.East),	new AxisInfo("Lat", AxisOrientationEnum.North));
		IGeocentricCoordinateSystem geoccs = cFac.CreateGeocentricCoordinateSystem("WGS84 geocentric", gcs.HorizontalDatum, LinearUnit.Metre, PrimeMeridian.Greenwich);

		ICoordinateTransformation trans = new CoordinateTransformationFactory().CreateFromCoordinateSystems(gcs, geoccs);

		SharpMap.Geometries.Point3D pGeo = new SharpMap.Geometries.Point3D(2.12955, 53.80939444, 73);
        SharpMap.Geometries.Point3D pGc = new Point3D(trans.MathTransform.Transform(pGeo.ToDoubleArray()));
		SharpMap.Geometries.Point3D pGeo2 = new Point3D(trans.MathTransform.Inverse().Transform(pGc.ToDoubleArray()));

		result.Text += PrintResultTable(gcs, geoccs, pGeo, pGc, new Point3D(3771793.97, 140253.34, 5124304.35), pGeo2, "Geocentric test");
		
		return;
	}
Пример #14
0
	private void TestAlbers()
	{
		CoordinateSystemFactory cFac = new SharpMap.CoordinateSystems.CoordinateSystemFactory();

		IEllipsoid ellipsoid = cFac.CreateFlattenedSphere("Clarke 1866", 6378206.4, 294.9786982138982,LinearUnit.USSurveyFoot);

		IHorizontalDatum datum = cFac.CreateHorizontalDatum("Clarke 1866", DatumType.HD_Geocentric, ellipsoid, null);
		IGeographicCoordinateSystem gcs = cFac.CreateGeographicCoordinateSystem("Clarke 1866", AngularUnit.Degrees, datum,
			PrimeMeridian.Greenwich, new AxisInfo("Lon", AxisOrientationEnum.East),
			new AxisInfo("Lat", AxisOrientationEnum.North));
        List<ProjectionParameter> parameters = new List<ProjectionParameter>();
		parameters.Add(new ProjectionParameter("central_meridian", -96));
		parameters.Add(new ProjectionParameter("latitude_of_origin", 23));
		parameters.Add(new ProjectionParameter("standard_parallel_1", 29.5));
		parameters.Add(new ProjectionParameter("standard_parallel_2", 45.5));
		parameters.Add(new ProjectionParameter("false_easting", 0));
		parameters.Add(new ProjectionParameter("false_northing", 0));
		IProjection projection = cFac.CreateProjection("Albers Conical Equal Area", "albers", parameters);

		IProjectedCoordinateSystem coordsys = cFac.CreateProjectedCoordinateSystem("Albers Conical Equal Area", gcs, projection, LinearUnit.Metre, new AxisInfo("East", AxisOrientationEnum.East), new AxisInfo("North", AxisOrientationEnum.North));

		ICoordinateTransformation trans = new CoordinateTransformationFactory().CreateFromCoordinateSystems(gcs, coordsys);

		SharpMap.Geometries.Point pGeo = new SharpMap.Geometries.Point(-75,35);
		SharpMap.Geometries.Point pUtm = new Point(trans.MathTransform.Transform(pGeo.ToDoubleArray()));
		SharpMap.Geometries.Point pGeo2 = new Point(trans.MathTransform.Inverse().Transform(pUtm.ToDoubleArray()));

		result.Text += PrintResultTable(gcs, coordsys, pGeo, pUtm, new Point(1885472.7,1535925), pGeo2, "Albers Conical Equal Area test");
	}
		public void TestMercator_2SP_Projection()
		{
			CoordinateSystemFactory cFac = new SharpMap.CoordinateSystems.CoordinateSystemFactory();

			IEllipsoid ellipsoid = cFac.CreateFlattenedSphere("Krassowski 1940", 6378245.0, 298.3, LinearUnit.Metre);

			IHorizontalDatum datum = cFac.CreateHorizontalDatum("Krassowski 1940", DatumType.HD_Geocentric, ellipsoid, null);
			IGeographicCoordinateSystem gcs = cFac.CreateGeographicCoordinateSystem("Krassowski 1940", AngularUnit.Degrees, datum,
				PrimeMeridian.Greenwich, new AxisInfo("Lon", AxisOrientationEnum.East),
				new AxisInfo("Lat", AxisOrientationEnum.North));
			System.Collections.Generic.List<ProjectionParameter> parameters = new System.Collections.Generic.List<ProjectionParameter>(5);
			parameters.Add(new ProjectionParameter("latitude_of_origin", 42));
			parameters.Add(new ProjectionParameter("central_meridian", 51));
			parameters.Add(new ProjectionParameter("false_easting", 0));
			parameters.Add(new ProjectionParameter("false_northing", 0));
			IProjection projection = cFac.CreateProjection("Mercator_2SP", "Mercator_2SP", parameters);

			IProjectedCoordinateSystem coordsys = cFac.CreateProjectedCoordinateSystem("Pulkovo 1942 / Mercator Caspian Sea", gcs, projection, LinearUnit.Metre, new AxisInfo("East", AxisOrientationEnum.East), new AxisInfo("North", AxisOrientationEnum.North));

			ICoordinateTransformation trans = new CoordinateTransformationFactory().CreateFromCoordinateSystems(gcs, coordsys);

			double[] pGeo = new double[] { 53, 53 };
			double[] pUtm = trans.MathTransform.Transform(pGeo);
			double[] pGeo2 = trans.MathTransform.Inverse().Transform(pUtm);

			double[] expected = new double[] { 165704.29, 5171848.07 };
			Assert.IsTrue(ToleranceLessThan(pUtm, expected, 0.02), String.Format("Mercator_2SP forward transformation outside tolerance, Expected {0}, got {1}", expected.ToString(), pUtm.ToString()));
			Assert.IsTrue(ToleranceLessThan(pGeo, pGeo2, 0.0000001), String.Format("Mercator_2SP reverse transformation outside tolerance, Expected {0}, got {1}", pGeo.ToString(), pGeo2.ToString()));
		}
        private static ICoordinateTransformation Proj2Proj(IProjectedCoordinateSystem source, IProjectedCoordinateSystem target)
        {
            ConcatenatedTransform ct = new ConcatenatedTransform();
            CoordinateTransformationFactory ctFac = new CoordinateTransformationFactory();
            //First transform from projection to geographic
            ct.CoordinateTransformationList.Add(ctFac.CreateFromCoordinateSystems(source, source.GeographicCoordinateSystem));
            //Transform geographic to geographic:
            ct.CoordinateTransformationList.Add(ctFac.CreateFromCoordinateSystems(source.GeographicCoordinateSystem, target.GeographicCoordinateSystem));
            //Transform to new projection
            ct.CoordinateTransformationList.Add(ctFac.CreateFromCoordinateSystems(target.GeographicCoordinateSystem, target));

            return new CoordinateTransformation(source,
                target, TransformType.Transformation, ct,
                String.Empty, String.Empty, -1, String.Empty, String.Empty);
        }
Пример #17
0
	protected void Button1_Click(object sender, EventArgs e)
	{
		lbOutput.Text = "";
		int inSRID = 0;
		int outSRID = 0;
		if (!int.TryParse(tbSRIDin.Text, out inSRID))
		{
			WriteError("Invalid SRID input number.");
			return;
		}
		if (!int.TryParse(tbSRIDout.Text, out outSRID))
		{
			WriteError("Invalid SRID output number.");
			return;
		}
		//Get input coordinate system by ID from CSV dataset
		ICoordinateSystem csIn = SridReader.GetCSbyID(inSRID);
		if (csIn == null)
		{
			WriteError("Unknown input SRID.");
			return;
		}
		//Get output coordinate system by ID from CSV dataset
		ICoordinateSystem csOut = SridReader.GetCSbyID(outSRID);
		if (csOut == null)
		{
			WriteError("Unknown output SRID.");
			return;
		}
		//Create coordinate transformation instance
		ICoordinateTransformation trans = null;
		try
		{
			trans = new CoordinateTransformationFactory().CreateFromCoordinateSystems(csIn, csOut);
		}
		catch (System.Exception ex)
		{
			WriteError(ex.Message);
			return;
		}
		lbOutput.Text += "<b>Input CS:</b>";
		WriteCoordSys(csIn);
		lbOutput.Text += "<b>Output CS:</b>";
		WriteCoordSys(csOut);
		string points = tbPoints.Text;
		lbOutput.Text += "<b>Transformed points:</b><br/>";
		foreach (string line in points.Split('\n'))
		{
			//Parse each line and transform the points.
			string[] vals = line.Split(',');
			if (vals.Length < 2) continue;
			double x = 0;
			double y = 0;
			if (!double.TryParse(vals[0], System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out x))
			{
				WriteError("Error parsing X", true);
				continue;
			}
			if (!double.TryParse(vals[1], System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out y))
			{
				WriteError("Error parsing Y", true);
				continue;
			}
			try
			{
				///Perform transformation
				double[] result = trans.MathTransform.Transform(new double[] { x, y });
				lbOutput.Text += String.Format(System.Globalization.CultureInfo.InvariantCulture, "{0} , {1}<br/>", result[0], result[1]);
			}
			catch(System.Exception ex)
			{
				WriteError(ex.Message, true);
			}
		}
	}
		public void TestTransverseMercator_Projection()
		{
			CoordinateSystemFactory cFac = new SharpMap.CoordinateSystems.CoordinateSystemFactory();

			IEllipsoid ellipsoid = cFac.CreateFlattenedSphere("Airy 1830", 6377563.396, 299.32496, LinearUnit.Metre);

			IHorizontalDatum datum = cFac.CreateHorizontalDatum("Airy 1830", DatumType.HD_Geocentric, ellipsoid, null);
			IGeographicCoordinateSystem gcs = cFac.CreateGeographicCoordinateSystem("Airy 1830", AngularUnit.Degrees, datum,
				PrimeMeridian.Greenwich, new AxisInfo("Lon", AxisOrientationEnum.East),
				new AxisInfo("Lat", AxisOrientationEnum.North));
			System.Collections.Generic.List<ProjectionParameter> parameters = new System.Collections.Generic.List<ProjectionParameter>(5);
			parameters.Add(new ProjectionParameter("latitude_of_origin", 49));
			parameters.Add(new ProjectionParameter("central_meridian", -2));
			parameters.Add(new ProjectionParameter("scale_factor", 0.9996012717));
			parameters.Add(new ProjectionParameter("false_easting", 400000));
			parameters.Add(new ProjectionParameter("false_northing", -100000));
			IProjection projection = cFac.CreateProjection("Transverse Mercator", "Transverse_Mercator", parameters);

			IProjectedCoordinateSystem coordsys = cFac.CreateProjectedCoordinateSystem("OSGB 1936 / British National Grid", gcs, projection, LinearUnit.Metre, new AxisInfo("East", AxisOrientationEnum.East), new AxisInfo("North", AxisOrientationEnum.North));

			ICoordinateTransformation trans = new CoordinateTransformationFactory().CreateFromCoordinateSystems(gcs, coordsys);

			double[] pGeo = new double[] { 0.5, 50.5 };
			double[] pUtm = trans.MathTransform.Transform(pGeo);
			double[] pGeo2 = trans.MathTransform.Inverse().Transform(pUtm);

			double[] expected = new double[] { 577274.99, 69740.50 };
			Assert.IsTrue(ToleranceLessThan(pUtm, expected, 0.02), String.Format("TransverseMercator forward transformation outside tolerance, Expected {0}, got {1}", expected.ToString(), pUtm.ToString()));
			Assert.IsTrue(ToleranceLessThan(pGeo, pGeo2, 0.0000001), String.Format("TransverseMercator reverse transformation outside tolerance, Expected {0}, got {1}", pGeo.ToString(), pGeo2.ToString()));
		}
        public void TestUnitTransforms()
        {
			ICoordinateSystem nadUTM = SRIDReader.GetCSbyID(2868); //UTM Arizona Central State Plane using Feet as units
			ICoordinateSystem wgs84GCS = SRIDReader.GetCSbyID(4326); //GCS WGS84
			ICoordinateTransformation trans = new CoordinateTransformationFactory().CreateFromCoordinateSystems(wgs84GCS, nadUTM);

			double[] p0 = new double[] { -111.89, 34.165 };
			double[] expected = new double[] { 708066.190579, 1151426.44638 };
			
			double[] p1 = trans.MathTransform.Transform(p0);
			double[] p2 = trans.MathTransform.Inverse().Transform(p1);

			Assert.IsTrue(ToleranceLessThan(p1, expected, 0.013), String.Format("Transformation outside tolerance, Expected [{0},{1}], got [{2},{3}]", expected[0], expected[1], p1[0],p1[1]));
			//WARNING: This accuracy is too poor!
			Assert.IsTrue(ToleranceLessThan(p0, p2, 0.0000001), String.Format("Transformation outside tolerance, Expected [{0},{1}], got [{2},{3}]", p0[0], p0[1], p2[0], p2[1]));
        }