[gdal-dev] Determining Native Data Field Type Names for a Given Layer or Driver

Andrew Joseph ap.joseph at live.com
Tue Sep 26 17:16:28 PDT 2017


I'm using the GDAL Java Bindings (most recent dev version 2.3.0) and looking
to determine the native datatype of a given layer field -or at least the
default mapping of the driver. For example I have manually written code like
the following for Postgres/Postgis:

  private static final BiMap<String,Integer> PG_OGR_GOMETRY_TYPE_MAP =
      new ImmutableBiMap.Builder<String, Integer>()
        .put("Point",wkbPoint)
        .put("LineString",wkbLineString)
        .put("Polygon",wkbPolygon)
        .put("Surface",wkbSurface)
        .put("Curve",wkbCurve)
        .put("MultiPoint",wkbMultiPoint)
        .put("MultiLineString",wkbMultiLineString)
        .put("MultiPolygon",wkbMultiPolygon)
        .put("GeometryCollection",wkbGeometryCollection)
        .put("CircularString",wkbCircularString)
        .put("CompoundCurve",wkbCompoundCurve)
        .put("CurvePolygon",wkbCurvePolygon)
        .put("MultiCurve",wkbMultiCurve)
        .put("MultiSurface",wkbMultiSurface)
        .put("PolyhedralSurface",wkbPolyhedralSurface)
        .build();

  private static final BiMap<String,Integer> POSTGIS_OGR_DATATYPE_MAP =
      new ImmutableBiMap.Builder<String, Integer>()
          .put("integer",OFTInteger)
          .put("real",OFTReal)
          .put("varchar",OFTString)
          .put("bytea",OFTBinary)
          .put("date",OFTDate)
          .put("time",OFTTime)
          .put("timestamp",OFTDateTime)
          .put("bigint",OFTInteger64)
          .put("integer[]",OFTIntegerList)
          .put("real[]",OFTRealList)
          .put("varchar[]",OFTStringList)
          .put("bigint[]",OFTInteger64List)
          .put("text",OFTWideString)
          .put("text[]",OFTWideStringList)
          .build();

However, it would obviously be orders of magnitude more
convenient/future-proofed to simply retrieve these mappings from the
driver/layer itself since each driver/layer must logically already have such
a mapping. In addition, is it possible to get the native datatypes that
would be generated when copying, say a shapefile to postgres without
actually copying the data itself?

I've tried layer.GetMetadata_Dict() and driver.GetMetadata_Dict() but have
come up bereft of the datatype mappings.






--
Sent from: http://osgeo-org.1560.x6.nabble.com/GDAL-Dev-f3742093.html


More information about the gdal-dev mailing list