Package org.geotools.geopkg
Class GeoPackage
Object
GeoPackage
- All Implemented Interfaces:
Closeable
,AutoCloseable
Provides access to a GeoPackage database.
- Author:
- Justin Deoliveira, OpenGeo, Niels Charlier
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
Add this among a AttributeType user data, in order to force a particularDataColumn
description for it.static final String
static final String
static final String
protected static final int
protected static final int
static final String
static final String
static String
The user version for GeoPackage 1.2 onwardsstatic final String
static final String
static final String
static final String
Adding this key into aPropertyType.getUserData()
with a value of true will allow creating tables without registering them as feature entries in the GeoPackage.static final String
static final String
static final String
static final String
protected GeoPkgGeomWriter.Configuration
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new empty GeoPackage, generating a new file.GeoPackage
(File file) Creates a GeoPackage from an existing file.GeoPackage
(File file, String user, String passwd) Creates a GeoPackage from an existing file specifying database credentials.GeoPackage
(File file, String user, String passwd, boolean readOnly) Creates a GeoPackage from an existing file specifying database credentials.GeoPackage
(File file, SQLiteConfig config, Map<String, Object> storeParams) GeoPackage
(JDBCDataStore dataStore) Builds a GeoPackage from the given store (that has supposedly been created by the {@link GeoPkgDataStoreFactory)}. -
Method Summary
Modifier and TypeMethodDescriptionvoid
add
(FeatureEntry entry, SimpleFeatureSource source, Filter filter) Adds a new feature dataset to the geopackage.void
add
(FeatureEntry entry, SimpleFeatureCollection collection) Adds a new feature dataset to the geopackage.void
Adds a tile to the geopackage.void
addCRS
(int srid) Adds an epsg crs to the geopackage, registering it in the spatial_ref_sys table.static void
addCRS
(Connection cx, int srid, String srsName, String organization, int organizationCoordSysId, String definition, String description) void
addCRS
(CoordinateReferenceSystem crs, String auth, int srid) Adds a crs to the geopackage, registering it in the spatial_ref_sys table.protected static void
void
void
close()
Closes the geopackage database connection.contents()
Returns list of contents of the geopackage.void
create
(FeatureEntry entry, SimpleFeatureType schema) Creates a new feature entry in the geopackage.void
Creates a new tile entry in the geopackage.void
Create a spatial indexLooks up a feature entry by name.protected FeatureEntry
feature
(String name, Connection cx) features()
Lists all the feature entries in the geopackage.static int
findSRID
(Connection cx, CoordinateReferenceSystem crs) The database data source.static SimpleDateFormat
Returns a new instance of SimpleDateFormat with the default GeoPackage ISO formatting<T extends GeoPkgExtension>
TgetExtension
(Class<T> extensionClass) Returns the extension by class, or null if the extension is not supported by this implementationgetExtension
(String name) Returns the extension by name, or null if the extension is not supported by this implementationgetFile()
The underlying database file.protected String
getSpatialIndexName
(FeatureEntry entry) int
getTileBound
(TileEntry entry, int zoom, boolean isMax, boolean isRow) Retrieve tile boundaries (min row, max row, min column and max column) for a particular zoom level, available in the actual databoolean
hasSpatialIndex
(FeatureEntry entry) Verifies if a spatial index is presentvoid
init()
Initializes the geopackage database.reader
(FeatureEntry entry, Filter filter, Transaction tx) Returns a reader for the contents of a feature dataset.reader
(TileEntry entry, Integer lowZoom, Integer highZoom, Integer lowCol, Integer highCol, Integer lowRow, Integer highRow) Retrieve tiles within certain zooms and column/row boundaries.searchSpatialIndex
(FeatureEntry entry, Double minX, Double minY, Double maxX, Double maxY) Searches a spatial index.Looks up a tile entry by name.tiles()
Lists all the tile entries in the geopackage.writer
(FeatureEntry entry, boolean append, Filter filter, Transaction tx) Returns a writer used to modify or add to the contents of a feature dataset.
-
Field Details
-
GEOPACKAGE_CONTENTS
- See Also:
-
GEOMETRY_COLUMNS
- See Also:
-
SPATIAL_REF_SYS
- See Also:
-
DATA_COLUMNS
- See Also:
-
TILE_MATRIX_METADATA
- See Also:
-
METADATA
- See Also:
-
METADATA_REFERENCE
- See Also:
-
TILE_MATRIX_SET
- See Also:
-
DATA_COLUMN_CONSTRAINTS
- See Also:
-
EXTENSIONS
- See Also:
-
SPATIAL_INDEX
- See Also:
-
SCHEMA
- See Also:
-
SKIP_REGISTRATION
Adding this key into aPropertyType.getUserData()
with a value of true will allow creating tables without registering them as feature entries in the GeoPackage. Used by extensions to create extra feature tables that should be visible only by clients aware of the specific extension intent and usage.- See Also:
-
DATA_COLUMN
Add this among a AttributeType user data, in order to force a particularDataColumn
description for it. It can be required to add more metadata, to force a mime type, or have fine grained control over its constraints- See Also:
-
GENERIC_GEOGRAPHIC_SRID
protected static final int GENERIC_GEOGRAPHIC_SRID- See Also:
-
GENERIC_PROJECTED_SRID
protected static final int GENERIC_PROJECTED_SRID- See Also:
-
GPKG_120_USER_VERSION
The user version for GeoPackage 1.2 onwards -
writerConfig
-
-
Constructor Details
-
GeoPackage
Creates a new empty GeoPackage, generating a new file.- Throws:
IOException
-
GeoPackage
Creates a GeoPackage from an existing file.This constructor assumes no credentials are required to connect to the database.
- Throws:
IOException
-
GeoPackage
Creates a GeoPackage from an existing file specifying database credentials.- Throws:
IOException
-
GeoPackage
Creates a GeoPackage from an existing file specifying database credentials.- Throws:
IOException
-
GeoPackage
Builds a GeoPackage from the given store (that has supposedly been created by the {@link GeoPkgDataStoreFactory)}. Used to get access to lower level methods and internals of the GeoPackage.- Parameters:
dataStore
-
-
GeoPackage
public GeoPackage(File file, SQLiteConfig config, Map<String, Object> storeParams) throws IOException- Throws:
IOException
-
-
Method Details
-
getWriterConfiguration
-
getFile
The underlying database file.Note: this value may be
null
depending on how the geopackage was initialized. -
getDataSource
The database data source. -
init
Initializes the geopackage database.This method creates all the necessary metadata tables.
- Throws:
IOException
-
close
public void close()Closes the geopackage database connection.The application should always call this method when done with a geopackage to prevent connection leakage.
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-
addCRS
Adds an epsg crs to the geopackage, registering it in the spatial_ref_sys table.This method will look up the srid in the local epsg database. Use
#addCRS(CoordinateReferenceSystem, int)
to specify an explicit CRS, authority, code entry.- Throws:
IOException
-
addDefaultSpatialReferences
- Throws:
SQLException
-
addCRS
public static void addCRS(Connection cx, int srid, String srsName, String organization, int organizationCoordSysId, String definition, String description) throws IOException - Throws:
IOException
-
addCRS
Adds a crs to the geopackage, registering it in the spatial_ref_sys table.- Parameters:
crs
- The crs to add.auth
- The authority code, example: epsgsrid
- The spatial reference system id.- Throws:
IOException
-
contents
Returns list of contents of the geopackage. -
features
Lists all the feature entries in the geopackage.- Throws:
IOException
-
feature
Looks up a feature entry by name.- Parameters:
name
- THe name of the feature entry.- Returns:
- The entry, or
null
if no such entry exists. - Throws:
IOException
-
feature
- Throws:
SQLException
IOException
-
getExtension
Returns the extension by name, or null if the extension is not supported by this implementation -
getExtension
Returns the extension by class, or null if the extension is not supported by this implementation -
create
Creates a new feature entry in the geopackage.The resulting feature dataset will be empty. The
#writer(FeatureEntry, boolean, Transaction)
method returns a writer object that can be used to populate the dataset.- Parameters:
entry
- Contains metadata about the feature entry.schema
- The schema of the feature dataset.- Throws:
IOException
- Any errors occurring while creating the new feature entry.
-
add
Adds a new feature dataset to the geopackage.- Parameters:
entry
- Contains metadata about the feature entry.collection
- The simple feature collection to add to the geopackage.- Throws:
IOException
- Any errors occurring while adding the new feature dataset.
-
add
Adds a new feature dataset to the geopackage.- Parameters:
entry
- Contains metadata about the feature entry.source
- The dataset to add to the geopackage.filter
- Filter specifying what subset of feature dataset to include, may benull
to specify no filter.- Throws:
IOException
- Any errors occurring while adding the new feature dataset.
-
writer
public SimpleFeatureWriter writer(FeatureEntry entry, boolean append, Filter filter, Transaction tx) throws IOException Returns a writer used to modify or add to the contents of a feature dataset.- Parameters:
entry
- The feature entry.append
- Flag controlling whether to modify existing contents, or append to the dataset.filter
- Filter determining what subset of dataset to modify, only relevant when append set to false. May benull
to specify no filter.tx
- Transaction object, may benull
to specify auto commit transaction.- Throws:
IOException
-
reader
public SimpleFeatureReader reader(FeatureEntry entry, Filter filter, Transaction tx) throws IOException Returns a reader for the contents of a feature dataset.- Parameters:
entry
- The feature entry.filter
- Filter Filter determining what subset of dataset to return. May benull
to specify no filter.tx
- Transaction object, may benull
to specify auto commit transaction.- Throws:
IOException
-
getDateFormat
Returns a new instance of SimpleDateFormat with the default GeoPackage ISO formatting -
createSpatialIndex
Create a spatial index- Parameters:
e
- feature entry to create spatial index for- Throws:
IOException
-
findSRID
-
tiles
Lists all the tile entries in the geopackage.- Throws:
IOException
-
tile
Looks up a tile entry by name.- Parameters:
name
- THe name of the tile entry.- Returns:
- The entry, or
null
if no such entry exists. - Throws:
IOException
-
create
Creates a new tile entry in the geopackage.- Parameters:
entry
- The tile entry.- Throws:
IOException
-
add
Adds a tile to the geopackage.- Parameters:
entry
- The tile metadata entry.tile
- The tile.- Throws:
IOException
-
reader
public TileReader reader(TileEntry entry, Integer lowZoom, Integer highZoom, Integer lowCol, Integer highCol, Integer lowRow, Integer highRow) throws IOException Retrieve tiles within certain zooms and column/row boundaries.- Parameters:
entry
- the tile entrylowZoom
- low zoom boundaryhighZoom
- high zoom boundarylowCol
- low column boundaryhighCol
- high column boundarylowRow
- low row boundaryhighRow
- high row boundary- Throws:
IOException
-
addRange
-
getSpatialIndexName
-
hasSpatialIndex
Verifies if a spatial index is present- Parameters:
entry
- The feature entry.- Returns:
- whether this feature entry has a spatial index available.
- Throws:
IOException
-
searchSpatialIndex
public Set<Identifier> searchSpatialIndex(FeatureEntry entry, Double minX, Double minY, Double maxX, Double maxY) throws IOException Searches a spatial index.- Parameters:
entry
- The feature entry.minX
- Optional minimum x boundary.minY
- Optional minimum y boundary.maxX
- Optional maximum x boundary.maxY
- Optional maximum y boundary.- Throws:
IOException
-
getTileBound
Retrieve tile boundaries (min row, max row, min column and max column) for a particular zoom level, available in the actual data- Parameters:
entry
- The tile entryzoom
- the zoom levelisMax
- true for max boundary, false for min boundaryisRow
- true for rows, false for columns- Returns:
- the min/max column/row of the zoom level available in the data, or 0 if no matching zoom_level is present
- Throws:
IOException
-