public static string CoordinatesConvertor(double InputX,double InputY, int InputWKID, int OutputWKID) { Geometry_GeometryServer geometryService = new Geometry_GeometryServer(); SpatialReference inputSpatialReference = new GeographicCoordinateSystem(); inputSpatialReference.WKID = InputWKID; inputSpatialReference.WKIDSpecified = true; SpatialReference outputSpatialReference = new ProjectedCoordinateSystem(); outputSpatialReference.WKID = OutputWKID; outputSpatialReference.WKIDSpecified = true; PointN pt = new PointN(); pt.X = InputX; pt.Y = InputY; Geometry[] inGeo = new Geometry[] { pt }; Geometry[] geo = geometryService.Project(inputSpatialReference, outputSpatialReference, false, null, null, inGeo); PointN nPt = (PointN)geo[0]; return (nPt.X.ToString() + ',' + nPt.Y.ToString()); }
////private static int _defaultWkid = int.Parse(ConfigurationManager.AppSettings["DefaultSpatialReference"]); ////private static int _sqlSR = int.Parse(ConfigurationManager.AppSettings["SqlSpatialReferenceWkid"]); /////// <summary> /////// The default spatial reference id (probably WGS_84 - id: 4326) /////// </summary> ////public static int DefaultSpatialReferenceId { get { return _defaultWkid; } } /////// <summary> /////// The default spatial reference system /////// </summary> ////public static SpatialReference DefaultSpatialReference { get { return DefaultSpatialReferenceId.ToSpatialReference(); } } /////// <summary> /////// The spatial reference that will be used when writing geometry data to a SQL Server database. /////// </summary> ////public static int SqlSpatialReference { get { return _sqlSR; } } ////public static int[] ProjectedWkids { get { return _projectedWkids; } } ////public static int[] GeographicWkids { get { return _geographicWkids; } } /// <summary> /// Returns a <see cref="SpatialReference"/> object corresponding to the specified WKID. /// </summary> /// <param name="wkid">A Well-Known Identifier (WKID) for a spatial reference system.</param> /// <returns> /// <para>Returns a <see cref="SpatialReference"/> object corresponding to <paramref name="wkid"/>.</para> /// <para> /// If <paramref name="wkid"/> matches one of the values defined in web.config, /// either a <see cref="GeographicCoordinateSystem"/> or <see cref="ProjectedCoordinateSystem"/> /// is returned. Otherwise a <see cref="UnknownCoordinateSystem"/> is returned. /// </para> /// </returns> public static SpatialReference ToSpatialReference(this int wkid) { SpatialReference sr; if (_projectedWkids.Contains(wkid)) { sr = new ProjectedCoordinateSystem(); } else if (_geographicWkids.Contains(wkid)) { sr = new GeographicCoordinateSystem(); } else { sr = new UnknownCoordinateSystem(); } sr.WKID = wkid; sr.WKIDSpecified = true; return sr; }
private static ProjectedCoordinateSystem GetEPSG900913(CoordinateSystemFactory csFact) { 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 = csFact.CreateProjection("Google Mercator", "mercator_1sp", parameters); GeographicCoordinateSystem wgs84 = csFact.CreateGeographicCoordinateSystem( "WGS 84", AngularUnit.Degrees, HorizontalDatum.WGS84, PrimeMeridian.Greenwich, new AxisInfo("north", AxisOrientationEnum.North), new AxisInfo("east", AxisOrientationEnum.East) ); ProjectedCoordinateSystem epsg900913 = csFact.CreateProjectedCoordinateSystem("Google Mercator", wgs84, projection, LinearUnit.Metre, new AxisInfo("East", AxisOrientationEnum.East), new AxisInfo("North", AxisOrientationEnum.North)); return(epsg900913); }
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); var heading = -leader.MAV.cs.yaw; var norotation = new HIL.Vector3(masterutm[1] - mavutm[1], masterutm[0] - mavutm[0], 0); float rad2deg = (float)(180 / Math.PI); float deg2rad = (float)(1.0 / rad2deg); norotation.x *= -1; norotation.y *= -1; return(new HIL.Vector3(norotation.x * Math.Cos(heading * deg2rad) - norotation.y * Math.Sin(heading * deg2rad), norotation.x * Math.Sin(heading * deg2rad) + norotation.y * Math.Cos(heading * deg2rad), 0)); }
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 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); // send position port.setGuidedModeWP(new Locationwp() { alt = (float)target.Alt, lat = target.Lat, lng = target.Lng, id = (ushort)MAVLink.MAV_CMD.WAYPOINT }); } else { Vector3 vel = new Vector3(Math.Cos(Leader.MAV.cs.groundcourse * deg2rad) * Leader.MAV.cs.groundspeed, Math.Sin(Leader.MAV.cs.groundcourse * deg2rad) * Leader.MAV.cs.groundspeed, Leader.MAV.cs.verticalspeed); port.setPositionTargetGlobalInt((byte)port.sysidcurrent, (byte)port.compidcurrent, true, true, false, MAVLink.MAV_FRAME.GLOBAL_RELATIVE_ALT_INT, target.Lat, target.Lng, target.Alt, vel.x, vel.y, -vel.z); } 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++; } }
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); // 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++; } }
/// <summary> /// 初始化常用的信息 /// </summary> private static void InitInfo() { pCTFAC = new CoordinateTransformationFactory(); pPCS = ProjectedCoordinateSystem.WGS84_UTM(50, true); pGCS = GeographicCoordinateSystem.WGS84; }
private static CoordinateTransformation Geoc2Geog(GeocentricCoordinateSystem source, GeographicCoordinateSystem target) { var geocMathTransform = CreateCoordinateOperation(source).Inverse(); if (source.PrimeMeridian.EqualParams(target.PrimeMeridian)) { return(new CoordinateTransformation(source, target, TransformType.Conversion, geocMathTransform, string.Empty, string.Empty, -1, string.Empty, string.Empty)); } var ct = new ConcatenatedTransform(); ct.CoordinateTransformationList.Add(new CoordinateTransformation(source, target, TransformType.Conversion, geocMathTransform, string.Empty, string.Empty, -1, string.Empty, string.Empty)); ct.CoordinateTransformationList.Add(new CoordinateTransformation(source, target, TransformType.Transformation, new PrimeMeridianTransform(source.PrimeMeridian, target.PrimeMeridian), string.Empty, string.Empty, -1, string.Empty, string.Empty)); return(new CoordinateTransformation(source, target, TransformType.Conversion, ct, string.Empty, string.Empty, -1, string.Empty, string.Empty)); }
/// <summary> /// Create a CIM Spatial Reference. Has to be created from scratch /// </summary> /// <param name="WKID">The wkid for the spatial reference to be created</param> /// <returns>A CIM spatial reference</returns> public ArcGIS.Core.Internal.CIM.SpatialReference CreateSpatialReference(int WKID) { ArcGIS.Core.Internal.CIM.SpatialReference sr = null; if (WKID == 104115 || WKID == 4326) { GeographicCoordinateSystem gs = new GeographicCoordinateSystem() { WKID = 104115, WKIDSpecified = true, LatestWKID = 104115, LatestVCSWKIDSpecified = true, LeftLongitude = -180, LeftLongitudeSpecified = true, HighPrecision = true, HighPrecisionSpecified = true, MTolerance = 0.001, MToleranceSpecified = true, ZTolerance = 0.001, ZToleranceSpecified = true, XYTolerance = 8.9831528411952133E-09, XYToleranceSpecified = true, MScale = 10000, MScaleSpecified = true, MOrigin = -100000, MOriginSpecified = true, ZScale = 10000, ZScaleSpecified = true, ZOrigin = -100000, ZOriginSpecified = true, XYScale = 999999999.99999988, XYScaleSpecified = true, XOrigin = -400, XOriginSpecified = true, YOrigin = -400, YOriginSpecified = true, WKT = "GEOGCS[\"GCS_ITRF_1988\",DATUM[\"D_ITRF_1988\",SPHEROID[\"GRS_1980\",6378137.0,298.257222101]],PRIMEM[\"Greenwich\",0.0],UNIT[\"Degree\",0.0174532925199433],AUTHORITY[\"ESRI\",104115]]" }; sr = gs as ArcGIS.Core.Internal.CIM.SpatialReference; } else if (WKID == 102100) { //Note: In testing, I could not get Web Mercator to //work on the mapview. ProjectedCoordinateSystem pcs = new ProjectedCoordinateSystem() { HighPrecision = true, HighPrecisionSpecified = true, LatestVCSWKID = 0, LatestVCSWKIDSpecified = false, LatestWKID = 3857, LatestWKIDSpecified = true, LeftLongitude = 0.0, LeftLongitudeSpecified = false, MOrigin = -100000.0, MOriginSpecified = true, MScale = 10000.0, MScaleSpecified = true, MTolerance = 0.001, MToleranceSpecified = true, VCSWKID = 0, VCSWKIDSpecified = false, WKID = 102100, WKIDSpecified = true, WKT = "PROJCS[\"WGS_1984_Web_Mercator_Auxiliary_Sphere\",GEOGCS[\"GCS_WGS_1984\",DATUM[\"D_WGS_1984\",SPHEROID[\"WGS_1984\",6378137.0,298.257223563]],PRIMEM[\"Greenwich\",0.0],UNIT[\"Degree\",0.0174532925199433]],PROJECTION[\"Mercator_Auxiliary_Sphere\"],PARAMETER[\"false ;_Easting\",0.0],PARAMETER[\"false ;_Northing\",0.0],PARAMETER[\"Central_Meridian\",0.0],PARAMETER[\"Standard_Parallel_1\",0.0],PARAMETER[\"Auxiliary_Sphere_Type\",0.0],UNIT[\"Meter\",1.0],AUTHORITY[\"EPSG\",3857]]", XOrigin = -20037700.0, XOriginSpecified = true, XYScale = 10000.0, XYScaleSpecified = true, XYTolerance = 0.001, XYToleranceSpecified = true, YOrigin = -30241100.0, YOriginSpecified = true, ZOrigin = -100000.0, ZOriginSpecified = true, ZScale = 10000.0, ZScaleSpecified = true, ZTolerance = 0.001, ZToleranceSpecified = true }; sr = pcs as ArcGIS.Core.Internal.CIM.SpatialReference; } else { throw new System.NotImplementedException(string.Format("Sorry. Support for wkid {0} is not implemented in this example", WKID)); } return(sr); }
/// <summary> /// Create a CIM Spatial Reference. Has to be created from scratch /// </summary> /// <param name="WKID">The wkid for the spatial reference to be created</param> /// <returns>A CIM spatial reference</returns> public SpatialReference CreateSpatialReference(int WKID) { SpatialReference sr = null; if (WKID == 104115 || WKID == 4326) { GeographicCoordinateSystem gs = new GeographicCoordinateSystem(); gs.WKID = 104115; gs.WKIDSpecified = true; gs.LatestWKID = 104115; gs.LatestVCSWKIDSpecified = true; gs.LeftLongitude = -180; gs.LeftLongitudeSpecified = true; gs.HighPrecision = true; gs.HighPrecisionSpecified = true; gs.MTolerance = 0.001; gs.MToleranceSpecified = true; gs.ZTolerance = 0.001; gs.ZToleranceSpecified = true; gs.XYTolerance = 8.9831528411952133E-09; gs.XYToleranceSpecified = true; gs.MScale = 10000; gs.MScaleSpecified = true; gs.MOrigin = -100000; gs.MOriginSpecified = true; gs.ZScale = 10000; gs.ZScaleSpecified = true; gs.ZOrigin = -100000; gs.ZOriginSpecified = true; gs.XYScale = 999999999.99999988; gs.XYScaleSpecified = true; gs.XOrigin = -400; gs.XOriginSpecified = true; gs.YOrigin = -400; gs.YOriginSpecified = true; gs.WKT = "GEOGCS[\"GCS_ITRF_1988\",DATUM[\"D_ITRF_1988\",SPHEROID[\"GRS_1980\",6378137.0,298.257222101]],PRIMEM[\"Greenwich\",0.0],UNIT[\"Degree\",0.0174532925199433],AUTHORITY[\"ESRI\",104115]]"; sr = gs as SpatialReference; } else if (WKID == 102100) { //Note: In testing, I could not get Web Mercator to //work on the mapview. ProjectedCoordinateSystem pcs = new ProjectedCoordinateSystem(); pcs.HighPrecision = true; pcs.HighPrecisionSpecified = true; pcs.LatestVCSWKID = 0; pcs.LatestVCSWKIDSpecified = false; pcs.LatestWKID = 3857; pcs.LatestWKIDSpecified = true; pcs.LeftLongitude = 0.0; pcs.LeftLongitudeSpecified = false; pcs.MOrigin = -100000.0; pcs.MOriginSpecified = true; pcs.MScale = 10000.0; pcs.MScaleSpecified = true; pcs.MTolerance = 0.001; pcs.MToleranceSpecified = true; pcs.VCSWKID = 0; pcs.VCSWKIDSpecified = false; pcs.WKID = 102100; pcs.WKIDSpecified = true; pcs.WKT = "PROJCS[\"WGS_1984_Web_Mercator_Auxiliary_Sphere\",GEOGCS[\"GCS_WGS_1984\",DATUM[\"D_WGS_1984\",SPHEROID[\"WGS_1984\",6378137.0,298.257223563]],PRIMEM[\"Greenwich\",0.0],UNIT[\"Degree\",0.0174532925199433]],PROJECTION[\"Mercator_Auxiliary_Sphere\"],PARAMETER[\"false ;_Easting\",0.0],PARAMETER[\"false ;_Northing\",0.0],PARAMETER[\"Central_Meridian\",0.0],PARAMETER[\"Standard_Parallel_1\",0.0],PARAMETER[\"Auxiliary_Sphere_Type\",0.0],UNIT[\"Meter\",1.0],AUTHORITY[\"EPSG\",3857]]"; pcs.XOrigin = -20037700.0; pcs.XOriginSpecified = true; pcs.XYScale = 10000.0; pcs.XYScaleSpecified = true; pcs.XYTolerance = 0.001; pcs.XYToleranceSpecified = true; pcs.YOrigin = -30241100.0; pcs.YOriginSpecified = true; pcs.ZOrigin = -100000.0; pcs.ZOriginSpecified = true; pcs.ZScale = 10000.0; pcs.ZScaleSpecified = true; pcs.ZTolerance = 0.001; pcs.ZToleranceSpecified = true; sr = pcs as SpatialReference; } else { throw new System.NotImplementedException(string.Format("Sorry. Support for wkid {0} is not implemented in this example", WKID)); } return sr; }
public override FeatureList process(FeatureList input, FilterEnv env) { FeatureList output = new FeatureList(); // HACER ALGO DEL ESTILO: if (transform == null) { //Create zone UTM 32N projection IProjectedCoordinateSystem utmProj = CreateUtmProjection(32); //Create geographic coordinate system (lets just reuse the CS from the projection) IGeographicCoordinateSystem geoCS = utmProj.GeographicCoordinateSystem; //Create transformation CoordinateTransformationFactory ctFac = new CoordinateTransformationFactory(); // TODO DANI Mirar de donde viene este source y target ICoordinateTransformation Coordinatetransform = null;// TODO = ctFac.CreateFromCoordinateSystems(source, target); //cs string wkt = "GEOGCS[\"GCS_WGS_1984\",DATUM[\"D_WGS_1984\",SPHEROID[\"WGS_1984\",6378137,298.257223563]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.0174532925199433]]"; //ICoordinateSystem cs = SharpMap.Converters.WellKnownText.CoordinateSystemWktReader.Parse(wkt) as ICoordinateSystem; ICoordinateSystem cs = ProjNet.Converters.WellKnownText.CoordinateSystemWktReader.Parse(wkt) as ICoordinateSystem; //wgs84 GeographicCoordinateSystem wgs84 = GeographicCoordinateSystem.WGS84; //gcs CoordinateSystemFactory cFac = new ProjNet.CoordinateSystems.CoordinateSystemFactory(); //CoordinateSystemFactory cFac = new SharpMap.CoordinateSystems.CoordinateSystemFactory(); //Create Bessel 1840 geographic coordinate system 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)); //coordsys //Collection<ProjectionParameter> parameters = new Collection<ProjectionParameter>(5); 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)); Coordinatetransform = ctFac.CreateFromCoordinateSystems(gcs, coordsys);//gcsWGS84 -> gcenCsWGS84 //Apply transformation transform = Coordinatetransform.MathTransform; } SharpMap.Geometries.Point p = new SharpMap.Geometries.Point(30.0, 20.0); p = GeometryTransform.TransformPoint(p, transform); /*IMPORTANTE * foreach (Feature feature in input) * { * feature.row.Geometry = GeometryTransform.TransformGeometry(feature.row.Geometry, transform); * //feature.row.Geometry = GeometryTransform.TransformMultiPolygon(feature.row.Geometry, transform); * } * IMPORTANTE*/ foreach (Feature f in input) { output.Add(f);//output = input } // Cosas a cambiar: // Primero, la construccion del transform está siguiendo el ejemplo, pero hay que tener en cuenta los datos del xml y construirlo en consecuencia // Segundo, el filtro debe retornar una NUEVA lista, y no modificar la inicial. Ahora modifica los valores de la lista inicial // IMPORTANTE RETORNAR NUEVA LISTA OUTPUT <----------- FALTA POR HACER #if TODO // first time through, establish a working SRS for output data. if (working_srs == null) { // first try to use the terrain SRS if so directed: SpatialReference new_out_srs = getUseTerrainSRS() ? env.getTerrainSRS() : null; if (new_out_srs == null) { // failing that, see if we have an SRS in a resource: if (getSRS() == null && getSRSScript() != null) { ScriptResult r = env.getScriptEngine().run(getSRSScript(), env); if (r.isValid()) { setSRS(env.getSession().getResources().getSRS(r.ToString())); } else { env.getReport().error(r.ToString()); } } new_out_srs = srs; } // set the "working" SRS that will be used for all features passing though this filter: working_srs = new_out_srs != null ? new_out_srs : env.getInputSRS(); // LOCALIZE points around a local origin (the working extent's centroid) if (working_srs != null && getLocalize()) //&& env.getExtent().getArea() > 0.0 ) { if (env.getCellExtent().getSRS().isGeographic() && env.getCellExtent().getWidth() > 179.0) { //NOP - no localization for big geog extent ... needs more thought perhaps } else { GeoPoint centroid0 = new_out_srs != null? new_out_srs.transform(env.getCellExtent().getCentroid()) : env.getCellExtent().getCentroid(); // we do want the localizer point on the surface if possible: GeoPoint centroid = clampToTerrain(centroid0, env); if (centroid == null) { centroid = centroid0; } Matrixd localizer; // For geocentric datasets, we need a special localizer matrix: if (working_srs.isGeocentric()) { localizer = working_srs.getEllipsoid().createGeocentricInvRefFrame(centroid); localizer.invert(localizer); } // For projected datasets, just a simple translation: else { localizer = osg.Matrixd.translate(-centroid); } working_srs = working_srs.cloneWithNewReferenceFrame(localizer); } } } // we have to assign the output SRS on each pass if (working_srs != null) { env.setOutputSRS(working_srs); } return(base.process(input, env)); #endif //throw new NotImplementedException(); if (successor != null) { if (successor is FeatureFilter) { FeatureFilter filter = (FeatureFilter)successor; FeatureList l = filter.process(output, env); } else if (successor is FragmentFilter) { FragmentFilter filter = (FragmentFilter)successor; FragmentList l = filter.process(output, env); } } return(output); }
/// <summary> /// Geographic to geographic transformation /// </summary> /// <remarks>Adds a datum shift if necessary</remarks> /// <param name="source"></param> /// <param name="target"></param> /// <returns></returns> private static ICoordinateTransformation CreateGeog2Geog(GeographicCoordinateSystem source, GeographicCoordinateSystem 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)); } //Create datum shift //Convert to geocentric, perform shift and return to geographic var ctFac = new CoordinateTransformationFactory(); var cFac = new CoordinateSystemFactory(); var sourceCentric = cFac.CreateGeocentricCoordinateSystem(source.HorizontalDatum.Name + " Geocentric", source.HorizontalDatum, LinearUnit.Metre, source.PrimeMeridian); var targetCentric = cFac.CreateGeocentricCoordinateSystem(target.HorizontalDatum.Name + " Geocentric", target.HorizontalDatum, LinearUnit.Metre, source.PrimeMeridian); var ct = new ConcatenatedTransform(); AddIfNotNull(ct, ctFac.CreateFromCoordinateSystems(source, sourceCentric)); AddIfNotNull(ct, ctFac.CreateFromCoordinateSystems(sourceCentric, targetCentric)); AddIfNotNull(ct, ctFac.CreateFromCoordinateSystems(targetCentric, target)); return(new CoordinateTransformation(source, target, TransformType.Transformation, ct, string.Empty, string.Empty, -1, string.Empty, string.Empty)); }
private static CoordinateTransformation Proj2Geog(ProjectedCoordinateSystem source, GeographicCoordinateSystem target) { if (source.GeographicCoordinateSystem.EqualParams(target)) { var 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 var ct = new ConcatenatedTransform(); var 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)); } }
/// <summary> /// /// </summary> /// <param name="tokenizer"></param> /// <returns></returns> private static IGeographicCoordinateSystem ReadGeographicCoordinateSystem(WktStreamTokenizer tokenizer) { /* * GEOGCS["OSGB 1936", * DATUM["OSGB 1936",SPHEROID["Airy 1830",6377563.396,299.3249646,AUTHORITY["EPSG","7001"]],TOWGS84[0,0,0,0,0,0,0],AUTHORITY["EPSG","6277"]] * PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]] * AXIS["Geodetic latitude","NORTH"] * AXIS["Geodetic longitude","EAST"] * AUTHORITY["EPSG","4277"] * ] */ tokenizer.ReadToken("["); string name = tokenizer.ReadDoubleQuotedWord(); tokenizer.ReadToken(","); tokenizer.ReadToken("DATUM"); IHorizontalDatum horizontalDatum = ReadHorizontalDatum(tokenizer); tokenizer.ReadToken(","); tokenizer.ReadToken("PRIMEM"); IPrimeMeridian primeMeridian = ReadPrimeMeridian(tokenizer); tokenizer.ReadToken(","); tokenizer.ReadToken("UNIT"); IAngularUnit angularUnit = ReadAngularUnit(tokenizer); string authority = String.Empty; long authorityCode = -1; tokenizer.NextToken(); List <AxisInfo> info = new List <AxisInfo>(2); if (tokenizer.GetStringValue() == ",") { tokenizer.NextToken(); while (tokenizer.GetStringValue() == "AXIS") { info.Add(ReadAxis(tokenizer)); tokenizer.NextToken(); if (tokenizer.GetStringValue() == ",") { tokenizer.NextToken(); } } if (tokenizer.GetStringValue() == ",") { tokenizer.NextToken(); } if (tokenizer.GetStringValue() == "AUTHORITY") { tokenizer.ReadAuthority(ref authority, ref authorityCode); tokenizer.ReadToken("]"); } } //This is default axis values if not specified. if (info.Count == 0) { info.Add(new AxisInfo("Lon", AxisOrientationEnum.East)); info.Add(new AxisInfo("Lat", AxisOrientationEnum.North)); } IGeographicCoordinateSystem geographicCS = new GeographicCoordinateSystem(angularUnit, horizontalDatum, primeMeridian, info, name, authority, authorityCode, String.Empty, String.Empty, String.Empty); return(geographicCS); }
public static Crtm05CoordinateSystem ToCrtm05(GeographicCoordinateSystem coordinates) { return(ToCrtm05(coordinates, new Parameters(), new Coefficients())); }
// Methods public ProjectedCoordinateSystem(string name, string authority, string authorityCode, string alias, string info, GeographicCoordinateSystem gcs, IProjection projection, ILinearUnit linearUnit, AxisInfo axis0, AxisInfo axis1) => throw null;
internal GeographicTransform(GeographicCoordinateSystem sourceGCS, GeographicCoordinateSystem targetGCS) { SourceGCS = sourceGCS; TargetGCS = targetGCS; }