Package org.gdal.ogr

Class ogr

  • All Implemented Interfaces:
    ogrConstants

    public class ogr
    extends java.lang.Object
    implements ogrConstants
    Class ogr is an uninstanciable class providing various utility functions as static methods.

    In particular, it provides ogr.RegisterAll() and ogr.Open() methods.

    • Method Detail

      • UseExceptions

        public static void UseExceptions()
        Use exceptions instead of error return codes.

        This is the default behavior : methods that in C/C++ return an OGRErr return code would throw a RuntimeException() in case the code it is different from ogr.OGRERR_NONE. By calling this method, you can get back to that original state if DontUseExceptions() was called in-between. This will only apply to the org.gdal.ogr.* package.

        Since:
        Java bindings 1.7.0
      • DontUseExceptions

        public static void DontUseExceptions()
        Use return code instead of exceptions.

        By default, methods that in C/C++ return an OGRErr return code would throw a RuntimeException() in case the code it is different from ogr.OGRERR_NONE. By calling this method, you can prevent the exception to be thrown and get the original error code (ogr.OGRERR_* codes) This will only apply to the org.gdal.ogr.* package.

        Since:
        Java bindings 1.7.0
      • GetUseExceptions

        public static boolean GetUseExceptions()
      • GetGEOSVersionMajor

        public static int GetGEOSVersionMajor()
      • GetGEOSVersionMinor

        public static int GetGEOSVersionMinor()
      • GetGEOSVersionMicro

        public static int GetGEOSVersionMicro()
      • CreateGeometryFromWkb

        public static Geometry CreateGeometryFromWkb​(byte[] wkb,
                                                     SpatialReference srs)
        Create a new Geometry from a well known binary (wkb) content.
        Parameters:
        wkb - the wkb content
        srs - the srs to assign to the geometry
        Returns:
        the new geometry
      • CreateGeometryFromWkb

        public static Geometry CreateGeometryFromWkb​(byte[] wkb)
        Create a new Geometry from a well known binary (wkb) content.
        Parameters:
        wkb - the wkb content
        Returns:
        the new geometry
        Since:
        Java bindings 1.7.0
      • CreateGeometryFromWkt

        public static Geometry CreateGeometryFromWkt​(java.lang.String wkt,
                                                     SpatialReference srs)
        Create a new Geometry from a well known text (wkt) content.
        Parameters:
        wkt - the wkt content
        srs - the srs to assign to the geometry
        Returns:
        the new geometry
      • CreateGeometryFromWkt

        public static Geometry CreateGeometryFromWkt​(java.lang.String wkt)
        Create a new Geometry from a well known text (wkt) string.
        Parameters:
        wkt - the wkt content
        Returns:
        the new geometry
        Since:
        Java bindings 1.7.0
      • CreateGeometryFromGML

        public static Geometry CreateGeometryFromGML​(java.lang.String gml)
        Create a new Geometry from a GML string.
        Parameters:
        gml - the GML string
        Returns:
        the new geometry
      • CreateGeometryFromJson

        public static Geometry CreateGeometryFromJson​(java.lang.String json)
        Create a new Geometry from a GeoJSON string.
        Parameters:
        json - the GeoJSON string
        Returns:
        the new geometry
      • CreateGeometryFromEsriJson

        public static Geometry CreateGeometryFromEsriJson​(java.lang.String input_string)
      • BuildPolygonFromEdges

        public static Geometry BuildPolygonFromEdges​(Geometry lineCollection,
                                                     int bBestEffort,
                                                     int bAutoClose,
                                                     double dfTolerance)
        Build a ring from a bunch of arcs.
        Parameters:
        lineCollection - geometry of type OGRGeometryCollection (or OGRMultiLineString) containing the line string geometries to be built into rings.
        bBestEffort - not yet implemented???.
        bAutoClose - indicates if the ring should be close when first and last points of the ring are the same.
        dfTolerance - tolerance into which two arcs are considered close enough to be joined.
        Returns:
        a polygon or null in case of failure
      • BuildPolygonFromEdges

        public static Geometry BuildPolygonFromEdges​(Geometry hLineCollection)
      • ApproximateArcAngles

        public static Geometry ApproximateArcAngles​(double dfCenterX,
                                                    double dfCenterY,
                                                    double dfZ,
                                                    double dfPrimaryRadius,
                                                    double dfSecondaryRadius,
                                                    double dfRotation,
                                                    double dfStartAngle,
                                                    double dfEndAngle,
                                                    double dfMaxAngleStepSizeDegrees)
        Stroke arc to linestring.

        Stroke an arc of a circle to a linestring based on a center point, radius, start angle and end angle, all angles in degrees.

        Parameters:
        dfCenterX - center X
        dfCenterY - center Y
        dfZ - center Z
        dfPrimaryRadius - X radius of ellipse.
        dfSecondaryRadius - Y radius of ellipse.
        dfRotation - rotation of the ellipse clockwise.
        dfStartAngle - angle to first point on arc (clockwise of X-positive)
        dfEndAngle - angle to last point on arc (clockwise of X-positive)
        dfMaxAngleStepSizeDegrees - the largest step in degrees along the arc.
        Returns:
        LineString geometry representing an approximation of the arc.
        Since:
        Java bindings 1.7.0
      • ForceToPolygon

        public static Geometry ForceToPolygon​(Geometry geom)
        Convert to polygon.

        Tries to force the provided geometry to be a polygon. Currently this just effects a change on multipolygons.

        Note: contrary to the C/C++ method, a new object is returned.

        Parameters:
        geom - the input geometry
        Returns:
        new geometry.
        Since:
        Java bindings 1.8.0
      • ForceToLineString

        public static Geometry ForceToLineString​(Geometry geom_in)
      • ForceToMultiPolygon

        public static Geometry ForceToMultiPolygon​(Geometry geom)
        Convert to multipolygon.

        Tries to force the provided geometry to be a multipolygon. Currently this just effects a change on polygons.

        Note: contrary to the C/C++ method, a new object is returned.

        Parameters:
        geom - the input geometry
        Returns:
        new geometry.
        Since:
        Java bindings 1.8.0
      • ForceToMultiPoint

        public static Geometry ForceToMultiPoint​(Geometry geom)
        Convert to multipoint.

        Tries to force the provided geometry to be a multipoint. Currently this just effects a change on points.

        Note: contrary to the C/C++ method, a new object is returned.

        Parameters:
        geom - the input geometry
        Returns:
        new geometry.
        Since:
        Java bindings 1.8.0
      • ForceToMultiLineString

        public static Geometry ForceToMultiLineString​(Geometry geom)
        Convert to multilinestring.

        Tries to force the provided geometry to be a multilinestring.

        • linestrings are placed in a multilinestring.
        • geometry collections will be converted to multilinestring if they only contain linestrings.
        • polygons will be changed to a collection of linestrings (one per ring).

        Note: contrary to the C/C++ method, a new object is returned.

        Parameters:
        geom - the input geometry
        Returns:
        new geometry.
        Since:
        Java bindings 1.8.0
      • ForceTo

        public static Geometry ForceTo​(Geometry geom_in,
                                       int eTargetType,
                                       java.util.Vector options)
      • ForceTo

        public static Geometry ForceTo​(Geometry geom_in,
                                       int eTargetType)
      • CreateRangeFieldDomain

        public static FieldDomain CreateRangeFieldDomain​(java.lang.String name,
                                                         java.lang.String description,
                                                         int type,
                                                         int subtype,
                                                         double min,
                                                         boolean minIsInclusive,
                                                         double max,
                                                         double maxIsInclusive)
      • CreateGlobFieldDomain

        public static FieldDomain CreateGlobFieldDomain​(java.lang.String name,
                                                        java.lang.String description,
                                                        int type,
                                                        int subtype,
                                                        java.lang.String glob)
      • GetDriverCount

        public static int GetDriverCount()
        Fetch the number of registered drivers.
        Returns:
        the drivers count.
      • GetOpenDSCount

        public static int GetOpenDSCount()
        Return the number of opened datasources.
        Returns:
        the number of opened datasources.
      • SetGenerate_DB2_V72_BYTE_ORDER

        public static int SetGenerate_DB2_V72_BYTE_ORDER​(int bGenerate_DB2_V72_BYTE_ORDER)
        Special entry point to enable the hack for generating DB2 V7.2 style WKB.

        DB2 seems to have placed (and require) an extra 0x30 or'ed with the byte order in WKB. This entry point is used to turn on or off the generation of such WKB.

      • RegisterAll

        public static void RegisterAll()
        Register all known configured OGR drivers.

        This function will drive any of the following that are configured into OGR. Many others as well that haven't been updated in this documentation (see full list):

        • Arc/Info Binary Coverage
        • Arc/Info .E00 (ASCII) Coverage
        • Atlas BNA
        • Comma Separated Value (.csv)
        • DODS/OPeNDAP
        • ESRI Personal GeoDatabase
        • ESRI ArcSDE
        • ESRI Shapefile
        • FMEObjects Gateway
        • GeoJSON
        • Geoconcept Export
        • GeoRSS
        • GML
        • GMT
        • GPX
        • GRASS
        • Informix DataBlade
        • INTERLIS
        • INGRES
        • KML
        • Mapinfo File
        • Microstation DGN
        • Memory
        • MySQL
        • Oracle Spatial
        • ODBC
        • OGDI Vectors
        • PostgreSQL
        • S-57 (ENC)
        • SDTS
        • SQLite
        • UK .NTF
        • U.S. Census TIGER/Line
        • VRT - Virtual Datasource
        • X-Plane/Flightgear aeronautical data

        This function should generally be called once at the beginning of the application.

      • GeometryTypeToName

        public static java.lang.String GeometryTypeToName​(int eType)
        Fetch a human readable name corresponding to an OGRwkBGeometryType value.
        Parameters:
        eType - the geometry type.
        Returns:
        human readable string, or null on failure.
        Since:
        Java bindings 1.7.0
      • GetFieldTypeName

        public static java.lang.String GetFieldTypeName​(int type)
        Fetch human readable name for a field type.
        Parameters:
        type - the field type to get name for.
        Returns:
        field type name
        Since:
        Java bindings 1.7.0
      • GetFieldSubTypeName

        public static java.lang.String GetFieldSubTypeName​(int type)
      • GT_Flatten

        public static int GT_Flatten​(int eType)
      • GT_SetZ

        public static int GT_SetZ​(int eType)
      • GT_SetM

        public static int GT_SetM​(int eType)
      • GT_SetModifier

        public static int GT_SetModifier​(int eType,
                                         int bSetZ,
                                         int bSetM)
      • GT_SetModifier

        public static int GT_SetModifier​(int eType,
                                         int bSetZ)
      • GT_HasZ

        public static int GT_HasZ​(int eType)
      • GT_HasM

        public static int GT_HasM​(int eType)
      • GT_IsSubClassOf

        public static int GT_IsSubClassOf​(int eType,
                                          int eSuperType)
      • GT_IsCurve

        public static int GT_IsCurve​(int arg0)
      • GT_IsSurface

        public static int GT_IsSurface​(int arg0)
      • GT_IsNonLinear

        public static int GT_IsNonLinear​(int arg0)
      • GT_GetCollection

        public static int GT_GetCollection​(int eType)
      • GT_GetCurve

        public static int GT_GetCurve​(int eType)
      • GT_GetLinear

        public static int GT_GetLinear​(int eType)
      • SetNonLinearGeometriesEnabledFlag

        public static void SetNonLinearGeometriesEnabledFlag​(int bFlag)
      • GetNonLinearGeometriesEnabledFlag

        public static int GetNonLinearGeometriesEnabledFlag()
      • GetOpenDS

        public static DataSource GetOpenDS​(int iDS)
        Return the iDS th datasource opened.
        Parameters:
        iDS - the index of the dataset to return (between 0 and GetOpenDSCount() - 1)
      • Open

        public static DataSource Open​(java.lang.String filename,
                                      int update)
        Open a file / data source with one of the registered drivers.

        This method loops through all the drivers registered with the driver manager trying each until one succeeds with the given data source.

        If this method fails, gdal.GetLastErrorMsg() can be used to check if there is an error message explaining why.

        The returned dataset should be properly closed with the DataSource.delete() method.

        Example:

            DataSource ds = ogr.Open( "polygon.shp" );
            if( ds == null )
            {
                return;
            }
        
            ... use the data source ...
        
            ds.delete();
          
        Parameters:
        filename - the name of the file, or data source to open.
        update - 0 for read-only access (the default) or 1 for read-write access.
        Returns:
        null on error or if the pass name is not supported by this driver, otherwise a pointer to an DataSource. This DataSource should be closed by calling the delete() method when it is no longer needed.
      • Open

        public static DataSource Open​(java.lang.String filename)
        Open a file / data source with one of the registered drivers.

        Same as below with update == 0

        Since:
        Java bindings 1.7.0
        See Also:
        Open(String filename, int update)
      • OpenShared

        public static DataSource OpenShared​(java.lang.String filename,
                                            int update)
        Open a file / data source with one of the registered drivers.

        This first try finding an existing open dataset matching exactly on the original datasource raw name used to open the datasource.

        NOTE: It is an error, but currently we ignore the bUpdate, and return whatever is open even if it is read-only and the application requested update access.

        See Also:
        Open(String filename, int update)
      • OpenShared

        public static DataSource OpenShared​(java.lang.String filename)
        Open a file / data source with one of the registered drivers.

        This first try finding an existing open dataset matching exactly on the original datasource raw name used to open the datasource.

        NOTE: It is an error, but currently we ignore the bUpdate, and return whatever is open even if it is read-only and the application requested update access.

        Since:
        Java bindings 1.7.0
        See Also:
        Open(String filename, int update)
      • GetDriverByName

        public static Driver GetDriverByName​(java.lang.String name)
        Fetch the indicated driver.
        Parameters:
        name - the driver name
        Returns:
        the driver, or null if no driver with that name is found
      • GetDriver

        public static Driver GetDriver​(int iDriver)
        Fetch the indicated driver.
        Parameters:
        iDriver - the driver index, from 0 to GetDriverCount()-1.
        Returns:
        the driver, or null if iDriver is out of range.
      • GeneralCmdLineProcessor

        public static java.util.Vector GeneralCmdLineProcessor​(java.util.Vector args,
                                                               int options)
        General utility option processing.

        Same as below but with arguments as a Vector of strings

        Returns:
        updated argument list as a new Vector of strings
        Since:
        Java bindings 1.7.0
        See Also:
        GeneralCmdLineProcessor(String[] args, int options)
      • GeneralCmdLineProcessor

        public static java.util.Vector GeneralCmdLineProcessor​(java.util.Vector args)
        General utility option processing.

        Same as below but with arguments as a Vector of strings and options == 0

        Returns:
        updated argument list as a new Vector of strings
        Since:
        Java bindings 1.7.0
        See Also:
        GeneralCmdLineProcessor(String[] args, int options)
      • GeneralCmdLineProcessor

        public static java.lang.String[] GeneralCmdLineProcessor​(java.lang.String[] args,
                                                                 int options)
        General utility option processing.

        This function is intended to provide a variety of generic commandline options for all OGR commandline utilities. It takes care of the following commandline options:

        • --version: report version of OGR in use.
        • --license: report OGR license info.
        • --formats: report all format drivers configured.
        • --format [format]: report details of one format driver.
        • --optfile filename: expand an option file into the argument list.
        • --config key value: set system configuration option.
        • --debug [on/off/value]: set debug level.
        • --mempreload dir: preload directory contents into /vsimem
        • --help-general: report detailed help on general options.

        The typical usage looks something like the following. Note that the formats should be registered so that the --formats and --format options will work properly.

          public static void main( Strings[] args )
          {
            ogr.RegisterAll();
        
            args = ogr.GeneralCmdLineProcessor( args, 0 );
          }
         
        Parameters:
        args - the argument list array
        options - currently unused
        Returns:
        updated argument list array.
        Since:
        Java bindings 1.7.0
      • GeneralCmdLineProcessor

        public static java.lang.String[] GeneralCmdLineProcessor​(java.lang.String[] args)
        General utility option processing.

        Same as below with options == 0

        Since:
        Java bindings 1.7.0
        See Also:
        GeneralCmdLineProcessor(String[] args, int options)
      • Open

        public static DataSource Open​(java.lang.String filename,
                                      boolean update)
        Open a file / data source with one of the registered drivers.

        Same as below with boolean value being transformed to 1 (for true) or 0 (for false)

        Since:
        Java bindings 1.7.0
        See Also:
        Open(String filename, int update)