private static int[] GetOrdinateOrder(BoundingBoxAxisOrderInterpretation bbaoi, int[] ordinateOrder) { switch (bbaoi) { case BoundingBoxAxisOrderInterpretation.Natural: return(new[] { 0, 1 }); case BoundingBoxAxisOrderInterpretation.Geographic: return(new[] { 1, 0 }); default: return(ordinateOrder); } }
/// <summary> /// Method to parse WMTS tile sources from a stream /// </summary> /// <param name="source">The source stream</param> /// <param name="bbaoi">The way how axis order should be interpreted for <ows:BoundingBox>es</param> /// <returns>An enumeration of tile sources</returns> public static IEnumerable <ITileSource> Parse(Stream source, BoundingBoxAxisOrderInterpretation bbaoi = BoundingBoxAxisOrderInterpretation.Natural) { var ser = new XmlSerializer(typeof(Capabilities)); Capabilities capabilties; using (var reader = new StreamReader(source)) capabilties = (Capabilities)ser.Deserialize(reader); var tileSchemas = GetTileMatrixSets(capabilties.Contents.TileMatrixSet, bbaoi); var tileSources = GetLayers(capabilties, tileSchemas); return(tileSources); }
private static List <ITileSchema> GetTileMatrixSets(IEnumerable <TileMatrixSet> tileMatrixSets, BoundingBoxAxisOrderInterpretation bbaoi) { // 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, GetOrdinateOrder(bbaoi, 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); }