GetScaleDenominator() public method

Gets Scale Denominator for ith matrix
public GetScaleDenominator ( int i ) : double
i int
return double
        private static XmlNode GenerateTileMatrixInfo(WmtsServiceDescription serviceDescription, XmlDocument capabilities, int i)
        {
            XmlNode matrixInfo = capabilities.CreateNode(XmlNodeType.Element, "TileMatrix", wmtsNamespaceURI);

            matrixInfo.AppendChild(createElement("ows:Identifier", serviceDescription.ZoomLevel.Keys.ToList()[i].ToString(), capabilities, false, wmtsNamespaceURI));
            matrixInfo.AppendChild(createElement("ScaleDenominator", serviceDescription.GetScaleDenominator(i).ToString(), capabilities, false, wmtsNamespaceURI));
            matrixInfo.AppendChild(createElement("TopLeftCorner", "-180 90", capabilities, false, wmtsNamespaceURI));
            matrixInfo.AppendChild(createElement("TileWidth", "256", capabilities, false, wmtsNamespaceURI));
            matrixInfo.AppendChild(createElement("TileHeight", "256", capabilities, false, wmtsNamespaceURI));
            matrixInfo.AppendChild(createElement("MatrixWidth", Math.Pow(2, i).ToString(), capabilities, false, wmtsNamespaceURI));
            matrixInfo.AppendChild(createElement("MatrixHeight", Math.Pow(2, i).ToString(), capabilities, false, wmtsNamespaceURI));

            return(matrixInfo);
        }
        private static XmlNode GenerateTileMatrixInfo(WmtsServiceDescription serviceDescription, XmlDocument capabilities, int i)
        {
            XmlNode matrixInfo = capabilities.CreateNode(XmlNodeType.Element, "TileMatrix", wmtsNamespaceURI);

            matrixInfo.AppendChild(createElement("ows:Identifier", serviceDescription.ZoomLevel.Keys.ToList()[i].ToString(), capabilities, false, wmtsNamespaceURI));
            matrixInfo.AppendChild(createElement("ScaleDenominator", serviceDescription.GetScaleDenominator(i).ToString(), capabilities, false, wmtsNamespaceURI));
            matrixInfo.AppendChild(createElement("TopLeftCorner", "-180 90", capabilities, false, wmtsNamespaceURI));
            matrixInfo.AppendChild(createElement("TileWidth", "256", capabilities, false, wmtsNamespaceURI));
            matrixInfo.AppendChild(createElement("TileHeight", "256", capabilities, false, wmtsNamespaceURI));
            matrixInfo.AppendChild(createElement("MatrixWidth", Math.Pow(2, i).ToString(), capabilities, false, wmtsNamespaceURI));
            matrixInfo.AppendChild(createElement("MatrixHeight", Math.Pow(2, i).ToString(), capabilities, false, wmtsNamespaceURI));

            return matrixInfo;
        }
Beispiel #3
0
        /// <summary>
        /// Request GetTile
        /// </summary>
        private void GetTile(NameValueCollection requestParams, Stream responseOutputStream, ref string responseContentType)
        {
            #region Verify the request

            if (requestParams["LAYERS"] == null)
            {
                WmtsException(WmtsExceptionCode.NotApplicable,
                              "Required parameter LAYER not specified.",
                              responseOutputStream,
                              ref responseContentType);
                return;
            }

            if (requestParams["STYLES"] == null)
            {
                WmtsException(WmtsExceptionCode.NotApplicable,
                              "Required parameter STYLE not specified.",
                              responseOutputStream,
                              ref responseContentType);
                return;
            }

            if (requestParams["TILEMATRIXSET"] == null)
            {
                WmtsException(WmtsExceptionCode.NotApplicable,
                              "Required parameter TILEMATRIXSET not specified.",
                              responseOutputStream,
                              ref responseContentType);
                return;
            }

            if (requestParams["TILEMATRIX"] == null)
            {
                WmtsException(WmtsExceptionCode.NotApplicable,
                              "Required parameter TILEMATRIX not specified.",
                              responseOutputStream,
                              ref responseContentType);
                return;
            }

            if (requestParams["TILEROW"] == null)
            {
                WmtsException(WmtsExceptionCode.NotApplicable,
                              "Required parameter TILEROW not specified.",
                              responseOutputStream,
                              ref responseContentType);
                return;
            }

            if (requestParams["TILECOL"] == null)
            {
                WmtsException(WmtsExceptionCode.NotApplicable,
                              "Required parameter TILECOL not specified.",
                              responseOutputStream,
                              ref responseContentType);
                return;
            }

            if (requestParams["FORMAT"] == null)
            {
                WmtsException(WmtsExceptionCode.NotApplicable,
                              "Required parameter FORMAT not specified.",
                              responseOutputStream,
                              ref responseContentType);
                return;
            }

            #endregion

            #region Render Settings

            Color backColor = Color.FromArgb(0, 0, 0, 0);

            if (_map.CosmeticRaster.Visible)
            {
                //Cosmetic layer all broken, this does not allow its use.
                WmtsException(WmtsExceptionCode.NotApplicable,
                              "WMTS  not support this settings rendering.",
                              responseOutputStream,
                              ref responseContentType);
                return;
            }
            //Render for inscriptions.
            var wmsFeatureRender = new WmsFeatureRender(_map.RenderingSettings);

            ImageCodecInfo imageEncoder = getEncoderInfo(requestParams["FORMAT"]);
            if (imageEncoder == null)
            {
                WmtsException(WmtsExceptionCode.NotApplicable,
                              "Wrong mime-type in FORMAT parameter.",
                              responseOutputStream,
                              ref responseContentType);
                return;
            }

            int tileRow = 0;
            int tileCol = 0;

            if (!int.TryParse(requestParams["TILEROW"], out tileRow))
            {
                WmtsException(WmtsExceptionCode.InvalidDimensionValue,
                              "Parameter TILEROW has wrong value.",
                              responseOutputStream,
                              ref responseContentType);
                return;
            }

            if (!int.TryParse(requestParams["TILECOL"], out tileCol))
            {
                WmsException(WmsExceptionCode.InvalidDimensionValue,
                             "Parameter TILECOL has wrong value.",
                             responseOutputStream,
                             ref responseContentType);
                return;
            }

            string tileMatrixName = "EPSG:3857:0";
            if (requestParams["TILEMATRIX"] != null)
            {
                tileMatrixName = requestParams["TILEMATRIX"];
            }



            Tile tile = new Tile(_map, (uint)tileRow, (uint)tileCol);
            tile.ScaleDenominator = _description.GetScaleDenominator(_description.ZoomLevel[tileMatrixName]);
            tile.PixelSize        = _description.GetPixelSize(_description.ZoomLevel[tileMatrixName]);
            tile.ZoomLevel        = (uint)_description.ZoomLevel[tileMatrixName];

            int width = tile.Width, height = tile.Height;

            BoundingRectangle originalBbox = tile.BBox;

            if (originalBbox == null)
            {
                WmtsException(WmtsExceptionCode.NotApplicable,
                              "Wrong Tile parameters.",
                              responseOutputStream,
                              ref responseContentType);
                return;
            }

            #endregion

            //Selected by default.
            bool[] _defaultVisibility      = new bool[_map.Layers.Count()];

            int j = 0;
            foreach (LayerBase layer in _map.Layers)
            {
                _defaultVisibility[j] = layer.Visible;
                layer.Visible         = false; //Turning off all the layers.
                j++;
            }

            lock (_syncRoot)
            {
                LayerBase[] useLayers   = null;
                int[]       indexLayers = null;
                #region Checking layers of inquiry

                if (!string.IsNullOrEmpty(requestParams["LAYER"]))
                {
                    #region Getting layers of inquiry

                    string[] layers = requestParams["LAYER"].Split(new[] { ',' });
                    if (_description.LayerLimit > 0)
                    {
                        if (layers.Length == 0 && _map.Layers.Count > _description.LayerLimit ||
                            layers.Length > _description.LayerLimit)
                        {
                            WmtsException(WmtsExceptionCode.OperationNotSupported,
                                          "The number of layers in the query exceeds the limit of layers in the WMTS.",
                                          responseOutputStream,
                                          ref responseContentType);
                            return;
                        }
                    }

                    #endregion

                    useLayers   = new LayerBase[layers.Length];
                    indexLayers = new int[layers.Length];
                    for (int i = 0; i < layers.Length; i++)
                    {
                        var layer     = layers[i];
                        var findLayer = false;
                        for (int k = 0; k < _map.Layers.Count; k++)
                        {
                            if (string.Equals(_map.Layers[k].Alias, layer,
                                              StringComparison.InvariantCultureIgnoreCase))
                            {
                                useLayers[i]   = _map.Layers[k];
                                indexLayers[i] = k;
                                findLayer      = true;
                                break;
                            }
                        }


                        if (!findLayer)
                        {
                            WmtsException(WmtsExceptionCode.LayerNotDefined,
                                          "Layer \"" + layer + "\" not found.",
                                          responseOutputStream,
                                          ref responseContentType);
                            return;
                        }
                    }

                    Array.Sort(indexLayers, useLayers);
                }

                #endregion

                BoundingRectangle bboxWithGutters = (BoundingRectangle)originalBbox.Clone();
                bboxWithGutters.Grow((double)GutterSize * originalBbox.Width / (double)width);

                try
                {
                    using (Image bmp = GetImage(width, height, backColor, useLayers, bboxWithGutters))
                    {
                        EncoderParameters encoderParams = new EncoderParameters(1);
                        encoderParams.Param[0] = new EncoderParameter(
                            System.Drawing.Imaging.Encoder.Quality, (long)_imageQuality);

                        using (MemoryStream ms = new MemoryStream())
                        {
                            bmp.Save(ms, imageEncoder, encoderParams);
                            byte[] buffer = ms.ToArray();
                            responseContentType = imageEncoder.MimeType;
                            responseOutputStream.Write(buffer, 0, buffer.Length);
                        }
                    }
                }
                catch (Exception except)
                {
                    WmtsException(WmtsExceptionCode.NotApplicable, except.Message, responseOutputStream, ref responseContentType);
                    return;
                }

                for (j = 0; j < _map.Layers.Count(); j++) //Restore it as it was.
                {
                    _map.Layers[j].Visible = _defaultVisibility[j];
                }
            }
        }