1

我想ogr2ogr -f "GeoJSON" destination.geojson source.geojson -s_srs EPSG:3068 -t_srs EPSG:4326用 java-gdal 编写代码。我试图通过查看这个示例来了解它应该如何工作,但由于 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)
4

0 回答 0