Skip to main content
100%

Using ogr2ogr from Scala

✓ Published0🌍 Public
BBrideau
Last edited Nov 25, 2017
Created on Nov 25, 2017

This example demonstrates how to invoke the GDAL `ogr2ogr` command-line utility directly from a Scala application to convert geographic data between formats. The code uses the `org.gdal.apps.ogr2ogr` class to execute conversions asynchronously via Scala’s `Future`, allowing non-blocking file processing. It shows two distinct conversions: one to ESRI Shapefile using default settings, and another to CSV with custom layer creation options (`-lco`) for geometry as WKT, automatic `.csvt` generation, and semicolon separators. The example reads from a GeoPackage input file and writes to organized subdirectories, demonstrating path handling with `java.nio.file.Paths` and directory creation via `Files.createDirectories`. Error handling is implemented through Scala’s `Try`-style success/failure callbacks.

AI-generated description

Similar vizzes