gdal python
时间: 2023-09-07 17:17:33 浏览: 109
GDAL (Geospatial Data Abstraction Library) is a popular open-source library for reading and writing geospatial data formats. It provides a Python API for developers to access its functionality.
To use GDAL in Python, you first need to install the GDAL library and its Python bindings. You can install it using pip by running the following command:
```
pip install gdal
```
Once installed, you can import the `gdal` module in your Python code and use its functions to read and write geospatial data files. Here's an example of how to open a raster file using GDAL in Python:
```python
from osgeo import gdal
# Open the raster file
raster = gdal.Open('path/to/raster.tif')
# Get the number of bands
num_bands = raster.RasterCount
# Get the raster size
width = raster.RasterXSize
height = raster.RasterYSize
# Get the projection and geotransform
projection = raster.GetProjection()
geotransform = raster.GetGeoTransform()
# Read the first band as a numpy array
band = raster.GetRasterBand(1)
data = band.ReadAsArray()
```
This is just a simple example, but GDAL provides many more functions for working with geospatial data in Python.
阅读全文