/// <summary> /// Creates and initializes an instance of ReprojectionService. /// </summary> /// <param name="sourceMapService">The inner map service that delivers the map images to be re-projected.</param> /// <param name="crs">The CRS to target by this instance.</param> /// <param name="reprojector">The re-projector to be used. Uses the default image re-projector if not explicitly set.</param> /// <param name="reprojectionServiceOptions">Additional options to be used by this map service.</param> public ReprojectionService(MapService sourceMapService, string crs, ImageReprojector reprojector = null, ReprojectionServiceOptions reprojectionServiceOptions = null) { // store parameters SourceMapService = sourceMapService; try { TargetToSourceTransformation = CoordinateTransformation.Get(Crs = crs, sourceMapService.Crs); } catch { throw new ArgumentException("Failed to setup coordinate transformation for source \"" + sourceMapService.Crs + "\" and target \"" + crs + "\""); } Reprojector = reprojector ?? new ImageReprojector(); ReprojectionServiceOptions = reprojectionServiceOptions ?? new ReprojectionServiceOptions(); }
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(); }
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 a bounding box from one CRS to another returning the resulting BoundingLines structure. /// </summary> /// <param name="boundingBox">Bounding box to transform.</param> /// <param name="sourceCrs">The source CRS.</param> /// <param name="targetCrs">The target CRS.</param> /// <param name="nSupportingPoints">Number of supporting points to use.</param> /// <returns>BoundingLines structure that corresponds to the bounding box in the target CRS.</returns> public static BoundingLines TransformBoundingBox(this IBoundingBox boundingBox, string sourceCrs, string targetCrs, int nSupportingPoints) { return(TransformBoundingBox(boundingBox, CoordinateTransformation.Get(sourceCrs, targetCrs), nSupportingPoints)); }
public Location transform(object from, object to, Location p) { return(CoordinateTransformation.Get(from as CoordinateReferenceSystem, to as CoordinateReferenceSystem).Transform(p)); }
private void SetProj4Transform(string spatialReferenceId) { var t = CoordinateTransformation.Get(spatialReferenceId, "PTV_MERCATOR"); transform = p => PtvMercatorToCanvas(t.Transform(p)); }
private static Func <Point, Point> TransformProj4(string sourceSrid, string destSrid) { return(CoordinateTransformation.Get(sourceSrid, destSrid).Transform); }