public class DataSource extends Object
The DataSource class is a binding for the C++ OGRDataSource class.
A data source potentially consists of many layers (Layer). A data source normally consists of one, or a related set of files, though the name doesn't have to be a real item in the file system. When an DataSource is destroyed, all it's associated Layer objects are also destroyed.
Modifier and Type | Method and Description |
---|---|
Layer |
CopyLayer(Layer src_layer,
String new_name)
Duplicate an existing layer.
|
Layer |
CopyLayer(Layer src_layer,
String new_name,
Vector options)
Duplicate an existing layer.
|
Layer |
CreateLayer(String name)
Create a new layer on the data source with the indicated name.
|
Layer |
CreateLayer(String name,
SpatialReference srs)
Create a new layer on the data source with the indicated name, coordinate system.
|
Layer |
CreateLayer(String name,
SpatialReference srs,
int geom_type)
Create a new layer on the data source with the indicated name, coordinate system, geometry type.
|
Layer |
CreateLayer(String name,
SpatialReference srs,
int geom_type,
Vector options)
Create a new layer on the data source with the indicated name, coordinate system, geometry type.
|
void |
delete()
Frees the native resource associated to a DataSource object and close the file.
|
int |
DeleteLayer(int index)
Delete the indicated layer from the datasource.
|
boolean |
equals(Object obj) |
Layer |
ExecuteSQL(String statement)
Execute an SQL statement against the data store.
|
Layer |
ExecuteSQL(String statement,
Geometry spatialFilter)
Execute an SQL statement against the data store.
|
Layer |
ExecuteSQL(String statement,
Geometry spatialFilter,
String dialect)
Execute an SQL statement against the data store.
|
Driver |
GetDriver()
Returns the driver that the dataset was opened with.
|
Layer |
GetLayer(int index)
Fetch a layer by index.
|
Layer |
GetLayer(String layer_name)
Fetch a layer by name.
|
Layer |
GetLayerByIndex(int index)
Fetch a layer by index.
|
Layer |
GetLayerByName(String layer_name)
Fetch a layer by name.
|
int |
GetLayerCount()
Get the number of layers in this data source.
|
String |
getName()
Returns the name of the data source.
|
String |
GetName()
Returns the name of the data source.
|
int |
GetRefCount()
Fetch reference count.
|
StyleTable |
GetStyleTable() |
int |
GetSummaryRefCount()
Fetch reference count of datasource and all owned layers.
|
int |
hashCode() |
void |
ReleaseResultSet(Layer layer)
Release results of ExecuteSQL().
|
void |
SetStyleTable(StyleTable table) |
int |
SyncToDisk()
Flush pending changes to disk.
|
boolean |
TestCapability(String cap)
Test if capability is available.
|
public void delete()
This method will delete the underlying C++ object. After it has been called, all native resources will have been destroyed, so it will be illegal (and likely to cause JVM crashes) to use any method on this object or any derived objects, such as Layer objects of this Dataset.
The delete() method must be called when a datasource has been opened in update or creation mode, otherwise data might not be properly flushed to the disk. You cannot rely on the finalization to call delete().
public Layer GetLayer(int index)
The returned layer remains owned by the DataSource and should not be deleted by the application.
index
- a layer number between 0 and GetLayerCount()-1.public Layer GetLayer(String layer_name)
layer_name
- the layer name of the layer to fetch.public String getName()
This string should be sufficient to open the data source if passed to the same Driver that this data source was opened with, but it need not be exactly the same string that was used to open the data source. Normally this is a filename.
public int GetRefCount()
public int GetSummaryRefCount()
public int GetLayerCount()
public Driver GetDriver()
public String GetName()
This string should be sufficient to open the data source if passed to the same Driver that this data source was opened with, but it need not be exactly the same string that was used to open the data source. Normally this is a filename.
public int DeleteLayer(int index)
If this method is supported the ODsCDeleteLayer capability will test true on the DataSource.
index
- the index of the layer to delete.public int SyncToDisk()
This call is intended to force the datasource to flush any pending writes to disk, and leave the disk file in a consistent state. It would not normally have any effect on read-only datasources.
Some data sources do not implement this method, and will still return ogr.OGRERR_NONE. An error is only returned if an error occurs while attempting to flush to disk.
The default implementation of this method just calls the SyncToDisk() method on each of the layers. Conceptionally, calling SyncToDisk() on a datasource should include any work that might be accomplished by calling SyncToDisk() on layers in that data source.
In any event, you should always close any opened datasource with delete() that will ensure all data is correctly flushed.
public Layer CreateLayer(String name, SpatialReference srs, int geom_type, Vector options)
The options argument can be used to control driver specific creation options. These options are normally documented in the format specific documentation.
Example:
Layer layer; Vector options = new Vector(); if( !ds.TestCapability( ogr.ODsCCreateLayer ) ) { ... } options.add("DIM=2"); layer = ds.CreateLayer( "NewLayer", null, ogr.wkbUnknown, options ); if( layer == null ) { ... }
name
- the name for the new layer. This should ideally not
match any existing layer on the datasource.srs
- the coordinate system to use for the new layer, or null if
no coordinate system is available.geom_type
- the geometry type for the layer. Use ogr.wkbUnknown if there
are no constraints on the types geometry to be written.options
- a vector of strings of the format name=value. Options are driver
specific, and driver information can be found at the following url:
OGR Formatspublic Layer CreateLayer(String name, SpatialReference srs, int geom_type)
Same as below with options == null.
CreateLayer(String name, SpatialReference srs, int geom_type, java.util.Vector options)
public Layer CreateLayer(String name, SpatialReference srs)
Same as below with geom_type == ogr.wkbUnknown and options == null.
CreateLayer(String name, SpatialReference srs, int geom_type, java.util.Vector options)
public Layer CreateLayer(String name)
Same as below with srs == null, geom_type == ogr.wkbUnknown and options == null.
CreateLayer(String name, SpatialReference srs, int geom_type, java.util.Vector options)
public Layer CopyLayer(Layer src_layer, String new_name, Vector options)
This function creates a new layer, duplicate the field definitions of the source layer and then duplicate each features of the source layer. The papszOptions argument can be used to control driver specific creation options. These options are normally documented in the format specific documentation. The source layer may come from another dataset.
src_layer
- source layer.new_name
- the name of the layer to create.options
- a StringList of name=value options. Options are driver
specific, and driver information can be found at the following url:
OGR Formatspublic Layer CopyLayer(Layer src_layer, String new_name)
Same as below with options == null.
CopyLayer(Layer src_layer, String new_name, java.util.Vector options)
public Layer GetLayerByIndex(int index)
The returned layer remains owned by the DataSource and should not be deleted by the application.
index
- a layer number between 0 and GetLayerCount()-1.public Layer GetLayerByName(String layer_name)
The returned layer remains owned by the DataSource and should not be deleted by the application.
layer_name
- the layer name of the layer to fetch.public boolean TestCapability(String cap)
One of the following data source capability names can be passed into this method, and a true or false value will be returned indicating whether or not the capability is available for this object.
The constant forms of the capability names should be used in preference to the strings themselves to avoid mispelling.
cap
- the capability to test.public Layer ExecuteSQL(String statement, Geometry spatialFilter, String dialect)
The result of an SQL query is either null for statements that are in error, or that have no results set, or a Layer representing a results set from the query. Note that this Layer is in addition to the layers in the data store and must be destroyed with ReleaseResultsSet() before the data source is closed (destroyed).
For more information on the SQL dialect supported internally by OGR review the OGR SQL document. Some drivers (ie. Oracle and PostGIS) pass the SQL directly through to the underlying RDBMS.
statement
- the SQL statement to execute.spatialFilter
- geometry which represents a spatial filter.dialect
- allows control of the statement dialect. By default it
is assumed to be "generic" SQL, whatever that is.public Layer ExecuteSQL(String statement, Geometry spatialFilter)
Same as below with dialect = ""
ExecuteSQL(String statement, Geometry spatialFilter, String dialect)
public Layer ExecuteSQL(String statement)
Same as below with spatialFilter == null and dialect = ""
ExecuteSQL(String statement, Geometry spatialFilter, String dialect)
public void ReleaseResultSet(Layer layer)
This method should only be used to deallocate Layers resulting from an ExecuteSQL() call on the same DataSource. Failure to deallocate a results set before destroying the DataSource may cause errors.
layer
- the result of a previous ExecuteSQL() call.public StyleTable GetStyleTable()
public void SetStyleTable(StyleTable table)