Java Code Examples for mil.nga.geopackage.features.columns.GeometryColumns

The following examples show how to use mil.nga.geopackage.features.columns.GeometryColumns. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: geopackage-android   Source File: FeatureDao.java    License: MIT License 6 votes vote down vote up
/**
 * Constructor
 *
 * @param database        database name
 * @param db              connection
 * @param geometryColumns geometry columns
 * @param table           feature table
 */
public FeatureDao(String database, GeoPackageConnection db, GeometryColumns geometryColumns,
                  FeatureTable table) {
    super(database, db, new FeatureConnection(db), table);

    this.featureDb = (FeatureConnection) getUserDb();
    this.geometryColumns = geometryColumns;
    if (geometryColumns.getContents() == null) {
        throw new GeoPackageException(GeometryColumns.class.getSimpleName()
                + " " + geometryColumns.getId() + " has null "
                + Contents.class.getSimpleName());
    }
    if (geometryColumns.getSrs() == null) {
        throw new GeoPackageException(GeometryColumns.class.getSimpleName()
                + " " + geometryColumns.getId() + " has null "
                + SpatialReferenceSystem.class.getSimpleName());
    }

    projection = geometryColumns.getProjection();
}
 
Example 2
Source Project: geopackage-android   Source File: GeoPackageImpl.java    License: MIT License 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public FeatureDao getFeatureDao(Contents contents) {

    if (contents == null) {
        throw new GeoPackageException("Non null "
                + Contents.class.getSimpleName()
                + " is required to create "
                + FeatureDao.class.getSimpleName());
    }

    GeometryColumns geometryColumns = contents.getGeometryColumns();
    if (geometryColumns == null) {
        throw new GeoPackageException("No "
                + GeometryColumns.class.getSimpleName() + " exists for "
                + Contents.class.getSimpleName() + " " + contents.getId());
    }

    return getFeatureDao(geometryColumns);
}
 
Example 3
Source Project: geopackage-android   Source File: FeatureTileUtils.java    License: MIT License 6 votes vote down vote up
/**
 * Create feature dao
 *
 * @return
 */
public static FeatureDao createFeatureDao(GeoPackage geoPackage) {

    BoundingBox boundingBox = new BoundingBox();

    GeometryColumns geometryColumns = new GeometryColumns();
    geometryColumns.setId(new TableColumnKey("feature_tiles",
            "geom"));
    geometryColumns.setGeometryType(GeometryType.GEOMETRY);
    geometryColumns.setZ((byte) 0);
    geometryColumns.setM((byte) 0);

    geoPackage.createFeatureTableWithMetadata(
            geometryColumns, boundingBox, ProjectionConstants.EPSG_WORLD_GEODETIC_SYSTEM);

    FeatureDao featureDao = geoPackage.getFeatureDao(geometryColumns);

    return featureDao;
}
 
Example 4
Source Project: geopackage-android   Source File: GeoPackageTestUtils.java    License: MIT License 6 votes vote down vote up
/**
 * Test create feature table with metadata
 *
 * @param geoPackage
 * @throws SQLException
 */
public static void testCreateFeatureTableWithMetadata(GeoPackage geoPackage)
        throws SQLException {

    GeometryColumns geometryColumns = new GeometryColumns();
    geometryColumns.setId(new TableColumnKey("feature_metadata", "geom"));
    geometryColumns.setGeometryType(GeometryType.POINT);
    geometryColumns.setZ((byte) 1);
    geometryColumns.setM((byte) 0);

    BoundingBox boundingBox = new BoundingBox(-90, -45, 90, 45);

    SpatialReferenceSystem srs = geoPackage.getSpatialReferenceSystemDao().getOrCreateCode(
            ProjectionConstants.AUTHORITY_EPSG, ProjectionConstants.EPSG_WEB_MERCATOR);
    geometryColumns = geoPackage.createFeatureTableWithMetadata(
            geometryColumns, boundingBox, srs.getId());

    validateFeatureTableWithMetadata(geoPackage, geometryColumns, null,
            null);
}
 
Example 5
Source Project: geopackage-android   Source File: GeoPackageTestUtils.java    License: MIT License 6 votes vote down vote up
/**
 * Test create feature table with metadata and id column
 *
 * @param geoPackage
 * @throws SQLException
 */
public static void testCreateFeatureTableWithMetadataIdColumn(
        GeoPackage geoPackage) throws SQLException {

    GeometryColumns geometryColumns = new GeometryColumns();
    geometryColumns.setId(new TableColumnKey("feature_metadata2", "geom2"));
    geometryColumns.setGeometryType(GeometryType.POINT);
    geometryColumns.setZ((byte) 1);
    geometryColumns.setM((byte) 0);

    BoundingBox boundingBox = new BoundingBox(-90, -45, 90, 45);

    SpatialReferenceSystem srs = geoPackage.getSpatialReferenceSystemDao().getOrCreateCode(
            ProjectionConstants.AUTHORITY_EPSG, ProjectionConstants.EPSG_WEB_MERCATOR);
    String idColumn = "my_id";
    geometryColumns = geoPackage.createFeatureTableWithMetadata(
            geometryColumns, idColumn, boundingBox, srs.getId());

    validateFeatureTableWithMetadata(geoPackage, geometryColumns, idColumn,
            null);
}
 
Example 6
Source Project: geopackage-android   Source File: GeoPackageTestUtils.java    License: MIT License 6 votes vote down vote up
/**
 * Test create feature table with metadata and additional columns
 *
 * @param geoPackage
 * @throws SQLException
 */
public static void testCreateFeatureTableWithMetadataAdditionalColumns(
        GeoPackage geoPackage) throws SQLException {

    GeometryColumns geometryColumns = new GeometryColumns();
    geometryColumns.setId(new TableColumnKey("feature_metadata3", "geom3"));
    geometryColumns.setGeometryType(GeometryType.POINT);
    geometryColumns.setZ((byte) 1);
    geometryColumns.setM((byte) 0);

    BoundingBox boundingBox = new BoundingBox(-90, -45, 90, 45);

    List<FeatureColumn> additionalColumns = getFeatureColumns();

    SpatialReferenceSystem srs = geoPackage.getSpatialReferenceSystemDao().getOrCreateCode(
            ProjectionConstants.AUTHORITY_EPSG, ProjectionConstants.EPSG_WEB_MERCATOR);
    geometryColumns = geoPackage.createFeatureTableWithMetadata(
            geometryColumns, additionalColumns, boundingBox, srs.getId());

    validateFeatureTableWithMetadata(geoPackage, geometryColumns, null,
            additionalColumns);
}
 
Example 7
Source Project: geopackage-android   Source File: GeoPackageTestUtils.java    License: MIT License 6 votes vote down vote up
/**
 * Test create feature table with metadata, id column, and additional
 * columns
 *
 * @param geoPackage
 * @throws SQLException
 */
public static void testCreateFeatureTableWithMetadataIdColumnAdditionalColumns(
        GeoPackage geoPackage) throws SQLException {

    GeometryColumns geometryColumns = new GeometryColumns();
    geometryColumns.setId(new TableColumnKey("feature_metadata4", "geom4"));
    geometryColumns.setGeometryType(GeometryType.POINT);
    geometryColumns.setZ((byte) 1);
    geometryColumns.setM((byte) 0);

    BoundingBox boundingBox = new BoundingBox(-90, -45, 90, 45);

    List<FeatureColumn> additionalColumns = getFeatureColumns();

    SpatialReferenceSystem srs = geoPackage.getSpatialReferenceSystemDao().getOrCreateCode(
            ProjectionConstants.AUTHORITY_EPSG, ProjectionConstants.EPSG_WEB_MERCATOR);
    String idColumn = "my_other_id";
    geometryColumns = geoPackage.createFeatureTableWithMetadata(
            geometryColumns, idColumn, additionalColumns, boundingBox,
            srs.getId());

    validateFeatureTableWithMetadata(geoPackage, geometryColumns, idColumn,
            additionalColumns);
}
 
Example 8
Source Project: geopackage-core-java   Source File: GeoPackageCoreImpl.java    License: MIT License 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public boolean createGeometryColumnsTable() {
	verifyWritable();

	boolean created = false;
	GeometryColumnsDao dao = getGeometryColumnsDao();
	try {
		if (!dao.isTableExists()) {
			created = tableCreator.createGeometryColumns() > 0;
		}
	} catch (SQLException e) {
		throw new GeoPackageException("Failed to check if "
				+ GeometryColumns.class.getSimpleName()
				+ " table exists and create it", e);
	}
	return created;
}
 
Example 9
Source Project: geopackage-core-java   Source File: GeoPackageCoreImpl.java    License: MIT License 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public GeometryColumns createFeatureTableWithMetadata(
		GeometryColumns geometryColumns, String idColumnName,
		List<FeatureColumn> additionalColumns, BoundingBox boundingBox,
		long srsId) {

	if (idColumnName == null) {
		idColumnName = "id";
	}

	List<FeatureColumn> columns = new ArrayList<FeatureColumn>();
	columns.add(FeatureColumn.createPrimaryKeyColumn(idColumnName));
	columns.add(FeatureColumn.createGeometryColumn(
			geometryColumns.getColumnName(),
			geometryColumns.getGeometryType()));

	if (additionalColumns != null) {
		columns.addAll(additionalColumns);
	}

	return createFeatureTableWithMetadata(geometryColumns, boundingBox,
			srsId, columns);
}
 
Example 10
Source Project: geopackage-core-java   Source File: GeoPackageDaoManager.java    License: MIT License 6 votes vote down vote up
/**
 * Unregister all GeoPackage DAO with the connection source
 * 
 * @param connectionSource
 *            connection source
 */
public static void unregisterDaos(ConnectionSource connectionSource) {
	// TODO when ormlite-core version > 5.1 is released, replace with:
	// "DaoManager.unregisterDaos(connectionSource);"
	// See https://github.com/j256/ormlite-core/pull/149
	unregisterDao(connectionSource, Contents.class,
			SpatialReferenceSystem.class,
			SpatialReferenceSystemSfSql.class,
			SpatialReferenceSystemSqlMm.class, Extensions.class,
			GriddedCoverage.class, GriddedTile.class, GeometryIndex.class,
			TableIndex.class, FeatureTileLink.class,
			ExtendedRelation.class, TileScaling.class,
			GeometryColumns.class, GeometryColumnsSfSql.class,
			GeometryColumnsSqlMm.class, Metadata.class,
			MetadataReference.class, DataColumns.class,
			DataColumnConstraints.class, TileMatrix.class,
			TileMatrixSet.class, ContentsId.class);
}
 
Example 11
Source Project: geopackage-core-java   Source File: Contents.java    License: MIT License 6 votes vote down vote up
/**
 * Get the Geometry Columns, should only return one or no value
 * 
 * @return geometry columns
 */
public GeometryColumns getGeometryColumns() {
	GeometryColumns result = null;
	if (geometryColumns.size() > 1) {
		// This shouldn't happen with the unique table name constraint on
		// geometry columns
		throw new GeoPackageException(
				"Unexpected state. More than one GeometryColumn has a foreign key to the Contents. Count: "
						+ geometryColumns.size());
	} else if (geometryColumns.size() == 1) {
		CloseableIterator<GeometryColumns> iterator = geometryColumns
				.closeableIterator();
		try {
			result = iterator.next();
		} finally {
			try {
				iterator.close();
			} catch (IOException e) {
				throw new GeoPackageException(
						"Failed to close the Geometry Columns iterator", e);
			}
		}
	}
	return result;
}
 
Example 12
Source Project: geopackage-mapcache-android   Source File: GeoPackageRepository.java    License: MIT License 6 votes vote down vote up
/**
 * Create feature table in the given geopackage
 */
public boolean createFeatureTable(String gpName, BoundingBox boundingBox, GeometryType geometryType, String tableName){
    GeometryColumns geometryColumns = new GeometryColumns();
    geometryColumns.setId(new TableColumnKey(tableName,
            "geom"));
    geometryColumns.setGeometryType(geometryType);
    geometryColumns.setZ((byte) 0);
    geometryColumns.setM((byte) 0);

    GeoPackage geoPackage = manager.open(gpName);
    try {
        GeometryColumns created = geoPackage.createFeatureTableWithMetadata(
                geometryColumns, boundingBox, ProjectionConstants.EPSG_WORLD_GEODETIC_SYSTEM);
        if(created != null) {
            return true;
        }
    } finally {
        geoPackage.close();
    }
    return false;
}
 
Example 13
Source Project: geopackage-java   Source File: FeatureDao.java    License: MIT License 6 votes vote down vote up
/**
 * Constructor
 * 
 * @param database
 *            database name
 * @param db
 *            GeoPackage connection
 * @param geometryColumns
 *            geometry columns
 * @param table
 *            feature table
 */
public FeatureDao(String database, GeoPackageConnection db,
		GeometryColumns geometryColumns, FeatureTable table) {
	super(database, db, new FeatureConnection(db), table);

	this.featureDb = (FeatureConnection) getUserDb();
	this.geometryColumns = geometryColumns;
	if (geometryColumns.getContents() == null) {
		throw new GeoPackageException(GeometryColumns.class.getSimpleName()
				+ " " + geometryColumns.getId() + " has null "
				+ Contents.class.getSimpleName());
	}
	if (geometryColumns.getSrs() == null) {
		throw new GeoPackageException(GeometryColumns.class.getSimpleName()
				+ " " + geometryColumns.getId() + " has null "
				+ SpatialReferenceSystem.class.getSimpleName());
	}

	projection = geometryColumns.getProjection();
}
 
Example 14
Source Project: geopackage-java   Source File: GeoPackageTextOutput.java    License: MIT License 6 votes vote down vote up
/**
 * Build text from a feature table
 * 
 * @param table
 *            feature table
 * @return text
 */
public String featureTable(String table) {

	StringBuilder output = new StringBuilder();
	FeatureDao featureDao = geoPackage.getFeatureDao(table);
	output.append("Table Name: " + featureDao.getTableName());
	output.append("\nFeatures: " + featureDao.count());

	GeometryColumns geometryColumns = featureDao.getGeometryColumns();

	output.append("\n\nContents\n\n")
			.append(textOutput(geometryColumns.getContents()));

	output.append("\n\nGeometry Columns\n\n")
			.append(textOutput(geometryColumns));

	return output.toString();
}
 
Example 15
Source Project: geopackage-java   Source File: GeoPackageTextOutput.java    License: MIT License 6 votes vote down vote up
/**
 * Text output from a GeometryColumns
 * 
 * @param geometryColumns
 *            geometry columns
 * @return text
 */
public String textOutput(GeometryColumns geometryColumns) {
	StringBuilder output = new StringBuilder();
	output.append("\t" + GeometryColumns.COLUMN_TABLE_NAME + ": "
			+ geometryColumns.getTableName());
	output.append("\n\t" + GeometryColumns.COLUMN_COLUMN_NAME + ": "
			+ geometryColumns.getColumnName());
	output.append("\n\t" + GeometryColumns.COLUMN_GEOMETRY_TYPE_NAME + ": "
			+ geometryColumns.getGeometryTypeName());
	output.append("\n" + textOutput(geometryColumns.getSrs()));
	output.append("\n\t" + GeometryColumns.COLUMN_Z + ": "
			+ geometryColumns.getZ());
	output.append("\n\t" + GeometryColumns.COLUMN_M + ": "
			+ geometryColumns.getM());
	return output.toString();
}
 
Example 16
Source Project: geopackage-java   Source File: FeatureTileUtils.java    License: MIT License 6 votes vote down vote up
/**
 * Create feature dao
 *
 * @return feature dao
 */
public static FeatureDao createFeatureDao(GeoPackage geoPackage) {

	BoundingBox boundingBox = new BoundingBox();

	GeometryColumns geometryColumns = new GeometryColumns();
	geometryColumns.setId(new TableColumnKey(TABLE_NAME, "geom"));
	geometryColumns.setGeometryType(GeometryType.GEOMETRY);
	geometryColumns.setZ((byte) 0);
	geometryColumns.setM((byte) 0);

	geoPackage.createFeatureTableWithMetadata(geometryColumns, boundingBox,
			ProjectionConstants.EPSG_WORLD_GEODETIC_SYSTEM);

	FeatureDao featureDao = geoPackage.getFeatureDao(geometryColumns);

	return featureDao;
}
 
Example 17
Source Project: geopackage-java   Source File: GeoPackageTestUtils.java    License: MIT License 6 votes vote down vote up
/**
 * Test create feature table with metadata
 * 
 * @param geoPackage
 * @throws SQLException
 */
public static void testCreateFeatureTableWithMetadata(GeoPackage geoPackage)
		throws SQLException {

	GeometryColumns geometryColumns = new GeometryColumns();
	geometryColumns.setId(new TableColumnKey("feature_metadata", "geom"));
	geometryColumns.setGeometryType(GeometryType.POINT);
	geometryColumns.setZ((byte) 1);
	geometryColumns.setM((byte) 0);

	BoundingBox boundingBox = new BoundingBox(-90, -45, 90, 45);

	SpatialReferenceSystem srs = geoPackage.getSpatialReferenceSystemDao()
			.getOrCreateCode(ProjectionConstants.AUTHORITY_EPSG,
					ProjectionConstants.EPSG_WEB_MERCATOR);
	geometryColumns = geoPackage.createFeatureTableWithMetadata(
			geometryColumns, boundingBox, srs.getId());

	validateFeatureTableWithMetadata(geoPackage, geometryColumns, null,
			null);
}
 
Example 18
Source Project: geopackage-java   Source File: GeoPackageTestUtils.java    License: MIT License 6 votes vote down vote up
/**
 * Test create feature table with metadata and id column
 * 
 * @param geoPackage
 * @throws SQLException
 */
public static void testCreateFeatureTableWithMetadataIdColumn(
		GeoPackage geoPackage) throws SQLException {

	GeometryColumns geometryColumns = new GeometryColumns();
	geometryColumns.setId(new TableColumnKey("feature_metadata2", "geom2"));
	geometryColumns.setGeometryType(GeometryType.POINT);
	geometryColumns.setZ((byte) 1);
	geometryColumns.setM((byte) 0);

	BoundingBox boundingBox = new BoundingBox(-90, -45, 90, 45);

	SpatialReferenceSystem srs = geoPackage.getSpatialReferenceSystemDao()
			.getOrCreateCode(ProjectionConstants.AUTHORITY_EPSG,
					ProjectionConstants.EPSG_WEB_MERCATOR);
	String idColumn = "my_id";
	geometryColumns = geoPackage.createFeatureTableWithMetadata(
			geometryColumns, idColumn, boundingBox, srs.getId());

	validateFeatureTableWithMetadata(geoPackage, geometryColumns, idColumn,
			null);
}
 
Example 19
Source Project: geopackage-java   Source File: GeoPackageTestUtils.java    License: MIT License 6 votes vote down vote up
/**
 * Test create feature table with metadata and additional columns
 * 
 * @param geoPackage
 * @throws SQLException
 */
public static void testCreateFeatureTableWithMetadataAdditionalColumns(
		GeoPackage geoPackage) throws SQLException {

	GeometryColumns geometryColumns = new GeometryColumns();
	geometryColumns.setId(new TableColumnKey("feature_metadata", "geom"));
	geometryColumns.setGeometryType(GeometryType.POINT);
	geometryColumns.setZ((byte) 1);
	geometryColumns.setM((byte) 0);

	BoundingBox boundingBox = new BoundingBox(-90, -45, 90, 45);

	List<FeatureColumn> additionalColumns = getFeatureColumns();

	SpatialReferenceSystem srs = geoPackage.getSpatialReferenceSystemDao()
			.getOrCreateCode(ProjectionConstants.AUTHORITY_EPSG,
					ProjectionConstants.EPSG_WEB_MERCATOR);
	geometryColumns = geoPackage.createFeatureTableWithMetadata(
			geometryColumns, additionalColumns, boundingBox, srs.getId());

	validateFeatureTableWithMetadata(geoPackage, geometryColumns, null,
			additionalColumns);
}
 
Example 20
Source Project: geopackage-java   Source File: GeoPackageTestUtils.java    License: MIT License 6 votes vote down vote up
/**
 * Test create feature table with metadata, id column, and additional
 * columns
 * 
 * @param geoPackage
 * @throws SQLException
 */
public static void testCreateFeatureTableWithMetadataIdColumnAdditionalColumns(
		GeoPackage geoPackage) throws SQLException {

	GeometryColumns geometryColumns = new GeometryColumns();
	geometryColumns.setId(new TableColumnKey("feature_metadata", "geom"));
	geometryColumns.setGeometryType(GeometryType.POINT);
	geometryColumns.setZ((byte) 1);
	geometryColumns.setM((byte) 0);

	BoundingBox boundingBox = new BoundingBox(-90, -45, 90, 45);

	List<FeatureColumn> additionalColumns = getFeatureColumns();

	SpatialReferenceSystem srs = geoPackage.getSpatialReferenceSystemDao()
			.getOrCreateCode(ProjectionConstants.AUTHORITY_EPSG,
					ProjectionConstants.EPSG_WEB_MERCATOR);
	String idColumn = "my_other_id";
	geometryColumns = geoPackage.createFeatureTableWithMetadata(
			geometryColumns, idColumn, additionalColumns, boundingBox,
			srs.getId());

	validateFeatureTableWithMetadata(geoPackage, geometryColumns, idColumn,
			additionalColumns);
}
 
Example 21
Source Project: geopackage-android   Source File: GeoPackageImpl.java    License: MIT License 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public FeatureDao getFeatureDao(GeometryColumns geometryColumns) {

    if (geometryColumns == null) {
        throw new GeoPackageException("Non null "
                + GeometryColumns.class.getSimpleName()
                + " is required to create "
                + FeatureDao.class.getSimpleName());
    }

    // Read the existing table and create the dao
    FeatureTableReader tableReader = new FeatureTableReader(geometryColumns);
    final FeatureTable featureTable = tableReader.readTable(database);
    featureTable.setContents(geometryColumns.getContents());
    FeatureDao dao = new FeatureDao(getName(), database, geometryColumns, featureTable);

    // Register the table name (with and without quotes) to wrap cursors with the feature cursor
    registerCursorWrapper(geometryColumns.getTableName(),
            new GeoPackageCursorWrapper() {

                @Override
                public Cursor wrapCursor(Cursor cursor) {
                    return new FeatureCursor(featureTable, cursor);
                }
            });

    // If the GeoPackage is writable and the feature table has a RTree Index
    // extension, drop the RTree triggers.  User defined functions are currently not supported.
    if (writable) {
        RTreeIndexExtension rtree = new RTreeIndexExtension(this);
        rtree.dropTriggers(featureTable);
    }

    return dao;
}
 
Example 22
Source Project: geopackage-android   Source File: GeoPackageImpl.java    License: MIT License 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public FeatureDao getFeatureDao(String tableName) {
    GeometryColumnsDao dao = getGeometryColumnsDao();
    List<GeometryColumns> geometryColumnsList;
    try {
        geometryColumnsList = dao.queryForEq(
                GeometryColumns.COLUMN_TABLE_NAME, tableName);
    } catch (SQLException e) {
        throw new GeoPackageException("Failed to retrieve "
                + FeatureDao.class.getSimpleName() + " for table name: "
                + tableName + ". Exception retrieving "
                + GeometryColumns.class.getSimpleName() + ".", e);
    }
    if (geometryColumnsList.isEmpty()) {
        throw new GeoPackageException(
                "No Feature Table exists for table name: " + tableName);
    } else if (geometryColumnsList.size() > 1) {
        // This shouldn't happen with the table name unique constraint on
        // geometry columns
        throw new GeoPackageException("Unexpected state. More than one "
                + GeometryColumns.class.getSimpleName()
                + " matched for table name: " + tableName + ", count: "
                + geometryColumnsList.size());
    }
    return getFeatureDao(geometryColumnsList.get(0));
}
 
Example 23
Source Project: geopackage-android   Source File: FeatureIndexManagerUtils.java    License: MIT License 5 votes vote down vote up
/**
 * Test large index
 *
 * @param activity    activity
 * @param geoPackage  GeoPackage
 * @param numFeatures num features
 * @param verbose     verbose printing
 * @throws SQLException upon error
 */
public static void testLargeIndex(Activity activity, GeoPackage geoPackage, int numFeatures,
                                  boolean verbose) throws SQLException {

    String featureTable = "large_index";

    GeometryColumns geometryColumns = new GeometryColumns();
    geometryColumns.setId(new TableColumnKey(featureTable, "geom"));
    geometryColumns.setGeometryType(GeometryType.POLYGON);
    geometryColumns.setZ((byte) 0);
    geometryColumns.setM((byte) 0);

    BoundingBox boundingBox = new BoundingBox(-180, -90, 180, 90);

    SpatialReferenceSystem srs = geoPackage.getSpatialReferenceSystemDao()
            .getOrCreateCode(ProjectionConstants.AUTHORITY_EPSG,
                    ProjectionConstants.EPSG_WORLD_GEODETIC_SYSTEM);
    List<FeatureColumn> additionalColumns = GeoPackageTestUtils
            .getFeatureColumns();
    geometryColumns = geoPackage.createFeatureTableWithMetadata(
            geometryColumns, additionalColumns, boundingBox, srs.getId());

    FeatureDao featureDao = geoPackage.getFeatureDao(geometryColumns);

    System.out.println();
    System.out.println("Inserting Feature Rows: " + numFeatures);
    TestUtils.addRowsToFeatureTable(geoPackage, geometryColumns,
            featureDao.getTable(), numFeatures, false, false, false);

    testTimedIndex(activity, geoPackage, featureTable, true, verbose);
}
 
Example 24
Source Project: geopackage-core-java   Source File: GeoPackageExtensions.java    License: MIT License 5 votes vote down vote up
/**
 * Copy the RTree Spatial extension for the table
 * 
 * @param geoPackage
 *            GeoPackage
 * @param table
 *            table name
 * @param newTable
 *            new table name
 * @since 3.3.0
 */
public static void copyRTreeSpatialIndex(GeoPackageCore geoPackage,
		String table, String newTable) {

	try {

		RTreeIndexCoreExtension rTreeIndexExtension = getRTreeIndexExtension(
				geoPackage);
		if (rTreeIndexExtension.has(table)) {
			GeometryColumnsDao geometryColumnsDao = geoPackage
					.getGeometryColumnsDao();

			GeometryColumns geometryColumns = geometryColumnsDao
					.queryForTableName(newTable);
			if (geometryColumns != null) {
				TableInfo tableInfo = TableInfo
						.info(geoPackage.getDatabase(), newTable);
				if (tableInfo != null) {
					String pk = tableInfo.getPrimaryKey().getName();
					rTreeIndexExtension.create(newTable,
							geometryColumns.getColumnName(), pk);
				}
			}
		}

	} catch (Exception e) {
		logger.log(Level.WARNING, "Failed to create RTree for table: "
				+ newTable + ", copied from table: " + table, e);
	}
}
 
Example 25
Source Project: geopackage-core-java   Source File: GeoPackageCoreImpl.java    License: MIT License 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public GeometryColumns createFeatureTableWithMetadata(
		GeometryColumns geometryColumns, BoundingBox boundingBox,
		long srsId) {
	return createFeatureTableWithMetadata(geometryColumns, null, null,
			boundingBox, srsId);
}
 
Example 26
Source Project: geopackage-core-java   Source File: GeoPackageCoreImpl.java    License: MIT License 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public GeometryColumns createFeatureTableWithMetadata(
		GeometryColumns geometryColumns, String idColumnName,
		BoundingBox boundingBox, long srsId) {
	return createFeatureTableWithMetadata(geometryColumns, idColumnName,
			null, boundingBox, srsId);
}
 
Example 27
Source Project: geopackage-core-java   Source File: GeoPackageCoreImpl.java    License: MIT License 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public GeometryColumns createFeatureTableWithMetadata(
		GeometryColumns geometryColumns,
		List<FeatureColumn> additionalColumns, BoundingBox boundingBox,
		long srsId) {
	return createFeatureTableWithMetadata(geometryColumns, null,
			additionalColumns, boundingBox, srsId);
}
 
Example 28
Source Project: geopackage-core-java   Source File: ContentsDao.java    License: MIT License 5 votes vote down vote up
/**
 * Get or create a Geometry Columns DAO
 * 
 * @return geometry columns dao
 * @throws SQLException
 *             upon dao creation failure
 */
private GeometryColumnsDao getGeometryColumnsDao() throws SQLException {
	if (geometryColumnsDao == null) {
		geometryColumnsDao = DaoManager.createDao(connectionSource,
				GeometryColumns.class);
	}
	return geometryColumnsDao;
}
 
Example 29
Source Project: geopackage-core-java   Source File: SpatialReferenceSystemDao.java    License: MIT License 5 votes vote down vote up
/**
 * Delete the Spatial Reference System, cascading
 * 
 * @param srs
 *            spatial reference system
 * @return deleted count
 * @throws SQLException
 *             upon deletion failure
 */
public int deleteCascade(SpatialReferenceSystem srs) throws SQLException {
	int count = 0;

	if (srs != null) {

		// Delete Contents
		ForeignCollection<Contents> contentsCollection = srs.getContents();
		if (!contentsCollection.isEmpty()) {
			ContentsDao dao = getContentsDao();
			dao.deleteCascade(contentsCollection);
		}

		// Delete Geometry Columns
		GeometryColumnsDao geometryColumnsDao = getGeometryColumnsDao();
		if (geometryColumnsDao.isTableExists()) {
			ForeignCollection<GeometryColumns> geometryColumnsCollection = srs
					.getGeometryColumns();
			if (!geometryColumnsCollection.isEmpty()) {
				geometryColumnsDao.delete(geometryColumnsCollection);
			}
		}

		// Delete Tile Matrix Set
		TileMatrixSetDao tileMatrixSetDao = getTileMatrixSetDao();
		if (tileMatrixSetDao.isTableExists()) {
			ForeignCollection<TileMatrixSet> tileMatrixSetCollection = srs
					.getTileMatrixSet();
			if (!tileMatrixSetCollection.isEmpty()) {
				tileMatrixSetDao.delete(tileMatrixSetCollection);
			}
		}

		// Delete
		count = delete(srs);
	}
	return count;
}
 
Example 30
Source Project: geopackage-core-java   Source File: SpatialReferenceSystemDao.java    License: MIT License 5 votes vote down vote up
/**
 * Get or create a Geometry Columns DAO
 * 
 * @return geometry columns dao
 * @throws SQLException
 *             upon creation failure
 */
private GeometryColumnsDao getGeometryColumnsDao() throws SQLException {
	if (geometryColumnsDao == null) {
		geometryColumnsDao = DaoManager.createDao(connectionSource,
				GeometryColumns.class);
	}
	return geometryColumnsDao;
}