org.gdal.ogr
Class ogr

java.lang.Object
  extended by org.gdal.ogr.ogr
All Implemented Interfaces:
ogrConstants

public class ogr
extends 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.


Field Summary
 
Fields inherited from interface org.gdal.ogr.ogrConstants
ALTER_ALL_FLAG, ALTER_NAME_FLAG, ALTER_TYPE_FLAG, ALTER_WIDTH_PRECISION_FLAG, NullFID, ODrCCreateDataSource, ODrCDeleteDataSource, ODsCCreateLayer, ODsCDeleteLayer, OFTBinary, OFTDate, OFTDateTime, OFTInteger, OFTIntegerList, OFTReal, OFTRealList, OFTString, OFTStringList, OFTTime, OFTWideString, OFTWideStringList, OGRERR_CORRUPT_DATA, OGRERR_FAILURE, OGRERR_NONE, OGRERR_NOT_ENOUGH_DATA, OGRERR_NOT_ENOUGH_MEMORY, OGRERR_UNSUPPORTED_GEOMETRY_TYPE, OGRERR_UNSUPPORTED_OPERATION, OGRERR_UNSUPPORTED_SRS, OJLeft, OJRight, OJUndefined, OLCAlterFieldDefn, OLCCreateField, OLCDeleteFeature, OLCDeleteField, OLCFastFeatureCount, OLCFastGetExtent, OLCFastSetNextByIndex, OLCFastSpatialFilter, OLCIgnoreFields, OLCRandomRead, OLCRandomWrite, OLCReorderFields, OLCSequentialWrite, OLCStringsAsUTF8, OLCTransactions, wkb25Bit, wkb25DBit, wkbGeometryCollection, wkbGeometryCollection25D, wkbLinearRing, wkbLineString, wkbLineString25D, wkbMultiLineString, wkbMultiLineString25D, wkbMultiPoint, wkbMultiPoint25D, wkbMultiPolygon, wkbMultiPolygon25D, wkbNDR, wkbNone, wkbPoint, wkbPoint25D, wkbPolygon, wkbPolygon25D, wkbUnknown, wkbXDR
 
Method Summary
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.
static Geometry BuildPolygonFromEdges(Geometry hLineCollection)
           
static Geometry BuildPolygonFromEdges(Geometry hLineCollection, int bBestEffort)
          Build a ring from a bunch of arcs.
static Geometry BuildPolygonFromEdges(Geometry hLineCollection, int bBestEffort, int bAutoClose)
          Build a ring from a bunch of arcs.
static Geometry BuildPolygonFromEdges(Geometry lineCollection, int bBestEffort, int bAutoClose, double dfTolerance)
          Build a ring from a bunch of arcs.
static Geometry CreateGeometryFromGML(String gml)
          Create a new Geometry from a GML string.
static Geometry CreateGeometryFromJson(String json)
          Create a new Geometry from a GeoJSON string.
static Geometry CreateGeometryFromWkb(byte[] wkb)
          Create a new Geometry from a well known binary (wkb) content.
static Geometry CreateGeometryFromWkb(byte[] wkb, SpatialReference srs)
          Create a new Geometry from a well known binary (wkb) content.
static Geometry CreateGeometryFromWkt(String wkt)
          Create a new Geometry from a well known text (wkt) string.
static Geometry CreateGeometryFromWkt(String wkt, SpatialReference srs)
          Create a new Geometry from a well known text (wkt) content.
static void DontUseExceptions()
          Use return code instead of exceptions.
static Geometry ForceToMultiLineString(Geometry geom)
          Convert to multilinestring.
static Geometry ForceToMultiPoint(Geometry geom)
          Convert to multipoint.
static Geometry ForceToMultiPolygon(Geometry geom)
          Convert to multipolygon.
static Geometry ForceToPolygon(Geometry geom)
          Convert to polygon.
static String[] GeneralCmdLineProcessor(String[] args)
          General utility option processing.
static String[] GeneralCmdLineProcessor(String[] args, int options)
          General utility option processing.
static Vector GeneralCmdLineProcessor(Vector args)
          General utility option processing.
static Vector GeneralCmdLineProcessor(Vector args, int options)
          General utility option processing.
static String GeometryTypeToName(int eType)
          Fetch a human readable name corresponding to an OGRwkBGeometryType value.
static Driver GetDriver(int iDriver)
          Fetch the indicated driver.
static Driver GetDriverByName(String name)
          Fetch the indicated driver.
static int GetDriverCount()
          Fetch the number of registered drivers.
static String GetFieldTypeName(int type)
          Fetch human readable name for a field type.
static DataSource GetOpenDS(int iDS)
          Return the iDS th datasource opened.
static int GetOpenDSCount()
          Return the number of opened datasources.
static DataSource Open(String filename)
          Open a file / data source with one of the registered drivers.
static DataSource Open(String filename, boolean update)
          Open a file / data source with one of the registered drivers.
static DataSource Open(String filename, int update)
          Open a file / data source with one of the registered drivers.
static DataSource OpenShared(String filename)
          Open a file / data source with one of the registered drivers.
static DataSource OpenShared(String filename, int update)
          Open a file / data source with one of the registered drivers.
static void RegisterAll()
          Register all known configured OGR drivers.
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.
static void UseExceptions()
          Use exceptions instead of error return codes.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

UseExceptions

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

This is the default behavious : 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

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(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(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(String gml)
Create a new Geometry from a GML string.

Parameters:
gml - the GML string
Returns:
the new geometry

CreateGeometryFromJson

public static Geometry CreateGeometryFromJson(String json)
Create a new Geometry from a GeoJSON string.

Parameters:
json - the GeoJSON string
Returns:
the new geometry

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,
                                             int bBestEffort,
                                             int bAutoClose)
Build a ring from a bunch of arcs.

Same as below with dfTolerance == 0.

Since:
Java bindings 1.7.0
See Also:
BuildPolygonFromEdges(Geometry lineCollection, int bBestEffort, int bAutoClose, double dfTolerance)

BuildPolygonFromEdges

public static Geometry BuildPolygonFromEdges(Geometry hLineCollection,
                                             int bBestEffort)
Build a ring from a bunch of arcs.

Same as below with bAutoClose == 0 and dfTolerance == 0.

Since:
Java bindings 1.7.0
See Also:
BuildPolygonFromEdges(Geometry lineCollection, int bBestEffort, int bAutoClose, double dfTolerance)

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

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.

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

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):

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


GeometryTypeToName

public static 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 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

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(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(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(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(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(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 Vector GeneralCmdLineProcessor(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 Vector GeneralCmdLineProcessor(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 String[] GeneralCmdLineProcessor(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:

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 String[] GeneralCmdLineProcessor(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(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)