如何在JavaGDAL中使用ogr2ogr

如何在JavaGDAL中使用ogr2ogr,java,geojson,gdal,ogr,java-binding,Java,Geojson,Gdal,Ogr,Java Binding,我想在JavaGDAL中编写ogr2ogr-f GeoJSON destination.GeoJSON source.GeoJSON-s_srs EPSG:3068-t_srs EPSG:4326。我试图通过查看了解它应该如何工作,但由于ogr2ogr有许多用途,我无法完全理解什么与我相关。以下是我的尝试: public static void ogr2ogr(String name, String sourceSRS, String destSRS) { ogr.Regist

我想在JavaGDAL中编写ogr2ogr-f GeoJSON destination.GeoJSON source.GeoJSON-s_srs EPSG:3068-t_srs EPSG:4326。我试图通过查看了解它应该如何工作,但由于ogr2ogr有许多用途,我无法完全理解什么与我相关。以下是我的尝试:

public static void ogr2ogr(String name, String sourceSRS, String destSRS) {

        ogr.RegisterAll();
        String pszFormat = "GeoJSON";
        DataSource poDS = ogr.Open(name + "_" + sourceSRS+".geojson", false);

        /* -------------------------------------------------------------------- */
        /* Try opening the output datasource as an existing, writable */
        /* -------------------------------------------------------------------- */
        DataSource poODS = ogr.Open(name + "_" + destSRS+".geojson", 0);
        Driver poDriver = ogr.GetDriverByName(pszFormat);
        SpatialReference poOutputSRS = new SpatialReference();
        poOutputSRS.SetFromUserInput( destSRS );
        SpatialReference poSourceSRS = new SpatialReference();
        poSourceSRS.SetFromUserInput( sourceSRS );
        CoordinateTransformation poCT  = CoordinateTransformation.CreateCoordinateTransformation( poSourceSRS, poOutputSRS );
        Layer poDstLayer = poODS.GetLayerByName("bla");
        Feature poDstFeature = new Feature( poDstLayer.GetLayerDefn() );
        Geometry poDstGeometry = poDstFeature.GetGeometryRef();
        int eErr = poDstGeometry.Transform( poCT );
        poDstLayer.CommitTransaction();
        poDstGeometry.AssignSpatialReference(poOutputSRS);
    }
我在poOutputSRS.SetFromUserInput destSRS获得此异常;那就是第99行:

ERROR 3: Cannot open file 'C:\Users\Users\Desktop\test\target_EPSG4326.geojson'
Exception in thread "main" java.lang.RuntimeException: OGR Error: Corrupt data
    at org.gdal.osr.osrJNI.SpatialReference_SetFromUserInput(Native Method)
    at org.gdal.osr.SpatialReference.SetFromUserInput(SpatialReference.java:455)
    at wmsRasterToGeojsonVector.GdalJava.ogr2ogr(GdalJava.java:99)
    at wmsRasterToGeojsonVector.GdalJava.main(GdalJava.java:30)