public void TestUnitDefinitions() { var uomr = new CrsUnitOfMeasureRegistry(); Assert.That(uomr[9001].ToMeter, Is.EqualTo(1)); Assert.That(uomr[1025].ToMeter, Is.EqualTo(0.001)); Assert.That(uomr[1033].ToMeter, Is.EqualTo(0.01)); Assert.That(Math.Abs(360 * uomr[9102].ToMeter - EarthCircumference), Is.LessThanOrEqualTo(1e-7)); }
public void TestEpsgCodeUom() { if (!File.Exists(EpsgAccessDatabase)) { throw new IgnoreException("Epsg Access Database not found"); } var connectionString = $"Provider=Microsoft.Jet.OLEDB.4.0; Data Source={EpsgAccessDatabase};"; using (var connection = new System.Data.OleDb.OleDbConnection(connectionString)) { connection.Open(); var cmd = connection.CreateCommand(); cmd.CommandText = SqlEpsgToUom; var uomr = new CrsUnitOfMeasureRegistry(); using (var dr = cmd.ExecuteReader()) { if (dr != null) { while (dr.Read()) { if ((int)dr[0] > 32768) { break; } CrsIdentifier crs; if (CrsIdentifier.TryParse(string.Format("urn:ogc:def:crs:EPSG::{0}", dr.GetInt32(0)), out crs)) { var uom = new UnitOfMeasure(); Assert.DoesNotThrow(() => uom = uomr[crs], "Getting unit of measure failed for {0}", crs); var uomCode = dr.GetInt32(1); if (uomCode == 9001 || uomCode == 1024) { Assert.AreEqual(1d, uom.ToMeter, "Unit of measure ToMeter is not 1d: {0}", crs); } else { Assert.AreNotEqual(1d, uom.ToMeter, "Unit of measure ToMeter should not be 1d: {0}", crs); } } } } } } }
private static List<ITileSchema> GetTileMatrixSets(IEnumerable<TileMatrixSet> tileMatrixSets) { // Get a set of well known scale sets. For these we don't need to have var wkss = new WellKnownScaleSets(); // Axis order registry var crsAxisOrder = new CrsAxisOrderRegistry(); // Unit of measure registry var crsUnitOfMeasure = new CrsUnitOfMeasureRegistry(); var tileSchemas = new List<ITileSchema>(); foreach (var tileMatrixSet in tileMatrixSets) { // Check if a Well-Known scale set is used, either by Identifier or WellKnownScaleSet property var ss = wkss[tileMatrixSet.Identifier.Value]; if (ss == null && !string.IsNullOrEmpty(tileMatrixSet.WellKnownScaleSet)) ss = wkss[tileMatrixSet.WellKnownScaleSet.Split(':').Last()]; // Try to parse the Crs var supportedCrs = tileMatrixSet.SupportedCRS; // Hack to fix broken crs spec supportedCrs = supportedCrs.Replace("6.18:3", "6.18.3"); CrsIdentifier crs; if (!CrsIdentifier.TryParse(supportedCrs, out crs)) { // If we cannot parse the crs, we cannot compute tile schema, thus ignore. // ToDo: Log this continue; } // Get the ordinate order for the crs (x, y) or (y, x) aka (lat, long) var ordinateOrder = crsAxisOrder[crs]; // Get the unit of measure for the crs var unitOfMeasure = crsUnitOfMeasure[crs]; // Create a new WMTS tile schema var tileSchema = new WmtsTileSchema(); // Add the resolutions foreach (var tileMatrix in tileMatrixSet.TileMatrix) { tileSchema.Resolutions.Add(ToResolution(tileMatrix, ordinateOrder, unitOfMeasure.ToMeter, ss)); } tileSchema.Extent = ToExtent(tileMatrixSet, tileSchema, ordinateOrder); // Fill in the remaining properties tileSchema.Name = tileMatrixSet.Identifier.Value; tileSchema.YAxis = YAxis.OSM; tileSchema.Srs = supportedCrs; tileSchema.SupportedSRS = crs; // record the tile schema tileSchemas.Add(tileSchema); } return tileSchemas; }
public void TestUnitDefinitions() { var uomr = new CrsUnitOfMeasureRegistry(); Assert.That(uomr[9001].ToMeter, Is.EqualTo(1)); Assert.That(uomr[1025].ToMeter, Is.EqualTo(0.001)); Assert.That(uomr[1033].ToMeter, Is.EqualTo(0.01)); Assert.That(Math.Abs(360 * uomr[9102].ToMeter - EarthCircumference), Is.LessThanOrEqualTo(1e-7)); }
public void TestEpsgCodeUom() { if (!File.Exists(EpsgAccessDatabase)) throw new IgnoreException("Epsg Access Database not found"); using (var cn = new System.Data.OleDb.OleDbConnection( string.Format("Provider=Microsoft.Jet.OLEDB.4.0; Data Source={0};", EpsgAccessDatabase))) { cn.Open(); var cmd = cn.CreateCommand(); cmd.CommandText = SqlEpsgToUom; var uomr = new CrsUnitOfMeasureRegistry(); using (var dr = cmd.ExecuteReader()) { if (dr != null) while (dr.Read()) { if ((int)dr[0] > 32768) break; CrsIdentifier crs; if (CrsIdentifier.TryParse(string.Format("urn:ogc:def:crs:EPSG::{0}", dr.GetInt32(0)), out crs)) { var uom = new UnitOfMeasure(); Assert.DoesNotThrow(() => uom = uomr[crs], "Getting unit of measure failed for {0}", crs); var uomCode = dr.GetInt32(1); if (uomCode == 9001 || uomCode == 1024) Assert.AreEqual(1d, uom.ToMeter, "Unit of measure ToMeter is not 1d: {0}", crs); else Assert.AreNotEqual(1d, uom.ToMeter, "Unit of measure ToMeter should not be 1d: {0}", crs); } } } } }