public static void GetSuitableZoom(this Dataset dataset, ref int minZoom, ref int maxZoom)
        {
            string projectionStr = dataset.GetProjection();

            double[] affineParas = new double[6];
            dataset.GetGeoTransform(affineParas);
            double xRes       = affineParas[1];
            double yRes       = -affineParas[5];
            double resolution = Math.Min(xRes, yRes);
            double dWidth     = Math.Max(dataset.RasterXSize * xRes, dataset.RasterYSize * yRes);
            string projcs     = null;
            string geogcs     = null;

            using (OSGeo.OSR.SpatialReference srcSR = new OSGeo.OSR.SpatialReference(projectionStr))
            {
                projcs = srcSR.GetAttrValue("PROJCS", 0);
                if (string.IsNullOrEmpty(projcs))
                {
                    geogcs = srcSR.GetAttrValue("GEOGCS", 0);
                }
            }
            bool isDegree     = projcs == null && geogcs != null;
            bool minZoomSeted = false;
            bool maxZoomSeted = false;

            for (int i = 0; i < 30; i++)
            {
                double tmpResolution = TileMatrix.GetResolution(isDegree, i);
                if (!minZoomSeted)
                {
                    if (dWidth / tmpResolution > 256)
                    {
                        if (i == 0)
                        {
                            minZoom = i;
                        }
                        else
                        {
                            minZoom = i - 1;
                        }
                        minZoomSeted = true;
                    }
                }
                if (!maxZoomSeted)
                {
                    if (resolution >= tmpResolution)
                    {
                        maxZoom      = i;
                        maxZoomSeted = true;
                    }
                }
                if (minZoomSeted && maxZoomSeted)
                {
                    break;
                }
            }
        }
示例#2
0
        public static List <double> GetResolutions(this TileMatrixSet tileMatrixSet, IEnumerable <string> tileMatrixIdentifiers)
        {
            List <double> resolutions = new List <double>();
            bool          isDegree    = tileMatrixSet.GetIsDegreeByLocalDb();

            foreach (var tileMatrixIdentifier in tileMatrixIdentifiers)
            {
                TileMatrix tileMatrix = tileMatrixSet.TileMatrix.FirstOrDefault(x => x.Identifier.Value == tileMatrixIdentifier);
                if (tileMatrix != null)
                {
                    double res = tileMatrix.GetResolution(isDegree);
                    resolutions.Add(res);
                }
            }
            return(resolutions);
        }
示例#3
0
        public static void GetSuitableZoom(this DataSource dataSource, ref int minZoom, ref int maxZoom)
        {
            string projcs = null;
            string geogcs = null;
            double xMin, yMin, xMax, yMax;

            using (var layer = dataSource.GetLayerByIndex(0))
            {
                string layerName = layer.GetName();//todo 调试是否乱码
                using (var spatialReference = layer.GetSpatialRef())
                {
                    projcs = spatialReference.GetAttrValue("PROJCS", 0);
                    if (string.IsNullOrEmpty(projcs))
                    {
                        geogcs = spatialReference.GetAttrValue("GEOGCS", 0);
                    }
                }
                layer.GetExtent(out xMin, out yMin, out xMax, out yMax);
            }
            double dWidth   = Math.Max(xMax - xMin, yMax - yMin);
            bool   isDegree = projcs == null && geogcs != null;

            for (int i = 0; i < 30; i++)
            {
                double tmpResolution = TileMatrix.GetResolution(isDegree, i);
                if (dWidth / tmpResolution > 256)
                {
                    if (i == 0)
                    {
                        minZoom = i;
                    }
                    else
                    {
                        minZoom = i - 1;
                    }
                    break;
                }
            }
            maxZoom = 19;
        }