Convert Figma logo to code with AI

OSGeo logogdal

GDAL is an open source MIT licensed translator library for raster and vector geospatial data formats.

4,773
2,498
4,773
473

Top Related Projects

Python tools for geographic data

Rasterio reads and writes geospatial raster datasets

10,326

QGIS is a free, open source, cross platform (lin/win/mac) geographical information system (GIS)

1,164

Geometry Engine, Open Source

3,832

Manipulation and analysis of geometric objects

1,682

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

  1. 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()}")
  1. 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
  1. 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:

  1. Install GDAL:

    pip install GDAL
    
  2. Import the required modules:

    from osgeo import gdal, ogr, osr
    
  3. Open a geospatial file:

    dataset = gdal.Open("path/to/your/file.tif")
    
  4. 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.

10,326

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.

1,164

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.

3,832

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))
1,682

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 Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

GDAL - Geospatial Data Abstraction Library

Build Status Build Status Build Status Build Status Build Status Build Status Build Status Build Status Build Status Documentation build Status Fuzzing Status Coverage Status OpenSSF Best Practices OpenSSF Scorecard

DOI

Powered by NumFOCUS

GDAL is an open source MIT licensed translator library for raster and vector geospatial data formats.

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