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)); }
static ProjHelper() { CoordinateTransformationFactory factory = new CoordinateTransformationFactory(); IGeographicCoordinateSystem wgs84 = GeographicCoordinateSystem.WGS84; IProjectedCoordinateSystem mercator = ProjectedCoordinateSystem.WebMercator; Transformation = factory.CreateFromCoordinateSystems(wgs84, mercator); }
private Coordinate Convert(Coordinate a, ICoordinateTransformation tx) { double[] point = new double[] { a.X, a.Y }; double[] result = tx.MathTransform.Transform(point); return new Coordinate(result[0], result[1]); }
public static BoundingBox InverseTransform(BoundingBox box, ICoordinateTransformation coordinateTransformation) { coordinateTransformation.MathTransform.Invert(); double[] point1 = coordinateTransformation.MathTransform.Transform(new[] { box.MinX, box.MinY }); double[] point2 = coordinateTransformation.MathTransform.Transform(new[] { box.MaxX, box.MaxY }); coordinateTransformation.MathTransform.Invert(); return new BoundingBox(point1[0], point1[1], point2[0], point2[1]); }
public static Envelope InverseTransform(Envelope box, ICoordinateTransformation CoordinateTransformation) { CoordinateTransformation.MathTransform.Invert(); double[] point1 = CoordinateTransformation.MathTransform.Transform(new double[] { box.MinX, box.MinY }); double[] point2 = CoordinateTransformation.MathTransform.Transform(new double[] { box.MaxX, box.MaxY }); CoordinateTransformation.MathTransform.Invert(); return new Envelope(point1[0], point1[1], point2[0], point2[1]); }
/// <summary> /// Initializes a new instance of the <see cref="ProjectionFilter">ProjectionFilter</see> class. /// </summary> /// <param name="projection">The <see cref="Geotools.CoordinateTransformations.ICoordinateTransformation">ICoordinateTransformation</see> to apply.</param> public ProjectionFilter( ICoordinateTransformation projection ) { if (projection==null) { throw new ArgumentNullException("projection"); } _projection = projection; }
public static void Transform(IGeometry geometry, ICoordinateTransformation coordinateTransformation) { var vertices = geometry.AllVertices(); foreach (var vertex in vertices) { double[] point = coordinateTransformation.MathTransform.Transform(new[] { vertex.X, vertex.Y }); vertex.X = point[0]; vertex.Y = point[1]; } }
public static IGeometry Transform(IGeometry geometry, ICoordinateTransformation CoordinateTransformation) { if (geometry is Point) { double[] point = CoordinateTransformation.MathTransform.Transform(new double[] { ((Point)geometry).X, ((Point)geometry).Y }); return new Point(point[0], point[1]); } else { throw new NotImplementedException("todo implement for other geometries"); } }
/// <summary> /// Creates a Meractor projection object. /// </summary> /// <param name="centralMeridian">The central merdian to use.</param> /// <param name="falseNorthing">The false northing to use.</param> /// <returns>ICoordinateTransformation that implements the Mercator projection.</returns> public static ICoordinateTransformation CreateUKNationalGridProjection(double centralMeridian, double falseNorthing) { string wktSourceCS = Projections.UKNationalGrid; wktSourceCS = String.Format(CultureInfo.InvariantCulture, wktSourceCS, falseNorthing, centralMeridian); IProjectedCoordinateSystem sourceCS = (IProjectedCoordinateSystem)CoordinateSystemWktReader.Create(wktSourceCS); IGeographicCoordinateSystem targetCS = CreateWgs84(); CoordinateTransformationFactory coordTransFactory = new CoordinateTransformationFactory(); ICoordinateTransformation projection = coordTransFactory.CreateFromCoordinateSystems(sourceCS, targetCS); return(projection); }
///<summary> /// 将点转换为经纬度点 /// </summary> /// <param name="point">平面坐标点</param> ///<returns>经纬度点</returns> ///<remarks></remarks> public LTE.Geometric.Point GetGeoPoint(LTE.Geometric.Point point) { lock (obj) { double[] p = new double[2]; p[0] = point.X; p[1] = point.Y; ICoordinateTransformation trans = pCTFAC.CreateFromCoordinateSystems(pPCS, pGCS); p = trans.MathTransform.Transform(p); point.X = p[0]; point.Y = p[1]; } return(point); }
public static ILineString Transform(this ICoordinateTransformation self, ILineString line) { var newCoords = new Coordinate[line.NumPoints]; for (var i = 0; i < line.NumPoints; i++) { var pt = line.GetPointN(i); var coord = newCoords[i]; var oldCoord = new Coordinate2D(pt.X, pt.Y); var transformedCoord = self.Transform(oldCoord); newCoords[i] = new Coordinate(transformedCoord.X, transformedCoord.Y); } return(new LineString(newCoords)); }
private static IPolygon ReProject(this IPolygon polygon, ICoordinateTransformation transformator) { var shell = ((ILinearRing)polygon.ExteriorRing).ReProject(transformator); var ringCount = polygon.NumInteriorRings; var holes = new ILinearRing[ringCount]; for (var i = 0; i < ringCount; i++) { holes[i] = ((ILinearRing)polygon.GetInteriorRingN(i)).ReProject(transformator); } return(new Polygon(shell, holes)); }
public void Filter(GeoAPI.Geometries.Coordinate coord) { ProjNet.CoordinateSystems.ICoordinateSystem equalArea = (ProjNet.CoordinateSystems.ICoordinateSystem)CoordinateSystemWktReader.Parse(ProjectionUtil.NORTH_AMERICAN_ALBERS_EQUAL_AREA_WKT); ProjNet.CoordinateSystems.IGeographicCoordinateSystem latlon = (ProjNet.CoordinateSystems.IGeographicCoordinateSystem)CoordinateSystemWktReader.Parse(ProjectionUtil.GCS_WGS84_WKT); ICoordinateTransformationFactory ctfac = new CoordinateTransformationFactory(); ICoordinateTransformation transformation = ctfac.CreateFromCoordinateSystems(latlon, equalArea); double[] newCoords = transformation.MathTransform.Transform(new double[] { coord.X, coord.Y }); coord.X = newCoords[0]; coord.Y = newCoords[1]; }
double calcpolygonarea(List <PointLatLng> 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)); }
private static void ToUTM(double longitude, double latitude, out double x, out double y, out string zone) { ICoordinateSystem gcs_WGS84 = GeographicCoordinateSystem.WGS84; IProjectedCoordinateSystem pcs_UTM31N = ProjectedCoordinateSystem.WGS84_UTM(23, false); CoordinateTransformationFactory ctfac = new CoordinateTransformationFactory(); ICoordinateTransformation trans = ctfac.CreateFromCoordinateSystems(gcs_WGS84, pcs_UTM31N); double[] fromPoint = new double[] { longitude, latitude }; double[] toPoint = trans.MathTransform.Transform(fromPoint); x = toPoint[0]; y = toPoint[1]; zone = "23S"; }
public void TestMichiganGeoRefToWebMercator() { var src = CoordinateSystemFactory.CreateFromWkt(wkt7151); var tgt = CoordinateSystems.ProjectedCoordinateSystem.WebMercator; ICoordinateTransformation transform = null; Assert.DoesNotThrow(() => transform = CoordinateTransformationFactory.CreateFromCoordinateSystems(src, tgt)); Assert.IsNotNull(transform); var ptSrc = new[] { 535247.9375, 324548.09375 }; double[] ptTgt = null; Assert.DoesNotThrow(() => ptTgt = transform.MathTransform.Transform(ptSrc)); Assert.IsNotNull(ptTgt); }
/// <summary> /// Helper function for applying a reprojection transformation on a single IGeometry /// </summary> /// <param name="geom"></param> /// <param name="trans"></param> /// <returns></returns> public static IGeometry ReprojectGeometry(IGeometry geom, ICoordinateTransformation trans) { double[] srcPt = new double[2], pt = null; foreach (ICoordinate coord in geom.Coordinates) { srcPt[0] = coord.X; srcPt[1] = coord.Y; pt = trans.MathTransform.Transform(srcPt); coord.X = pt[0]; coord.Y = pt[1]; } return(geom); }
//获取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); }
public bool Single_Direct(TestAttribute ta, object setup, ref double x, ref double y) { ICoordinateTransformation t = GetTransformation(true); for (int i = 0; i < ta.PerPoint; ++i) { x = p.X; y = p.Y; double?z; t.Transform(x, y, null, out x, out y, out z); } return(true); }
public void Single_Transform_Proj_Point(TestAttribute ta, object setup, ref double x, ref double y) { ICoordinateTransformation t = GetTransformation(false); System.Windows.Point pOut = new System.Windows.Point(); for (int i = 0; i < ta.PerPoint; ++i) { pOut = t.Transform(p); } x = pOut.X; y = pOut.Y; }
void SetCoordinateTransformation() { // Source Coordinate System use by OSM var sourceCS = GeographicCoordinateSystem.WGS84; // Target Coordinate System used by LiDAR data (Berlin) // https://epsg.io/25833 var ETRS89_EPSG25833 = "PROJCS[\"ETRS89 / UTM zone 33N\", 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\"]], PROJECTION[\"Transverse_Mercator\"], PARAMETER[\"latitude_of_origin\", 0], PARAMETER[\"central_meridian\", 15], PARAMETER[\"scale_factor\", 0.9996], PARAMETER[\"false_easting\", 500000], PARAMETER[\"false_northing\", 0], UNIT[\"metre\", 1, AUTHORITY[\"EPSG\", \"9001\"]], AXIS[\"Easting\", EAST], AXIS[\"Northing\", NORTH], AUTHORITY[\"EPSG\", \"25833\"]]"; var cf = new CoordinateSystemFactory(); var targetCS = cf.CreateFromWkt(ETRS89_EPSG25833); CoordinateTransformationFactory ctfac = new CoordinateTransformationFactory(); CoordinateTransformation = ctfac.CreateFromCoordinateSystems(sourceCS, targetCS); }
static GeoUtils() { _utmZone = ConfigManager.ConfigFile.UtmZone; _utmNorth = ConfigManager.ConfigFile.IsUtmNorth; CoordinateTransformationFactory _ctf = new CoordinateTransformationFactory(); _transformationFromWGS84ToUTM = _ctf.CreateFromCoordinateSystems(GeographicCoordinateSystem.WGS84, ProjectedCoordinateSystem.WGS84_UTM(_utmZone, _utmNorth)); _transformationFromWGS84ToMercator = _ctf.CreateFromCoordinateSystems(GeographicCoordinateSystem.WGS84, ProjectedCoordinateSystem.WebMercator); _transformationFromMercatorToWGS84 = _ctf.CreateFromCoordinateSystems(ProjectedCoordinateSystem.WebMercator, GeographicCoordinateSystem.WGS84); _transformationFromUTMToUGS84 = _ctf.CreateFromCoordinateSystems(ProjectedCoordinateSystem.WGS84_UTM(_utmZone, _utmNorth), GeographicCoordinateSystem.WGS84); _transformationFromUTMToMercator = _ctf.CreateFromCoordinateSystems(ProjectedCoordinateSystem.WGS84_UTM(_utmZone, _utmNorth), ProjectedCoordinateSystem.WebMercator); _transformationFromMercatorToUTM = _ctf.CreateFromCoordinateSystems(ProjectedCoordinateSystem.WebMercator, ProjectedCoordinateSystem.WGS84_UTM(_utmZone, _utmNorth)); _utmOrigin = default(GeoPointUTM); }
public void TestCreateFromTransformationCode2() { ICoordinateTransformation UKNationalGrid1 = _CTfactory.CreateFromTransformationCode("1681"); double long1 = 2.5; double lat1 = 53.2; CoordinatePoint pt = new CoordinatePoint(); pt.Ord = new Double[2]; pt.Ord[0] = long1; pt.Ord[1] = lat1; CoordinatePoint result1 = UKNationalGrid1.MathTransform.Transform(pt); double metersX = (double)result1.Ord[0]; double metersY = (double)result1.Ord[1]; }
public void Bulk_100000_Direct_XY(TestAttribute ta, object setup, ref double x, ref double y) { double[][] xy = bulk_XY_100000; int j = random.Next(xy[0].Length); ICoordinateTransformation t = GetTransformation(true); for (int i = 0; i < ta.PerPoint / xy[0].Length; ++i) { t.Transform(xy[0], xy[1], null, xy[2], xy[3], null); x = xy[2][j]; y = xy[3][j]; } }
public static Geometry Transform(Geometry geometry, ICoordinateTransformation transformer) { if (geometry is null) { throw new ArgumentNullException(nameof(geometry)); } if (transformer is null) { throw new ArgumentNullException(nameof(transformer)); } geometry = geometry.Copy(); geometry.Apply(new MathTransformFilter(transformer.MathTransform)); return(geometry); }
// NOT USED private IList <double[]> TransformCords(IList <double[]> coordinates, bool reverse = true) { CoordinateTransformationFactory cFact = new CoordinateTransformationFactory(); ICoordinateTransformation cTrans = null; if (reverse) { cTrans = cFact.CreateFromCoordinateSystems(ProjectedCoordinateSystem.WebMercator, GeographicCoordinateSystem.WGS84); } else { cTrans = cFact.CreateFromCoordinateSystems(GeographicCoordinateSystem.WGS84, ProjectedCoordinateSystem.WebMercator); } return(cTrans.MathTransform.TransformList(coordinates)); }
private static void Initialize() { if (_fromCS == null) { if (_fromCS == null) { string utmWkt = @" 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""]], 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]]"; // WGS 84 string wgsWkt = @" GEOGCS[""GCS_WGS_1984"", DATUM[""D_WGS_1984"",SPHEROID[""WGS_1984"",6378137,298.257223563]], PRIMEM[""Greenwich"",0], UNIT[""Degree"",0.0174532925199433] ]"; // Initialize objects needed for coordinate transformation _fromCS = ProjNet.Converters.WellKnownText.CoordinateSystemWktReader.Parse(wgsWkt) as IGeographicCoordinateSystem; _toCS = ProjNet.Converters.WellKnownText.CoordinateSystemWktReader.Parse(utmWkt) as IProjectedCoordinateSystem; _ctfac = new CoordinateTransformationFactory(); _trans = _ctfac.CreateFromCoordinateSystems(_fromCS, _toCS); } } }
public string getCoordinates(int X, int Y) { GeoAPI.Geometries.Coordinate p = _sharpMap.ImageToWorld(new PointF(X, Y)); PointF pUTM = new PointF(); IProjectedCoordinateSystem utmProj = Helpers.CoordinateSystem.CreateUtmProjection(34); IGeographicCoordinateSystem geoCS = utmProj.GeographicCoordinateSystem; CoordinateTransformationFactory ctFac = new CoordinateTransformationFactory(); ICoordinateTransformation transform = ctFac.CreateFromCoordinateSystems(geoCS, utmProj); double[] c = new double[2]; c[0] = p.X; c[1] = p.Y; c = transform.MathTransform.Transform(c); pUTM.X = (float)c[0]; pUTM.Y = (float)c[1]; return(pUTM.X + " : " + pUTM.Y); }
public void TestGeocentric() { CoordinateSystemFactory cFac = new CoordinateSystemFactory(); IGeographicCoordinateSystem gcs = cFac.CreateGeographicCoordinateSystem("ETRF89 Geographic", AngularUnit.Degrees, HorizontalDatum.ETRF89, PrimeMeridian.Greenwich, new AxisInfo("East", AxisOrientationEnum.East), new AxisInfo("North", AxisOrientationEnum.North)); IGeocentricCoordinateSystem gcenCs = cFac.CreateGeocentricCoordinateSystem("ETRF89 Geocentric", HorizontalDatum.ETRF89, LinearUnit.Metre, PrimeMeridian.Greenwich); CoordinateTransformationFactory gtFac = new CoordinateTransformationFactory(); ICoordinateTransformation ct = gtFac.CreateFromCoordinateSystems(gcs, gcenCs); double[] pExpected = new double[] { 2 + 7.0 / 60 + 46.38 / 3600, 53 + 48.0 / 60 + 33.82 / 3600 }; // Point.FromDMS(2, 7, 46.38, 53, 48, 33.82); double[] pExpected3D = new double[] { pExpected[0], pExpected[1], 73.0 }; double[] p0 = new double[] { 3771793.97, 140253.34, 5124304.35 }; double[] p1 = ct.MathTransform.Transform(pExpected3D) as double[]; double[] p2 = ct.MathTransform.Inverse().Transform(p1) as double[]; Assert.IsTrue(ToleranceLessThan(p1, p0, 0.01)); Assert.IsTrue(ToleranceLessThan(p2, pExpected, 0.00001)); }
public 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); }
private Coordinate[] transformCoordinates(ICoordinateTransformation trans, Coordinate[] source) { if (trans == null) { return(source); } List <Coordinate> coordlist = new List <Coordinate>(); foreach (var c in source) { double[] coords = trans.MathTransform.Transform(new double[] { c.X, c.Y, c.Z }); coordlist.Add(new Coordinate(coords[0], coords[1], coords[2])); } return(coordlist.Reverse <Coordinate>().ToArray()); }
public static void Main() { //////Add this to class constructor NtsGeometryServices.Instance = new NtsGeometryServices( NetTopologySuite.Geometries.Implementation.CoordinateArraySequenceFactory.Instance, new NetTopologySuite.Geometries.PrecisionModel(1000d), 4326, // Note the following arguments are only valid for NTS v2.2 // Geometry overlay operation function set to use (Legacy or NG) NetTopologySuite.Geometries.GeometryOverlay.NG, // Coordinate equality comparer to use (CoordinateEqualityComparer or PerOrdinateEqualityComparer) new NetTopologySuite.Geometries.CoordinateEqualityComparer()); //Transform Projection //*****Add ProjNet to make transform //https://docs.microsoft.com/en-us/ef/core/modeling/spatial //2nd Way //Add WKT projection coordinate system const string outputWKT = @""; CoordinateSystemFactory csFact = new CoordinateSystemFactory(); var csWgs84Text = ProjNet.CoordinateSystems.GeographicCoordinateSystem.WGS84.WKT; var csWgs84 = csFact.CreateFromWkt(csWgs84Text); var outputProjection = csFact.CreateFromWkt(outputWKT); CoordinateTransformationFactory ctFact = new CoordinateTransformationFactory(); ICoordinateTransformation trans = ctFact.CreateFromCoordinateSystems(csWgs84, outputProjection); var mt = trans.MathTransform; // Use the following website to look up the arguement below that should match outputProjection ESRG //http://epsg.io var gf = NtsGeometryServices.Instance.CreateGeometryFactory(XXXX); //////End of Class Constructor //IMPORTANT-ALL GEOMETRY POINTS MUST BE WRAPPED WITH mt.Transform() // Create a point at Aurich (lat=53.4837, long=7.5404) var pntAUR = gf.CreatePoint(mt.Transform(new NetTopologySuite.Geometries.Coordinate(7.5404, 53.4837))); // Create a point at Emden (lat=53.3646, long=7.1559) var pntLER = gf.CreatePoint(mt.Transform(new NetTopologySuite.Geometries.Coordinate(7.1559, 53.3646))); // Create a point at Leer (lat=53.2476, long=7.4550) var pntEMD = gf.CreatePoint(mt.Transform(new NetTopologySuite.Geometries.Coordinate(7.4550, 53.2476))); var distancepntAURpntLER = pntAUR.Distance(pntLER); Console.WriteLine($"{distancepntAURpntLER} miles"); }
private IExtents TransformExtents(IExtents ext) { if (!Provider.SpatialReference.EqualParams(ext.SpatialReference)) { if (Provider.CoordinateTransformationFactory == null) { throw new MissingCoordinateTransformationFactoryException( "Data requires transformation however no CoordinateTransformationFactory is set"); } ICoordinateTransformation ct = Provider.CoordinateTransformationFactory.CreateFromCoordinateSystems(ext.SpatialReference, Provider. OriginalSpatialReference); return(ct.Transform(ext, Provider.GeometryFactory)); } return(ext); }
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); }
public PointLatLngAlt ToLLA() { IProjectedCoordinateSystem utm = ProjectedCoordinateSystem.WGS84_UTM(Math.Abs(zone), zone < 0 ? false : true); ICoordinateTransformation trans = ctfac.CreateFromCoordinateSystems(wgs84, utm); // get leader utm coords double[] pll = trans.MathTransform.Inverse().Transform(this); PointLatLngAlt ans = new PointLatLngAlt(pll[1], pll[0]); if (this.Tag != null) { ans.Tag = this.Tag.ToString(); } return(ans); }
/// <summary> /// Helper for generating transformed points on a line (x0,y0) - (x1,y1), /// given the number of points to generate and a coordinate transformation. /// </summary> /// <param name="t">Coordinate transformation to use.</param> /// <param name="x0">x-coordinate of start point</param> /// <param name="y0">y-coordinate of start point</param> /// <param name="x1">x-coordinate of end point</param> /// <param name="y1">y-coordinate of end point</param> /// <param name="n">Number of points to generate.</param> /// <returns>Generated points</returns> private static Location[] MakeLineString(ICoordinateTransformation t, double x0, double y0, double x1, double y1, int n) { // setup interpolator var pointInterpolator = new { x = x0, xi = (x1 - x0) / (n - 1), y = y0, yi = (y1 - y0) / (n - 1) }; // local function for interpolating points given an index Func <int, Location> interpolatedLocation = index => new Location( pointInterpolator.x + index * pointInterpolator.xi, pointInterpolator.y + index * pointInterpolator.yi ); // create and return locations using interpolator and coordinate transformation return(t.Transform(Enumerable.Range(0, n).Select(interpolatedLocation).ToArray())); }
public static void TestGitHubIssue53() { // arrange CoordinateSystemFactory csFact = new CoordinateSystemFactory(); CoordinateTransformationFactory ctFact = new CoordinateTransformationFactory(); ICoordinateSystem csWgs84 = GeographicCoordinateSystem.WGS84; IProjectedCoordinateSystem csUtm35N = ProjectedCoordinateSystem.WGS84_UTM(35, true); ICoordinateTransformation csTrans = ctFact.CreateFromCoordinateSystems(csWgs84, csUtm35N); ICoordinateTransformation csTransBack = ctFact.CreateFromCoordinateSystems(csUtm35N, csWgs84); // act double[] point = new[] { 42.5, 24.5 }; var r = csTrans.MathTransform.Transform(point); var rBack = csTransBack.MathTransform.Transform(r); // assert Assert.AreEqual(point[0], rBack[0], 1e-5); Assert.AreEqual(point[1], rBack[1], 1e-5); }
private Polygon transformPolygon(ICoordinateTransformation trans, Polygon polygon) { if (trans == null) { return(polygon); } Coordinate[] extRing = this.transformCoordinates(trans, polygon.ExteriorRing.Coordinates); List <LinearRing> holes = new List <LinearRing>(); foreach (var hole in polygon.Holes) { Coordinate[] holeCoords = this.transformCoordinates(trans, hole.Coordinates); holes.Add(new LinearRing(holeCoords)); } return(new Polygon(new LinearRing(extRing), holes.ToArray())); }
public void Test1() { IDbConnection connection = Global.GetEPSGDatabaseConnection(); _CTfactory = new CoordinateTransformationEPSGFactory(connection); _UKNationalGrid1 = _CTfactory.CreateFromTransformationCode("1681"); _geometryFactory = new GeometryFactory(_pm, 4326); string wkt = "POINT ( -2.0 49.0 )"; Assertion.AssertEquals("Point 1", true, Compare(wkt, "POINT (400000 -100000)")); wkt = "MULTIPOINT( -2 49, -1 50)"; Assertion.AssertEquals("Multipoint 1", true, Compare(wkt, "MULTIPOINT (400000 -100000, 471660 11644)")); wkt = "MULTIPOINT EMPTY"; Assertion.AssertEquals("Multipoint 2", true, Compare(wkt, "MULTIPOINT EMPTY")); wkt = "LINESTRING(50 31, 54 31, 54 29, 50 29, 50 31 )"; Assertion.AssertEquals("LineString 1 1", true, Compare(wkt, "LINESTRING (5664915 -615242, 6117479 -308294, 6306392 -569639, 5827846 -873669, 5664915 -615242)")); wkt = "POLYGON( ( 50 31, 54 31, 54 29, 50 29, 50 31) )"; Assertion.AssertEquals("Multipoint 3", true, Compare(wkt, "POLYGON ((5664915 -615242, 6117479 -308294, 6306392 -569639, 5827846 -873669, 5664915 -615242))")); //wkt = "POLYGON( ( 1 1, 10 1, 10 10, 1 10, 1 1),(4 4, 5 4, 5 5, 4 5, 4 4 ))"; //Assertion.AssertEquals("Multipoint 4",true,Compare(wkt,"POLYGON ((733898 -5416388, 1744907 -5414055, 1724214 -4397377, 728899 -4420227, 733898 -5416388), "+ //"(1067192 -5082521, 1178905 -5081633, 1177832 -4970278, 1066275 -4971386, 1067192 -5082521))")); // these tests fail because the strings are too long/ have a CR in the middle of the string. Should really fix this. awc. //wkt = "MULTILINESTRING (( 10.05 10.28 , 20.95 20.89 ),( 20.95 20.89, 31.92 21.45)) "; //Assertion.AssertEquals("Multipoint 5",false,Compare(wkt,"MULTILINESTRING ((1724213.5597264355 -4397376.6478565233, 2839122.2852214454 -3022771.8465291355), \n "+ // "(2839122.2852214454 -3022771.8465291355, 4095081.5366646093 -2776957.6041615554))")); //wkt = "MULTIPOLYGON (((10 10, 10 20, 20 20, 20 15 , 10 10), (50 40, 50 50, 60 50, 60 40, 50 40)))"; //Assertion.AssertEquals("Multipoint 6",true,Compare(wkt,"MULTIPOLYGON (((1724213.5597264355 -4397376.6478565233, 1662268.9948102259 -3270049.5581512651, 2745586.9073599684 -3156174.8212744244, 2817027.1068546474 -3744257.1145197917, 1724213.5597264355 -4397376.6478565233), "+ // "(4882561.4795353347 438327.55639206013, 3970695.8611971624 1430641.0215268317, 4530976.2509158608 2096414.3039089143, 5721871.0214089518 1247465.211354611, 4882561.4795353347 438327.55639206013)))")); //wkt = "GEOMETRYCOLLECTION(POINT ( 3 4 ),LINESTRING(50 31, 54 31, 54 29, 50 29, 50 31 ))"; //Assertion.AssertEquals("Multipoint 7",true,Compare(wkt,"GEOMETRYCOLLECTION (POINT (955682.872367636 -5083270.4404414054),"+ // "LINESTRING (-7.5557896002384908 49.766496583001434, -7.555734311078294 49.766499242352, -7.5557322582139372 49.76648133658518, -7.5557875473539609 49.7664786772363, -7.5557896002384908 49.766496583001434))")); }
public void Test1() { IDbConnection connection = Global.GetEPSGDatabaseConnection(); _CTfactory = new CoordinateTransformationEPSGFactory(connection); _UKNationalGrid1 = _CTfactory.CreateFromTransformationCode("1681"); _geometryFactory = new GeometryFactory(_pm,4326); string wkt = "POINT ( -2.0 49.0 )"; Assertion.AssertEquals("Point 1",true,Compare(wkt,"POINT (400000 -100000)")); wkt = "MULTIPOINT( -2 49, -1 50)"; Assertion.AssertEquals("Multipoint 1",true,Compare(wkt,"MULTIPOINT (400000 -100000, 471660 11644)")); wkt = "MULTIPOINT EMPTY"; Assertion.AssertEquals("Multipoint 2",true,Compare(wkt,"MULTIPOINT EMPTY")); wkt = "LINESTRING(50 31, 54 31, 54 29, 50 29, 50 31 )"; Assertion.AssertEquals("LineString 1 1",true,Compare(wkt,"LINESTRING (5664915 -615242, 6117479 -308294, 6306392 -569639, 5827846 -873669, 5664915 -615242)")); wkt = "POLYGON( ( 50 31, 54 31, 54 29, 50 29, 50 31) )"; Assertion.AssertEquals("Multipoint 3",true,Compare(wkt,"POLYGON ((5664915 -615242, 6117479 -308294, 6306392 -569639, 5827846 -873669, 5664915 -615242))")); //wkt = "POLYGON( ( 1 1, 10 1, 10 10, 1 10, 1 1),(4 4, 5 4, 5 5, 4 5, 4 4 ))"; //Assertion.AssertEquals("Multipoint 4",true,Compare(wkt,"POLYGON ((733898 -5416388, 1744907 -5414055, 1724214 -4397377, 728899 -4420227, 733898 -5416388), "+ //"(1067192 -5082521, 1178905 -5081633, 1177832 -4970278, 1066275 -4971386, 1067192 -5082521))")); // these tests fail because the strings are too long/ have a CR in the middle of the string. Should really fix this. awc. //wkt = "MULTILINESTRING (( 10.05 10.28 , 20.95 20.89 ),( 20.95 20.89, 31.92 21.45)) "; //Assertion.AssertEquals("Multipoint 5",false,Compare(wkt,"MULTILINESTRING ((1724213.5597264355 -4397376.6478565233, 2839122.2852214454 -3022771.8465291355), \n "+ // "(2839122.2852214454 -3022771.8465291355, 4095081.5366646093 -2776957.6041615554))")); //wkt = "MULTIPOLYGON (((10 10, 10 20, 20 20, 20 15 , 10 10), (50 40, 50 50, 60 50, 60 40, 50 40)))"; //Assertion.AssertEquals("Multipoint 6",true,Compare(wkt,"MULTIPOLYGON (((1724213.5597264355 -4397376.6478565233, 1662268.9948102259 -3270049.5581512651, 2745586.9073599684 -3156174.8212744244, 2817027.1068546474 -3744257.1145197917, 1724213.5597264355 -4397376.6478565233), "+ // "(4882561.4795353347 438327.55639206013, 3970695.8611971624 1430641.0215268317, 4530976.2509158608 2096414.3039089143, 5721871.0214089518 1247465.211354611, 4882561.4795353347 438327.55639206013)))")); //wkt = "GEOMETRYCOLLECTION(POINT ( 3 4 ),LINESTRING(50 31, 54 31, 54 29, 50 29, 50 31 ))"; //Assertion.AssertEquals("Multipoint 7",true,Compare(wkt,"GEOMETRYCOLLECTION (POINT (955682.872367636 -5083270.4404414054),"+ // "LINESTRING (-7.5557896002384908 49.766496583001434, -7.555734311078294 49.766499242352, -7.5557322582139372 49.76648133658518, -7.5557875473539609 49.7664786772363, -7.5557896002384908 49.766496583001434))")); }
private void TransformLayers(ICoordinateTransformation coorTransform) { foreach (SharpMap.Layers.ILayer layer in _map.Layers) { SharpMap.Layers.VectorLayer vLayer = layer as SharpMap.Layers.VectorLayer; if (vLayer != null) { if (vLayer.CoordinateTransformation != null) _coordinateTransformations.Add(vLayer, vLayer.CoordinateTransformation); vLayer.CoordinateTransformation = coorTransform; } else { SharpMap.Layers.LabelLayer lLayer = layer as SharpMap.Layers.LabelLayer; if (lLayer != null) { if (lLayer.CoordinateTransformation != null) _coordinateTransformations.Add(lLayer, lLayer.CoordinateTransformation); lLayer.CoordinateTransformation = coorTransform; } } } }
/// <summary> /// Initializes a new instance of the FlipYFilter class. /// </summary> /// <param name="coordinateTransform">The coordinate transformation to apply.</param> public ProjectionFilter(ICoordinateTransformation coordinateTransform) { _coordinateTransform = coordinateTransform; }
public bool Compare2(string wkt, string expectedProjectedWkt, GeometryFactory geometryFactory, ICoordinateTransformation transformation) { Geometry geometry =(Geometry)geometryFactory.CreateFromWKT(wkt); Geometry projectedGeometry = (Geometry)geometry.Project(transformation); string actualProjectedWkt=projectedGeometry.ToText(); return Geotools.UnitTests.Utilities.Compare.WktStrings(expectedProjectedWkt,actualProjectedWkt); }
/// <summary> /// Projects all the points in a multipolygon and returns a new multipolygon object. /// </summary> /// <param name="coordinateTransform">The coordinate transformation to use for projection.</param> /// <returns>The projected multipolygon object.</returns> public override Geometry Project(ICoordinateTransformation coordinateTransform) { if (coordinateTransform==null) { throw new ArgumentNullException("coordinateTransform"); } if (!(coordinateTransform.MathTransform is Geotools.CoordinateTransformations.MapProjection)) { throw new ArgumentException("transform must be a MapProjection."); } Polygon[] projectedPolygons = new Polygon[_geometries.Length]; IGeometry projectedPolygon; for(int i=0; i<_geometries.Length; i++) { projectedPolygon = _geometries[i].Project(coordinateTransform); projectedPolygons[i] = (Polygon)projectedPolygon; } return _geometryFactory.CreateMultiPolygon(projectedPolygons); }
public static RectangleF Unproject( RectangleF rectangle, ICoordinateTransformation projection ) { PointF topLeft = new PointF(rectangle.Left, rectangle.Top); PointF bottomRight = new PointF(rectangle.Right, rectangle.Bottom); topLeft = Unproject(topLeft, projection); bottomRight = Unproject(bottomRight, projection); return RectangleF.FromLTRB(topLeft.X, topLeft.Y, bottomRight.X, bottomRight.Y); }
internal FeatureMerger(FeatureDataTable target, ICoordinateTransformation transform, IGeometryFactory geoFactory, Boolean preserveChanges, SchemaMergeAction mergeAction) { //if ((SchemaMergeAction.CoerceTypes & mergeAction) != SchemaMergeAction.None) //{ // throw new NotImplementedException("SchemaMergeAction.ConvertTypes is currently not supported."); //} if ((SchemaMergeAction.KeyByType & mergeAction) != SchemaMergeAction.None) { throw new NotImplementedException("SchemaMergeAction.KeyByType is currently not supported."); } //if ((SchemaMergeAction.CaseInsensitive & mergeAction) != SchemaMergeAction.None) //{ // throw new NotImplementedException("SchemaMergeAction.CaseInsensitive is currently not supported."); //} _isTableStandalone = true; _targetDataTable = target; _transform = transform; _geoFactory = geoFactory; _preserveChanges = preserveChanges; _mergeAction = mergeAction; _innerMerger = createInnerMerger(target, preserveChanges, mergeAction); }
/// <summary> /// Initializes a new instance of the <see cref="DefaultSimpleTransform"/> class. /// </summary> /// <param name="sourceCsWkt">The source cs WKT.</param> /// <param name="targetCsWkt">The target cs WKT.</param> internal DefaultSimpleTransform(string sourceCsWkt, string targetCsWkt) { //Check for and replace the WGS84.PseudoMercator WKT string srcWkt = sourceCsWkt == CSMAP_WGS84_PSEUDO_MERCATOR ? POPULAR_VISUALISATION_CRS : sourceCsWkt; string dstWkt = targetCsWkt == CSMAP_WGS84_PSEUDO_MERCATOR ? POPULAR_VISUALISATION_CRS : targetCsWkt; var fact = new CoordinateSystemFactory(); _source = fact.CreateFromWkt(srcWkt); _target = fact.CreateFromWkt(dstWkt); var tfact = new CoordinateTransformationFactory(); _trans = tfact.CreateFromCoordinateSystems(_source, _target); }
public void Load(string fileName, System.Text.Encoding encoding) { try { m_shapeFileData = new SharpMap.Data.Providers.ShapeFile(fileName); m_shapeFileData.Encoding = encoding; m_shapeLayer.CoordinateTransformation = Transform2Mercator(m_shapeFileData.CoordinateSystem); m_googleMapCoordinateTransformation = Transform2Mercator(m_shapeFileData.CoordinateSystem); //m_shapeLayer.DataSource = m_shapeFileData; //if (myMap.Layers.IndexOf(m_shapeLayer) == -1) //{ //myMap.Layers.Add(m_shapeFileLayer); //} } catch (Exception ex) { System.Windows.Forms.MessageBox.Show(ex.Message); } }
private static void AddIfNotNull(ConcatenatedTransform concatTrans, ICoordinateTransformation trans) { if (trans != null) concatTrans.CoordinateTransformationList.Add(trans); }
// gets transform between raster's native projection and the map projection private void GetTransform(ICoordinateSystem mapProjection) { if (mapProjection == null || _projectionWkt == "") { _transform = null; return; } CoordinateSystemFactory cFac = new CoordinateSystemFactory(); // get our two projections ICoordinateSystem srcCoord = cFac.CreateFromWkt(_projectionWkt); ICoordinateSystem tgtCoord = mapProjection; // raster and map are in same projection, no need to transform if (srcCoord.WKT == tgtCoord.WKT) { _transform = null; return; } // create transform _transform = new CoordinateTransformationFactory().CreateFromCoordinateSystems(srcCoord, tgtCoord); }
/// <summary> /// Projects a multi line string. /// </summary> /// <param name="coordinateTransform">The coordinate transformation to use.</param> /// <returns>A projected multi line string.</returns> public override Geometry Project(ICoordinateTransformation coordinateTransform) { if (coordinateTransform==null) { throw new ArgumentNullException("coordinateTransform"); } if (!(coordinateTransform.MathTransform is Geotools.CoordinateTransformations.MapProjection)) { throw new ArgumentException("coordinateTransform must be a MapProjection."); } LineString[] projectedlines = new LineString[_geometries.Length]; IGeometry projectedline; for(int i=0; i<_geometries.Length; i++) { projectedline = _geometries[i].Project(coordinateTransform); projectedlines[i] = (LineString)projectedline; } return _geometryFactory.CreateMultiLineString(projectedlines); }
private static void MetersToDegrees( float x, float y, out float projectedX, out float projectedY, ICoordinateTransformation projection ) { PointF point = new PointF(x, y); PointF projectedPoint = Unproject(point, projection); projectedX = projectedPoint.X; projectedY = projectedPoint.Y; }
public static Envelope UnprojectedExtents( Envelope extents, ICoordinateTransformation projection ) { if ( projection == null ) { throw new ArgumentNullException("projection"); } if ( extents == null ) { return extents; } float[] longitudes = new float[4]; float[] latitudes = new float[4]; MetersToDegrees((float) extents.getMinX(), (float) extents.getMaxY(), out longitudes[0], out latitudes[0], projection); MetersToDegrees((float) extents.getMinX(), (float) extents.getMinY(), out longitudes[1], out latitudes[1], projection); MetersToDegrees((float) extents.getMaxX(), (float) extents.getMaxY(), out longitudes[2], out latitudes[2], projection); MetersToDegrees((float) extents.getMaxX(), (float) extents.getMinY(), out longitudes[3], out latitudes[3], projection); float xMin = longitudes[0]; float yMin = latitudes[0]; float xMax = longitudes[0]; float yMax = latitudes[0]; for ( int i = 0; i < 4; i++ ) { xMin = Math.Min(xMin, longitudes[i]); yMin = Math.Min(yMin, latitudes[i]); xMax = Math.Max(xMax, longitudes[i]); yMax = Math.Max(yMax, latitudes[i]); } return new Envelope(xMin, xMax, yMin, yMax); }
// FIX_PERF private static void setFeatureRowFromIFeatureDataRecord(IFeatureDataRecord srcFeature, FeatureDataRow targetFeature, ColumnMapper columnMapper, ICoordinateTransformation transform, IGeometryFactory geoFactory) { //for (Int32 i = 0; i < srcFeature.FieldCount; i++) //{ // String colName = srcFeature.GetName(i); // targetFeature[colName] = srcFeature.GetValue(i); //} if (transform != null)//jd: to prevent case when transform is null - probably because a test was done earlier. need to check { if (srcFeature.Geometry.SpatialReference.EqualParams(transform.Target)) { transform = null; } } srcFeature.GetValues(columnMapper.SourceValues); targetFeature.ItemArray = columnMapper.Map(); targetFeature.Geometry = transform == null ? srcFeature.Geometry : transform.Transform(srcFeature.Geometry, geoFactory); targetFeature.IsFullyLoaded = targetFeature.IsFullyLoaded || srcFeature.IsFullyLoaded; }
private static void mergeFeature(FeatureDataTable target, IFeatureDataRecord srcFeature, FeatureDataRow targetFeature, ColumnMapper columnMapper, ICoordinateTransformation transform, IGeometryFactory geoFactory, Boolean preserveChanges) { if (targetFeature == null) { targetFeature = target.NewRow(); setFeatureRowFromIFeatureDataRecord(srcFeature, targetFeature, columnMapper, transform, geoFactory); target.AddRow(targetFeature); } else { if (preserveChanges && targetFeature.RowState == DataRowState.Modified) { throw new NotImplementedException("Merging updates to original features " + "state not yet implemented."); } setFeatureRowFromIFeatureDataRecord(srcFeature, targetFeature, columnMapper, transform, geoFactory); } }
// gets transform between raster's native projection and the map projection private void GetTransform(ProjectionInfo mapProjection) { if (mapProjection == null || _projectionWkt == "") { _transform = null; return; } // get our two projections ProjectionInfo srcCoord = new ProjectionInfo(); srcCoord.ReadEsriString(_projectionWkt); ProjectionInfo tgtCoord = mapProjection; // raster and map are in same projection, no need to transform if (srcCoord.Matches(tgtCoord)) { _transform = null; return; } // create transform _transform = new CoordinateTransformation {Source = srcCoord, Target = tgtCoord}; }
public UtfGridController() { this.projection = ProjHelper.LatLonToGoogle(); }
} // public override string ToString() /// <summary> /// Projects each item in a geometry collection. /// </summary> /// <param name="coordinateTransform">The transformation to use.</param> /// <returns>The resulting projected geometry.</returns> public override Geometry Project(ICoordinateTransformation coordinateTransform) { if (coordinateTransform==null) { throw new ArgumentNullException("coordinateTransform"); } if (!(coordinateTransform.MathTransform is Geotools.CoordinateTransformations.MapProjection)) { throw new ArgumentException("CoordinateTransform must be a MapProjection."); } Geometry[] geometryArray = new Geometry[_geometries.Length]; Geometry geometry = null; Geometry projectedGeometry = null; for (int i=0;i<_geometries.Length; i++) { geometry = (Geometry)_geometries.GetValue(i); projectedGeometry = (Geometry)geometry.Project( coordinateTransform ); geometryArray[i] = projectedGeometry; } return _geometryFactory.CreateGeometryCollection(geometryArray); }
/// <summary> /// Releases managed resources /// </summary> protected override void ReleaseManagedResources() { _coordinateTransform = null; _reverseCoordinateTransform = null; _style = null; base.ReleaseManagedResources(); }
/// <summary> /// Creates a projected linear ring. /// </summary> /// <param name="coordinateTransform">The coordinate transformation to use.</param> /// <returns>A projected linear ring.</returns> public override Geometry Project(ICoordinateTransformation coordinateTransform) { if (coordinateTransform==null) { throw new ArgumentNullException("coordinateTransform"); } if (!(coordinateTransform.MathTransform is Geotools.CoordinateTransformations.MapProjection)) { throw new ArgumentException("CoordinateTransform must be a MapProjection."); } int sourceSRID = int.Parse(coordinateTransform.SourceCS.AuthorityCode); int targetSRID = int.Parse(coordinateTransform.TargetCS.AuthorityCode); MapProjection projection = (MapProjection)coordinateTransform.MathTransform; int newSRID = GetNewSRID(coordinateTransform); Coordinates projectedCoordinates = new Coordinates(); double x=0.0; double y=0.0; Coordinate projectedCoordinate; Coordinate external; Coordinate coordinate; for(int i=0; i < _points.Count; i++) { coordinate = _points[i]; external = _geometryFactory.PrecisionModel.ToExternal( coordinate ); if (this._SRID==sourceSRID) { projection.MetersToDegrees(external.X, external.Y, out x, out y); } else if (this._SRID==targetSRID) { projection.DegreesToMeters(external.X, external.Y, out x, out y); } projectedCoordinate = _geometryFactory.PrecisionModel.ToInternal(new Coordinate( x, y) ); projectedCoordinates.Add( projectedCoordinate ); } return new LinearRing( projectedCoordinates, this.PrecisionModel, newSRID); }