public CreateFromCoordinateSystems ( ICoordinateSystem sourceCS, ICoordinateSystem targetCS ) : ICoordinateTransformation | ||
sourceCS | ICoordinateSystem | Source coordinate system |
targetCS | ICoordinateSystem | Target coordinate system |
return | ICoordinateTransformation |
internal ActualCoordinateSystem(ICoordinateSystem coordinateSystem) { if (coordinateSystem == null) throw new ArgumentNullException("coordinateSystem"); //NOXLATE CoordinateTransformationFactory f = new CoordinateTransformationFactory(); CoordinateSystemFactory cf = new CoordinateSystemFactory(); m_transform = f.CreateFromCoordinateSystems(coordinateSystem, cf.CreateFromWkt(XY_M)); }
public void TestNAD27toWGS84() { CoordinateSystemFactory csFact = new CoordinateSystemFactory(); CoordinateTransformationFactory ctFact = new CoordinateTransformationFactory(); ICoordinateSystem ESPG32054 = csFact.CreateFromWkt( "PROJCS[\"NAD27 / Wisconsin South\",GEOGCS[\"NAD27\",DATUM[\"North_American_Datum_1927\",SPHEROID[\"Clarke 1866\",6378206.4,294.9786982138982,AUTHORITY[\"EPSG\",\"7008\"]],AUTHORITY[\"EPSG\",\"6267\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.01745329251994328,AUTHORITY[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4267\"]],PROJECTION[\"Lambert_Conformal_Conic_2SP\"],PARAMETER[\"standard_parallel_1\",42.73333333333333],PARAMETER[\"standard_parallel_2\",44.06666666666667],PARAMETER[\"latitude_of_origin\",42],PARAMETER[\"central_meridian\",-90],PARAMETER[\"false_easting\",2000000],PARAMETER[\"false_northing\",0],UNIT[\"US survey foot\",0.3048006096012192,AUTHORITY[\"EPSG\",\"9003\"]],AUTHORITY[\"EPSG\",\"32054\"]]"); GeographicCoordinateSystem WGS84 = (ProjNet.CoordinateSystems.GeographicCoordinateSystem)GeographicCoordinateSystem.WGS84; ICoordinateTransformation trans = ctFact.CreateFromCoordinateSystems(ESPG32054, WGS84); List<double[]> points = new List<double[]> { new[] { 2555658.00, 388644.00}, new[] { 2557740.000, 387024.000} }; for (int i = 0; i < points.Count; i++) { double[] rst = trans.MathTransform.Transform(points[i]); Console.WriteLine(rst[0].ToString()+" \t"+ rst[1].ToString()); } }
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 SpatialReference createSRSfromWKT(string wkt, ICoordinateSystem source) { SpatialReference result = null; //SetUp coordinate transformation ProjNet.CoordinateSystems.CoordinateSystemFactory csf = new ProjNet.CoordinateSystems.CoordinateSystemFactory(); cs = csf.CreateFromWkt(wkt); ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory ctf = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory(); ctf.CreateFromCoordinateSystems(source, cs); ProjNet.CoordinateSystems.Transformations.ICoordinateTransformation ct = ctf.CreateFromCoordinateSystems(cs, source); //crear SharpMapSpatialReference usando el coordinateTranformation. throw new NotImplementedException(); }
static ProjHelper() { CoordinateTransformationFactory factory = new CoordinateTransformationFactory(); IGeographicCoordinateSystem wgs84 = GeographicCoordinateSystem.WGS84; IProjectedCoordinateSystem mercator = ProjectedCoordinateSystem.WebMercator; Transformation = factory.CreateFromCoordinateSystems(wgs84, mercator); }
public void TestTransformListOfDoubleArray() { CoordinateSystemFactory csFact = new CoordinateSystemFactory(); CoordinateTransformationFactory ctFact = new CoordinateTransformationFactory(); ICoordinateSystem utm35ETRS = csFact.CreateFromWkt( "PROJCS[\"ETRS89 / ETRS-TM35\",GEOGCS[\"ETRS89\",DATUM[\"D_ETRS_1989\",SPHEROID[\"GRS_1980\",6378137,298.257222101]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.017453292519943295]],PROJECTION[\"Transverse_Mercator\"],PARAMETER[\"latitude_of_origin\",0],PARAMETER[\"central_meridian\",27],PARAMETER[\"scale_factor\",0.9996],PARAMETER[\"false_easting\",500000],PARAMETER[\"false_northing\",0],UNIT[\"Meter\",1]]"); IProjectedCoordinateSystem utm33 = ProjectedCoordinateSystem.WGS84_UTM(33, true); ICoordinateTransformation trans = ctFact.CreateFromCoordinateSystems(utm35ETRS, utm33); List<double[]> points = new List<double[]> { new[] {290586.087, 6714000 }, new[] {90586.392, 6713996.224}, new[] {290590.133, 6713973.772}, new[] {290594.111, 6713957.416}, new[] {290596.615, 6713943.567}, new[] {290596.701, 6713939.485} }; double[][] tpoints = trans.MathTransform.TransformList(points).ToArray(); for (int i = 0; i < points.Count; i++) { Console.WriteLine(tpoints[i]); NUnit.Framework.Assert.IsTrue(Equal(tpoints[i], trans.MathTransform.Transform(points[i]))); } }
public void TestTransform() { CoordinateSystemFactory csFactory = new CoordinateSystemFactory(); const string sourceCsWkt = "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 sourceCs = csFactory.CreateFromWkt(sourceCsWkt); Assert.That(sourceCs, Is.Not.Null); const string targetCsWkt = "PROJCS[\"WGS 84 / Australian Antarctic Lambert\",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\"]],PROJECTION[\"Lambert_Conformal_Conic_2SP\"],PARAMETER[\"standard_parallel_1\",-68.5],PARAMETER[\"standard_parallel_2\",-74.5],PARAMETER[\"latitude_of_origin\",-50],PARAMETER[\"central_meridian\",70],PARAMETER[\"false_easting\",6000000],PARAMETER[\"false_northing\",6000000],UNIT[\"metre\",1,AUTHORITY[\"EPSG\",\"9001\"]],AUTHORITY[\"EPSG\",\"3033\"]]"; ICoordinateSystem targetCs = csFactory.CreateFromWkt(targetCsWkt); Assert.That(targetCs, Is.Not.Null); CoordinateTransformationFactory ctFactory = new CoordinateTransformationFactory(); ICoordinateTransformation coordTransformation = ctFactory.CreateFromCoordinateSystems(sourceCs, targetCs); IGeometryFactory gf = GeometryFactory.Default; const string geomWkt = "MULTIPOINT (152.83949210500001 -42.14413555,152.83910355899999 -42.129844618)"; WKTReader reader = new WKTReader(gf); IGeometry geom = reader.Read(geomWkt); Assert.That(geom, Is.Not.Null); Assert.That(geom.IsValid, Is.True); Assert.That(geom, Is.InstanceOf<IMultiPoint>()); IMultiPoint mp = (IMultiPoint)geom; foreach (IPoint pt in mp.Geometries) { IGeometry tp = GeometryTransform.TransformGeometry(gf, pt, coordTransformation.MathTransform); Assert.That(tp, Is.Not.Null); Assert.That(tp.IsValid, Is.True); } IGeometry transformed = GeometryTransform.TransformGeometry(gf, mp, coordTransformation.MathTransform); Assert.That(transformed, Is.Not.Null); Assert.That(transformed.IsValid, Is.True); }
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)); return ctFac.CreateFromCoordinateSystems(sourceCs, targetCs); }
public HIL.Vector3 getOffsetFromLeader(MAVLinkInterface leader, MAVLinkInterface mav) { //convert Wgs84ConversionInfo to utm CoordinateTransformationFactory ctfac = new CoordinateTransformationFactory(); GeographicCoordinateSystem wgs84 = GeographicCoordinateSystem.WGS84; int utmzone = (int)((leader.MAV.cs.lng - -186.0) / 6.0); IProjectedCoordinateSystem utm = ProjectedCoordinateSystem.WGS84_UTM(utmzone, leader.MAV.cs.lat < 0 ? false : true); ICoordinateTransformation trans = ctfac.CreateFromCoordinateSystems(wgs84, utm); double[] masterpll = { leader.MAV.cs.lng, leader.MAV.cs.lat }; // get leader utm coords double[] masterutm = trans.MathTransform.Transform(masterpll); double[] mavpll = { mav.MAV.cs.lng, mav.MAV.cs.lat }; //getLeader follower utm coords double[] mavutm = trans.MathTransform.Transform(mavpll); return new HIL.Vector3(masterutm[1] - mavutm[1], masterutm[0] - mavutm[0], 0); }
public override void SendCommand() { if (masterpos.Lat == 0 || masterpos.Lng == 0) return; Console.WriteLine(DateTime.Now); Console.WriteLine("Leader {0} {1} {2}",masterpos.Lat,masterpos.Lng,masterpos.Alt); int a = 0; foreach (var port in MainV2.Comports) { if (port == Leader) continue; PointLatLngAlt target = new PointLatLngAlt(masterpos); try { //convert Wgs84ConversionInfo to utm CoordinateTransformationFactory ctfac = new CoordinateTransformationFactory(); GeographicCoordinateSystem wgs84 = GeographicCoordinateSystem.WGS84; int utmzone = (int)((masterpos.Lng - -186.0) / 6.0); IProjectedCoordinateSystem utm = ProjectedCoordinateSystem.WGS84_UTM(utmzone, masterpos.Lat < 0 ? false : true); ICoordinateTransformation trans = ctfac.CreateFromCoordinateSystems(wgs84, utm); double[] pll1 = { target.Lng, target.Lat }; double[] p1 = trans.MathTransform.Transform(pll1); // add offsets to utm p1[0] += ((HIL.Vector3)offsets[port]).x; p1[1] += ((HIL.Vector3)offsets[port]).y; // convert back to wgs84 IMathTransform inversedTransform = trans.MathTransform.Inverse(); double[] point = inversedTransform.Transform(p1); target.Lat = point[1]; target.Lng = point[0]; target.Alt += ((HIL.Vector3)offsets[port]).z; port.setGuidedModeWP(new Locationwp() { alt = (float)target.Alt, lat = target.Lat, lng = target.Lng, id = (byte)MAVLink.MAV_CMD.WAYPOINT }); Console.WriteLine("{0} {1} {2} {3}", port.ToString(), target.Lat, target.Lng, target.Alt); } catch (Exception ex) { Console.WriteLine("Failed to send command " + port.ToString() + "\n" + ex.ToString()); } a++; } }
private static ICoordinateTransformation GetCoordinateTransformation() { //The SRS for this datasource is EPSG:4326, therefore we need to transfrom it to OSM projection var ctf = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory(); var cf = new ProjNet.CoordinateSystems.CoordinateSystemFactory(); var 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\"]]"); var epsg3785 = 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\",\"3785\"]]"); return(ctf.CreateFromCoordinateSystems(epsg4326, epsg3785));
public void WebMercatorCanBeTranformed(int srid) { var wkt = SharpMap.Converters.WellKnownText.SpatialReference.SridToWkt(srid); var csf = new CoordinateSystemFactory(); var cs = csf.CreateFromWkt(wkt); var ctf = new CoordinateTransformationFactory(); Assert.DoesNotThrow(() => ctf.CreateFromCoordinateSystems(cs, GeographicCoordinateSystem.WGS84), "Could not reproject SRID:" + srid); }
//获取shp投影方式 public ICoordinateTransformation getmapTransform(config.ProjPara proj) { CoordinateTransformationFactory ctFac = new CoordinateTransformationFactory(); CoordinateSystemFactory cFac = new CoordinateSystemFactory(); ICoordinateTransformation transform = null; //等经纬,shp数据原始投影 var epsg4326 = cFac.CreateFromWkt("GEOGCS[\"GCS_WGS_1984\",DATUM[\"WGS_1984\",SPHEROID[\"WGS_84\",6378137.0,298.257223563]],PRIMEM[\"Greenwich\",0.0],UNIT[\"Degree\",0.0174532925199433]]"); //目标坐标系 var epsg3857 = cFac.CreateFromWkt(getSrcCoordinate(proj)); transform = ctFac.CreateFromCoordinateSystems(epsg4326, epsg3857); return transform; }
/// <summary> /// 地理坐标转换为投影坐标 /// </summary> /// <param name="source"></param> /// <param name="target"></param> /// <returns></returns> 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)); } }
public static Coordinate ConvertDegreesToUTM(ICoordinate coordinate) { var ctfac = new CoordinateTransformationFactory(); ProjNet.CoordinateSystems.ICoordinateSystem wgs84geo = ProjNet.CoordinateSystems.GeographicCoordinateSystem.WGS84; int zone = (int)System.Math.Ceiling((coordinate.X + 180) / 6); ProjNet.CoordinateSystems.ICoordinateSystem utm = ProjNet.CoordinateSystems.ProjectedCoordinateSystem.WGS84_UTM(zone, coordinate.Y > 0); var trans = ctfac.CreateFromCoordinateSystems(wgs84geo, utm); double[] pUtm = trans.MathTransform.Transform(new[] { coordinate.X, coordinate.Y }); return new Coordinate { X = pUtm[0], Y = pUtm[1], }; }
public SpatialReference(KinectReader kinectReader, PositionReader positionReader) { this.kinectReader = kinectReader; this.positionReader = positionReader; string wkt = "GEOGCS[\"GCS_WGS_1984\",DATUM[\"D_WGS_1984\",SPHEROID[\"WGS_1984\",6378137,298.257223563]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.0174532925199433]]"; this.wgs84 = (ICoordinateSystem)ProjNet.Converters.WellKnownText.CoordinateSystemWktReader.Parse(wkt); //hardcoded UTM 55S - should parameterize string toWKT = "PROJCS[\"WGS 72BE / UTM zone 55S\",GEOGCS[\"WGS 72BE\",DATUM[\"WGS_1972_Transit_Broadcast_Ephemeris\",SPHEROID[\"WGS 72\",6378135,298.26,AUTHORITY[\"EPSG\",\"7043\"]],TOWGS84[0,0,1.9,0,0,0.814,-0.38],AUTHORITY[\"EPSG\",\"6324\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.01745329251994328,AUTHORITY[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4324\"]],PROJECTION[\"Transverse_Mercator\"],PARAMETER[\"latitude_of_origin\",0],PARAMETER[\"central_meridian\",147],PARAMETER[\"scale_factor\",0.9996],PARAMETER[\"false_easting\",500000],PARAMETER[\"false_northing\",10000000],UNIT[\"metre\",1,AUTHORITY[\"EPSG\",\"9001\"]],AUTHORITY[\"EPSG\",\"32555\"]]"; this.toCs = (ICoordinateSystem)ProjNet.Converters.WellKnownText.CoordinateSystemWktReader.Parse(toWKT); CoordinateTransformationFactory ctfac = new CoordinateTransformationFactory(); this.toGridtrans = ctfac.CreateFromCoordinateSystems(wgs84, toCs); }
/// <summary> /// Creates transformation from source coordinate system to specified target system which is the fitted one /// </summary> /// <param name="source"></param> /// <param name="target"></param> /// <returns></returns> private static ICoordinateTransformation Any2Fitt(ICoordinateSystem source, IFittedCoordinateSystem target) { //Transform form base system of fitted to target coordinate system - use invered math transform IMathTransform invMt = CreateFittedTransform(target).Inverse(); //case when source system is equal to base system of the fitted if (target.BaseCoordinateSystem.EqualParams(source)) { //Transform form base system of fitted to target coordinate system return(CreateTransform(source, target, TransformType.Transformation, invMt)); } ConcatenatedTransform ct = new ConcatenatedTransform(); //First transform from source to base system of fitted CoordinateTransformationFactory ctFac = new CoordinateTransformationFactory(); ct.CoordinateTransformationList.Add(ctFac.CreateFromCoordinateSystems(source, target.BaseCoordinateSystem)); //Transform form base system of fitted to target coordinate system - use invered math transform ct.CoordinateTransformationList.Add(CreateTransform(target.BaseCoordinateSystem, target, TransformType.Transformation, invMt)); return(CreateTransform(source, target, TransformType.Transformation, ct)); }
public void TestTransformListOfCoordinates() { CoordinateSystemFactory csFact = new CoordinateSystemFactory(); CoordinateTransformationFactory ctFact = new CoordinateTransformationFactory(); ICoordinateSystem utm35ETRS = csFact.CreateFromWkt( "PROJCS[\"ETRS89 / ETRS-TM35\",GEOGCS[\"ETRS89\",DATUM[\"D_ETRS_1989\",SPHEROID[\"GRS_1980\",6378137,298.257222101]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.017453292519943295]],PROJECTION[\"Transverse_Mercator\"],PARAMETER[\"latitude_of_origin\",0],PARAMETER[\"central_meridian\",27],PARAMETER[\"scale_factor\",0.9996],PARAMETER[\"false_easting\",500000],PARAMETER[\"false_northing\",0],UNIT[\"Meter\",1]]"); IProjectedCoordinateSystem utm33 = ProjectedCoordinateSystem.WGS84_UTM(33, true); ICoordinateTransformation trans = ctFact.CreateFromCoordinateSystems(utm35ETRS, utm33); Coordinate[] points = new Coordinate[] { new Coordinate(290586.087, 6714000), new Coordinate(290586.392, 6713996.224), new Coordinate(290590.133, 6713973.772), new Coordinate(290594.111, 6713957.416), new Coordinate(290596.615, 6713943.567), new Coordinate(290596.701, 6713939.485) }; Coordinate[] tpoints = trans.MathTransform.TransformList(points).ToArray(); for (int i = 0; i < points.Length; i++) Assert.That(tpoints[i].Equals(trans.MathTransform.Transform(points[i]))); }
static void Main(string[] args) { var wktWGS84 = "GEOGCS[\"GCS_WGS_1984\",DATUM[\"D_WGS_1984\",SPHEROID[\"WGS_1984\",6378137,298.257223563]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.0174532925199433]]"; var wgs84 = CoordinateSystemWktReader.Parse(wktWGS84) as ICoordinateSystem; var wktMercator = "PROJCS[\"World_Mercator\",GEOGCS[\"GCS_WGS_1984\",DATUM[\"WGS_1984\",SPHEROID[\"WGS_1984\",6378137,298.257223563]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.017453292519943295]],PROJECTION[\"Mercator_1SP\"],PARAMETER[\"False_Easting\",0],PARAMETER[\"False_Northing\",0],PARAMETER[\"Central_Meridian\",0],PARAMETER[\"latitude_of_origin\",0],UNIT[\"Meter\",1]]"; var mercator = CoordinateSystemWktReader.Parse(wktMercator) as ICoordinateSystem; var transFactory = new CoordinateTransformationFactory(); var trans = transFactory.CreateFromCoordinateSystems(wgs84, mercator); var fromPoints = new List<double[]>(); using (var sr = new StreamReader("32332.dat")) { while (!sr.EndOfStream) { var val = sr.ReadLine().Split("".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); if (val[0].Contains("nan") || val[1].Contains("nan")) { continue; } var x = double.Parse(val[0]); var y = double.Parse(val[1]); fromPoints.Add(new double[] { x, y }); } } var toPoints = trans.MathTransform.TransformList(fromPoints); using (var sw = new StreamWriter("result.dat")) { foreach (var toPoint in toPoints) { sw.WriteLine("{0} {1}", toPoint[0], toPoint[1]); } } }
/// <summary> /// Creates transformation from fitted coordinate system to the target one /// </summary> /// <param name="source"></param> /// <param name="target"></param> /// <returns></returns> private static ICoordinateTransformation Fitt2Any(IFittedCoordinateSystem source, ICoordinateSystem target) { //transform from fitted to base system of fitted (which is equal to target) IMathTransform mt = CreateFittedTransform(source); //case when target system is equal to base system of the fitted if (source.BaseCoordinateSystem.EqualParams(target)) { //Transform form base system of fitted to target coordinate system return(CreateTransform(source, target, TransformType.Transformation, mt)); } //Transform form base system of fitted to target coordinate system ConcatenatedTransform ct = new ConcatenatedTransform(); ct.CoordinateTransformationList.Add(CreateTransform(source, source.BaseCoordinateSystem, TransformType.Transformation, mt)); //Transform form base system of fitted to target coordinate system CoordinateTransformationFactory ctFac = new CoordinateTransformationFactory(); ct.CoordinateTransformationList.Add(ctFac.CreateFromCoordinateSystems(source.BaseCoordinateSystem, target)); return(CreateTransform(source, target, TransformType.Transformation, ct)); }
private static ICoordinateTransformation GetCoordinateTransformation() { //The SRS for this datasource is EPSG:4326, therefore we need to transfrom it to OSM projection var ctf = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory(); var cf = new ProjNet.CoordinateSystems.CoordinateSystemFactory(); var 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\"]]"); var epsg3785 = 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\",\"3785\"]]"); return ctf.CreateFromCoordinateSystems(epsg4326, epsg3785);
private static ICoordinateTransformationCore CloneCoordinateTransformation(ICoordinateTransformationCore ict) { return(CoordinateTransformationFactory.CreateFromCoordinateSystems(ict.SourceCS, ict.TargetCS)); }
public SpatialReference createSRSfromWKT(string wkttarget, string wktsource) { ProjNet.CoordinateSystems.CoordinateSystemFactory csf = new ProjNet.CoordinateSystems.CoordinateSystemFactory(); ProjNet.CoordinateSystems.ICoordinateSystem csSource = csf.CreateFromWkt(wktsource); ProjNet.CoordinateSystems.ICoordinateSystem csTarget = csf.CreateFromWkt(wkttarget); ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory ctf = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory(); ProjNet.CoordinateSystems.Transformations.ICoordinateTransformation ct = ctf.CreateFromCoordinateSystems(csSource, csTarget); SharpMapSpatialReference sr = new SharpMapSpatialReference(); sr.CoordinateSystem = csSource; sr.MathTransform = ct.MathTransform; return(sr); }
public void TestTransformAllWKTs() { //GeographicCoordinateSystem.WGS84 CoordinateTransformationFactory fact = new CoordinateTransformationFactory(); CoordinateSystemFactory fac = new CoordinateSystemFactory(); int parsecount = 0; StreamReader sr = File.OpenText(@"..\..\SRID.csv"); string line = ""; while (!sr.EndOfStream) { line = sr.ReadLine(); int split = line.IndexOf(';'); if (split > -1) { string srid = line.Substring(0, split); string wkt = line.Substring(split + 1); ICoordinateSystem cs = CoordinateSystemWktReader.Parse(wkt) as ICoordinateSystem; if (cs == null) continue; //We check this in another test. if (cs is IProjectedCoordinateSystem) { switch ((cs as IProjectedCoordinateSystem).Projection.ClassName) { //Skip not supported projections case "Oblique_Stereographic": case "Transverse_Mercator_South_Orientated": case "Hotine_Oblique_Mercator": case "Lambert_Conformal_Conic_1SP": case "Krovak": case "Cassini_Soldner": case "Lambert_Azimuthal_Equal_Area": case "Tunisia_Mining_Grid": case "New_Zealand_Map_Grid": case "Polyconic": case "Lambert_Conformal_Conic_2SP_Belgium": case "Polar_Stereographic": continue; default: break; } } try { ICoordinateTransformation trans = fact.CreateFromCoordinateSystems(GeographicCoordinateSystem.WGS84, cs); } catch (Exception ex) { if (cs is IProjectedCoordinateSystem) Assert.Fail("Could not create transformation from:\r\n" + wkt + "\r\n" + ex.Message + "\r\nClass name:" + (cs as IProjectedCoordinateSystem).Projection.ClassName); else Assert.Fail("Could not create transformation from:\r\n" + wkt + "\r\n" + ex.Message); } parsecount++; } } sr.Close(); Assert.AreEqual(parsecount, 2536, "Not all WKT was processed"); }
// gets transform between raster's native projection and the map projection private void GetTransform(ICoordinateSystem mapProjection) { if (mapProjection == null || Projection == "") { CoordinateTransformation = null; return; } var cFac = new CoordinateSystemFactory(); // get our two projections ICoordinateSystem srcCoord = cFac.CreateFromWkt(Projection); ICoordinateSystem tgtCoord = mapProjection; // raster and map are in same projection, no need to transform if (srcCoord.WKT == tgtCoord.WKT) { CoordinateTransformation = null; return; } // create transform var ctFac = new CoordinateTransformationFactory(); CoordinateTransformation = ctFac.CreateFromCoordinateSystems(srcCoord, tgtCoord); ReverseCoordinateTransformation = ctFac.CreateFromCoordinateSystems(tgtCoord, srcCoord); }
private static Map InitializeMapOsmWithXls(float angle) { Map map = new Map(); TileLayer tileLayer = new TileLayer(new OsmTileSource(), "TileLayer - OSM with XLS"); map.Layers.Add(tileLayer); //Get data from excel var xlsPath = string.Format(XlsConnectionString, System.IO.Directory.GetCurrentDirectory(), "GeoData\\Cities.xls"); var ds = new System.Data.DataSet("XLS"); using (var cn = new System.Data.OleDb.OleDbConnection(xlsPath)) { cn.Open(); using (var da = new System.Data.OleDb.OleDbDataAdapter(new System.Data.OleDb.OleDbCommand("SELECT * FROM [Cities$]", cn))) da.Fill(ds); } #if !DotSpatialProjections //The SRS for this datasource is EPSG:4326, therefore we need to transfrom it to OSM projection var ctf = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory(); var cf = new ProjNet.CoordinateSystems.CoordinateSystemFactory(); var 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\"]]"); var epsg3785 = 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\",\"3785\"]]"); var ct = ctf.CreateFromCoordinateSystems(epsg4326, epsg3785); foreach (System.Data.DataRow row in ds.Tables[0].Rows) { if (row["X"] == DBNull.Value || row["Y"] == DBNull.Value) continue; double[] coords = new double[] { Convert.ToDouble(row["X"]), Convert.ToDouble(row["Y"])}; coords = ct.MathTransform.Transform(coords); row["X"] = coords[0]; row["Y"] = coords[1]; } #else var epsg4326 = DotSpatial.Projections.KnownCoordinateSystems.Geographic.World.WGS1984; var epsg3785 = new DotSpatial.Projections.ProjectionInfo(); epsg3785.ReadEsriString("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\",\"3785\"]]"); foreach (System.Data.DataRow row in ds.Tables[0].Rows) { if (row["X"] == DBNull.Value || row["Y"] == DBNull.Value) continue; double[] coords = new double[] { Convert.ToDouble(row["X"]), Convert.ToDouble(row["Y"])}; DotSpatial.Projections.Reproject.ReprojectPoints(coords, null, epsg4326, epsg3785, 0, 1); row["X"] = coords[0]; row["Y"] = coords[1]; } #endif //Add Rotation Column ds.Tables[0].Columns.Add("Rotation", typeof (float)); foreach (System.Data.DataRow row in ds.Tables[0].Rows) row["Rotation"] = -angle; //Set up provider var xlsProvider = new SharpMap.Data.Providers.DataTablePoint(ds.Tables[0], "OID", "X", "Y"); var xlsLayer = new SharpMap.Layers.VectorLayer("XLS", xlsProvider); xlsLayer.Style.Symbol = SharpMap.Styles.VectorStyle.DefaultSymbol; //Add layer to map map.Layers.Add(xlsLayer); var xlsLabelLayer = new SharpMap.Layers.LabelLayer("XLSLabel"); xlsLabelLayer.DataSource = xlsProvider; xlsLabelLayer.LabelColumn = "Name"; xlsLabelLayer.PriorityColumn = "Population"; xlsLabelLayer.Style.CollisionBuffer = new System.Drawing.SizeF(2f, 2f); xlsLabelLayer.Style.CollisionDetection = true; xlsLabelLayer.LabelFilter = SharpMap.Rendering.LabelCollisionDetection.ThoroughCollisionDetection; map.Layers.Add(xlsLabelLayer); map.ZoomToBox(tileLayer.Envelope); return map; }
/// <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 Map InitializeMapOsmWithXls(float angle) { Map map = new Map(); TileLayer tileLayer = new TileLayer(new OsmTileSource(), "TileLayer - OSM with XLS"); map.Layers.Add(tileLayer); //Get data from excel var xlsPath = string.Format(XlsConnectionString, System.IO.Directory.GetCurrentDirectory(), "GeoData\\Cities.xls"); var ds = new System.Data.DataSet("XLS"); using (var cn = new System.Data.OleDb.OleDbConnection(xlsPath)) { cn.Open(); using (var da = new System.Data.OleDb.OleDbDataAdapter(new System.Data.OleDb.OleDbCommand("SELECT * FROM [Cities$]", cn))) da.Fill(ds); } #if !DotSpatialProjections //The SRS for this datasource is EPSG:4326, therefore we need to transfrom it to OSM projection var ctf = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory(); var cf = new ProjNet.CoordinateSystems.CoordinateSystemFactory(); var 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\"]]"); var epsg3785 = 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\",\"3785\"]]"); var ct = ctf.CreateFromCoordinateSystems(epsg4326, epsg3785); foreach (System.Data.DataRow row in ds.Tables[0].Rows) { if (row["X"] == DBNull.Value || row["Y"] == DBNull.Value) { continue; } double[] coords = new double[] { Convert.ToDouble(row["X"]), Convert.ToDouble(row["Y"]) }; coords = ct.MathTransform.Transform(coords); row["X"] = coords[0]; row["Y"] = coords[1]; } #else var epsg4326 = DotSpatial.Projections.KnownCoordinateSystems.Geographic.World.WGS1984; var epsg3785 = new DotSpatial.Projections.ProjectionInfo(); epsg3785.ReadEsriString("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\",\"3785\"]]"); foreach (System.Data.DataRow row in ds.Tables[0].Rows) { if (row["X"] == DBNull.Value || row["Y"] == DBNull.Value) { continue; } double[] coords = new double[] { Convert.ToDouble(row["X"]), Convert.ToDouble(row["Y"]) }; DotSpatial.Projections.Reproject.ReprojectPoints(coords, null, epsg4326, epsg3785, 0, 1); row["X"] = coords[0]; row["Y"] = coords[1]; } #endif //Add Rotation Column ds.Tables[0].Columns.Add("Rotation", typeof(float)); foreach (System.Data.DataRow row in ds.Tables[0].Rows) { row["Rotation"] = -angle; } //Set up provider var xlsProvider = new SharpMap.Data.Providers.DataTablePoint(ds.Tables[0], "OID", "X", "Y"); var xlsLayer = new SharpMap.Layers.VectorLayer("XLS", xlsProvider); xlsLayer.Style.Symbol = SharpMap.Styles.VectorStyle.DefaultSymbol; //Add layer to map map.Layers.Add(xlsLayer); var xlsLabelLayer = new SharpMap.Layers.LabelLayer("XLSLabel"); xlsLabelLayer.DataSource = xlsProvider; xlsLabelLayer.LabelColumn = "Name"; xlsLabelLayer.PriorityColumn = "Population"; xlsLabelLayer.Style.CollisionBuffer = new System.Drawing.SizeF(2f, 2f); xlsLabelLayer.Style.CollisionDetection = true; xlsLabelLayer.LabelFilter = SharpMap.Rendering.LabelCollisionDetection.ThoroughCollisionDetection; map.Layers.Add(xlsLabelLayer); map.ZoomToBox(tileLayer.Envelope); return(map); }
public SpatialReference createSRSfromWKT(string wkt, ICoordinateSystem source) { SpatialReference result = null; //SetUp coordinate transformation ProjNet.CoordinateSystems.CoordinateSystemFactory csf = new ProjNet.CoordinateSystems.CoordinateSystemFactory(); cs = csf.CreateFromWkt(wkt); ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory ctf = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory(); ctf.CreateFromCoordinateSystems(source, cs); ProjNet.CoordinateSystems.Transformations.ICoordinateTransformation ct = ctf.CreateFromCoordinateSystems(cs, source); //crear SharpMapSpatialReference usando el coordinateTranformation. throw new NotImplementedException(); }
public SpatialReference createSRSfromWKT(string wkttarget, string wktsource) { ProjNet.CoordinateSystems.CoordinateSystemFactory csf = new ProjNet.CoordinateSystems.CoordinateSystemFactory(); ProjNet.CoordinateSystems.ICoordinateSystem csSource = csf.CreateFromWkt(wktsource); ProjNet.CoordinateSystems.ICoordinateSystem csTarget = csf.CreateFromWkt(wkttarget); ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory ctf = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory(); ProjNet.CoordinateSystems.Transformations.ICoordinateTransformation ct = ctf.CreateFromCoordinateSystems(csSource, csTarget); SharpMapSpatialReference sr = new SharpMapSpatialReference(); sr.CoordinateSystem = csSource; sr.MathTransform = ct.MathTransform; return sr; }
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); }
public void Test_EPSG_21780_PrimeMeredianTransformation() { string wkt4326 = "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\"]]"; string wkt21780 = "PROJCS[\"Bern 1898 (Bern) / LV03C\",GEOGCS[\"Bern 1898 (Bern)\",DATUM[\"CH1903_Bern\",SPHEROID[\"Bessel 1841\",6377397.155,299.1528128,AUTHORITY[\"EPSG\",\"7004\"]],AUTHORITY[\"EPSG\",\"6801\"]],PRIMEM[\"Bern\",7.439583333333333,AUTHORITY[\"EPSG\",\"8907\"]],UNIT[\"degree\",0.01745329251994328,AUTHORITY[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4801\"]],PROJECTION[\"Hotine_Oblique_Mercator\"],PARAMETER[\"latitude_of_center\",46.95240555555556],PARAMETER[\"longitude_of_center\",0],PARAMETER[\"azimuth\",90],PARAMETER[\"rectified_grid_angle\",90],PARAMETER[\"scale_factor\",1],PARAMETER[\"false_easting\",0],PARAMETER[\"false_northing\",0],UNIT[\"metre\",1,AUTHORITY[\"EPSG\",\"9001\"]],AUTHORITY[\"EPSG\",\"21780\"]]"; //test data from http://spatialreference.org/ref/epsg/21780/ double[] sourceCoord = new double[] { 160443.329034, 23582.55586 }; double[] expectedTargetCoord = new double[] { 9.5553588867188, 47.145080566406 }; ICoordinateSystem cs1 = ProjNet.Converters.WellKnownText.CoordinateSystemWktReader.Parse(wkt21780, System.Text.Encoding.Default) as ICoordinateSystem; ICoordinateSystem cs2 = ProjNet.Converters.WellKnownText.CoordinateSystemWktReader.Parse(wkt4326, System.Text.Encoding.Default) as ICoordinateSystem; CoordinateTransformationFactory ctf = new CoordinateTransformationFactory(); var ict = ctf.CreateFromCoordinateSystems(cs1, cs2); double[] transformedCoord = ict.MathTransform.Transform(sourceCoord); Assert.IsTrue(transformedCoord.Length >= 2); Assert.AreEqual(expectedTargetCoord[0], transformedCoord[0], 0.001); Assert.AreEqual(expectedTargetCoord[1], transformedCoord[1], 0.001); //and back var ictb = ctf.CreateFromCoordinateSystems(cs2, cs1); transformedCoord = ictb.MathTransform.Transform(transformedCoord); Assert.IsTrue(transformedCoord.Length >= 2); Assert.AreEqual(sourceCoord[0], transformedCoord[0], 0.1); Assert.AreEqual(sourceCoord[1], transformedCoord[1], 0.1); }
private static IMathTransform CreateTransformation(KeyValuePair<ICoordinateSystem, ICoordinateSystem> fromTo) { var ctFactory = new CoordinateTransformationFactory(); return ctFactory.CreateFromCoordinateSystems(fromTo.Key, fromTo.Value).MathTransform; }
private static ICoordinateTransformation Proj2Geog(IProjectedCoordinateSystem source, IGeographicCoordinateSystem target) { if (source.GeographicCoordinateSystem.EqualParams(target)) { IMathTransform mathTransform = CreateCoordinateOperation(source.Projection, source.GeographicCoordinateSystem.HorizontalDatum.Ellipsoid, source.LinearUnit).Inverse(); 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, source.GeographicCoordinateSystem)); ct.CoordinateTransformationList.Add(ctFac.CreateFromCoordinateSystems(source.GeographicCoordinateSystem, target)); return new CoordinateTransformation(source, target, TransformType.Transformation, ct, String.Empty, String.Empty, -1, String.Empty, String.Empty); } }
public override void SendCommand() { if (masterpos.Lat == 0 || masterpos.Lng == 0) return; Console.WriteLine(DateTime.Now); Console.WriteLine("Leader {0} {1} {2}", masterpos.Lat, masterpos.Lng, masterpos.Alt); int a = 0; foreach (var port in MainV2.Comports) { if (port == Leader) continue; PointLatLngAlt target = new PointLatLngAlt(masterpos); try { //convert Wgs84ConversionInfo to utm CoordinateTransformationFactory ctfac = new CoordinateTransformationFactory(); GeographicCoordinateSystem wgs84 = GeographicCoordinateSystem.WGS84; int utmzone = (int) ((masterpos.Lng - -186.0)/6.0); IProjectedCoordinateSystem utm = ProjectedCoordinateSystem.WGS84_UTM(utmzone, masterpos.Lat < 0 ? false : true); ICoordinateTransformation trans = ctfac.CreateFromCoordinateSystems(wgs84, utm); double[] pll1 = {target.Lng, target.Lat}; double[] p1 = trans.MathTransform.Transform(pll1); double heading = -Leader.MAV.cs.yaw; double length = offsets[port].length(); var x = ((HIL.Vector3)offsets[port]).x; var y = ((HIL.Vector3)offsets[port]).y; // add offsets to utm p1[0] += x*Math.Cos(heading*deg2rad) - y*Math.Sin(heading*deg2rad); p1[1] += x*Math.Sin(heading*deg2rad) + y*Math.Cos(heading*deg2rad); if (port.MAV.cs.firmware == MainV2.Firmwares.ArduPlane) { // project the point forwards gs*5 var gs = port.MAV.cs.groundspeed; p1[1] += gs*5*Math.Cos((-heading)*deg2rad); p1[0] += gs*5*Math.Sin((-heading)*deg2rad); } // convert back to wgs84 IMathTransform inversedTransform = trans.MathTransform.Inverse(); double[] point = inversedTransform.Transform(p1); target.Lat = point[1]; target.Lng = point[0]; target.Alt += ((HIL.Vector3) offsets[port]).z; if (port.MAV.cs.firmware == MainV2.Firmwares.ArduPlane) { var dist = target.GetDistance(new PointLatLngAlt(port.MAV.cs.lat, port.MAV.cs.lng, port.MAV.cs.alt)); dist -= port.MAV.cs.groundspeed*5; var leadergs = Leader.MAV.cs.groundspeed; var newspeed = (leadergs + (float) (dist/10)); if (newspeed < 5) newspeed = 5; port.setParam("TRIM_ARSPD_CM", newspeed*100.0f); } port.setGuidedModeWP(new Locationwp() { alt = (float) target.Alt, lat = target.Lat, lng = target.Lng, id = (ushort)MAVLink.MAV_CMD.WAYPOINT }); Console.WriteLine("{0} {1} {2} {3}", port.ToString(), target.Lat, target.Lng, target.Alt); } catch (Exception ex) { Console.WriteLine("Failed to send command " + port.ToString() + "\n" + ex.ToString()); } a++; } }
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); }
double calcpolygonarea(List<PointLatLngAlt> polygon) { // should be a closed polygon // coords are in lat long // need utm to calc area if (polygon.Count == 0) { CustomMessageBox.Show("Please define a polygon!"); return 0; } // close the polygon if (polygon[0] != polygon[polygon.Count - 1]) polygon.Add(polygon[0]); // make a full loop CoordinateTransformationFactory ctfac = new CoordinateTransformationFactory(); GeographicCoordinateSystem wgs84 = GeographicCoordinateSystem.WGS84; int utmzone = (int)((polygon[0].Lng - -186.0) / 6.0); IProjectedCoordinateSystem utm = ProjectedCoordinateSystem.WGS84_UTM(utmzone, polygon[0].Lat < 0 ? false : true); ICoordinateTransformation trans = ctfac.CreateFromCoordinateSystems(wgs84, utm); double prod1 = 0; double prod2 = 0; for (int a = 0; a < (polygon.Count - 1); a++) { double[] pll1 = { polygon[a].Lng, polygon[a].Lat }; double[] pll2 = { polygon[a + 1].Lng, polygon[a + 1].Lat }; double[] p1 = trans.MathTransform.Transform(pll1); double[] p2 = trans.MathTransform.Transform(pll2); prod1 += p1[0] * p2[1]; prod2 += p1[1] * p2[0]; } double answer = (prod1 - prod2) / 2; if (polygon[0] == polygon[polygon.Count - 1]) polygon.RemoveAt(polygon.Count - 1); // unmake a full loop return Math.Abs(answer); }
public void TestObliqueStereographicProjection() { //test data from http://www.spatialreference.org/ref/epsg/2171/ double[] Coord2171 = new double[] { 4615496.325851, 5605702.221723 }; double[] Coord4326 = new double[] { 20.78002815042, 50.25299100927 }; string wkt4326 = "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\"]]"; string wkt2171 = "PROJCS[\"Pulkovo 1942(58) / Poland zone I\",GEOGCS[\"Pulkovo 1942(58)\",DATUM[\"Pulkovo_1942_58\",SPHEROID[\"Krassowsky 1940\",6378245,298.3,AUTHORITY[\"EPSG\",\"7024\"]],TOWGS84[33.4,-146.6,-76.3,-0.359,-0.053,0.844,-0.84],AUTHORITY[\"EPSG\",\"6179\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.01745329251994328,AUTHORITY[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4179\"]],PROJECTION[\"Oblique_Stereographic\"],PARAMETER[\"latitude_of_origin\",50.625],PARAMETER[\"central_meridian\",21.08333333333333],PARAMETER[\"scale_factor\",0.9998],PARAMETER[\"false_easting\",4637000],PARAMETER[\"false_northing\",5647000],UNIT[\"metre\",1,AUTHORITY[\"EPSG\",\"9001\"]],AUTHORITY[\"EPSG\",\"2171\"]]"; ICoordinateSystem cs1 = CoordinateSystemFactory.CreateFromWkt(wkt4326); ICoordinateSystem cs2 = CoordinateSystemFactory.CreateFromWkt(wkt2171); CoordinateTransformationFactory ctf = new CoordinateTransformationFactory(); var ict = ctf.CreateFromCoordinateSystems(cs2, cs1); double[] transformedCoord4326 = ict.MathTransform.Transform(Coord2171); Assert.AreEqual(Coord4326[0], transformedCoord4326[0], 0.01); Assert.AreEqual(Coord4326[1], transformedCoord4326[1], 0.01); var ict2 = ctf.CreateFromCoordinateSystems(cs1, cs2); double[] transformedCoord2171 = ict2.MathTransform.Transform(Coord4326); Assert.AreEqual(Coord2171[0], transformedCoord2171[0], 1); Assert.AreEqual(Coord2171[1], transformedCoord2171[1], 1); }