[TestCase(3022, 3021, new double[] { 1536875.736, 7037950.238 }, new double[] { 1649079.352, 7041217.283 }, 1E-3)] // tolerance 1 mm public void Reproject_Swedish_Projections_Using_AuthorityCodes(int fromEpsgCode, int toEpsgCode, double[] xy, double[] expected, double tolerance) { var sourceProjection = ProjectionInfo.FromAuthorityCode("EPSG", fromEpsgCode); var targetProjection = ProjectionInfo.FromAuthorityCode("EPSG", toEpsgCode); Reproject.ReprojectPoints(xy, null, sourceProjection, targetProjection, 0, 1); Assert.AreEqual(expected[0], xy[0], tolerance); Assert.AreEqual(expected[1], xy[1], tolerance); }
public void OSGB36_Reprojection() { var sourceProjection = ProjectionInfo.FromAuthorityCode("EPSG", 27700); var targetProjection = ProjectionInfo.FromAuthorityCode("EPSG", 4326); var xy = new double[] { 465000, 170000 }; Reproject.ReprojectPoints(xy, null, sourceProjection, targetProjection, 0, 1); // see http://www.ordnancesurvey.co.uk/gps/transformation const double expectedX = -1.066488; const double expectedY = 51.425291; const double eps = 0.0001; Assert.AreEqual(expectedX, xy[0], eps); Assert.AreEqual(expectedY, xy[1], eps); }
/// <summary> /// Creates a spatial reference object given its Well-known text representation. /// The output object may be either a <see cref="T:GeoAPI.CoordinateSystems.IGeographicCoordinateSystem" /> or /// a <see cref="T:GeoAPI.CoordinateSystems.IProjectedCoordinateSystem" />. /// </summary> /// <param name="wkt">The Well-known text representation for the spatial reference</param> /// <returns>The resulting spatial reference object</returns> public ICoordinateSystem CreateFromWkt(string wkt) { //Hack: DotSpatial.Projections does not handle Authority and AuthorityCode var pos1 = 10 + wkt.LastIndexOf("AUTHORITY[", StringComparison.InvariantCulture); var pos2 = wkt.IndexOf("]", pos1, StringComparison.InvariantCulture) - 1; var parts = wkt.Substring(pos1, pos2 - pos1 + 1).Split(','); var auth = parts[0].Replace("\"", "").Trim(); var code = int.Parse(parts[1].Replace("\"", ""), NumberStyles.Integer, NumberFormatInfo.InvariantInfo); ProjectionInfo pi = null; try { pi = ProjectionInfo.FromEsriString(wkt); } catch (Exception) { try { pi = ProjectionInfo.FromAuthorityCode(auth, code); } catch (Exception) { } } if (pi == null) { return(null); } pi.Authority = auth; pi.AuthorityCode = code; return(new DotSpatialCoordinateSystem(pi)); }
public void TestKnownTileSources() { var serManager = _appManager.SerializationManager; var tmpPath = System.IO.Path.GetTempFileName(); tmpPath = System.IO.Path.ChangeExtension(tmpPath, "dspx"); Console.WriteLine(tmpPath); var map = _appManager.Map; var dict = new Dictionary <KnownTileSource, bool>(); foreach (KnownTileSource kts in Enum.GetValues(typeof(KnownTileSource))) { map.Layers.Clear(); try { var lyr1 = BTL.CreateKnownLayer(kts, GetApiKey(kts)); var lyrT = (BTL)lyr1.Clone(); map.Layers.Add(lyr1); map.Projection = ProjectionInfo.FromAuthorityCode("EPSG", 4326); map.ZoomToMaxExtent(); try { serManager.SaveProject(tmpPath); serManager.OpenProject(tmpPath); if (_appManager.Map.Layers.Count < 1) { throw new Exception("Layer not loaded"); } if (!(_appManager.Map.Layers[0] is BTL)) { throw new Exception("Layer is not BruTileLayer"); } var lyr2 = (BTL)_appManager.Map.Layers[0]; List <string> mismatched; if (lyrT.Matches(lyr2, out mismatched)) { Console.WriteLine("Deserialized '{0}' Mismatches in", kts); foreach (var mis in mismatched) { Console.WriteLine("- {0}", mis); } Console.WriteLine(); dict.Add(kts, false); } else { dict.Add(kts, true); } } catch (Exception) { Console.WriteLine("Deserialized '{0}' failed", kts); dict.Add(kts, false); } } catch (Exception) { Console.WriteLine("Failed to create BruTileLayer for '{0}'", kts); } } System.IO.File.Delete(tmpPath); }