0

I have no trouble reading files of different types using GDAL's Java bindings (version 2.2.1) via the org.gdal.ogr.ogr.OpenShared(filePath) method to create a DataSource. If I want to create a SQLite file from a DataSource, however, how would I do it?

Looking in the JavaDocs, I've found some ExportTo methods on the Geometry object that you can use to manually build GeoJSON, WKT, KML and others: http://gdal.org/java/org/gdal/ogr/Geometry.html

There doesn't seem to be anything in the Driver class that would let you use them to export a DataSource however.

Using ogr2ogr it would be as simple as running the following:

ogr2ogr -f "SQLite" ./output.sqlite3 ./input.geojson

And there is this technique for running ogr2ogr from within Java, but I would have assumed there'd be something native in the Java bindings.

Brideau
  • 4,564
  • 4
  • 24
  • 33

1 Answers1

0

I've accepted that the best way to do this is to simply include the ogr2ogr.java file from the GitHub repo in my project and wrap it in a function that makes it cleaner to access. It is almost a direct port of the original C++ GDAL file.

The one change I made was to rename the ogr2ogr main function to execute so that it didn't confuse application when I ran it.

Brideau
  • 4,564
  • 4
  • 24
  • 33