banner
Riceneeder

Riceneeder

卜得山火贲之变艮卦,象曰:装饰既成,宜静宜止。2025下半年,不宜躁进,宜守正持中,沉淀与反思,将为日后之再发打下基石。
github
email

Some points on adaptive zoning using ArcGIS and Maxent

The recent research topic involves using these two software programs, where meteorological factors are needed for Maxent. However, the future bioclimatic factors downloaded from WorldClim are only available as a single TIFF file containing 19 bands, which needs to be manually split into 19 files. I couldn't find a method to split using ArcGIS, so I turned to Python.

The code is as follows:

import gdal
import os

input_file = "G:/4.其他/wc2.1_30s_bioc_ACCESS-CM2_ssp126_2041-2060.tif"#downloaded tif file
output_folder = "G:/4.其他/feature_bio/"#output folder

if not os.path.exists(output_folder):
   os.makedirs(output_folder)

dataset = gdal.Open(input_file)
num_bands = dataset.RasterCount

for i in range(num_bands):
   band = dataset.GetRasterBand(i + 1)
   output_file = os.path.join(output_folder, f"bio_{i + 1}.tif")
   driver = gdal.GetDriverByName("GTiff")
   new_dataset = driver.Create(output_file, dataset.RasterXSize, dataset.RasterYSize, 1, gdal.GDT_Float32)
   new_dataset.SetProjection(dataset.GetProjection())
   new_dataset.SetGeoTransform(dataset.GetGeoTransform())
   new_dataset.GetRasterBand(1).WriteArray(band.ReadAsArray())
   print(f"Creating {output_file}...")
   new_dataset.FlushCache()
   new_dataset = None

dataset = None

However, there is a problem; when installing GDAL, it is likely to report an error, and I haven't found the specific reason. The recommended method online is to use conda:

conda install gdal

In practice, there may be situations where installation fails or it cannot be called after installation. The solutions are:

  1. If the installation fails:
    Download the corresponding .whl file from the GitHub repository, for example, for Python 3.11, download GDAL-3.7.1-cp311-cp311-win_amd64.whl, and then manually install it using pip install GDAL-3.7.1-cp311-cp311-win_amd64.whl
  2. If it cannot be called:
    In the folder where Python installs various environment packages, such as: D:Path\To\python3.9.12\Lib\site-packages\, create a new gdal.py file and copy the following code into it:
# import osgeo.gdal as a convenience
from osgeo.gdal import deprecation_warn
deprecation_warn('gdal')
from osgeo.gdal import *
Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.