Exemplo n.º 1
0
        public static bool GetIsDegreeByLocalDb(this TileMatrixSet tileMatrixSet)
        {
            bool ret          = false;
            var  SupportedCRS = tileMatrixSet.SupportedCRS;

            if (string.IsNullOrEmpty(SupportedCRS) || !SupportedCRS.Contains(":EPSG:"))
            {
                return(ret);
            }
            string[] array         = SupportedCRS.Split(':');
            bool     convertResult = int.TryParse(array[array.Length - 1], out int epsg);
            String   projcs        = SpatialReferenceHelper.GetProjcs(epsg);
            String   geogcs        = SpatialReferenceHelper.GetGeogcs(epsg);

            ret = string.IsNullOrEmpty(projcs) && !string.IsNullOrEmpty(geogcs);
            return(ret);
        }
Exemplo n.º 2
0
        public static LayerType AddToCapabilities(Capabilities capabilities, string name, string projectionStr, double xMin, double yMin, double xMax, double yMax, int minLevel, int maxLevel)
        {
            LayerType layerType = null;

            if (capabilities == null || capabilities == null || minLevel < 0 || minLevel > maxLevel)
            {
                return(layerType);
            }
            if (capabilities.Contents == null)
            {
                capabilities.Contents = new ContentsType();
            }
            DatasetDescriptionSummaryBaseType[] datasets = capabilities.Contents.DatasetDescriptionSummary;
            if (datasets?.Any(x => x.Identifier.Value == name) == true)
            {
                return(layerType);
            }
            int layerCount = datasets == null ? 1 : datasets.Length + 1;

            capabilities.Contents.DatasetDescriptionSummary = new DatasetDescriptionSummaryBaseType[layerCount];
            datasets?.CopyTo(capabilities.Contents.DatasetDescriptionSummary, 0);
            datasets = capabilities.Contents.DatasetDescriptionSummary;

            #region 获取layerType
            layerType = CreateLayerType(name);
            string                 projcs = null;
            string                 geogcs = null;
            double                 semimajor;
            BoundingBoxType[]      boundingBoxs       = CreateBoundingBoxTypes(xMin, yMin, xMax, yMax);
            WGS84BoundingBoxType[] WGS84BoundingBoxes = null;

            using (OSGeo.OSR.SpatialReference srcSR = new OSGeo.OSR.SpatialReference(projectionStr))
            {
                semimajor = srcSR.GetSemiMajor();
                projcs    = srcSR.GetAttrValue("PROJCS", 0);
                if (string.IsNullOrEmpty(projcs))
                {
                    geogcs = srcSR.GetAttrValue("GEOGCS", 0);
                }
                using (OSGeo.OSR.SpatialReference destSR = new OSGeo.OSR.SpatialReference(""))
                {
                    destSR.SetWellKnownGeogCS("EPSG:4326");
                    double WGS84XMin = xMin;
                    double WGS84YMin = yMin;
                    double WGS84XMax = xMax;
                    double WGS84YMax = yMax;
                    if (srcSR.IsSame(destSR) != 1)
                    {
                        double[] leftBottom = { xMin, yMin };
                        double[] topRight   = { xMax, yMax };
                        srcSR.CoordTransform(destSR, leftBottom, topRight);
                        WGS84XMin = leftBottom[0];
                        WGS84YMin = leftBottom[1];
                        WGS84XMax = topRight[0];
                        WGS84YMax = topRight[1];
                    }
                    WGS84BoundingBoxes = CreateWGS84BoundingBoxTypes(WGS84XMin, WGS84YMin, WGS84XMax, WGS84YMax);
                }
            }
            string tileMatrixSetName = !string.IsNullOrEmpty(projcs) ? projcs : geogcs;
            TileMatrixSetLink[] tileMatrixSetLinks = CreateTileMatrixSetLinks(tileMatrixSetName);
            layerType.BoundingBox       = boundingBoxs;
            layerType.WGS84BoundingBox  = WGS84BoundingBoxes;
            layerType.TileMatrixSetLink = tileMatrixSetLinks;
            #endregion
            datasets[datasets.Length - 1] = layerType;

            #region 设置tileMatrixSet
            TileMatrixSet[] tileMatrixSets = capabilities.Contents.TileMatrixSet;
            if (tileMatrixSets?.Any(x => x.Identifier.Value == tileMatrixSetName) != true)
            {
                int tileMatrixSetCount = tileMatrixSets == null ? 1 : tileMatrixSets.Length + 1;
                capabilities.Contents.TileMatrixSet = new TileMatrixSet[tileMatrixSetCount];
                tileMatrixSets?.CopyTo(capabilities.Contents.TileMatrixSet, 0);
                tileMatrixSets = capabilities.Contents.TileMatrixSet;
                bool         isDegree     = projcs == null;
                TileMatrix[] tileMatrices = CreateTileMatrices(semimajor, isDegree, xMin, yMin, xMax, yMax, minLevel, maxLevel);

                int?wkid = null;
                if (!string.IsNullOrEmpty(projcs))
                {
                    wkid = SpatialReferenceHelper.GetWellKnownWkidFromProjecs(projcs);
                }
                else if (!string.IsNullOrEmpty(geogcs))
                {
                    wkid = SpatialReferenceHelper.GetWellKnownWkidFromGeogcs(geogcs);
                }
                if (wkid.HasValue)
                {
                    TileMatrixSet tileMatrixSet = new TileMatrixSet()
                    {
                        Identifier = new CodeType()
                        {
                            Value = tileMatrixSetName
                        },
                        SupportedCRS = $"urn:ogc:def:crs:EPSG::{wkid.Value}",//TODO 待修改 根据名称获取EPSG,网上下载arcgis的
                        TileMatrix   = tileMatrices
                    };
                    tileMatrixSets[tileMatrixSets.Length - 1] = tileMatrixSet;
                }
            }
            #endregion
            return(layerType);
        }