gdal
GDAL is an open source MIT licensed translator library for raster and vector geospatial data formats.
Top Related Projects
Python tools for geographic data
Rasterio reads and writes geospatial raster datasets
QGIS is a free, open source, cross platform (lin/win/mac) geographical information system (GIS)
Geometry Engine, Open Source
Manipulation and analysis of geometric objects
PostGIS spatial database extension to PostgreSQL [mirror]
Quick Overview
GDAL (Geospatial Data Abstraction Library) is a powerful open-source library for reading, writing, and processing geospatial data formats. It provides a single abstract data model for all supported formats, allowing developers to work with various geospatial data types using a consistent API. GDAL is widely used in GIS software, remote sensing applications, and geospatial data processing workflows.
Pros
- Supports a vast array of raster and vector geospatial data formats
- Provides a unified API for working with different data types and formats
- Offers powerful data transformation and processing capabilities
- Actively maintained with regular updates and improvements
Cons
- Steep learning curve for beginners due to its extensive functionality
- Large library size, which may impact deployment in resource-constrained environments
- Documentation can be overwhelming and sometimes lacks detailed examples
- Performance can be slower compared to format-specific libraries for certain operations
Code Examples
- Reading a raster file and accessing its metadata:
from osgeo import gdal
dataset = gdal.Open("example.tif")
print(f"Driver: {dataset.GetDriver().ShortName}")
print(f"Size: {dataset.RasterXSize} x {dataset.RasterYSize} x {dataset.RasterCount}")
print(f"Projection: {dataset.GetProjection()}")
- Reading and writing vector data:
from osgeo import ogr
# Open the input shapefile
input_ds = ogr.Open("input.shp")
input_layer = input_ds.GetLayer()
# Create a new shapefile
driver = ogr.GetDriverByName("ESRI Shapefile")
output_ds = driver.CreateDataSource("output.shp")
output_layer = output_ds.CreateLayer("output", input_layer.GetSpatialRef(), ogr.wkbPolygon)
# Copy features from input to output
for feature in input_layer:
output_layer.CreateFeature(feature)
# Close the datasets
input_ds = None
output_ds = None
- Reprojecting a raster:
from osgeo import gdal
input_raster = gdal.Open("input.tif")
output = gdal.Warp("output.tif", input_raster, dstSRS="EPSG:4326")
output = None # Close the dataset
Getting Started
To get started with GDAL, follow these steps:
-
Install GDAL:
pip install GDAL
-
Import the required modules:
from osgeo import gdal, ogr, osr
-
Open a geospatial file:
dataset = gdal.Open("path/to/your/file.tif")
-
Start working with the data using GDAL's API. Refer to the documentation and examples for specific operations you want to perform.
Competitor Comparisons
Python tools for geographic data
Pros of GeoPandas
- Higher-level API, easier for data analysis and manipulation
- Integrates well with pandas and other Python data science libraries
- Better suited for working with vector data and tabular geospatial information
Cons of GeoPandas
- Limited support for raster data operations
- Slower performance for large datasets compared to GDAL
- Narrower scope of functionality, focusing primarily on vector data
Code Comparison
GeoPandas:
import geopandas as gpd
gdf = gpd.read_file("shapefile.shp")
gdf['area'] = gdf.geometry.area
gdf.plot()
GDAL:
from osgeo import gdal, ogr
ds = ogr.Open("shapefile.shp")
layer = ds.GetLayer()
for feature in layer:
geometry = feature.GetGeometryRef()
GeoPandas provides a more concise and intuitive API for common geospatial operations, while GDAL offers lower-level access and broader functionality across various data formats and types. GeoPandas is ideal for data analysis workflows, whereas GDAL is better suited for more complex geospatial processing tasks and working with both vector and raster data.
Rasterio reads and writes geospatial raster datasets
Pros of rasterio
- More Pythonic API, easier to use for Python developers
- Better integration with NumPy arrays
- Faster read/write operations for certain use cases
Cons of rasterio
- Limited functionality compared to GDAL's extensive feature set
- Smaller community and ecosystem
- Dependency on GDAL for core functionality
Code Comparison
rasterio
import rasterio
with rasterio.open('example.tif') as src:
data = src.read()
profile = src.profile
GDAL
from osgeo import gdal
ds = gdal.Open('example.tif')
data = ds.ReadAsArray()
profile = ds.GetMetadata()
Summary
GDAL is a comprehensive geospatial data abstraction library with extensive functionality and broad language support. rasterio, built on top of GDAL, provides a more Pythonic interface specifically for raster data manipulation in Python. While rasterio offers improved ease of use and performance for certain tasks, it has a narrower scope compared to GDAL's full feature set. The choice between the two depends on the specific requirements of the project and the developer's familiarity with Python.
QGIS is a free, open source, cross platform (lin/win/mac) geographical information system (GIS)
Pros of QGIS
- Comprehensive GUI for geospatial data visualization and analysis
- Extensive plugin ecosystem for additional functionality
- User-friendly interface suitable for both beginners and experts
Cons of QGIS
- Larger codebase and more complex architecture
- Slower performance for certain operations compared to GDAL
- Higher resource requirements for installation and operation
Code Comparison
QGIS (Python):
layer = QgsVectorLayer("path/to/shapefile.shp", "layer_name", "ogr")
if not layer.isValid():
print("Layer failed to load!")
QgsProject.instance().addMapLayer(layer)
GDAL (Python):
from osgeo import ogr
driver = ogr.GetDriverByName("ESRI Shapefile")
dataSource = driver.Open("path/to/shapefile.shp", 0)
layer = dataSource.GetLayer()
QGIS provides a higher-level API for working with geospatial data, while GDAL offers more low-level control. QGIS builds upon GDAL's functionality, adding a user interface and additional features for data manipulation and visualization.
Geometry Engine, Open Source
Pros of GEOS
- Specialized focus on geometry operations and spatial predicates
- Lightweight and efficient for specific geometric tasks
- Easier to integrate into projects requiring only geometric functionality
Cons of GEOS
- Limited scope compared to GDAL's broader geospatial capabilities
- Lacks raster data handling and coordinate system transformations
- Smaller community and ecosystem of tools/extensions
Code Comparison
GEOS (C++):
#include <geos/geom/Geometry.h>
#include <geos/geom/GeometryFactory.h>
geos::geom::GeometryFactory::Ptr factory = geos::geom::GeometryFactory::create();
geos::geom::Geometry* point = factory->createPoint(geos::geom::Coordinate(1, 1));
GDAL (C++):
#include "ogrsf_frmts.h"
OGRPoint point;
point.setX(1);
point.setY(1);
GDAL offers a more comprehensive suite of geospatial tools, including raster and vector data handling, coordinate system transformations, and various data formats support. It's better suited for complex geospatial projects requiring diverse functionality.
GEOS, on the other hand, excels in geometric operations and is ideal for projects focused specifically on computational geometry. It's more lightweight and can be easier to integrate when only geometric functionality is needed.
Both libraries have their strengths and are often used together in geospatial applications, with GEOS providing advanced geometry operations and GDAL offering broader geospatial capabilities.
Manipulation and analysis of geometric objects
Pros of Shapely
- Simpler API and easier to learn for basic geometric operations
- Pure Python implementation, making it more portable and easier to install
- Better suited for small to medium-scale geometric computations
Cons of Shapely
- Limited functionality compared to GDAL's extensive geospatial capabilities
- Slower performance for large-scale operations or complex geometric calculations
- Lacks support for advanced geospatial data formats and coordinate systems
Code Comparison
Shapely example:
from shapely.geometry import Point, Polygon
point = Point(0, 0)
polygon = Polygon([(0, 0), (1, 1), (1, 0)])
print(polygon.contains(point))
GDAL example:
from osgeo import ogr
point = ogr.Geometry(ogr.wkbPoint)
point.AddPoint(0, 0)
polygon = ogr.Geometry(ogr.wkbPolygon)
ring = ogr.Geometry(ogr.wkbLinearRing)
ring.AddPoint(0, 0)
ring.AddPoint(1, 1)
ring.AddPoint(1, 0)
ring.AddPoint(0, 0)
polygon.AddGeometry(ring)
print(polygon.Contains(point))
PostGIS spatial database extension to PostgreSQL [mirror]
Pros of PostGIS
- Specialized for spatial database operations, offering advanced geospatial querying and indexing capabilities
- Tightly integrated with PostgreSQL, providing a robust and scalable spatial database solution
- Supports a wide range of spatial data types and functions, including raster data handling
Cons of PostGIS
- Limited to PostgreSQL database environments, lacking the flexibility of GDAL's multi-format support
- Steeper learning curve for users not familiar with PostgreSQL or spatial databases
- Less suitable for standalone geospatial data processing tasks outside of a database context
Code Comparison
PostGIS:
SELECT ST_AsText(ST_Buffer(ST_GeomFromText('POINT(0 0)'), 1));
GDAL:
from osgeo import ogr
point = ogr.Geometry(ogr.wkbPoint)
point.AddPoint(0, 0)
buffer = point.Buffer(1)
print(buffer.ExportToWkt())
Both examples create a buffer around a point, but PostGIS uses SQL within a database context, while GDAL uses Python for standalone processing.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
GDAL - Geospatial Data Abstraction Library
GDAL is an open source MIT licensed translator library for raster and vector geospatial data formats.
- Main site: https://gdal.org - Developer and user docs, links to other resources
- GIT repository: https://github.com/OSGeo/gdal
- Bug tracker: https://github.com/OSGeo/gdal/issues
- Download: https://download.osgeo.org/gdal
- Wiki: https://trac.osgeo.org/gdal - Various user and developer contributed documentation and hints
- Mailing list: https://lists.osgeo.org/mailman/listinfo/gdal-dev
The GDAL project uses a custom governance and is fiscally sponsored by NumFOCUS. Consider making a tax-deductible donation to help the project pay for developer time, professional services, travel, workshops, and a variety of other needs.
NumFOCUS is 501(c)(3) non-profit charity in the United States; as such, donations to NumFOCUS are tax-deductible as allowed by law. As with any donation, you should consult with your personal tax adviser or the IRS about your particular tax situation.
How to build
See BUILDING.md
How to contribute
See CONTRIBUTING.md
Docker images
See docker/
Code of Conduct
See doc/source/community/code_of_conduct.rst
Security policy
See SECURITY.md
Citing GDAL/OGR in publications
See CITATION and CITATION.cff
Top Related Projects
Python tools for geographic data
Rasterio reads and writes geospatial raster datasets
QGIS is a free, open source, cross platform (lin/win/mac) geographical information system (GIS)
Geometry Engine, Open Source
Manipulation and analysis of geometric objects
PostGIS spatial database extension to PostgreSQL [mirror]
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot