public static bool Transform(this DMesh3 dMesh, SpatialReference to) { string crs = dMesh.FindMetadata("CRS") as string; if (crs != null && crs != "") { SpatialReference from = new SpatialReference(null); if (crs.Contains("+proj")) { from.ImportFromProj4(crs); } else if (crs.StartsWith("epsg") || crs.StartsWith("EPSG")) { int epsg = int.Parse(crs.Split(':')[1]); from.ImportFromEPSG(epsg); } else { from.ImportFromWkt(ref crs); }; try { CoordinateTransformation trans = new CoordinateTransformation(from, to); for (int i = 0; i < dMesh.VertexCount; i++) { if (dMesh.IsVertex(i)) { Vector3d vertex = dMesh.GetVertex(i); double[] dV = new double[3] { vertex.x, vertex.y, vertex.z }; trans.TransformPoint(dV); AppState.instance.mapTrans.TransformPoint(dV); dMesh.SetVertex(i, new Vector3d(dV)); } } ; return(true); } catch { return(false); } } try { for (int i = 0; i < dMesh.VertexCount; i++) { if (dMesh.IsVertex(i)) { Vector3d vertex = dMesh.GetVertex(i); double[] dV = new double[3] { vertex.x, vertex.y, vertex.z }; AppState.instance.mapTrans.TransformPoint(dV); dMesh.SetVertex(i, new Vector3d(dV)); } } ; return(true); } catch { return(false); } }
public void LatLonToPixel(double lat, double lon, out float col, out float row) { var o = new double[3]; latLonToPixel.TransformPoint(o, lon, lat, 0d); col = (float)((o[0] - AffineTransform[0]) / AffineTransform[1]); row = (float)((o[1] - AffineTransform[3]) / AffineTransform[5]); }
public float PixelToTerrainOffset(int pixelX, int pixelY) { double x = pixelX * _affineTransform[1] + _affineTransform[0]; double y = pixelY * _affineTransform[5] + _affineTransform[3]; var o = new double[3]; _pixelToLineSample.TransformPoint(o, x, y, 0d); double x1 = o[0]; double y1 = o[1]; int line = 30400 / 2 - (int)(y1 / 20d + 0.5d); int sample = 30400 / 2 + (int)(x1 / 20d + 0.5d); return(LineSampleToTerrainOffset(line, sample)); }
/// <summary> /// Convert a netDXF Vector3 in z-up coordinate frame to a Vectir3D in Y-up coordinate frame /// using the optional Coordinate Transform to reproject the point if present /// </summary> /// <param name="v">DXF.Vector3</param> /// <param name="ct">Coordinate transform</param> /// <returns>Vector3d</returns> public static Vector3d ToVector3d(this DXF.Vector3 v, CoordinateTransformation ct = null) { double[] vlocal = new double[3] { v.X, v.Y, v.Z }; if (ct != null) { ct.TransformPoint(vlocal); } return(new Vector3d((float)vlocal[0], (float)vlocal[2], (float)vlocal[1])); }
/// <summary> /// Cibvert vector3D in Y-up coordinate frame to a netDXF Vector3 in z-up coordinate frame /// using the optional CoordinateTranform to reproject the dpoint if present /// </summary> /// <param name="v"> Vector3d</param> /// <param name="transform">Coordinate Transform</param> /// <returns>DXF.Vector3</returns> public static DXF.Vector3 ToDxfVector3(this Vector3d v, CoordinateTransformation transform = null) { double[] vlocal = new double[3] { v.x, v.z, v.y }; if (transform != null) { transform.TransformPoint(vlocal); } return(new DXF.Vector3(vlocal[0], vlocal[1], vlocal[2])); }
public static void CoordTransform(this OSGeo.OSR.SpatialReference srcSR, OSGeo.OSR.SpatialReference destSR, params double[][] inouts) { if (srcSR.IsSame(destSR) <= 0) { using (OSGeo.OSR.CoordinateTransformation coordinateTransformation = new OSGeo.OSR.CoordinateTransformation(srcSR, destSR)) { foreach (var inout in inouts) { coordinateTransformation.TransformPoint(inout); } } } }
public void PixelToLatLon(double pixelX, double pixelY, out double lat, out double lon) { if (pixelToLatLon == null || AffineTransform == null) { throw new Exception(@"No coordinate transform has been provided to go from pixels to lat/lon"); } double x = pixelX * AffineTransform[1] + AffineTransform[0]; double y = pixelY * AffineTransform[5] + AffineTransform[3]; var o = new double[3]; pixelToLatLon.TransformPoint(o, x, y, 0d); lat = o[1]; lon = o[0]; }