OSGeo / gdal

GDAL is an open source MIT licensed translator library for raster and vector geospatial data formats.
https://gdal.org
Other
4.8k stars 2.51k forks source link

How to convert GeoPackage to MBTiles vector tiles on Android #10871

Closed huytm2k3 closed 2 days ago

huytm2k3 commented 3 days ago

What is the bug?

Cannot convert gpkg to mbtitles with ogr2ogr.java

Steps to reproduce the issue

I'm trying to convert a .gpkg file to MBTiles vector format on Android with ogr2ogr.java (https://github.com/OSGeo/gdal/blob/master/swig/java/apps/ogr2ogr.java) But it throws this error: Only Byte supported. (Although it works if I replace MBTiles driver with GeoJSON)

How do I fix that?

Many thanks!

Versions and provenance

3.7.0

Additional context

No response

huytm2k3 commented 3 days ago

This is my React Native JS code:

const result = await GdalModule.RNOgr2ogr([
        '-f', 'MBTiles',
        outputPath,
        primaryFile.destinationPath,
        '-s_srs', 'EPSG:4326',
        '-t_srs', 'EPSG:3857',
        '-dsco', 'MAXZOOM=20',
        '-dsco', 'MINZOOM=12',
        '-dsco', 'FORMAT=MBTILES',
        '-dsco', 'MAX_SIZE=1500000',
        '-dsco', 'EXTENT=8192',
        '-lco', 'MAXZOOM=20',
        '-lco', 'MINZOOM=12'
])

And my native code:

@ReactMethod
    public void RNOgr2ogr(ReadableArray args, Promise promise) {
        try {
            // Convert ReadableArray to String[]
            String[] strArgs = new String[args.size()];
            for (int i = 0; i < args.size(); i++) {
                strArgs[i] = args.getString(i);
            }
            // Pass the string array to ogr2ogr
            ogr2ogr.main(strArgs);
            promise.resolve("Success");
        } catch (Exception e) {
            promise.reject("GDAL_ERROR", e);
        }
    }
lnicola commented 3 days ago

This comes from https://github.com/OSGeo/gdal/blob/master/frmts/mbtiles/mbtilesdataset.cpp#L2997-L3001.

Just to make sure, you said that the equivalent ogr2ogr invocation (with all the creation options) works on a computer?

huytm2k3 commented 3 days ago

This comes from https://github.com/OSGeo/gdal/blob/master/frmts/mbtiles/mbtilesdataset.cpp#L2997-L3001.

Just to make sure, you said that the equivalent ogr2ogr invocation (with all the creation options) works on a computer?

Yes, it works on my computer when I use ogr2ogr with all the creation options above

jratike80 commented 3 days ago

The error comes from a wrong raster data type. It is an odd error if ogr2ogr is used. Maybe your Android build lacks something that is needed for MBTiles vectors. Does it have GEOS?

huytm2k3 commented 3 days ago

The error comes from a wrong raster data type. It is an odd error if ogr2ogr is used. Maybe your Android build lacks something that is needed for MBTiles vectors. Does it have GEOS?

I think I'm really missing GEOS, I'm trying to rebuild gdal.

Thank you <3

rouault commented 3 days ago

I should note that ogr2ogr.java is more a "toy" application nowadays compared to the C++ ogr2ogr, although it should still work OK for basic use cases. You might better succeed with org.gdal.gdal.VectorTranslate(): https://gdal.org/en/latest/java/org/gdal/gdal/gdal.html#VectorTranslate(java.lang.String,org.gdal.gdal.Dataset,org.gdal.gdal.VectorTranslateOptions) , which is the API entry point for ogr2ogr. In any case, you should definitely first by starting to have a GDAL build against GEOS to be able to generate vector tiles.