public void Bulk_Transform_Enum(System.Windows.Point[][] xy, bool test, bool bProj, TestAttribute ta, object setup, ref double x, ref double y) { Console.WriteLine("--- WARNING --- Bulk_Transform_Enum has been rewritten, name is misleading ---"); int j = random.Next(xy[0].Length); List <Test> _test = new List <Test>(); for (int i = 0; i < xy[0].Length; i++) { _test.Add(new Test { p = xy[0][i] }); } ICoordinateTransformation t = GetTransformation(!bProj); t.Transform <Test>(_test, u => u.p, (u, v) => u.p = v); for (int i = 0; i < ta.PerPoint / xy[0].Length; ++i) { t.Transform(xy[0], xy[1]); x = xy[1][j].X; y = xy[1][j].Y; } }
/// <summary> /// Creates the transformation function that determines the position of a /// source pixel, given the position of a target pixel. /// </summary> /// <param name="targetMapRectangle">The requested target rectangle.</param> /// <param name="targetSize">The requested target size.</param> /// <param name="sourceBoundingBox">The source bounding box corresponding to the target map rectangle..</param> /// <param name="sourceSize">The source size corresponding to the target size.</param> /// <returns>Position of source pixel</returns> protected virtual Func <PointD, PointD> GetTransformFunction(MapRectangle targetMapRectangle, Size targetSize, IBoundingBox sourceBoundingBox, Size sourceSize) { return(target => { // knowing the map rectangle, we can compute the logical coordinate corresponding to the position of the target pixel var pLogicalTarget = new Location( targetMapRectangle.Left + (targetMapRectangle.Right - targetMapRectangle.Left) * (target.X / (targetSize.Width - 1)), targetMapRectangle.Top - (targetMapRectangle.Top - targetMapRectangle.Bottom) * (target.Y / (targetSize.Height - 1)) ); // transform this logical coordinate into the source CRS var pLogicalSource = TargetToSourceTransformation.Transform(pLogicalTarget); // knowing the source bounding box and its configured orientation, we can now // turn the logical source coordinate into the logical offsets (left and top) var sourceOffset = new SizeD( new[] { ContentAlignment.TopLeft, ContentAlignment.BottomLeft }.Contains(SourceMapService.MinAlignment) ? pLogicalSource.X - sourceBoundingBox.MinX : sourceBoundingBox.MaxX - pLogicalSource.X, new[] { ContentAlignment.BottomLeft, ContentAlignment.BottomRight }.Contains(SourceMapService.MinAlignment) ? sourceBoundingBox.MaxY - pLogicalSource.Y : pLogicalSource.Y - sourceBoundingBox.MinY ); // and finally, we an turn the logical offsets into the pixel position return new PointD( sourceSize.Width * sourceOffset.Width / sourceBoundingBox.Size().Width, sourceSize.Height * sourceOffset.Height / sourceBoundingBox.Size().Height ); }); }
public void Single_Transform_Proj_XY(TestAttribute ta, object setup, ref double x, ref double y) { ICoordinateTransformation t = GetTransformation(false); for (int i = 0; i < ta.PerPoint; ++i) { t.Transform(p.X, p.Y, out x, out y); } }
public void TestLineInterception() { var wktReader = new WKTReader(); var ab_4326 = wktReader.Read("LINESTRING(11.4047661 48.1403687,11.4053519 48.141055)") as ILineString; var a_4326 = ab_4326.GetPointN(0); var b_4326 = ab_4326.GetPointN(1); var a = _transformation4326To3395.Transform(a_4326.ToCoordinate2D()); var b = _transformation4326To3395.Transform(b_4326.ToCoordinate2D()); var points = new String[] { "POINT(11.406501117689324 48.14051652560591)", // East "POINT(11.406713245538327 48.14182906667162)", // Northeast "POINT(11.404923416812364 48.14258477213369)", // North "POINT(11.403300759321036 48.14105540093837)", // Northwest "POINT(11.403193249043934 48.140881120346386)", // West "POINT(11.40327279698731 48.13987351306362)", // Southwest "POINT(11.405221721600025 48.1392039845402)", // South "POINT(11.406255844863914 48.13963486923349)" // Southeast }; foreach (var pointWkt in points) { var c_4326 = wktReader.Read(pointWkt) as IPoint; var c = _transformation4326To3395.Transform(c_4326.ToCoordinate2D()); var f = Spatial.Intercept(a, b, c); var p = Spatial.Interpolate(a, b, f); var res = Intercept(a, b, c); var s = Spatial.Distance(p, c); var p_4326 = _transformation3395To4326.Transform(p); var s_esri = this.DistanceEpsg4326(p_4326, c_4326.ToCoordinate2D()); Assert.InRange(f > 1 ? 1 : f < 0 ? 0 : f, res.Item3 - 0.2, res.Item3 + 0.2); Assert.InRange(p.X, res.Item1.X - 50, res.Item1.X + 50); Assert.InRange(p.Y, res.Item1.Y - 50, res.Item1.Y + 50); AssertEquals(s, s_esri, 10E-6); } }
public static RectangleD Transform(this RectangleD @this, ICoordinateTransformation transformation) { double[] pts = new double[8]; pts[0] = @this.Left; pts[1] = @this.Bottom; pts[2] = @this.Right; pts[3] = @this.Bottom; pts[4] = @this.Right; pts[5] = @this.Top; pts[6] = @this.Left; pts[7] = @this.Top; transformation.Transform(pts, 4); return(RectangleD.FromLTRB(Math.Min(pts[0], pts[6]), Math.Min(pts[5], pts[7]), Math.Max(pts[2], pts[4]), Math.Max(pts[1], pts[3]))); }
public void Bulk_Transform_XY(double[][] xy, bool bProj, TestAttribute ta, object setup, ref double x, ref double y) { int j = random.Next(xy[0].Length); ICoordinateTransformation t = GetTransformation(!bProj); for (int i = 0; i < ta.PerPoint / xy[0].Length; ++i) { t.Transform(xy[0], xy[1], xy[2], xy[3]); x = xy[2][j]; y = xy[3][j]; } }
public void Bulk_Transform_Point(System.Windows.Point[][] xy, bool bProj, TestAttribute ta, object setup, ref double x, ref double y) { int j = random.Next(xy[0].Length); ICoordinateTransformation t = GetTransformation(!bProj); for (int i = 0; i < ta.PerPoint / xy[0].Length; ++i) { xy[1] = t.Transform(xy[0]); x = xy[1][j].X; y = xy[1][j].Y; } }
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)); }
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; }
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 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]; } }
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); }
/// <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 RectangleD Transform(this RectangleD @this, ICRS source, ICRS target) { if (source == null || target == null || source.IsEquivalent(target)) { return(@this); } using (ICoordinateTransformation transformation = CoordinateReferenceSystemFactory.Default.CreateCoordinateTrasformation(source, target)) { double[] pts = new double[8]; pts[0] = @this.Left; pts[1] = @this.Bottom; pts[2] = @this.Right; pts[3] = @this.Bottom; pts[4] = @this.Right; pts[5] = @this.Top; pts[6] = @this.Left; pts[7] = @this.Top; transformation.Transform(pts, 4); return(RectangleD.FromLTRB(Math.Min(pts[0], pts[6]), Math.Min(pts[5], pts[7]), Math.Max(pts[2], pts[4]), Math.Max(pts[1], pts[3]))); } }
private void Run(System.Reflection.MethodInfo mi, TestAttribute ta) { proj4Transformation.Transform(new Location()); try { double x = 0, y = 0; object[] args = new object[] { ta, null, x, y }; HiResTimer timer = new HiResTimer(); bool bSucceeded = ta.Enabled; if (bSucceeded) { try { mi.Invoke(this, args); } catch { bSucceeded = false; } } double d = timer.Elapsed; if (ta.Enabled) { Console.WriteLine("{0}: {1} after {2:0}ms ({3:0}ns per point), x={4:0}, y={5:0}", ta.TestName, bSucceeded ? "succeeded" : "FAILED", d, 1000000.0 * d / ta.PerPoint, args[2], args[3]); } } catch (Exception ex) { Console.WriteLine("Test \"" + mi.Name + "\" failed with " + ex.GetType().FullName + ": " + ex.Message); Console.WriteLine(ex.StackTrace.ToString()); } }
static void SimpleTest() { // create some places var places = new Place[] { new Place { Location = new Location(841090, 5006420), Name = "Frankfurt" }, new Place { Location = new Location(1323560, 5230020), Name = "Berlin" } }; // get a transformation for transforming from PTV GeoMinSek to PTV Mercator ICoordinateTransformation t = CoordinateTransformation.Get( CoordinateReferenceSystem.Mapserver.cfGEOMINSEK, CoordinateReferenceSystem.XServer.PTV_MERCATOR ); // transform the places t.Transform <Place>( places, place => place.Location, (place, loc) => place.Location = loc ); double d_Frankfurt_Berlin = CoordinateReferenceSystem.XServer.PTV_MERCATOR.GetHaversineDistance(965820, 6458402, 1489888, 6883432); Console.WriteLine("-- simple test --\n"); // Location l = new Location(1528170, 6623338); // Location m = new Location(33411907, 5656638); // Console.WriteLine("" + m + " == " + l.Transform("cfMERCATOR", "cfUTM")); TestBase.Run(); Console.WriteLine("\n<press return to continue>"); Console.ReadLine(); }
/// <summary> /// Transforms a point into a way point description for xRoute /// </summary> /// <param name="p">Point to create the way point from</param> /// <param name="viaType">Via type to be set, if any</param> /// <returns>Newly created way point</returns> public static WaypointDesc ToWayPoint(this System.Windows.Point p, ViaTypeEnum?viaType = null) { p = Wgs84ToPtvSmartUnitsTransform.Transform(p); var wayPointDesc = new WaypointDesc { linkType = LinkType.AUTO_LINKING, wrappedCoords = new[] { new Point { point = new PlainPoint { x = p.X, y = p.Y } } } }; if (viaType.HasValue) { wayPointDesc.viaType = new ViaType { viaType = viaType.Value } } ; return(wayPointDesc); }
/// <summary> /// Transforms a point into a way point description for xRoute /// </summary> /// <param name="p">Point to create the way point from</param> /// <param name="viaType">Via type to be set, if any</param> /// <returns>Newly created way point</returns> public static Demo.XrouteService.WaypointDesc ToWaypoint(this Point p, Demo.XrouteService.ViaTypeEnum?viaType = null) { p = Wgs84ToPtvSmartUnitsTransform.Transform(p); var waypointDesc = new Demo.XrouteService.WaypointDesc { linkType = Demo.XrouteService.LinkType.AUTO_LINKING, wrappedCoords = new[] { new Demo.XrouteService.Point { point = new Demo.XrouteService.PlainPoint { x = p.X, y = p.Y } } } }; if (viaType.HasValue) { waypointDesc.viaType = new Demo.XrouteService.ViaType { viaType = viaType.Value } } ; return(waypointDesc); }
protected IGeometry TransformGeometry(IGeometry geom) { if (geom.SpatialReference == null && Provider.SpatialReference == null) { return(geom); } if (!Provider.SpatialReference.EqualParams(geom.SpatialReference)) { if (Provider.CoordinateTransformationFactory == null) { throw new MissingCoordinateTransformationFactoryException( "Data requires transformation however no CoordinateTransformationFactory is set"); } ICoordinateTransformation ct = Provider.CoordinateTransformationFactory.CreateFromCoordinateSystems(geom.SpatialReference, Provider. OriginalSpatialReference); return(ct.Transform(geom, Provider.GeometryFactory)); } return(geom); }
static void Main(string[] args) { SimpleTest(); Console.SetWindowSize(120, 60); Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture; string r1 = Registry.GetContent(); string r2 = Registry.GetContent(true); Direct.CoordinateTransformation.Enabled = true; double x = 8, y = 49; CoordinateTransformation.Get("EPSG:4326", "PTV_MERCATOR").Transform(x, y, out x, out y); string wkt = Registry.Get("cfGeoMinSek").WKT; MessageBox.Show(wkt); CoordinateReferenceSystem.Parse("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs +custom=Ptv.Components.Projections.Custom.GeoMinSekTransformation"); Registry.SetContent(r1, true, true); ICoordinateTransformation t = Proj4.CoordinateTransformation.Get("cfGEOMINSEK", "EPSG:76131"); System.Windows.Point p = new System.Windows.Point(959361, 5332563); t.Transform(p); SimpleTest(); ExtendedTest(); }
/// <summary> /// Transforms coordinates from PTV Mercator to WSG84; /// </summary> /// <param name="p">Point to transform</param> /// <returns>Transformed point</returns> public static Point PtvMercatorToWgs84(this Point p) { return(PtvMercatorToWgs84Transform.Transform(p)); }
/// <summary> /// Transforms xRoute WKB coordinates from PTV SmartUnits to WSG84. /// </summary> /// <param name="c">Extension object</param> /// <returns>Transformed point</returns> public static Point PtvSmartUnitsToWgs84(this ICoordinate c) { return(PtvSmartUnitsToWgs84Transform.Transform(new Point(c.X, c.Y))); }
public CartesianSpatialOperationTest() { _reyk_3395 = _transformation4326To3395.Transform(_reyk_4326); _berl_3395 = _transformation4326To3395.Transform(_berl_4326); _mosk_3395 = _transformation4326To3395.Transform(_mosk_4326); }
public static RectangleD Transform(this RectangleD @this, ICoordinateTransformation transformation) { return(transformation.Transform(@this)); }
/// <summary> /// Transforms coordinates from WSG84 to PTV Mercator. /// </summary> /// <param name="p">Point to transform</param> /// <returns>Transformed point</returns> public static System.Windows.Point Wgs84ToPtvMercator(this System.Windows.Point p) { return(Wgs84ToPtvMercatorTransform.Transform(p)); }
/// <summary> /// Transforms coordinates from PTV Mercator to WSG84; /// </summary> /// <param name="p">Point to transform</param> /// <returns>Transformed point</returns> public static System.Windows.Point PtvMercatorToWgs84(this System.Windows.Point p) { return(PtvMercatorToWgs84Transform.Transform(p)); }
// 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; }
/// <summary> /// Transforms coordinates from WSG84 to PTV Mercator. /// </summary> /// <param name="p">Point to transform</param> /// <returns>Transformed point</returns> public static Point Wgs84ToPtvMercator(this Point p) { return(Wgs84ToPtvMercatorTransform.Transform(p)); }
/// <summary> /// Transforms xRoute WKB coordinates from PTV SmartUnits to WSG84. /// </summary> /// <param name="c">Extension object</param> /// <returns>Transformed point</returns> public static System.Windows.Point PtvSmartUnitsToWgs84(this ICoordinate c) { return(PtvSmartUnitsToWgs84Transform.Transform(new System.Windows.Point(c.X, c.Y))); }