Esempio n. 1
0
        private static Extent ToExtent(TileMatrixSet tileMatrixSet, WmtsTileSchema tileSchema, int[] ordinateOrder)
        {
            var boundingBox = tileMatrixSet.Item;

            if (boundingBox != null)
            {
                // the BoundingBox element should always be in the same CRS as the SupportedCRS, we make a check anyway
                if (string.IsNullOrEmpty(boundingBox.crs) || boundingBox.crs == tileMatrixSet.SupportedCRS)
                {
                    var lowerCorner = boundingBox.LowerCorner;
                    var upperCorner = boundingBox.UpperCorner;

                    var lowerCornerDimensions = GetDimensions(lowerCorner);
                    var upperCornerDimensions = GetDimensions(upperCorner);

                    var xi = ordinateOrder[0];
                    var yi = ordinateOrder[1];

                    return(new Extent(
                               lowerCornerDimensions[xi],
                               lowerCornerDimensions[yi],
                               upperCornerDimensions[xi],
                               upperCornerDimensions[yi]));
                }
            }

            // Compute the extent of the tile schema
            var resolution = tileSchema.Resolutions.Last();

            return(ToExtent(resolution.Value));
        }
Esempio n. 2
0
        private static List <ITileSchema> GetTileMatrixSets(IEnumerable <TileMatrixSet> tileMatrixSets)
        {
            var tileSchemas = new List <ITileSchema>();

            foreach (var tileMatrixSet in tileMatrixSets)
            {
                var tileSchema = new WmtsTileSchema();
                foreach (var tileMatrix in tileMatrixSet.TileMatrix)
                {
                    tileSchema.Resolutions.Add(ToResolution(tileMatrix));
                }

                // Extent should be determined by the WGS84BoundingBox of the layer but
                // this would involve projection.
                // also the Extent should move to the tileSource because it could differ
                // between layers.
                tileSchema.Extent = ToExtent(tileSchema.Resolutions.First().Value);

                tileSchema.Name = tileMatrixSet.Identifier.Value;
                tileSchema.Axis = AxisDirection.InvertedY;
                tileSchema.Srs  = tileMatrixSet.SupportedCRS;
                tileSchemas.Add(tileSchema);
            }
            return(tileSchemas);
        }
Esempio n. 3
0
        /// <summary>
        /// Creates a copy of this schema with <see cref="Format"/> set to <paramref name="format"/>
        /// </summary>
        /// <param name="title">The layer title</param>
        /// <param name="layer">The layer identifier</param>
        /// <param name="abstract">A description for the layers content</param>
        /// <param name="tileMatrixSet">The TileMatrixSet identifier</param>
        /// <param name="style">The style identifier</param>
        /// <param name="format">The format used for this style</param>
        /// <returns>A tile schema</returns>
        internal WmtsTileSchema CreateSpecific(string title, string layer, string @abstract, string tileMatrixSet, string style, string format)
        {
            if (string.IsNullOrEmpty(layer))
            {
                throw new ArgumentNullException("layer");
            }
            if (string.IsNullOrEmpty(tileMatrixSet))
            {
                throw new ArgumentNullException("tileMatrixSet");
            }
            if (string.IsNullOrEmpty(format))
            {
                throw new ArgumentNullException("format");
            }

            if (@abstract == null)
            {
                @abstract = string.Empty;
            }
            if (string.IsNullOrEmpty(style))
            {
                style = "null";
            }

            if (!format.StartsWith("image/"))
            {
                throw new ArgumentException("Not an image mime type");
            }

            var res = new WmtsTileSchema
            {
                YAxis         = YAxis,
                Extent        = new Extent(Extent.MinX, Extent.MinY, Extent.MaxX, Extent.MaxY),
                Title         = title,
                Layer         = layer,
                Abstract      = @abstract,
                TileMatrixSet = tileMatrixSet,
                Style         = style,
                Format        = format,
                Name          = Name,
                Srs           = Srs,
                SupportedSRS  = SupportedSRS
            };

            foreach (var resolution in Resolutions)
            {
                res.Resolutions.Add(resolution);
            }

            return(res);
        }
Esempio n. 4
0
        /// <summary>
        /// Creates a copy of this schema with <see cref="Format"/> set to <paramref name="format"/>
        /// </summary>
        /// <param name="abstract">A description for the layers content</param>
        /// <param name="style">The style identifier</param>
        /// <param name="format">The format used for this style</param>
        /// <param name="identifier">The layer identifier</param>
        /// <returns>A tile schema</returns>
        internal WmtsTileSchema CreateSpecific(string identifier, string @abstract, string style, string format)
        {
            if (string.IsNullOrEmpty(identifier))
            {
                throw new ArgumentNullException("identifier");
            }
            if (string.IsNullOrEmpty(format))
            {
                throw new ArgumentNullException("format");
            }

            if (@abstract == null)
            {
                @abstract = string.Empty;
            }
            if (string.IsNullOrEmpty(style))
            {
                style = "null";
            }

            if (!format.StartsWith("image/"))
            {
                throw new ArgumentException("Not an image mime type");
            }

            var res = new WmtsTileSchema();

            res.YAxis      = YAxis;
            res.Extent     = new Extent(Extent.MinX, Extent.MinY, Extent.MaxX, Extent.MaxY);
            res.Name       = identifier;
            res.Abstract   = @abstract;
            res.Style      = style;
            res.Format     = format;
            res.Identifier = identifier;
            res.Name       = Name;
            foreach (var resolution in Resolutions)
            {
                res.Resolutions.Add(resolution);
            }
            res.Srs          = Srs;
            res.SupportedSRS = SupportedSRS;
            return(res);
        }
Esempio n. 5
0
        /// <summary>
        /// Creates a copy of this schema with <see cref="Format"/> set to <paramref name="format"/>
        /// </summary>
        /// <param name="title">The layer title</param>
        /// <param name="layer">The layer identifier</param>
        /// <param name="abstract">A description for the layers content</param>
        /// <param name="tileMatrixSet">The TileMatrixSet identifier</param>
        /// <param name="style">The style identifier</param>
        /// <param name="format">The format used for this style</param>
        /// <returns>A tile schema</returns>
        internal WmtsTileSchema CreateSpecific(string title, string layer, string @abstract, string tileMatrixSet, string style, string format)
        {
            if (string.IsNullOrEmpty(layer))
                throw new ArgumentNullException("layer");
            if (string.IsNullOrEmpty(tileMatrixSet))
                throw new ArgumentNullException("tileMatrixSet");
            if (string.IsNullOrEmpty(format))
                throw new ArgumentNullException("format");

            if (@abstract == null) @abstract = string.Empty;
            if (string.IsNullOrEmpty(style)) style = "null";

            if (!format.StartsWith("image/"))
                throw new ArgumentException("Not an image mime type");

            var res = new WmtsTileSchema
            {
                YAxis = YAxis,
                Extent = new Extent(Extent.MinX, Extent.MinY, Extent.MaxX, Extent.MaxY),
                Title = title,
                Layer = layer,
                Abstract = @abstract,
                TileMatrixSet = tileMatrixSet,
                Style = style,
                Format = format,
                Name = Name,
                Srs = Srs,
                SupportedSRS = SupportedSRS
            };

            foreach (var resolution in Resolutions) res.Resolutions.Add(resolution);

            return res;
        }
Esempio n. 6
0
        private static Extent ToExtent(TileMatrixSet tileMatrixSet, WmtsTileSchema tileSchema, int[] ordinateOrder)
        {
            var boundingBox = tileMatrixSet.Item;
            if (boundingBox != null)
            {
                // the BoundingBox element should always be in the same CRS as the SupportedCRS, we make a check anyway
                if (string.IsNullOrEmpty(boundingBox.crs) || boundingBox.crs == tileMatrixSet.SupportedCRS)
                {
                    var lowerCorner = boundingBox.LowerCorner;
                    var upperCorner = boundingBox.UpperCorner;

                    var lowerCornerDimensions = GetDimensions(lowerCorner);
                    var upperCornerDimensions = GetDimensions(upperCorner);

                    var xi = ordinateOrder[0];
                    var yi = ordinateOrder[1];

                    return new Extent(
                        lowerCornerDimensions[xi],
                        lowerCornerDimensions[yi],
                        upperCornerDimensions[xi],
                        upperCornerDimensions[yi]);
                }
            }

            // Compute the extent of the tile schema
            var resolution = tileSchema.Resolutions.Last();
            return ToExtent(resolution.Value);
        }
Esempio n. 7
0
        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;
        }
Esempio n. 8
0
        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);
        }
        /// <summary>
        /// Creates a copy of this schema with <see cref="Format"/> set to <paramref name="format"/>
        /// </summary>
        /// <param name="abstract">A description for the layers content</param>
        /// <param name="style">The style identifier</param>
        /// <param name="format">The format used for this style</param>
        /// <param name="identifier">The layer identifier</param>
        /// <returns>A tile schema</returns>
        internal WmtsTileSchema CreateSpecific(string identifier, string @abstract, string style, string format)
        {
            if (string.IsNullOrEmpty(identifier))
                throw new ArgumentNullException("identifier");
            if (string.IsNullOrEmpty(format))
                throw new ArgumentNullException("format");

            if (@abstract == null) @abstract = string.Empty;
            if (string.IsNullOrEmpty(style)) style = "null";

            if (!format.StartsWith("image/"))
                throw new ArgumentException("Not an image mime type");

            var res = new WmtsTileSchema();
            res.YAxis = YAxis;
            res.Extent = new Extent(Extent.MinX, Extent.MinY, Extent.MaxX, Extent.MaxY);
            res.Name = identifier;
            res.Abstract = @abstract;
            res.Style = style;
            res.Format = format;
            res.Identifier = identifier;
            res.Name = Name;
            foreach (var resolution in Resolutions)
                res.Resolutions.Add(resolution);
            res.Srs = Srs;
            res.SupportedSRS = SupportedSRS;
            return res;
        }