/// <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 CoordinateSystemFactory CreateNad83ToLambertFactory(out IGeographicCoordinateSystem gcs, out IProjectedCoordinateSystem coordsys) { CoordinateSystemFactory cfac = new CoordinateSystemFactory(); // Define ellipsoid GRS 1980 used by NAD83 IEllipsoid ellipsoid = cfac.CreateFlattenedSphere("GRS 1980", 6378137, 298.257222101, LinearUnit.Metre); // Define NAD83 system IHorizontalDatum datum = cfac.CreateHorizontalDatum("NAD83 (CSRS)", DatumType.HD_Other, ellipsoid, null); gcs = cfac.CreateGeographicCoordinateSystem("NAD83 (CSRS)", AngularUnit.Degrees, datum, PrimeMeridian.Greenwich, new AxisInfo("Lon", AxisOrientationEnum.East), new AxisInfo("Lat", AxisOrientationEnum.North)); // Define Lambert parameters List <ProjectionParameter> parameters = new List <ProjectionParameter>(5); parameters.Add(new ProjectionParameter("latitude_of_origin", 44)); parameters.Add(new ProjectionParameter("central_meridian", -70)); parameters.Add(new ProjectionParameter("standard_parallel_1", 50)); parameters.Add(new ProjectionParameter("standard_parallel_2", 46)); parameters.Add(new ProjectionParameter("false_easting", 800000)); parameters.Add(new ProjectionParameter("false_northing", 0)); IProjection projection = cfac.CreateProjection("Lambert Conic Conformal (2SP)", "lambert_conformal_conic_2sp", parameters); coordsys = cfac.CreateProjectedCoordinateSystem("NAD83/Lambert", gcs, projection, LinearUnit.Metre, new AxisInfo("East", AxisOrientationEnum.East), new AxisInfo("North", AxisOrientationEnum.North)); return(cfac); }
/// <summary> /// Creates map object from <see cref="CartoProject"/> /// </summary> /// <param name="project"></param> /// <param name="definitions"></param> /// <param name="env"></param> /// <param name="cartoTranslator"></param> /// <returns></returns> private static Map CreateMap(CartoProject project, List <CartoDefinition> definitions, Env env, ICartoTranslator cartoTranslator) { Map map = new Map(project.Name); map.Size = new SizeF(700, 500); map.MinimumScale = ConvertUtility.ToScaleDenominator(project.MinZoom); map.MaximumScale = ConvertUtility.ToScaleDenominator(project.MaxZoom); // if (project.Bounds != null) // map.WGS84Bounds = project.Bounds[0] + "," + project.Bounds[1] + "," + project.Bounds[2] + "," + project.Bounds[3]; map.CRS = cartoTranslator.ToCoordinateSystem(string.IsNullOrEmpty(project.Srs) ? project.SrsName : project.Srs, !string.IsNullOrEmpty(project.SrsName)); SetMapProperties(map, GetProperties(definitions, env, "Map"), cartoTranslator); SetFontSets(map, definitions, env, cartoTranslator); if (project.Center != null) { if (map.CoordinateSystem == null) { CoordinateSystemFactory csFactory = new CoordinateSystemFactory(); map.CoordinateSystem = (CoordinateSystem)csFactory.CreateSphericalMercatorCoordinateSystem(); } double cx = Convert.ToDouble(project.Center[0]); double cy = Convert.ToDouble(project.Center[1]); double cz = Convert.ToDouble(project.Center[2]); double scale = MapSurfer.Utilities.MapUtility.GetTileMapResolution(cz); GeoAPI.CoordinateSystems.Transformations.ICoordinateTransformation trans = CoordinateTransformationFactory.CreateCoordinateTransformation(GeographicCoordinateSystem.WGS84, map.CoordinateSystem); trans.MathTransform.Transform(ref cx, ref cy, ref cz); map.SetCenterAndZoom(cx, cy, scale); } return(map); }
public static ProjNet.CoordinateSystems.Transformations.ICoordinateTransformation Transform2Lambert(ICoordinateSystem source) { if (source == null) throw new ArgumentException("Source coordinate system is null"); if (!(source is IGeographicCoordinateSystem)) throw new ArgumentException("Source coordinate system must be geographic"); CoordinateSystemFactory cFac = new CoordinateSystemFactory(); List<ProjectionParameter> parameters = new List<ProjectionParameter>(); parameters.Add(new ProjectionParameter("latitude_of_origin", 50)); parameters.Add(new ProjectionParameter("central_meridian", -95)); parameters.Add(new ProjectionParameter("standard_parallel_1", 33)); parameters.Add(new ProjectionParameter("standard_parallel_2", 45)); parameters.Add(new ProjectionParameter("false_easting", 0)); parameters.Add(new ProjectionParameter("false_northing", 0)); IProjection projection = cFac.CreateProjection("Lambert Conformal Conic 2SP", "lambert_conformal_conic_2sp", parameters); IProjectedCoordinateSystem coordsys = cFac.CreateProjectedCoordinateSystem("Lambert Conformal Conic 2SP", source as IGeographicCoordinateSystem, projection, ProjNet.CoordinateSystems.LinearUnit.Metre, new AxisInfo("East", AxisOrientationEnum.East), new AxisInfo("North", AxisOrientationEnum. North)); return new CoordinateTransformationFactory().CreateFromCoordinateSystems(source, coordsys); }
private void TestGeocentric() { CoordinateSystemFactory cFac = new 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); var pGeo = new Coordinate(2.12955, 53.80939444, 73); var pGc = Transform(trans.MathTransform, pGeo); trans.MathTransform.Invert(); var pGeo2 = Transform(trans.MathTransform, pGc); trans.MathTransform.Invert(); result.Text += PrintResultTable(gcs, geoccs, pGeo, pGc, new Coordinate(3771793.97, 140253.34, 5124304.35), pGeo2, "Geocentric test"); return; }
public void Test25832To3857() { const string wkt1 = //"PROJCS[\"ETRS89 / UTM zone 32N\",GEOGCS[\"ETRS89\",DATUM[\"European_Terrestrial_Reference_System_1989\",SPHEROID[\"GRS 1980\",6378137,298.257222101,AUTHORITY[\"EPSG\",\"7019\"]],AUTHORITY[\"EPSG\",\"6258\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.01745329251994328,AUTHORITY[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4258\"]],PROJECTION[\"Transverse_Mercator\"],PARAMETER[\"latitude_of_origin\",0],PARAMETER[\"central_meridian\",9],PARAMETER[\"scale_factor\",0.9996],PARAMETER[\"false_easting\",500000],PARAMETER[\"false_northing\",0],UNIT[\"metre\",1,AUTHORITY[\"EPSG\",\"9001\"]],AUTHORITY[\"EPSG\",\"25832\"]]"; "PROJCS[\"ETRS89 / UTM zone 32N\",GEOGCS[\"ETRS89\",DATUM[\"European_Terrestrial_Reference_System_1989\",SPHEROID[\"GRS 1980\",6378137,298.257222101,AUTHORITY[\"EPSG\",\"7019\"]],TOWGS84[0,0,0,0,0,0,0],AUTHORITY[\"EPSG\",\"6258\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4258\"]],UNIT[\"metre\",1,AUTHORITY[\"EPSG\",\"9001\"]],PROJECTION[\"Transverse_Mercator\"],PARAMETER[\"latitude_of_origin\",0],PARAMETER[\"central_meridian\",9],PARAMETER[\"scale_factor\",0.9996],PARAMETER[\"false_easting\",500000],PARAMETER[\"false_northing\",0],AUTHORITY[\"EPSG\",\"25832\"],AXIS[\"Easting\",EAST],AXIS[\"Northing\",NORTH]]"; ICoordinateSystem cs1 = null, cs2 = null; Assert.DoesNotThrow(() => cs1 = CoordinateSystemFactory.CreateFromWkt(wkt1)); Assert.IsNotNull(cs1); const string wkt2 = "PROJCS[\"WGS 84 / Pseudo-Mercator\",GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\", SPHEROID[\"WGS 84\",6378137,298.257223563,AUTHORITY[\"EPSG\",\"7030\"]],AUTHORITY[\"EPSG\",\"6326\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4326\"]],UNIT[\"metre\",1,AUTHORITY[\"EPSG\",\"9001\"]],PROJECTION[\"Mercator_1SP\"],PARAMETER[\"latitude_of_origin\", 0],PARAMETER[\"central_meridian\",0],PARAMETER[\"scale_factor\",1],PARAMETER[\"false_easting\",0],PARAMETER[\"false_northing\",0],EXTENSION[\"PROJ4\",\"+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs\"],AUTHORITY[\"EPSG\",\"3857\"],AXIS[\"X\",EAST],AXIS[\"Y\",NORTH]]"; Assert.DoesNotThrow(() => cs2 = CoordinateSystemFactory.CreateFromWkt(wkt2)); Assert.IsNotNull(cs2); ICoordinateTransformation ct = null; Assert.DoesNotThrow(() => ct = CoordinateTransformationFactory.CreateFromCoordinateSystems(cs1, cs2)); Assert.IsNotNull(ct); Assert.DoesNotThrow(() => ct = CoordinateTransformationFactory.CreateFromCoordinateSystems(cs2, cs1)); Assert.IsNotNull(ct); Assert.DoesNotThrow(() => ct = CoordinateTransformationFactory.CreateFromCoordinateSystems(cs1, ProjectedCoordinateSystem.WebMercator)); Assert.IsNotNull(ct); Assert.DoesNotThrow(() => ct = CoordinateTransformationFactory.CreateFromCoordinateSystems(ProjectedCoordinateSystem.WebMercator, cs1)); Assert.IsNotNull(ct); }
private static ICoordinateTransformation GetCartesianTransform(ref ReferenceOriginWgs84Point referenceOrigin) { if (referenceOrigin == null) { throw new ArgumentException("reference origin point must have value"); } var csFactory = new CoordinateSystemFactory(); var projectionParameters = new List <ProjectionParameter> { new ProjectionParameter("latitude_of_origin", referenceOrigin.Lat), new ProjectionParameter("central_meridian", referenceOrigin.Lon), new ProjectionParameter("false_easting", 0), new ProjectionParameter("false_northing", 0) }; var projection = csFactory.CreateProjection("Mercator_1SP", "Mercator", projectionParameters); IProjectedCoordinateSystem projectedCoordinateSystem = csFactory.CreateProjectedCoordinateSystem("My WGS84", GeographicCoordinateSystem.WGS84, projection, LinearUnit.Metre, new AxisInfo("E", AxisOrientationEnum.East), new AxisInfo("N", AxisOrientationEnum.North)); referenceOrigin.ProjectedCoordinateSystem = projectedCoordinateSystem; var ctFactory = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory(); var transform = ctFactory.CreateFromCoordinateSystems(GeographicCoordinateSystem.WGS84, projectedCoordinateSystem); var transformedPoint = transform.MathTransform.Transform(new[] { referenceOrigin.Lon, referenceOrigin.Lat }); var shift = transformedPoint[1] * -1; referenceOrigin.ShiftedY = shift; return(transform); }
public void TestNtsIssue191() { List <ProjectionParameter> parameters = new List <ProjectionParameter>(); parameters.Add(new ProjectionParameter("latitude_of_center", 45.30916666666666)); parameters.Add(new ProjectionParameter("longitude_of_center", -86)); parameters.Add(new ProjectionParameter("azimuth", 337.25556)); parameters.Add(new ProjectionParameter("rectified_grid_angle", 337.25556)); parameters.Add(new ProjectionParameter("scale_factor", 0.9996)); parameters.Add(new ProjectionParameter("false_easting", 2546731.496)); parameters.Add(new ProjectionParameter("false_northing", -4354009.816)); CoordinateSystemFactory factory = new CoordinateSystemFactory(); IProjection projection = factory.CreateProjection("Test Oblique", "oblique_mercator", parameters); Assert.That(projection, Is.Not.Null); IGeographicCoordinateSystem wgs84 = GeographicCoordinateSystem.WGS84; IProjectedCoordinateSystem dummy = factory.CreateProjectedCoordinateSystem("dummy pcs", wgs84, projection, LinearUnit.Metre, new AxisInfo("X", AxisOrientationEnum.East), new AxisInfo("Y", AxisOrientationEnum.North)); Assert.That(dummy, Is.Not.Null); CoordinateTransformationFactory transformationFactory = new CoordinateTransformationFactory(); ICoordinateTransformation transform = transformationFactory.CreateFromCoordinateSystems(wgs84, dummy); Assert.That(transform, Is.Not.Null); IMathTransform mathTransform = transform.MathTransform; IMathTransform inverse = mathTransform.Inverse(); Assert.That(inverse, Is.Not.Null); }
private void botonConectar_Click(object sender, EventArgs e) { if (gps.EsConectado) { gps.Stop(); botonConectar.Text = "Conectar"; } else { try { var coordinateSystemFactory = new CoordinateSystemFactory(); var coordinateTransformationFactory = new CoordinateTransformationFactory(); transformación = coordinateTransformationFactory.CreateFrom3DCoordinateSystems( CoordinateSystemAuthorityFactory.CreateGeographicCoordinateSystem(4979), coordinateSystemFactory.CreateFromWkt(Digi21.DigiNG.DigiNG.Wkt), SelectTransformationHelper.DialogSelectTransformation, CreateVerticalTransformationHelper.DialogCreateVerticalTransformation); } catch (Exception ex) { MessageBox.Show($"Se detectó el error: {ex.Message} al intentar crear una transformación entre el sistema de referencia de coordenadas del GPS y el de la ventana de dibujo"); return; } botonConectar.Enabled = false; gps.Start(); } }
override public FeatureList process(FeatureList input, FilterEnv env) { foreach (Feature feature in input) { CoordinateSystemFactory csf = new CoordinateSystemFactory(); ICoordinateSystem cssource = csf.CreateFromWkt(((SharpMapSpatialReference)feature.getGeometry().SpatialReference).CoordinateSystem.WKT); ICoordinateSystem cstarget; if (translateScript != null) { //Console.WriteLine(Registry.instance().GetEngine("Python").run(TranslateScript).asString()); cstarget = csf.CreateFromWkt(Registry.instance().GetEngine("Python").run(TranslateScript).asString()); } else { cstarget = csf.CreateFromWkt(env.getInputSRS().WKT); } CoordinateTransformationFactory ctf = new CoordinateTransformationFactory(); ICoordinateTransformation ct = ctf.CreateFromCoordinateSystems(cssource, cstarget); //if (feature.getGeometry().GeometryType == GeometryType2.Point) //{ // Point p = (Point)feature.getGeometry(); //GeometryTransform.TransformPoint(feature, ct.MathTransform); Geometry geom = feature.getGeometry(); Geometry geomRst = GeometryTransform.TransformGeometry(geom, ct.MathTransform); feature.setGeometry(geomRst); //} } return(input); }
public void TestAngularUnitsEqualParamsIssue() { //string sourceWkt = " UNIT[\"degree\",0.01745329251994328,AUTHORITY[\"EPSG\",\"9122\"]"; string wkt = "PROJCS[\"DHDN / Gauss-Kruger zone 3\",GEOGCS[\"DHDN\",DATUM[\"Deutsches_Hauptdreiecksnetz\",SPHEROID[\"Bessel 1841\",6377397.155,299.1528128,AUTHORITY[\"EPSG\",\"7004\"]],AUTHORITY[\"EPSG\",\"6314\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.01745329251994328,AUTHORITY[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4314\"]],PROJECTION[\"Transverse_Mercator\"],PARAMETER[\"latitude_of_origin\",0],PARAMETER[\"central_meridian\",9],PARAMETER[\"scale_factor\",1],PARAMETER[\"false_easting\",3500000],PARAMETER[\"false_northing\",0],UNIT[\"metre\",1,AUTHORITY[\"EPSG\",\"9001\"]],AUTHORITY[\"EPSG\",\"31467\"]]"; var pcs1 = CoordinateSystemFactory.CreateFromWkt(wkt) as ProjectedCoordinateSystem; Assert.NotNull(pcs1); Assert.NotNull(pcs1.GeographicCoordinateSystem); Assert.NotNull(pcs1.GeographicCoordinateSystem.AngularUnit); string savedWkt = pcs1.WKT; var pcs2 = CoordinateSystemFactory.CreateFromWkt(savedWkt) as ProjectedCoordinateSystem; //test AngularUnit parsing via ProjectedCoordinateSystem Assert.NotNull(pcs2); Assert.NotNull(pcs2.GeographicCoordinateSystem); Assert.NotNull(pcs2.GeographicCoordinateSystem.AngularUnit); //check equality of angular units via RadiansPerUnit Assert.AreEqual(pcs1.GeographicCoordinateSystem.AngularUnit.RadiansPerUnit, pcs2.GeographicCoordinateSystem.AngularUnit.RadiansPerUnit, 0.0000000000001); //check equality of angular units Assert.AreEqual(true, pcs1.GeographicCoordinateSystem.AngularUnit.EqualParams(pcs2.GeographicCoordinateSystem.AngularUnit)); }
public static ProjNet.CoordinateSystems.Transformations.ICoordinateTransformation Transform2Lambert(ICoordinateSystem source) { if (source == null) { throw new ArgumentException("Source coordinate system is null"); } if (!(source is IGeographicCoordinateSystem)) { throw new ArgumentException("Source coordinate system must be geographic"); } CoordinateSystemFactory cFac = new CoordinateSystemFactory(); List <ProjectionParameter> parameters = new List <ProjectionParameter>(); parameters.Add(new ProjectionParameter("latitude_of_origin", 50)); parameters.Add(new ProjectionParameter("central_meridian", -95)); parameters.Add(new ProjectionParameter("standard_parallel_1", 33)); parameters.Add(new ProjectionParameter("standard_parallel_2", 45)); parameters.Add(new ProjectionParameter("false_easting", 0)); parameters.Add(new ProjectionParameter("false_northing", 0)); IProjection projection = cFac.CreateProjection("Lambert Conformal Conic 2SP", "lambert_conformal_conic_2sp", parameters); IProjectedCoordinateSystem coordsys = cFac.CreateProjectedCoordinateSystem("Lambert Conformal Conic 2SP", source as IGeographicCoordinateSystem, projection, ProjNet.CoordinateSystems.LinearUnit.Metre, new AxisInfo("East", AxisOrientationEnum.East), new AxisInfo("North", AxisOrientationEnum. North)); return(new CoordinateTransformationFactory().CreateFromCoordinateSystems(source, coordsys)); }
public static Geometry ProjectTo4326(this Geometry geometry) { var sourceCoordinateSystem = new CoordinateSystemFactory().CreateFromWkt(CoordinateSystemsWkTs[geometry.SRID]); var transformation = new CoordinateTransformationFactory().CreateFromCoordinateSystems(sourceCoordinateSystem, GeographicCoordinateSystem.WGS84); return(Transform(geometry, transformation.MathTransform, 4326)); }
private ProjNet.CoordinateSystems.ICoordinateSystem getMercatorProjection() { CoordinateSystemFactory factory = new CoordinateSystemFactory(); ProjNet.CoordinateSystems.IGeographicCoordinateSystem wgs84 = factory.CreateGeographicCoordinateSystem("WGS 84", AngularUnit.Degrees, HorizontalDatum.WGS84, PrimeMeridian.Greenwich, new ProjNet.CoordinateSystems.AxisInfo("north", ProjNet.CoordinateSystems.AxisOrientationEnum.North), new AxisInfo("east", AxisOrientationEnum.East)); List <ProjectionParameter> parameters = new List <ProjectionParameter> { new ProjectionParameter("semi_major", 6378137), new ProjectionParameter("semi_minor", 6378137), new ProjectionParameter("latitude_of_origin", 0.0), new ProjectionParameter("central_meridian", 0.0), new ProjectionParameter("scale_factor", 1.0), new ProjectionParameter("false_easting", 0.0), new ProjectionParameter("false_northing", 0.0) }; IProjection projection = factory.CreateProjection("Mercator", "mercator_1sp", parameters); IProjectedCoordinateSystem mercator = factory.CreateProjectedCoordinateSystem("Mercator", wgs84, projection, LinearUnit.Metre, new AxisInfo("East", AxisOrientationEnum.East), new AxisInfo("North", AxisOrientationEnum.North)); return(mercator); }
public static ICoordinateTransformation LatLonToGoogle() { CoordinateSystemFactory csFac = new CoordinateSystemFactory(); CoordinateTransformationFactory ctFac = new CoordinateTransformationFactory(); IGeographicCoordinateSystem sourceCs = csFac.CreateGeographicCoordinateSystem( "WGS 84", AngularUnit.Degrees, HorizontalDatum.WGS84, PrimeMeridian.Greenwich, new AxisInfo("north", AxisOrientationEnum.North), new AxisInfo("east", AxisOrientationEnum.East)); List <ProjectionParameter> parameters = new List <ProjectionParameter> { new ProjectionParameter("semi_major", 6378137.0), new ProjectionParameter("semi_minor", 6378137.0), new ProjectionParameter("latitude_of_origin", 0.0), new ProjectionParameter("central_meridian", 0.0), new ProjectionParameter("scale_factor", 1.0), new ProjectionParameter("false_easting", 0.0), new ProjectionParameter("false_northing", 0.0) }; IProjection projection = csFac.CreateProjection("Google Mercator", "mercator_1sp", parameters); IProjectedCoordinateSystem targetCs = csFac.CreateProjectedCoordinateSystem( "Google Mercator", sourceCs, projection, LinearUnit.Metre, new AxisInfo("East", AxisOrientationEnum.East), new AxisInfo("North", AxisOrientationEnum.North)); ICoordinateTransformation transformation = ctFac.CreateFromCoordinateSystems(sourceCs, targetCs); return(transformation); }
// GIS RV09 - Slide 4 private IProjectedCoordinateSystem CreateUtmProjection(int utmZone) { CoordinateSystemFactory cFac = new CoordinateSystemFactory(); // Create geographic coordinate system based on the WGS84 datum IEllipsoid ellipsoid = cFac.CreateFlattenedSphere("WGS 84", 6378137, 298.257223563, LinearUnit.Metre); IHorizontalDatum datum = cFac.CreateHorizontalDatum("WGS 84", DatumType.HD_Geocentric, ellipsoid, null); IGeographicCoordinateSystem gcs = cFac.CreateGeographicCoordinateSystem("WGS 84", AngularUnit.Degrees, datum, PrimeMeridian.Greenwich, new AxisInfo("Lon", AxisOrientationEnum.East), new AxisInfo("Lat", AxisOrientationEnum.North)); // Create UTM projection List <ProjectionParameter> parameters = new List <ProjectionParameter>(); parameters.Add(new ProjectionParameter("latitude_of_origin", 0)); parameters.Add(new ProjectionParameter("central_meridian", -183 + 6 * utmZone)); parameters.Add(new ProjectionParameter("scale_factor", 0.9996)); parameters.Add(new ProjectionParameter("false_easting", 500000)); parameters.Add(new ProjectionParameter("false_northing", 0.0)); IProjection projection = cFac.CreateProjection("Transverse Mercator", "Transverse_Mercator", parameters); return(cFac.CreateProjectedCoordinateSystem("WGS 84 / UTM zone " + utmZone.ToString() + "N", gcs, projection, LinearUnit.Metre, new AxisInfo("East", AxisOrientationEnum.East), new AxisInfo("Norh", AxisOrientationEnum.North))); }
public static ICoordinateSystem GetProjection(string shapeFilePath) { var projectionFilePath = Path.ChangeExtension(shapeFilePath, "prj"); var projection = File.ReadAllText(projectionFilePath); var cfac = new CoordinateSystemFactory(); return(cfac.CreateFromWkt(projection)); }
public void Test_Constructor1() { ICoordinateSystemFactory csFactory = new CoordinateSystemFactory(); IEllipsoid ellipsoid = new Ellipsoid(20926348, -1.0, 294.26068, true, new LinearUnit(1)); Assertion.AssertEquals("ctor. 2 ", 20926348.0, ellipsoid.SemiMajorAxis); Assertion.AssertEquals("ctor. 3 ", 20855233.000877455, ellipsoid.SemiMinorAxis); }
public static ICoordinateTransformation GetCoordinateTransformer( ICoordinateSystem source, ICoordinateSystem dest) { var ctfac = new CoordinateTransformationFactory(); var cfac = new CoordinateSystemFactory(); return(ctfac.CreateFromCoordinateSystems(source, dest)); }
public void TestCentralMeridianParse() { const string strSouthPole = "PROJCS[\"South_Pole_Lambert_Azimuthal_Equal_Area\",GEOGCS[\"GCS_WGS_1984\",DATUM[\"D_WGS_1984\",SPHEROID[\"WGS_1984\",6378137,298.257223563]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.017453292519943295]],PROJECTION[\"Lambert_Azimuthal_Equal_Area\"],PARAMETER[\"False_Easting\",0],PARAMETER[\"False_Northing\",0],PARAMETER[\"Central_Meridian\",-127],PARAMETER[\"Latitude_Of_Origin\",-90],UNIT[\"Meter\",1]]"; var pCoordSysFactory = new CoordinateSystemFactory(); var pSouthPole = pCoordSysFactory.CreateFromWkt(strSouthPole); Assert.IsNotNull(pSouthPole); }
public static Coordinate[] Transform(Coordinate[] points, string sourceCoordinateSystemString, string targetCoordinateSystemString = "GEOGCS[\"GCS_WGS_1984\",DATUM[\"D_WGS_1984\",SPHEROID[\"WGS_1984\",6378137,298.257223563]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.0174532925199433]]") { CoordinateSystemFactory coordinateSystemFactory = new CoordinateSystemFactory(); ICoordinateSystem sourceCoordinateSystem = coordinateSystemFactory.CreateFromWkt(sourceCoordinateSystemString); ICoordinateSystem targetCoordinateSystem = coordinateSystemFactory.CreateFromWkt(targetCoordinateSystemString); ICoordinateTransformation trans = (new CoordinateTransformationFactory()).CreateFromCoordinateSystems(sourceCoordinateSystem, targetCoordinateSystem); return(trans.MathTransform.TransformList(points).ToArray()); }
private static ICoordinateTransformation GetCoordinateTransformation() { //The SRS for this datasource is EPSG:4326, therefore we need to transfrom it to OSM projection CoordinateTransformationFactory ctf = new CoordinateTransformationFactory(); CoordinateSystemFactory cf = new CoordinateSystemFactory(); ICoordinateSystem epsg4326 = cf.CreateFromWkt("GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563,AUTHORITY[\"EPSG\",\"7030\"]],AUTHORITY[\"EPSG\",\"6326\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.01745329251994328,AUTHORITY[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4326\"]]"); ICoordinateSystem epsg3857 = cf.CreateFromWkt("PROJCS[\"Popular Visualisation CRS / Mercator\", GEOGCS[\"Popular Visualisation CRS\", DATUM[\"Popular Visualisation Datum\", SPHEROID[\"Popular Visualisation Sphere\", 6378137, 0, AUTHORITY[\"EPSG\",\"7059\"]], TOWGS84[0, 0, 0, 0, 0, 0, 0], AUTHORITY[\"EPSG\",\"6055\"]],PRIMEM[\"Greenwich\", 0, AUTHORITY[\"EPSG\", \"8901\"]], UNIT[\"degree\", 0.0174532925199433, AUTHORITY[\"EPSG\", \"9102\"]], AXIS[\"E\", EAST], AXIS[\"N\", NORTH], AUTHORITY[\"EPSG\",\"4055\"]], PROJECTION[\"Mercator\"], PARAMETER[\"False_Easting\", 0], PARAMETER[\"False_Northing\", 0], PARAMETER[\"Central_Meridian\", 0], PARAMETER[\"Latitude_of_origin\", 0], UNIT[\"metre\", 1, AUTHORITY[\"EPSG\", \"9001\"]], AXIS[\"East\", EAST], AXIS[\"North\", NORTH], AUTHORITY[\"EPSG\",\"3857\"]]"); return(ctf.CreateFromCoordinateSystems(epsg4326, epsg3857));
public void TestAlbersProjection() { var cFac = new CoordinateSystemFactory(); var ellipsoid = cFac.CreateFlattenedSphere( "Clarke 1866", 6378206.4, 294.9786982138982, LinearUnit.USSurveyFoot); var datum = cFac.CreateHorizontalDatum( "Clarke 1866", DatumType.HD_Geocentric, ellipsoid, null); var gcs = cFac.CreateGeographicCoordinateSystem( "Clarke 1866", AngularUnit.Degrees, datum, PrimeMeridian.Greenwich, new AxisInfo("Lon", AxisOrientationEnum.East), new AxisInfo("Lat", AxisOrientationEnum.North)); var parameters = new 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)); var projection = cFac.CreateProjection( "Albers Conical Equal Area", "albers", parameters); var coordsys = cFac.CreateProjectedCoordinateSystem( "Albers Conical Equal Area", gcs, projection, LinearUnit.Metre, new AxisInfo("East", AxisOrientationEnum.East), new AxisInfo("North", AxisOrientationEnum.North)); var trans = new CoordinateTransformationFactory().CreateFromCoordinateSystems(gcs, coordsys); var f = GeometryFactory.Default; var pGeo = f.CreatePoint(new Coordinate(-75, 35)); var pUtm = GeometryTransform.TransformPoint(f, pGeo, trans.MathTransform); var pGeo2 = GeometryTransform.TransformPoint(f, pUtm, trans.MathTransform.Inverse()); var expected = f.CreatePoint(new Coordinate(1885472.7, 1535925)); Assert.IsTrue(ToleranceLessThan(pUtm, expected, 0.05), string.Format("Albers forward transformation outside tolerance, Expected [{0},{1}], got [{2},{3}]", expected.X, expected.Y, pUtm.X, pUtm.Y)); Assert.IsTrue(ToleranceLessThan(pGeo, pGeo2, 0.0000001), string.Format("Albers reverse transformation outside tolerance, Expected [{0},{1}], got [{2},{3}]", pGeo.X, pGeo.Y, pGeo2.X, pGeo2.Y)); }
public static ICoordinateSystem GetProjection(ZipArchiveEntry projectionEntry) { using (var projectionStream = projectionEntry.Open()) using (var stream = new StreamReader(projectionStream)) { var projection = stream.ReadToEnd(); var cfac = new CoordinateSystemFactory(); return(cfac.CreateFromWkt(projection)); } }
private void CreateCoordinateSystemFromWkt(string value) { if (CoordinateSystemFactory == null || string.IsNullOrEmpty(srsWkt)) { CoordinateSystem = null; return; } CoordinateSystem = CoordinateSystemFactory.CreateFromWkt(value); }
public void TestCreateFlattenedSphere1() { ICoordinateSystemFactory csFactory = new CoordinateSystemFactory(); IEllipsoid ellipsoid = csFactory.CreateFlattenedSphere("test", 20926348.0, 294.26068, new LinearUnit(1)); Assertion.AssertEquals("ctor. 1 ", "test", ellipsoid.Name); Assertion.AssertEquals("ctor. 2 ", 20926348.0, ellipsoid.SemiMajorAxis); Assertion.AssertEquals("ctor. 3 ", 20855233.000877455, ellipsoid.SemiMinorAxis); Assertion.AssertEquals("ctor. 4 ", 294.26068, ellipsoid.InverseFlattening); }
static void Main(string[] args) { Console.WriteLine("Transforma las coordenadas modelo de un archivo .abs.xml de un SRC a otro. No transforma el cálculo, solo las coordenadas modelo."); if (args.Length < 4) { Console.Error.WriteLine("Error: No has proporcionado los parámetros suficientes."); Console.Error.WriteLine("[ruta del archivo .prj con la cadena WKT de las coordenadas modelo originales del archivo .abs.xml.]"); Console.Error.WriteLine("[ruta del archivo .prj con la cadena WKT de las coordenadas modelo destino del archivo .abs.xml.]"); Console.Error.WriteLine("[ruta del archivo .abs.xml a transformar]"); Console.Error.WriteLine("[ruta del archivo .abs.xml a generar con las coordenadas transformadas]"); Console.Error.WriteLine(""); Console.Error.WriteLine("Ejemplo:"); Console.Error.WriteLine(@"TransformaCoordenadasModeloOriAbsoluta E:\Tickets\435\wgs84-16n.prj E:\Tickets\435\wgs84.prj E:\Tickets\435\a.abs.xml E:\Tickets\435\b.abs.xml"); return; } var fábricaSrc = new CoordinateSystemFactory(); var srcOrigen = fábricaSrc.CreateFromWkt(File.ReadAllText(args[0])); var srcDestino = fábricaSrc.CreateFromWkt(File.ReadAllText(args[1])); var transformación = CoordinateTransformationFactory.CreateFromHorizontalCoordinateSystems(srcOrigen, srcDestino, null); var abs = new XmlDocument(); abs.Load(args[2]); var nsManager = new XmlNamespaceManager(abs.NameTable); nsManager.AddNamespace("abs", "http://schemas.digi21.net/Digi3D/AbsoluteOrientation/v1.0"); var coordenadasModelo = abs.SelectNodes("/abs:absolute/abs:points/abs:point/abs:model", nsManager); foreach (XmlNode coordenadaModelo in coordenadasModelo) { var nodoX = coordenadaModelo.SelectSingleNode("abs:x", nsManager); var nodoY = coordenadaModelo.SelectSingleNode("abs:y", nsManager); double[] coordenadasUtm = { double.Parse(nodoX.InnerText, CultureInfo.InvariantCulture), double.Parse(nodoY.InnerText, CultureInfo.InvariantCulture), }; var coordenadasGeo = transformación.MathTransform.Transform(coordenadasUtm); var clonX = nodoX.Clone(); clonX.InnerText = coordenadasGeo[0].ToString(CultureInfo.InvariantCulture); coordenadaModelo.ReplaceChild(clonX, nodoX); var clonY = nodoY.Clone(); clonY.InnerText = coordenadasGeo[1].ToString(CultureInfo.InvariantCulture); coordenadaModelo.ReplaceChild(clonY, nodoY); } abs.Save(args[3]); }
private void BuildGrid() { var gridLines = new List <Feature>(); if (CoordinateSystemFactory == null) { log.DebugFormat("Showing map grid is only supported when map has coordinate system defined"); return; // can only draw if coordinate system factory is available } for (var i = -180; i <= 180; i += 10) { var coordinates = new ICoordinate[179]; for (var j = -89; j <= 89; j++) { coordinates[j + 89] = new Coordinate(i, j); } gridLines.Add(new Feature { Geometry = new LineString(coordinates) }); } for (var i = -90; i <= 90; i += 10) { var coordinates = new ICoordinate[361]; for (var j = -180; j <= 180; j++) { coordinates[j + 180] = new Coordinate(j, i); } gridLines.Add(new Feature { Geometry = new LineString(coordinates) }); } var src = CoordinateSystemFactory.CreateFromEPSG(4326 /* WGS84 */); var dst = CoordinateSystem; var transformation = dst == null ? null : CoordinateSystemFactory.CreateTransformation(src, dst); gridLayer = new VectorLayer { DataSource = new FeatureCollection { Features = gridLines, CoordinateSystem = src }, CoordinateTransformation = transformation, ShowInTreeView = false, ShowInLegend = false, Selectable = false, Map = this }; gridLayer.Style.Line.Color = Color.FromArgb(50, 100, 100, 100); }
private const string XY_M = "LOCAL_CS[\"Non-Earth (Meter)\",LOCAL_DATUM[\"Local Datum\",0],UNIT[\"Meter\", 1],AXIS[\"X\",EAST],AXIS[\"Y\",NORTH]]"; //NOXLATE internal ActualCoordinateSystem(ICoordinateSystem coordinateSystem) { if (coordinateSystem == null) { throw new ArgumentNullException(nameof(coordinateSystem)); //NOXLATE } CoordinateTransformationFactory f = new CoordinateTransformationFactory(); CoordinateSystemFactory cf = new CoordinateSystemFactory(); m_transform = f.CreateFromCoordinateSystems(coordinateSystem, cf.CreateFromWkt(XY_M)); }
public Projections() { CoordinateSystemFactory c = new CoordinateSystemFactory(); ICoordinateSystem osgb = c.CreateFromWkt("PROJCS[\"OSGB 1936 / British National Grid\",GEOGCS[\"OSGB 1936\",DATUM[\"OSGB_1936\",SPHEROID[\"Airy 1830\",6377563.396,299.3249646,AUTHORITY[\"EPSG\",\"7001\"]],AUTHORITY[\"EPSG\",\"6277\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.01745329251994328,AUTHORITY[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4277\"]],PROJECTION[\"Transverse_Mercator\"],PARAMETER[\"latitude_of_origin\",49],PARAMETER[\"central_meridian\",-2],PARAMETER[\"scale_factor\",0.9996012717],PARAMETER[\"false_easting\",400000],PARAMETER[\"false_northing\",-100000],UNIT[\"metre\",1,AUTHORITY[\"EPSG\",\"9001\"]],AUTHORITY[\"EPSG\",\"27700\"]]"); ICoordinateSystem wgs = c.CreateFromWkt("GEOGCS[\"GCS_WGS_1984\",DATUM[\"D_WGS_1984\",SPHEROID[\"WGS_1984\",6378137,298.257223563]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.0174532925199433]]"); CoordinateTransformationFactory trf = new CoordinateTransformationFactory(); this.OsgbToWgs = trf.CreateFromCoordinateSystems(osgb, wgs); this.WgsToOsgb = trf.CreateFromCoordinateSystems(wgs, osgb); }
public static LambertCoordinate ConvertNAD83ToLambertMtq(double lat, double lon) { IGeographicCoordinateSystem gcs; IProjectedCoordinateSystem coordsys; CoordinateSystemFactory cfac = CreateNad83ToLambertFactory(out gcs, out coordsys); // execute transformation ICoordinateTransformation trans = new CoordinateTransformationFactory().CreateFromCoordinateSystems(gcs, coordsys); return(new LambertCoordinate(trans.MathTransform.Transform(new[] { lon, lat }))); }
public void TestAlbersProjection() { ICoordinateSystemFactory cFac = new CoordinateSystemFactory(); ILinearUnit usSurveyFoot = cFac.CreateLinearUnit(); IEllipsoid ellipsoid = cFac.CreateFlattenedSphere( 6378206.4, 294.9786982138982, LinearUnit.USSurveyFoot, "Clarke 1866"); IHorizontalDatum datum = cFac.CreateHorizontalDatum( DatumType.HorizontalGeocentric, ellipsoid, null, "Clarke 1866"); IGeographicCoordinateSystem gcs = cFac.CreateGeographicCoordinateSystem( "Clarke 1866", AngularUnit.Degrees, datum, PrimeMeridian.Greenwich, new AxisInfo("Lon", AxisOrientation.East), new AxisInfo("Lat", AxisOrientation.North)); //Collection<ProjectionParameter> parameters = new Collection<ProjectionParameter>(5); Collection<ProjectionParameter> parameters = new Collection<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( gcs, projection, LinearUnit.Metre, new AxisInfo("East", AxisOrientation.East), new AxisInfo("North", AxisOrientation.North)); ICoordinateTransformation trans = new CoordinateTransformationFactory() .CreateFromCoordinateSystems(gcs, coordsys); IPoint pGeo = new Point(-75, 35); IPoint pUtm = trans.MathTransform.Transform(pGeo); IPoint pGeo2 = trans.MathTransform.Inverse().Transform(pUtm); IPoint expected = new IPoint(1885472.7, 1535925); Assert.IsTrue(toleranceLessThan(pUtm, expected, 0.05), String.Format("Albers forward transformation outside tolerance, Expected {0}, got {1}", expected, pUtm)); Assert.IsTrue(toleranceLessThan(pGeo, pGeo2, 0.0000001), String.Format("Albers reverse transformation outside tolerance, Expected {0}, got {1}", pGeo.ToString(), pGeo2.ToString())); }
private void TestAlbers() { CoordinateSystemFactory cFac = new 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); var pGeo = new Coordinate(-75, 35); var pUtm = Transform(trans.MathTransform, pGeo); trans.MathTransform.Invert(); var pGeo2 = Transform(trans.MathTransform, pUtm); trans.MathTransform.Invert(); result.Text += PrintResultTable(gcs, coordsys, pGeo, pUtm, new Coordinate(1885472.7, 1535925), pGeo2, "Albers Conical Equal Area test"); }
public void TestMercator_1SP_Projection() { CoordinateSystemFactory cFac = new 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", AxisOrientation.East), new AxisInfo("Lat", AxisOrientation.North)); //Collection<ProjectionParameter> parameters = new Collection<ProjectionParameter>(5); Collection<ProjectionParameter> parameters = new Collection<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", AxisOrientation.East), new AxisInfo("North", AxisOrientation.North)); ICoordinateTransformation trans = new CoordinateTransformationFactory().CreateFromCoordinateSystems(gcs, coordsys); Point pGeo = new Point(120, -3); Point pUtm = trans.MathTransform.Transform(pGeo); Point pGeo2 = trans.MathTransform.Inverse().Transform(pUtm); Point expected = new Point(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())); }
public void TestLambertConicConformal2SP_Projection() { CoordinateSystemFactory cFac = new 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", AxisOrientation.East), new AxisInfo("Lat", AxisOrientation.North)); //Collection<ProjectionParameter> parameters = new Collection<ProjectionParameter>(5); Collection<ProjectionParameter> parameters = new Collection<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", AxisOrientation.East), new AxisInfo("North", AxisOrientation.North)); ICoordinateTransformation trans = new CoordinateTransformationFactory().CreateFromCoordinateSystems(gcs, coordsys); Point pGeo = new Point(-96, 28.5); Point pUtm = trans.MathTransform.Transform(pGeo); Point pGeo2 = trans.MathTransform.Inverse().Transform(pUtm); Point expected = new Point(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())); }
public static ProjNet.CoordinateSystems.Transformations.ICoordinateTransformation Transform2Mercator(ICoordinateSystem source) { CoordinateSystemFactory cFac = new CoordinateSystemFactory(); List<ProjectionParameter> parameters = new List<ProjectionParameter>(); parameters.Add(new ProjectionParameter("latitude_of_origin", 0)); parameters.Add(new ProjectionParameter("central_meridian", 0)); parameters.Add(new ProjectionParameter("false_easting", 0)); parameters.Add(new ProjectionParameter("false_northing", 0)); IProjection projection = cFac.CreateProjection("Mercator", "Mercator_2SP", parameters); IProjectedCoordinateSystem coordsys = cFac.CreateProjectedCoordinateSystem("Mercator", source as IGeographicCoordinateSystem, projection, ProjNet.CoordinateSystems.LinearUnit.Metre, new AxisInfo("East", AxisOrientationEnum.East), new AxisInfo("North", AxisOrientationEnum. North)); return new CoordinateTransformationFactory().CreateFromCoordinateSystems(source, coordsys); }
/// <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); } }
public void TestMercator_2SP_Projection() { CoordinateSystemFactory cFac = new 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", AxisOrientation.East), new AxisInfo("Lat", AxisOrientation.North)); //Collection<ProjectionParameter> parameters = new Collection<ProjectionParameter>(5); Collection<ProjectionParameter> parameters = new Collection<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", AxisOrientation.East), new AxisInfo("North", AxisOrientation.North)); ICoordinateTransformation trans = new CoordinateTransformationFactory().CreateFromCoordinateSystems(gcs, coordsys); Point pGeo = new Point(53, 53); Point pUtm = trans.MathTransform.Transform(pGeo); Point pGeo2 = trans.MathTransform.Inverse().Transform(pUtm); Point expected = new Point(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())); }
public void TestGeocentric() { CoordinateSystemFactory cFac = new CoordinateSystemFactory(); IGeographicCoordinateSystem gcs = cFac.CreateGeographicCoordinateSystem("ETRF89 Geographic", AngularUnit.Degrees, HorizontalDatum.ETRF89, PrimeMeridian.Greenwich, new AxisInfo("East", AxisOrientation.East), new AxisInfo("North", AxisOrientation.North)); IGeocentricCoordinateSystem gcenCs = cFac.CreateGeocentricCoordinateSystem("ETRF89 Geocentric", HorizontalDatum.ETRF89, LinearUnit.Metre, PrimeMeridian.Greenwich); CoordinateTransformationFactory gtFac = new CoordinateTransformationFactory(); ICoordinateTransformation ct = gtFac.CreateFromCoordinateSystems(gcs, gcenCs); Point pExpected = Point.FromDMS(2, 7, 46.38, 53, 48, 33.82); Point3D pExpected3D = new Point3D(pExpected.X, pExpected.Y, 73.0); Point3D p0 = new Point3D(3771793.97, 140253.34, 5124304.35); Point3D p1 = ct.MathTransform.Transform(pExpected3D) as Point3D; Point3D p2 = ct.MathTransform.Inverse().Transform(p1) as Point3D; Assert.IsTrue(toleranceLessThan(p1, p0, 0.01)); Assert.IsTrue(toleranceLessThan(p2, pExpected, 0.00001)); }
private void TestLambertConicConformal_2SP() { CoordinateSystemFactory cFac = new 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); var pGeo = new Coordinate(-96, 28.5); var pUtm = Transform(trans.MathTransform, pGeo); trans.MathTransform.Invert(); var pGeo2 = Transform(trans.MathTransform, pUtm); trans.MathTransform.Invert(); result.Text += PrintResultTable(gcs, coordsys, pGeo, pUtm, new Coordinate(2963503.91, 254759.80), pGeo2, "Lambert Conic Conformal 2SP test"); }
private static ICoordinateSystem GetCoordinateSystemForSrid(int srid) { if (srid <= 0) return null; ICoordinateSystem res = null; #if !DotSpatialProjections if (_sridCoordinateSystem.TryGetValue(srid, out res)) return res; var wkt = Converters.WellKnownText.SpatialReference.SridToWkt(srid); if (string.IsNullOrEmpty(wkt)) { Logger.Error( fmh => fmh("No definition for SRID {0}!", srid)); return null; } var csFactory = new CoordinateSystemFactory(); try { res = csFactory.CreateFromWkt(wkt); } catch (Exception) { Logger.Error( fmh => fmh("Could not parse definition for SRID {0}:\n{1}", srid, wkt)); return null; } _sridCoordinateSystem.Add(srid, res); #else try { if (_sridDefinition != null) { string proj4; if (_sridDefinition.TryGetValue(srid, out proj4)) res = ICoordinateSystem.FromProj4String(proj4); } if (res == null) res = DotSpatial.Projections.ProjectionInfo.FromEpsgCode(srid); } catch (Exception) { Logger.Error( fmh => fmh("Could not get coordinate system for SRID {0}!", srid) ); return null; } #endif return res; }
public void TestTransverseMercator_Projection() { CoordinateSystemFactory cFac = new 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", AxisOrientation.East), new AxisInfo("Lat", AxisOrientation.North)); //Collection<ProjectionParameter> parameters = new Collection<ProjectionParameter>(5); Collection<ProjectionParameter> parameters = new Collection<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", AxisOrientation.East), new AxisInfo("North", AxisOrientation.North)); ICoordinateTransformation trans = new CoordinateTransformationFactory().CreateFromCoordinateSystems(gcs, coordsys); Point pGeo = new Point(0.5, 50.5); Point pUtm = trans.MathTransform.Transform(pGeo); Point pGeo2 = trans.MathTransform.Inverse().Transform(pUtm); Point expected = new Point(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())); }
private void TestTransverseMercator() { CoordinateSystemFactory cFac = new 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); var pGeo = new Coordinate(0.5, 50.5); var pUtm = Transform(trans.MathTransform, pGeo); trans.MathTransform.Invert(); var pGeo2 = Transform(trans.MathTransform, pUtm); trans.MathTransform.Invert(); result.Text += PrintResultTable(gcs, coordsys, pGeo, pUtm, new Coordinate(577274.99, 69740.50), pGeo2, "Transverse Mercator test"); }
private void TestMercator_2SP() { CoordinateSystemFactory cFac = new 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); var pGeo = new Coordinate(53, 53); var pUtm = Transform(trans.MathTransform, pGeo); trans.MathTransform.Invert(); var pGeo2 = Transform(trans.MathTransform, pUtm); trans.MathTransform.Invert(); result.Text += PrintResultTable(gcs, coordsys, pGeo, pUtm, new Coordinate(165704.29, 5171848.07), pGeo2, "Mercator_2SP test"); }
private void TestMercator_1SP() { CoordinateSystemFactory cFac = new 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); var pGeo = new Coordinate(120, -3); var pUtm = Transform(trans.MathTransform, pGeo); trans.MathTransform.Invert(); var pGeo2 = Transform(trans.MathTransform, pUtm); trans.MathTransform.Invert(); result.Text += PrintResultTable(gcs, coordsys, pGeo, pUtm, new Coordinate(5009726.58, 569150.82), pGeo2, "Mercator_1SP test"); }