Example #1
0
 /// <summary>
 /// Create a cropped bounding box.
 /// </summary>
 /// <returns>The crop info.</returns>
 /// <param name="boundingBoxType">The type of the bounding box to be cropped.</param>
 /// <param name="crop">Crop.</param>
 /// <param name="adjustedScale">Adjusted scale.</param>
 public AGSCropInfo Crop(BoundingBoxType boundingBoxType, ICropSelfComponent crop, PointF adjustedScale)
 {
     if (crop == null)
     {
         return(new AGSCropInfo(this, null, CropFrom.None));
     }
     return(crop.Crop(ref this, boundingBoxType, adjustedScale));
 }
        public override byte[] GetTile(Capabilities capabilities, string path, GetTile getTile)
        {
            byte[] buffer = null;
            if (capabilities == null || string.IsNullOrWhiteSpace(path) || getTile == null)
            {
                return(buffer);
            }
            IMapLayer mapLayer = DataHelper.GetMapLayer(path);

            if (mapLayer != null)
            {
                LayerType layerType = capabilities.Contents?.DatasetDescriptionSummary?.FirstOrDefault(x => x.Identifier?.Value == getTile.Layer && x is LayerType) as LayerType;
                if (layerType != null)
                {
                    BoundingBoxType boundingBoxType       = layerType.BoundingBox?.Length > 0 ? layerType.BoundingBox[0] : layerType.WGS84BoundingBox?.Length > 0 ? layerType.WGS84BoundingBox[0] : null;
                    string          layerTileMatrixSetStr = layerType.TileMatrixSetLink[0].TileMatrixSet;
                    TileMatrixSet   layerTileMatrixSet    = capabilities.Contents.TileMatrixSet?.FirstOrDefault(x => x.Identifier?.Value == layerTileMatrixSetStr);
                    TileMatrix      layerTileMatrix       = layerTileMatrixSet.TileMatrix?.FirstOrDefault(x => x.Identifier.Value == getTile.TileMatrix);

                    if (layerTileMatrix != null)
                    {
                        bool ret = WmtsHelper.ComputeTileBoundary(layerType, layerTileMatrix, getTile.TileCol, getTile.TileRow, out double tileXMin, out double tileYMin, out double tileXMax, out double tileYMax);
                        if (ret)
                        {
                            Extent    extent     = new Extent(tileXMin, tileYMin, tileXMax, tileYMax);
                            int       tileWidth  = Convert.ToInt32(layerTileMatrix.TileWidth);
                            int       tileHeight = Convert.ToInt32(layerTileMatrix.TileHeight);
                            Rectangle rectangle  = new Rectangle(0, 0, tileWidth, tileHeight);
                            using (Bitmap bmp = GetBitmap(mapLayer, extent, rectangle))
                            {
                                ImageFormat imageFormat = null;
                                if (string.IsNullOrWhiteSpace(getTile.Format) || !getTile.Format.Contains('/'))
                                {
                                    imageFormat = ImageFormat.Png;
                                }
                                else
                                {
                                    string[] formatMimeArray = getTile.Format.Split('/');
                                    switch (formatMimeArray[1])
                                    {
                                    case "jpg":
                                        imageFormat = ImageFormat.Jpeg;
                                        break;

                                    default:
                                        imageFormat = ImageFormat.Png;
                                        break;
                                    }
                                }
                                buffer = GetBitmapBuffer(bmp, imageFormat);
                            }
                        }
                    }
                }
                mapLayer.Dispose();
            }
            return(buffer);
        }
Example #3
0
 public Physics()
 {
     Mass                  = float.PositiveInfinity;
     Restitution           = 0f;
     EntityPhysicsType     = PhysicsType.KINEMATICS;
     EntityBoundingBoxType = BoundingBoxType.AABB;
     EntityImpluseType     = ImpluseType.NONE;
     CollideeManifold      = new List <CollisionManifold>();
 }
Example #4
0
 /**
  * @private
  */
 override protected void _onClear()
 {
     type   = BoundingBoxType.None;
     color  = 0x000000;
     x      = 0.0f;
     y      = 0.0f;
     width  = 0.0f;
     height = 0.0f;
     vertices.Clear();
 }
Example #5
0
 public static BoundingBoxType[] GetBoundingBoxTypes(double xMin, double yMin, double xMax, double yMax)
 {
     BoundingBoxType[] boundingBoxTypes = new BoundingBoxType[]
     {
         new BoundingBoxType()
         {
             LowerCorner = $"{xMin} {yMin}",
             UpperCorner = $"{xMax} {yMax}"
         }
     };
     return(boundingBoxTypes);
 }
Example #6
0
        /// <summary>
        /// Create a cropped bounding box.
        /// </summary>
        /// <returns>The crop info.</returns>
        /// <param name="crop">Crop.</param>
        /// <param name="adjustedScale">Adjusted scale.</param>
        public AGSCropInfo Crop(BoundingBoxType boundingBoxType, ICropSelfComponent crop, PointF adjustedScale)
        {
            if (crop == null)
            {
                return(new AGSCropInfo(this, null));
            }
            float scaleX                   = adjustedScale.X;
            float scaleY                   = adjustedScale.Y;
            float spriteWidth              = Width / scaleX;
            float spriteHeight             = Height / scaleY;
            var   args                     = new BeforeCropEventArgs(this, boundingBoxType);
            FourCorners <Vector2> cropArea = crop.GetCropArea(args, spriteWidth, spriteHeight, out float width, out float height);

            if (!crop.CropEnabled)
            {
                return(new AGSCropInfo(this, null));
            }
            if (width <= 0f || height <= 0f)
            {
                return(default);
Example #7
0
        public static bool ComputeTileBoundary(LayerType layerType, TileMatrix layerTileMatrix, int tileCol, int tileRow, out double tileXMin, out double tileYMin, out double tileXMax, out double tileYMax)
        {
            bool result = false;

            tileXMin = 0;
            tileYMin = 0;
            tileXMax = 0;
            tileYMax = 0;
            if (layerType == null || layerTileMatrix == null)
            {
                return(result);
            }
            bool ret0 = layerTileMatrix.TopLeftCorner.ToPosition(out double left, out double top);

            if (!ret0)
            {
                return(result);
            }
            BoundingBoxType boundingBoxType = layerType.BoundingBox?.Length > 0 ? layerType.BoundingBox[0] : layerType.WGS84BoundingBox?.Length > 0 ? layerType.WGS84BoundingBox[0] : null;

            if (boundingBoxType == null)
            {
                return(result);
            }
            bool ret1 = boundingBoxType.LowerCorner.ToPosition(out double xMin, out double yMin);
            bool ret2 = boundingBoxType.UpperCorner.ToPosition(out double xMax, out double yMax);

            if (!ret1 || !ret2)
            {
                return(result);
            }
            int tileWidth  = Convert.ToInt32(layerTileMatrix.TileWidth);
            int tileHeight = Convert.ToInt32(layerTileMatrix.TileHeight);

            tileXMin = left + tileCol * tileWidth * layerTileMatrix.ScaleDenominator;
            tileXMax = left + (tileCol + 1) * tileWidth * layerTileMatrix.ScaleDenominator;
            tileYMax = top - tileRow * tileHeight * layerTileMatrix.ScaleDenominator;
            tileYMin = top - (tileRow + 1) * tileHeight * layerTileMatrix.ScaleDenominator;
            result   = true;
            return(result);
        }
Example #8
0
        private async Task <ContentResult> GetFeatureInfo(string serviceName, GetFeatureInfo getFeatureInfo)
        {
            GetTile         getTile    = getFeatureInfo.GetTile;
            string          content    = null;
            ExceptionReport exception  = null;
            int             statusCode = 200;

            #region Validate parameters
            if (string.IsNullOrWhiteSpace(serviceName))
            {
                exception  = ExceptionReportHelper.GetExceptionReport("MissingParameterValue", "serviceName", exceptionText: "Bad request");
                statusCode = 400;
                goto Exception;
            }
            string serviceType = getTile.service;
            if (string.IsNullOrWhiteSpace(serviceType))
            {
                exception  = ExceptionReportHelper.GetExceptionReport("MissingParameterValue", "service", exceptionText: "Bad request");
                statusCode = 400;
                goto Exception;
            }
            if (serviceType != "wmts")
            {
                exception  = ExceptionReportHelper.GetExceptionReport("InvalidParameterValue", "version", exceptionText: "Bad request");
                statusCode = 400;
                goto Exception;
            }
            string version = getTile.version;
            if (string.IsNullOrWhiteSpace(version))
            {
                exception  = ExceptionReportHelper.GetExceptionReport("MissingParameterValue", "version", exceptionText: "Bad request");
                statusCode = 400;
                goto Exception;
            }
            if (version != "1.0.0")
            {
                exception  = ExceptionReportHelper.GetExceptionReport("InvalidParameterValue", "version", exceptionText: "Bad request");
                statusCode = 400;
                goto Exception;
            }
            string layerName = getTile.Layer;
            if (string.IsNullOrWhiteSpace(layerName))
            {
                exception  = ExceptionReportHelper.GetExceptionReport("MissingParameterValue", "layer", exceptionText: "Bad request");
                statusCode = 400;
                goto Exception;
            }
            string style = getTile.Style;
            if (string.IsNullOrWhiteSpace(style))
            {
                exception  = ExceptionReportHelper.GetExceptionReport("MissingParameterValue", "style", exceptionText: "Bad request");
                statusCode = 400;
                goto Exception;
            }
            string format = getTile.Format;
            if (string.IsNullOrWhiteSpace(format))
            {
                exception  = ExceptionReportHelper.GetExceptionReport("MissingParameterValue", "format", exceptionText: "Bad request");
                statusCode = 400;
                goto Exception;
            }
            string tileMatrixSet = getTile.TileMatrixSet;
            if (string.IsNullOrWhiteSpace(tileMatrixSet))
            {
                exception  = ExceptionReportHelper.GetExceptionReport("MissingParameterValue", "tileMatrixSet", exceptionText: "Bad request");
                statusCode = 400;
                goto Exception;
            }
            string tileMatrix = getTile.TileMatrix;
            if (string.IsNullOrWhiteSpace(tileMatrix))
            {
                exception  = ExceptionReportHelper.GetExceptionReport("MissingParameterValue", "tileMatrix", exceptionText: "Bad request");
                statusCode = 400;
                goto Exception;
            }
            ServiceRecord serviceRecord = await GetServiceRecord(serviceName, version);

            if (serviceRecord == null)
            {
                exception  = ExceptionReportHelper.GetExceptionReport("InvalidParameterValue", exceptionText: "Bad request");
                statusCode = 400;
                goto Exception;
            }
            if (!System.IO.File.Exists(serviceRecord.Path))
            {
                exception  = ExceptionReportHelper.GetExceptionReport("NoApplicableCode", exceptionText: "Internal server error");
                statusCode = 500;
                goto Exception;
            }
            LayerRecord layerRecord = await GetLayerRecord(serviceRecord, layerName);

            if (layerRecord == null)
            {
                exception  = ExceptionReportHelper.GetExceptionReport("InvalidParameterValue", exceptionText: "Bad request");
                statusCode = 400;
                goto Exception;
            }
            if (!System.IO.File.Exists(layerRecord.Path))
            {
                exception  = ExceptionReportHelper.GetExceptionReport("NoApplicableCode", exceptionText: "Internal server error");
                statusCode = 500;
                goto Exception;
            }
            #endregion
            GetCapabilities getCapabilities = new GetCapabilities();
            IWmtsService    wmts1Service    = GetWmts1Service(version);
            Capabilities    capabilities    = wmts1Service.GetCapabilities(serviceRecord.Path, getCapabilities);
            if (capabilities == null)
            {
                exception  = ExceptionReportHelper.GetExceptionReport("NoApplicableCode", exceptionText: "Internal server error");
                statusCode = 500;
                goto Exception;
            }
            LayerType layerType = capabilities.Contents?.DatasetDescriptionSummary?.FirstOrDefault(x => x.Identifier?.Value == layerName && x is LayerType) as LayerType;
            if (layerType == null)
            {
                exception  = ExceptionReportHelper.GetExceptionReport("NoApplicableCode", exceptionText: "Internal server error");
                statusCode = 500;
                goto Exception;
            }
            if (!layerType.Format.Contains(format))
            {
                exception  = ExceptionReportHelper.GetExceptionReport("InvalidParameterValue", "format", exceptionText: "Bad request");
                statusCode = 400;
                goto Exception;
            }
            if (layerType.TileMatrixSetLink == null || layerType.TileMatrixSetLink.Length == 0)
            {
                exception  = ExceptionReportHelper.GetExceptionReport("NoApplicableCode", exceptionText: "Internal server error");
                statusCode = 500;
                goto Exception;
            }
            string layerTileMatrixSetStr = layerType.TileMatrixSetLink[0].TileMatrixSet;
            if (layerTileMatrixSetStr != null)
            {
                TileMatrixSet layerTileMatrixSet = capabilities.Contents.TileMatrixSet?.FirstOrDefault(x => x.Identifier?.Value == layerTileMatrixSetStr);
                if (layerTileMatrixSet != null)
                {
                    TileMatrix layerTileMatrix = layerTileMatrixSet.TileMatrix?.FirstOrDefault(x => x.Identifier.Value == getTile.TileMatrix);
                    if (layerTileMatrix != null)
                    {
                        bool ret = layerTileMatrix.TopLeftCorner.ToPosition(out double left, out double top);
                        if (!ret)
                        {
                            exception  = ExceptionReportHelper.GetExceptionReport("NoApplicableCode", exceptionText: "Internal server error");
                            statusCode = 500;
                            goto Exception;
                        }
                        BoundingBoxType boundingBoxType = layerType.BoundingBox?.Length > 0 ? layerType.BoundingBox[0] : layerType.WGS84BoundingBox?.Length > 0 ? layerType.WGS84BoundingBox[0] : null;
                        if (boundingBoxType == null)
                        {
                            exception  = ExceptionReportHelper.GetExceptionReport("NoApplicableCode", exceptionText: "Internal server error");
                            statusCode = 500;
                            goto Exception;
                        }
                        bool ret1 = boundingBoxType.LowerCorner.ToPosition(out double xMin, out double yMin);
                        bool ret2 = boundingBoxType.UpperCorner.ToPosition(out double xMax, out double yMax);
                        if (!ret1 || !ret2)
                        {
                            exception  = ExceptionReportHelper.GetExceptionReport("NoApplicableCode", exceptionText: "Internal server error");
                            statusCode = 500;
                            goto Exception;
                        }
                        double tileXMin = 0, tileYMin = 0, tileXMax = 0, tileYMax = 0;
                        int    tileWidth  = Convert.ToInt32(layerTileMatrix.TileWidth);
                        int    tileHeight = Convert.ToInt32(layerTileMatrix.TileHeight);
                        tileXMin = left + getTile.TileCol * tileWidth * layerTileMatrix.ScaleDenominator;
                        tileXMax = left + (getTile.TileCol + 1) * tileWidth * layerTileMatrix.ScaleDenominator;
                        tileYMax = top - getTile.TileRow * tileHeight * layerTileMatrix.ScaleDenominator;
                        tileYMin = top - (getTile.TileRow + 1) * tileHeight * layerTileMatrix.ScaleDenominator;
                        if (tileXMax <= xMin || tileXMin >= xMax || tileYMax <= yMin || tileYMin >= yMax)
                        {
                            exception  = ExceptionReportHelper.GetExceptionReport("TileOutOfRange", exceptionText: "Bad request");
                            statusCode = 400;
                            goto Exception;
                        }
                        if (getFeatureInfo.I < 0 || getFeatureInfo.I >= tileWidth || getFeatureInfo.J < 0 || getFeatureInfo.J >= tileHeight)
                        {
                            exception  = ExceptionReportHelper.GetExceptionReport("PointIJOutOfRange", exceptionText: "Bad request");
                            statusCode = 400;
                            goto Exception;
                        }
                    }
                }
            }
            FeatureInfoResponse featureInfoResponse = wmts1Service.GetFeatureInfo(serviceRecord.Path, getFeatureInfo);
            content = XmlHelper.XmlSerialize(featureInfoResponse, Encoding, null);
            goto Success;
Exception:
            content = XmlHelper.XmlSerialize(exception, Encoding, null);
Success:
            ContentResult result = new ContentResult()
            {
                StatusCode = statusCode,
                Content    = content
            };
            return(result);
        }
Example #9
0
			public SRSEnumerator(BoundingBoxType par) 
			{
                this.SetSamplerState(0, SamplerStateparent = par;
                this.SetSamplerState(0, SamplerStatenIndex = -1;
			}
        private async Task <ActionResult> GetTile(string serviceName, GetTile getTile)
        {
            ActionResult    result     = null;
            ExceptionReport exception  = null;
            int             statusCode = 200;

            #region Validate parameters
            if (string.IsNullOrWhiteSpace(serviceName))
            {
                exception  = ExceptionReportHelper.GetExceptionReport("MissingParameterValue", "serviceName", exceptionText: "Bad request");
                statusCode = 400;
                goto Exception;
            }
            string serviceType = getTile.service;
            if (string.IsNullOrWhiteSpace(serviceType))
            {
                exception  = ExceptionReportHelper.GetExceptionReport("MissingParameterValue", "service", exceptionText: "Bad request");
                statusCode = 400;
                goto Exception;
            }
            if (serviceType.ToLower() != "wmts")
            {
                exception  = ExceptionReportHelper.GetExceptionReport("InvalidParameterValue", "version", exceptionText: "Bad request");
                statusCode = 400;
                goto Exception;
            }
            string version = getTile.version;
            if (string.IsNullOrWhiteSpace(version))
            {
                exception  = ExceptionReportHelper.GetExceptionReport("MissingParameterValue", "version", exceptionText: "Bad request");
                statusCode = 400;
                goto Exception;
            }
            if (version != "1.0.0")
            {
                exception  = ExceptionReportHelper.GetExceptionReport("InvalidParameterValue", "version", exceptionText: "Bad request");
                statusCode = 400;
                goto Exception;
            }
            string layerName = getTile.Layer;
            if (string.IsNullOrWhiteSpace(layerName))
            {
                exception  = ExceptionReportHelper.GetExceptionReport("MissingParameterValue", "layer", exceptionText: "Bad request");
                statusCode = 400;
                goto Exception;
            }
            string style = getTile.Style;
            if (string.IsNullOrWhiteSpace(style))
            {
                exception  = ExceptionReportHelper.GetExceptionReport("MissingParameterValue", "style", exceptionText: "Bad request");
                statusCode = 400;
                goto Exception;
            }
            string format = getTile.Format;
            if (string.IsNullOrWhiteSpace(format))
            {
                exception  = ExceptionReportHelper.GetExceptionReport("MissingParameterValue", "format", exceptionText: "Bad request");
                statusCode = 400;
                goto Exception;
            }
            string tileMatrixSet = getTile.TileMatrixSet;
            if (string.IsNullOrWhiteSpace(tileMatrixSet))
            {
                exception  = ExceptionReportHelper.GetExceptionReport("MissingParameterValue", "tileMatrixSet", exceptionText: "Bad request");
                statusCode = 400;
                goto Exception;
            }
            string tileMatrix = getTile.TileMatrix;
            if (string.IsNullOrWhiteSpace(tileMatrix))
            {
                exception  = ExceptionReportHelper.GetExceptionReport("MissingParameterValue", "tileMatrix", exceptionText: "Bad request");
                statusCode = 400;
                goto Exception;
            }
            ServiceRecord serviceRecord = await GetServiceRecord(serviceName, version);

            if (serviceRecord == null)
            {
                exception  = ExceptionReportHelper.GetExceptionReport("InvalidParameterValue", exceptionText: "Bad request");
                statusCode = 400;
                goto Exception;
            }
            if (!System.IO.File.Exists(serviceRecord.Path))
            {
                exception  = ExceptionReportHelper.GetExceptionReport("NoApplicableCode", exceptionText: "Internal server error");
                statusCode = 500;
                goto Exception;
            }
            LayerRecord layerRecord = await GetLayerRecord(serviceRecord, layerName);

            if (layerRecord == null)
            {
                exception  = ExceptionReportHelper.GetExceptionReport("InvalidParameterValue", exceptionText: "Bad request");
                statusCode = 400;
                goto Exception;
            }
            #endregion
            GetCapabilities getCapabilities = new GetCapabilities(version);
            IWmtsService    wmts1Service    = GetWmts1Service(version);
            Capabilities    capabilities    = wmts1Service.GetCapabilities(serviceRecord.Path, getCapabilities);
            if (capabilities == null)
            {
                exception  = ExceptionReportHelper.GetExceptionReport("NoApplicableCode", exceptionText: "Internal server error");
                statusCode = 500;
                goto Exception;
            }
            LayerType layerType = capabilities.GetLayerType(layerRecord.Name);
            if (layerType == null)
            {
                exception  = ExceptionReportHelper.GetExceptionReport("NoApplicableCode", exceptionText: "Internal server error");
                statusCode = 500;
                goto Exception;
            }
            if (!layerType.Format.Contains(format))
            {
                exception  = ExceptionReportHelper.GetExceptionReport("InvalidParameterValue", "format", exceptionText: "Bad request");
                statusCode = 400;
                goto Exception;
            }
            if (layerType.TileMatrixSetLink == null || layerType.TileMatrixSetLink.Length == 0)
            {
                exception  = ExceptionReportHelper.GetExceptionReport("NoApplicableCode", exceptionText: "Internal server error");
                statusCode = 500;
                goto Exception;
            }
            string layerTileMatrixSetStr = layerType.TileMatrixSetLink[0].TileMatrixSet;
            if (layerTileMatrixSetStr != null)
            {
                TileMatrixSet layerTileMatrixSet = capabilities.Contents.TileMatrixSet?.FirstOrDefault(x => x.Identifier?.Value == layerTileMatrixSetStr);
                if (layerTileMatrixSet != null)
                {
                    TileMatrix layerTileMatrix = layerTileMatrixSet.TileMatrix?.FirstOrDefault(x => x.Identifier.Value == getTile.TileMatrix);
                    if (layerTileMatrix != null)
                    {
                        bool ret = layerTileMatrix.TopLeftCorner.ToPosition(out double left, out double top);
                        if (!ret)
                        {
                            exception  = ExceptionReportHelper.GetExceptionReport("NoApplicableCode", exceptionText: "Internal server error");
                            statusCode = 500;
                            goto Exception;
                        }
                        BoundingBoxType boundingBoxType = layerType.BoundingBox?.Length > 0 ? layerType.BoundingBox[0] : layerType.WGS84BoundingBox?.Length > 0 ? layerType.WGS84BoundingBox[0] : null;
                        if (boundingBoxType == null)
                        {
                            exception  = ExceptionReportHelper.GetExceptionReport("NoApplicableCode", exceptionText: "Internal server error");
                            statusCode = 500;
                            goto Exception;
                        }
                        bool ret0 = boundingBoxType.LowerCorner.ToPosition(out double xMin, out double yMin);
                        bool ret1 = boundingBoxType.UpperCorner.ToPosition(out double xMax, out double yMax);
                        if (!ret0 || !ret1)
                        {
                            exception  = ExceptionReportHelper.GetExceptionReport("NoApplicableCode", exceptionText: "Internal server error");
                            statusCode = 500;
                            goto Exception;
                        }
                        bool isDegree = layerTileMatrixSet.GetIsDegreeByLocalDb();
                        layerTileMatrix.GetTileIndex(isDegree, xMin, yMax, out int startCol, out int startRow);
                        int matrixWidth  = Convert.ToInt32(layerTileMatrix.MatrixWidth);
                        int matrixHeight = Convert.ToInt32(layerTileMatrix.MatrixHeight);
                        if (getTile.TileCol < startCol || getTile.TileCol >= startCol + matrixWidth || getTile.TileRow < startRow || getTile.TileRow >= startRow + matrixHeight)
                        {
                            exception  = ExceptionReportHelper.GetExceptionReport("TileOutOfRange", exceptionText: "Bad request");
                            statusCode = 400;
                            goto Exception;
                        }
                    }
                }
            }
            try
            {
                byte[] tileBuffer = wmts1Service.GetTile(capabilities, layerRecord.Path, getTile);
                result = new FileContentResult(tileBuffer, getTile.Format);
            }
            catch (Exception e)
            {
                Debug.WriteLine($"获取瓦片{getTile.TileMatrix}_{getTile.TileCol}_{getTile.TileRow}失败:{e.Message}");
            }
            goto Success;
Exception:
            string content = XmlHelper.XmlSerialize(exception, Encoding, null);
            result         = new ContentResult()
            {
                StatusCode = statusCode,
                Content    = content
            };
Success:
            return(result);
        }
        public override FeatureInfoResponse GetFeatureInfo(Capabilities capabilities, string path, GetFeatureInfo getFeatureInfo)
        {
            FeatureInfoResponse featureInfoResponse = null;

            if (capabilities == null || string.IsNullOrEmpty(path) || getFeatureInfo == null)
            {
                return(featureInfoResponse);
            }
            LayerFactory layerFactory = new LayerFactory();

            #region 验证getTile参数
            GetTile   getTile   = getFeatureInfo.GetTile;
            LayerType layerType = capabilities.GetLayerType(getTile.Layer);
            if (layerType == null)
            {
                return(featureInfoResponse);
            }
            TileMatrixSet tileMatrixSet = capabilities.GetTileMatrixSet(getTile.TileMatrixSet);
            if (tileMatrixSet == null)
            {
                return(featureInfoResponse);
            }
            TileMatrix tileMatrix = tileMatrixSet.GetTileMatrix(getTile.TileMatrix);
            if (tileMatrix == null)
            {
                return(featureInfoResponse);
            }
            BoundingBoxType boundingBoxType = layerType.BoundingBox.FirstOrDefault();
            if (boundingBoxType == null)
            {
                return(featureInfoResponse);
            }
            bool ret = boundingBoxType.LowerCorner.ToPosition(out double xMin, out double yMin);
            if (!ret)
            {
                return(featureInfoResponse);
            }
            ret = boundingBoxType.UpperCorner.ToPosition(out double xMax, out double yMax);
            if (!ret)
            {
                return(featureInfoResponse);
            }
            bool isDegree = tileMatrixSet.GetIsDegreeByLocalDb();
            tileMatrix.GetTileIndex(isDegree, xMin, yMax, out int startCol, out int startRow);
            int matrixWidth  = Convert.ToInt32(tileMatrix.MatrixWidth);
            int matrixHeight = Convert.ToInt32(tileMatrix.MatrixHeight);
            if (getTile.TileCol < startCol || getTile.TileCol >= startCol + matrixWidth || getTile.TileRow < startRow || getTile.TileRow >= startRow + matrixHeight)
            {
                return(featureInfoResponse);
            }
            if (!layerType.Style.Any(x => x.Identifier.Value == getTile.Style))
            {
                return(featureInfoResponse);
            }
            #endregion

            #region 验证getFeatureInfo参数
            int tileWidth  = Convert.ToInt32(tileMatrix.TileWidth);
            int tileHeight = Convert.ToInt32(tileMatrix.TileHeight);
            if (getFeatureInfo.J < 0 || getFeatureInfo.J >= tileHeight || getFeatureInfo.I < 0 || getFeatureInfo.I >= tileWidth)
            {
                return(featureInfoResponse);
            }
            #endregion

            using (var dataSource = LayerFactory.OpenDataSource(path))
            {
                if (dataSource == null)
                {
                    return(featureInfoResponse);
                }
                using (var layer = dataSource.GetLayerByName(getTile.Layer))
                {
                    if (layer == null)
                    {
                        return(featureInfoResponse);
                    }
                    tileMatrix.GetFeatureInfoBoundary(isDegree, getTile.TileRow, getTile.TileCol, getFeatureInfo.J, getFeatureInfo.I, out double ftInfoXMin, out double ftInfoYMin, out double ftInfoXMax, out double ftInfoYMax);
                    layer.SetSpatialFilterRect(ftInfoXMin, ftInfoYMin, ftInfoXMax, ftInfoYMax);
                    FeatureCollectionType featureCollectionType = new FeatureCollectionType();
                    featureInfoResponse = new FeatureInfoResponse()
                    {
                        Item = featureCollectionType
                    };
                    var ft = layer.GetNextFeature();
                    while (ft != null)
                    {
                        ft = layer.GetNextFeature();
                        //todo添加查询的feature
                    }
                }
            }
            return(featureInfoResponse);
        }
        public override byte[] GetTile(Capabilities capabilities, string path, GetTile getTile)
        {
            byte[] buffer = null;
            if (capabilities == null || string.IsNullOrEmpty(path) || getTile == null)
            {
                return(buffer);
            }
            LayerFactory layerFactory = new LayerFactory();

            #region 验证getTile参数
            LayerType layerType = capabilities.GetLayerType(getTile.Layer);
            if (layerType == null)
            {
                return(buffer);
            }
            TileMatrixSet tileMatrixSet = capabilities.GetTileMatrixSet(getTile.TileMatrixSet);
            if (tileMatrixSet == null)
            {
                return(buffer);
            }
            TileMatrix tileMatrix = tileMatrixSet.GetTileMatrix(getTile.TileMatrix);
            if (tileMatrix == null)
            {
                return(buffer);
            }
            BoundingBoxType boundingBoxType = layerType.BoundingBox.FirstOrDefault();
            if (boundingBoxType == null)
            {
                return(buffer);
            }
            bool ret = boundingBoxType.LowerCorner.ToPosition(out double xMin, out double yMin);
            if (!ret)
            {
                return(buffer);
            }
            ret = boundingBoxType.UpperCorner.ToPosition(out double xMax, out double yMax);
            if (!ret)
            {
                return(buffer);
            }
            bool isDegree = tileMatrixSet.GetIsDegreeByLocalDb();
            tileMatrix.GetTileIndex(isDegree, xMin, yMax, out int startCol, out int startRow);
            int matrixWidth  = Convert.ToInt32(tileMatrix.MatrixWidth);
            int matrixHeight = Convert.ToInt32(tileMatrix.MatrixHeight);
            if (getTile.TileCol < startCol || getTile.TileCol >= startCol + matrixWidth || getTile.TileRow < startRow || getTile.TileRow >= startRow + matrixHeight)
            {
                return(buffer);
            }
            if (!layerType.Style.Any(x => x.Identifier.Value == getTile.Style))
            {
                return(buffer);
            }
            if (!layerType.Format.Contains(getTile.Format))
            {
                return(buffer);
            }
            #endregion

            using (var layer = layerFactory.OpenLayer(path))
            {
                if (layer == null)
                {
                    return(buffer);
                }
                tileMatrix.GetTileBoundary(isDegree, getTile.TileRow, getTile.TileCol, out double tileXMin, out double tileYMin, out double tileXMax, out double tileYMax);
                using (Envelope envelope = new Envelope())
                {
                    envelope.MinX = tileXMin;
                    envelope.MinY = tileYMin;
                    envelope.MaxX = tileXMax;
                    envelope.MaxY = tileYMax;
                    int       tileWidth  = Convert.ToInt32(tileMatrix.TileWidth);
                    int       tileHeight = Convert.ToInt32(tileMatrix.TileHeight);
                    Rectangle rectangle  = new Rectangle(0, 0, tileWidth, tileHeight);
                    using (var image = new Image <Rgba32>(rectangle.Width, rectangle.Height))
                    {
                        layer.DrawReagion(image, rectangle, envelope, false, null, null);
                        using (MemoryStream ms = new MemoryStream())
                        {
                            string formatName = getTile.Format.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries)[1];
                            switch (formatName)
                            {
                            case "png":
                                image.SaveAsPng(ms);
                                break;

                            case "jpeg":
                                image.SaveAsJpeg(ms);
                                break;

                            default:
                                return(buffer);
                            }
                            buffer = ms.ToArray();
                        }
                    }
                }
            }
            return(buffer);
        }
 public AGSCropInfo Crop(ref AGSBoundingBox box, BoundingBoxType boundingBoxType, PointF adjustedScale)
 {
     (var isGuaranteed, var cropFromGuarantee) = isGuaranteedToFullyCrop();
     if (isGuaranteed)
     {
         return(LastCrop = new AGSCropInfo(default, null, cropFromGuarantee));
 /// <summary>
 /// Initializes a new instance of the <see cref="T:AGS.API.BeforeCropEventArgs"/> struct.
 /// </summary>
 /// <param name="boundingBox">Bounding box.</param>
 /// <param name="boundingBoxType">Bounding box type.</param>
 public BeforeCropEventArgs(AGSBoundingBox boundingBox, BoundingBoxType boundingBoxType)
 {
     BoundingBox     = boundingBox;
     BoundingBoxType = boundingBoxType;
 }
Example #15
0
        public static LayerType GetLayerType(IDataSet dataSet)
        {
            LayerType layerType = null;

            if (dataSet == null)
            {
                return(layerType);
            }
            LanguageStringType[] titles = new LanguageStringType[]
            {
                new LanguageStringType()
                {
                    Value = dataSet.Name
                }
            };
            LanguageStringType[] abstracts = new LanguageStringType[]
            {
                new LanguageStringType()
                {
                    Value = dataSet.Name
                }
            };
            var extent = dataSet.Extent;

            BoundingBoxType[]      boundingBoxs       = null;
            WGS84BoundingBoxType[] WGS84BoundingBoxes = null;
            ProjectionInfo         wgs84PrjInfo       = KnownCoordinateSystems.Geographic.World.WGS1984;

            if (dataSet.Projection.Equals(wgs84PrjInfo))//wgs84
            {
                WGS84BoundingBoxes = new WGS84BoundingBoxType[]
                {
                    new WGS84BoundingBoxType()
                    {
                        LowerCorner = $"{extent.MinX} {extent.MinY}",
                        UpperCorner = $"{extent.MaxX} {extent.MaxY}"
                    }
                };
            }
            else
            {
                boundingBoxs = new BoundingBoxType[]
                {
                    new BoundingBoxType()
                    {
                        LowerCorner = $"{extent.MinX} {extent.MinY}",
                        UpperCorner = $"{extent.MaxX} {extent.MaxY}"
                    }
                };
                using (IDataSet tmpDs = DataManager.DefaultDataManager.OpenFile(dataSet.Filename))
                {
                    tmpDs.Reproject(wgs84PrjInfo);
                    WGS84BoundingBoxes = new WGS84BoundingBoxType[]
                    {
                        new WGS84BoundingBoxType()
                        {
                            LowerCorner = $"{tmpDs.Extent.MinX} {tmpDs.Extent.MinY}",
                            UpperCorner = $"{tmpDs.Extent.MaxX} {tmpDs.Extent.MaxY}"
                        }
                    };
                }
            }
            CodeType identifier = new CodeType()
            {
                Value = dataSet.Name
            };
            Style style = new Style()
            {
                isDefault  = true,
                Identifier = new CodeType()
                {
                    Value = "default"
                }
            };

            Style[] styles = new Style[]
            {
                style
            };
            string[] formats = new string[]
            {
                "image/png", "image/jpg"
            };
            TileMatrixSetLink[] tileMatrixSetLinks = new TileMatrixSetLink[]
            {
                new TileMatrixSetLink()
                {
                    TileMatrixSet = dataSet.Projection.Name
                }
            };
            layerType = new LayerType()
            {
                Title             = titles,
                Abstract          = abstracts,
                BoundingBox       = boundingBoxs,
                WGS84BoundingBox  = WGS84BoundingBoxes,
                Identifier        = identifier,
                Style             = styles,
                Format            = formats,
                TileMatrixSetLink = tileMatrixSetLinks
            };
            return(layerType);
        }