Пример #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="point"></param>
        /// <returns></returns>
        public override double[] Transform(double[] point)
        {
            // check whether we were in a knot interpolation
            for (int k = 0; k < _sourceControlPoints.Length; k++)
            {
                if (_sourceControlPoints[k].X == point[0] &&
                    _sourceControlPoints[k].Y == point[1])
                {
                    // hit
                    return(_destinationControlPoints[k].Values());
                }
            }

            ICoordinate source = PlanimetryEnvironment.NewCoordinate(point);
            ICoordinate result =
                PlanimetryEnvironment.NewCoordinate(_optimalAffineTransform.Transform(point));

            double[] distances = new double[_sourceControlPoints.Length];
            double[] w         = new double[_sourceControlPoints.Length];

            // calculation of distances to nodes
            double maxDistance = 0;

            for (int t = 0; t < _sourceControlPoints.Length; t++)
            {
                distances[t] = PlanimetryAlgorithms.Distance(_sourceControlPoints[t], source);
                if (maxDistance < distances[t])
                {
                    maxDistance = distances[t];
                }
            }

            // calculation of the weights of the denominators of nodes
            double sum = 0;

            for (int k = 0; k < _sourceControlPoints.Length; k++)
            {
                double temp = (maxDistance - distances[k]) / (maxDistance * distances[k]);
                sum += Math.Pow(temp, 2);
            }

            // calculation of the weights of nodes
            for (int k = 0; k < _sourceControlPoints.Length; k++)
            {
                double temp = (maxDistance - distances[k]) / (maxDistance * distances[k]);
                w[k] = Math.Pow(temp, 2) / sum;
            }

            for (int k = 0; k < _sourceControlPoints.Length; k++)
            {
                result.X += w[k] * _controlPointsShifts[k].X;
                result.Y += w[k] * _controlPointsShifts[k].Y;
            }

            return(result.Values());
        }
Пример #2
0
        /// <summary>
        /// Request GetFeatureInfo
        /// </summary>
        protected override void GetFeatureInfo(NameValueCollection requestParams, Stream responseOutputStream, ref string responseContentType)
        {
            #region Processing Request GetFeatureInfo

            int featureCount = 1;
            if (requestParams["FEATURE_COUNT"] != null)
            {
                int.TryParse(requestParams["FEATURE_COUNT"], out featureCount);
            }

            int x = 0, y = 0;

            if (requestParams["X"] == null)
            {
                WmsException(WmsExceptionCode.NotApplicable,
                             "Required parameter X undefined.",
                             responseOutputStream,
                             ref responseContentType);
                return;
            }
            else if (!int.TryParse(requestParams["X"], out x))
            {
                WmsException(WmsExceptionCode.NotApplicable,
                             "Parameter X has wrong value.",
                             responseOutputStream,
                             ref responseContentType);
                return;
            }


            if (requestParams["Y"] == null)
            {
                WmsException(WmsExceptionCode.NotApplicable,
                             "Required parameter Y undefined.",
                             responseOutputStream,
                             ref responseContentType);
                return;
            }
            else if (!int.TryParse(requestParams["Y"], out y))
            {
                WmsException(WmsExceptionCode.NotApplicable,
                             "Parameter Y has wrong value.",
                             responseOutputStream,
                             ref responseContentType);
                return;
            }

            int width  = 0;
            int height = 0;
            if (!int.TryParse(requestParams["WIDTH"], out width))
            {
                WmsException(WmsExceptionCode.InvalidDimensionValue,
                             "Parameter WIDTH has wrong value.",
                             responseOutputStream,
                             ref responseContentType);
                return;
            }
            else if (_description.MaxWidth > 0 && width > _description.MaxWidth)
            {
                WmsException(WmsExceptionCode.OperationNotSupported,
                             "Parameter WIDTH is too large.",
                             responseOutputStream,
                             ref responseContentType);
                return;
            }
            if (!int.TryParse(requestParams["HEIGHT"], out height))
            {
                WmsException(WmsExceptionCode.InvalidDimensionValue,
                             "Parameter HEIGHT has wrong value.",
                             responseOutputStream,
                             ref responseContentType);
                return;
            }
            else if (_description.MaxHeight > 0 && height > _description.MaxHeight)
            {
                WmsException(WmsExceptionCode.OperationNotSupported,
                             "Parameter HEIGHT is too large.",
                             responseOutputStream,
                             ref responseContentType);
                return;
            }

            BoundingRectangle bbox = ParseBbox(requestParams["bbox"]);
            if (bbox == null)
            {
                WmsException(WmsExceptionCode.NotApplicable,
                             "Parameter BBOX has wrong value.",
                             responseOutputStream,
                             ref responseContentType);
                return;
            }

            string mimeTypeNeeded = "text/html";
            if (requestParams["INFO_FORMAT"] != null)
            {
                mimeTypeNeeded = requestParams["INFO_FORMAT"];
            }

            List <FeatureLayer> queryableLayers = new List <FeatureLayer>();
            if (!string.IsNullOrEmpty(requestParams["LAYERS"]))
            {
                string[] layers = requestParams["LAYERS"].Split(new[] { ',' });
                foreach (string layer in layers)
                {
                    LayerBase l = null;
                    int       i;
                    for (i = 0; i < _map.Layers.Count; i++)
                    {
                        if (string.Equals(_map.Layers[i].Alias, layer,
                                          StringComparison.InvariantCultureIgnoreCase))
                        {
                            l = _map.Layers[i];
                        }
                    }


                    if (l == null)
                    {
                        WmsException(WmsExceptionCode.LayerNotDefined,
                                     "Layer \"" + layer + "\" not found.",
                                     responseOutputStream,
                                     ref responseContentType);
                        return;
                    }
                    else if (!(l is FeatureLayer) || !((FeatureLayer)l).FeaturesSelectable)
                    {
                        WmsException(WmsExceptionCode.LayerNotQueryable,
                                     "Layer \"" + layer + "\" is not queryable.",
                                     responseOutputStream,
                                     ref responseContentType);
                        return;
                    }
                    else
                    {
                        queryableLayers.Add((FeatureLayer)l);
                    }
                }

                queryableLayers.Sort(
                    (FeatureLayer l1, FeatureLayer l2) =>
                    _map.Layers.IndexOf(l1) > _map.Layers.IndexOf(l2) ? -1 : 1);

                List <Feature> selectedFeatures = new List <Feature>();

                if (queryableLayers.Count > 0)
                {
                    lock (_syncRoot)
                    {
                        // calculate the error of selection of point and line objects
                        _map.SelectionPointRadius =
                            _selectionMargin * bbox.Width / width;

                        double resultX = bbox.Width / width * x + bbox.MinX;
                        double resultY = bbox.MaxY - bbox.Height / height * y;

                        ICoordinate point = PlanimetryEnvironment.NewCoordinate(resultX, resultY);

                        ICoordinate tempPoint = PlanimetryEnvironment.NewCoordinate(x, y);
                        if (_map.OnTheFlyTransform != null)
                        {
                            ICoordinate delta =
                                PlanimetryEnvironment.NewCoordinate(tempPoint.X + _map.SelectionPointRadius,
                                                                    tempPoint.Y);
                            IMathTransform inverseTransform = _map.OnTheFlyTransform.Inverse();

                            delta =
                                PlanimetryEnvironment.NewCoordinate(inverseTransform.Transform(delta.Values()));

                            _map.SelectionPointRadius =
                                PlanimetryAlgorithms.Distance(
                                    PlanimetryEnvironment.NewCoordinate(
                                        inverseTransform.Transform(tempPoint.Values())), delta);
                        }
                        if (queryableLayers[0].Map.OnTheFlyTransform != null)
                        {
                            IMathTransform inverseTransform = queryableLayers[0].Map.OnTheFlyTransform.Inverse();
                            point =
                                PlanimetryEnvironment.NewCoordinate(inverseTransform.Transform(point.Values()));
                        }

                        foreach (LayerBase l in queryableLayers)
                        {
                            FeatureLayer fl = l as FeatureLayer;
                            if (fl != null)
                            {
                                Feature feature = null;
                                fl.SelectObject(point, out feature);
                                if (feature != null)
                                {
                                    selectedFeatures.Add(feature);
                                }

                                if (selectedFeatures.Count == featureCount)
                                {
                                    break;
                                }
                            }
                        }
                    }
                }


                WmsFeaturesInfoNeededEventArgs args = new WmsFeaturesInfoNeededEventArgs(selectedFeatures,
                                                                                         mimeTypeNeeded,
                                                                                         responseOutputStream,
                                                                                         responseContentType);
                OnFeaturesInfoNeeded(args);
                responseContentType = args.ResponseContentType;

                return;
            }

            StringBuilder sb = new StringBuilder();
            sb.Append("none");

            byte[] bytes = Encoding.UTF8.GetBytes(sb.ToString().ToCharArray());
            responseOutputStream.Write(bytes, 0, bytes.Length);
            responseContentType = "text/html";

            #endregion
        }
Пример #3
0
        private ICoordinate PrepareForSelect(Point position)
        {
            //BoundingRectangle mapCoordsViewBox = _map.MapViewBoxFromPresentationViewBox(_viewBox);

            double x = _viewBox.Width / ActualWidth * position.X + _viewBox.MinX;
            double y = _viewBox.MaxY - _viewBox.Height / ActualHeight * position.Y;

            // Caculate the error of selecting the point and line objects
            _map.SelectionPointRadius = _selectionMargin * _viewBox.Width / ActualWidth;

            ICoordinate result = PlanimetryEnvironment.NewCoordinate(x, y);

            if (_map.OnTheFlyTransform != null)
            {
                ICoordinate    delta            = PlanimetryEnvironment.NewCoordinate(result.X + _map.SelectionPointRadius, result.Y);
                IMathTransform inverseTransform = _map.OnTheFlyTransform.Inverse();

                delta = PlanimetryEnvironment.NewCoordinate(inverseTransform.Transform(delta.Values()));

                _map.SelectionPointRadius =
                    PlanimetryAlgorithms.Distance(PlanimetryEnvironment.NewCoordinate(inverseTransform.Transform(result.Values())), delta);
            }

            return(result);
        }
Пример #4
0
        /// <summary>
        ///GetFeatureInfo request
        /// </summary>
        protected override void GetFeatureInfo(NameValueCollection requestParams, Stream responseOutputStream, ref string responseContentType)
        {
            #region Request processing GetFeatureInfo

            int x = 0, y = 0, featureCount = 1;
            int row, column;

            if (requestParams["FEATURE_COUNT"] != null)
            {
                int.TryParse(requestParams["FEATURE_COUNT"], out featureCount);
            }

            if (requestParams["I"] == null)
            {
                WmtsException(WmtsExceptionCode.NotApplicable,
                              "Required parameter I undefined.",
                              responseOutputStream,
                              ref responseContentType);
                return;
            }
            else if (!int.TryParse(requestParams["I"], out x))
            {
                WmtsException(WmtsExceptionCode.NotApplicable,
                              "Parameter I has wrong value.",
                              responseOutputStream,
                              ref responseContentType);
                return;
            }

            if (requestParams["J"] == null)
            {
                WmtsException(WmtsExceptionCode.NotApplicable,
                              "Required parameter J undefined.",
                              responseOutputStream,
                              ref responseContentType);
                return;
            }
            else if (!int.TryParse(requestParams["J"], out y))
            {
                WmtsException(WmtsExceptionCode.NotApplicable,
                              "Parameter J has wrong value.",
                              responseOutputStream,
                              ref responseContentType);
                return;
            }

            if (requestParams["TILEROW"] == null)
            {
                WmtsException(WmtsExceptionCode.NotApplicable,
                              "Required parameter TILEROW undefined.",
                              responseOutputStream,
                              ref responseContentType);
                return;
            }
            else if (!int.TryParse(requestParams["TILEROW"], out row))
            {
                WmtsException(WmtsExceptionCode.NotApplicable,
                              "Parameter TILEROW has wrong value.",
                              responseOutputStream,
                              ref responseContentType);
                return;
            }

            if (requestParams["TILECOL"] == null)
            {
                WmtsException(WmtsExceptionCode.NotApplicable,
                              "Required parameter TILECOL undefined.",
                              responseOutputStream,
                              ref responseContentType);
                return;
            }
            else if (!int.TryParse(requestParams["TILECOL"], out column))
            {
                WmtsException(WmtsExceptionCode.NotApplicable,
                              "Parameter TILECOL has wrong value.",
                              responseOutputStream,
                              ref responseContentType);
                return;
            }

            string mimeTypeNeeded = "text/html";
            if (requestParams["INFO_FORMAT"] != null)
            {
                mimeTypeNeeded = requestParams["INFO_FORMAT"];
            }

            Tile tile             = new Tile(_map, (uint)row, (uint)column);
            //_description.Tile = tile; //
            //tile.PixelSize = _description.GetScaleDenominator(_description.ZoomLevel[tileMatrixName]); //
            //tile.ScaleDenominator = _description.GetPixelSize(_description.ZoomLevel[tileMatrixName]); //
            BoundingRectangle bbox = tile.BBox;
            int width = tile.Width, height = tile.Height;

            List <FeatureLayer> queryableLayers = new List <FeatureLayer>();
            if (!string.IsNullOrEmpty(requestParams["LAYER"]))
            {
                string[] layers = requestParams["LAYER"].Split(new[] { ',' });
                foreach (string layer in layers)
                {
                    LayerBase l = null;
                    int       i;
                    for (i = 0; i < _map.Layers.Count; i++)
                    {
                        if (string.Equals(_map.Layers[i].Alias, layer,
                                          StringComparison.InvariantCultureIgnoreCase))
                        {
                            l = _map.Layers[i];
                        }
                    }


                    if (l == null)
                    {
                        WmtsException(WmtsExceptionCode.LayerNotDefined,
                                      "Layer \"" + layer + "\" not found.",
                                      responseOutputStream,
                                      ref responseContentType);
                        return;
                    }
                    else if (!(l is FeatureLayer) || !((FeatureLayer)l).FeaturesSelectable)
                    {
                        WmtsException(WmtsExceptionCode.LayerNotQueryable,
                                      "Layer \"" + layer + "\" is not queryable.",
                                      responseOutputStream,
                                      ref responseContentType);
                        return;
                    }
                    else
                    {
                        queryableLayers.Add((FeatureLayer)l);
                    }
                }

                queryableLayers.Sort(
                    (FeatureLayer l1, FeatureLayer l2) =>
                    _map.Layers.IndexOf(l1) > _map.Layers.IndexOf(l2) ? -1 : 1);

                List <Feature> selectedFeatures = new List <Feature>();

                if (queryableLayers.Count > 0)
                {
                    lock (_syncRoot)
                    {
                        // calculate the error of selection of point and line objects
                        _map.SelectionPointRadius =
                            _selectionMargin * bbox.Width / width;

                        double resultX = bbox.Width / width * x + bbox.MinX;
                        double resultY = bbox.MaxY - bbox.Height / height * y;

                        ICoordinate point = PlanimetryEnvironment.NewCoordinate(resultX, resultY);

                        ICoordinate tempPoint = PlanimetryEnvironment.NewCoordinate(x, y);

                        if (_map.OnTheFlyTransform != null)
                        {
                            ICoordinate delta =
                                PlanimetryEnvironment.NewCoordinate(tempPoint.X + _map.SelectionPointRadius,
                                                                    tempPoint.Y);
                            IMathTransform inverseTransform = _map.OnTheFlyTransform.Inverse();

                            delta =
                                PlanimetryEnvironment.NewCoordinate(inverseTransform.Transform(delta.Values()));

                            _map.SelectionPointRadius =
                                PlanimetryAlgorithms.Distance(
                                    PlanimetryEnvironment.NewCoordinate(
                                        inverseTransform.Transform(tempPoint.Values())), delta);
                        }

                        if (queryableLayers[0].Map.OnTheFlyTransform != null)
                        {
                            IMathTransform inverseTransform = queryableLayers[0].Map.OnTheFlyTransform.Inverse();
                            point =
                                PlanimetryEnvironment.NewCoordinate(inverseTransform.Transform(point.Values()));
                        }

                        foreach (LayerBase l in queryableLayers)
                        {
                            FeatureLayer fl = l as FeatureLayer;
                            if (fl != null)
                            {
                                Feature feature = null;
                                fl.SelectObject(point, out feature);
                                if (feature != null)
                                {
                                    selectedFeatures.Add(feature);
                                }

                                if (selectedFeatures.Count == featureCount)
                                {
                                    break;
                                }
                            }
                        }
                    }
                }

                WmsFeaturesInfoNeededEventArgs args = new WmsFeaturesInfoNeededEventArgs(selectedFeatures,
                                                                                         mimeTypeNeeded,
                                                                                         responseOutputStream,
                                                                                         responseContentType);
                OnFeaturesInfoNeeded(args);
                responseContentType = args.ResponseContentType;

                return;
            }

            StringBuilder sb = new StringBuilder();
            sb.Append("none");

            byte[] bytes = Encoding.UTF8.GetBytes(sb.ToString().ToCharArray());
            responseOutputStream.Write(bytes, 0, bytes.Length);
            responseContentType = "text/html";

            #endregion
        }