mil.nga.geopackage.core.srs.SpatialReferenceSystem Java Examples

The following examples show how to use mil.nga.geopackage.core.srs.SpatialReferenceSystem. 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 File: GeoPackageTestUtils.java    From geopackage-java with 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 #2
Source File: GeoPackageTestUtils.java    From geopackage-android with 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 #3
Source File: GeoPackageTestUtils.java    From geopackage-android with 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 #4
Source File: GeoPackageCoreImpl.java    From geopackage-core-java with MIT License 6 votes vote down vote up
/**
 * Get the Spatial Reference System by id
 *
 * @param srsId
 *            srs id
 * @return srs
 */
private SpatialReferenceSystem getSrs(long srsId) {
	SpatialReferenceSystem srs;
	try {
		srs = getSpatialReferenceSystemDao().queryForId(srsId);
	} catch (SQLException e1) {
		throw new GeoPackageException(
				"Failed to retrieve Spatial Reference System. SRS ID: "
						+ srsId);
	}
	if (srs == null) {
		throw new GeoPackageException(
				"Spatial Reference System could not be found. SRS ID: "
						+ srsId);
	}
	return srs;
}
 
Example #5
Source File: GeoPackageTestUtils.java    From geopackage-android with 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 #6
Source File: GeoPackageTableCreator.java    From geopackage-core-java with MIT License 6 votes vote down vote up
/**
 * Create the minimum required GeoPackage tables
 */
public void createRequired() {

	// Create the Spatial Reference System table (spec Requirement 10)
	createSpatialReferenceSystem();

	// Create the Contents table (spec Requirement 13)
	createContents();

	// Create the required Spatial Reference Systems (spec Requirement
	// 11)
	try {
		SpatialReferenceSystemDao dao = DaoManager.createDao(
				db.getConnectionSource(), SpatialReferenceSystem.class);
		dao.createWgs84();
		dao.createUndefinedCartesian();
		dao.createUndefinedGeographic();
	} catch (SQLException e) {
		throw new GeoPackageException(
				"Error creating default required Spatial Reference Systems",
				e);
	}
}
 
Example #7
Source File: GeoPackageDaoManager.java    From geopackage-core-java with 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 #8
Source File: GeoPackageRepository.java    From geopackage-mapcache-android with MIT License 6 votes vote down vote up
/**
 * Create a tile table in the given GeoPackage
 * @return
 */
public boolean createTileTable(String gpName, BoundingBox boundingBox, long epsg, String tableName, TileScaling scaling){
    GeoPackage geoPackage = manager.open(gpName);
    try {
        // Create the srs if needed
        SpatialReferenceSystemDao srsDao = geoPackage.getSpatialReferenceSystemDao();
        SpatialReferenceSystem srs = srsDao.getOrCreateFromEpsg(epsg);
        // Create the tile table
        mil.nga.sf.proj.Projection projection = ProjectionFactory.getProjection(epsg);
        BoundingBox bbox = LoadTilesTask.transform(boundingBox, projection);
        geoPackage.createTileTableWithMetadata(
                tableName, bbox, srs.getSrsId(),
                bbox, srs.getSrsId());

        TileTableScaling tileTableScaling = new TileTableScaling(geoPackage, tableName);
        tileTableScaling.createOrUpdate(scaling);
    } catch (Exception e) {
        Log.i("Exception", e.toString());
        return false;
    } finally {
        geoPackage.close();
    }
    return true;
}
 
Example #9
Source File: GeoPackageTestUtils.java    From geopackage-android with 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 #10
Source File: FeatureDao.java    From geopackage-java with 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 #11
Source File: GeoPackageTestUtils.java    From geopackage-java with 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 #12
Source File: GeoPackageTestUtils.java    From geopackage-java with 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 #13
Source File: GeoPackageTestUtils.java    From geopackage-java with 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 #14
Source File: FeatureDao.java    From geopackage-android with 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 #15
Source File: CrsWktExtension.java    From geopackage-core-java with MIT License 5 votes vote down vote up
/**
 * Get the extension definition
 * 
 * @param srsId
 *            srs id
 * @return definition
 */
public String getDefinition(long srsId) {
	String definition = connection.querySingleTypedResult("SELECT "
			+ COLUMN_NAME + " FROM " + SpatialReferenceSystem.TABLE_NAME
			+ " WHERE " + SpatialReferenceSystem.COLUMN_SRS_ID + " = ?",
			new String[] { String.valueOf(srsId) });
	return definition;
}
 
Example #16
Source File: GeoPackageExample.java    From geopackage-android with MIT License 5 votes vote down vote up
private static void createCrsWktExtension(GeoPackage geoPackage)
        throws SQLException {

    CrsWktExtension wktExtension = new CrsWktExtension(geoPackage);
    wktExtension.getOrCreate();

    SpatialReferenceSystemDao srsDao = geoPackage
            .getSpatialReferenceSystemDao();

    SpatialReferenceSystem srs = srsDao.queryForOrganizationCoordsysId(
            ProjectionConstants.AUTHORITY_EPSG,
            ProjectionConstants.EPSG_WORLD_GEODETIC_SYSTEM);

    SpatialReferenceSystem testSrs = new SpatialReferenceSystem();
    testSrs.setSrsName("test");
    testSrs.setSrsId(12345);
    testSrs.setOrganization("test_org");
    testSrs.setOrganizationCoordsysId(testSrs.getSrsId());
    testSrs.setDefinition(srs.getDefinition());
    testSrs.setDescription(srs.getDescription());
    testSrs.setDefinition_12_063(srs.getDefinition_12_063());
    srsDao.create(testSrs);

    SpatialReferenceSystem testSrs2 = new SpatialReferenceSystem();
    testSrs2.setSrsName("test2");
    testSrs2.setSrsId(54321);
    testSrs2.setOrganization("test_org");
    testSrs2.setOrganizationCoordsysId(testSrs2.getSrsId());
    testSrs2.setDefinition(srs.getDefinition());
    testSrs2.setDescription(srs.getDescription());
    srsDao.create(testSrs2);

}
 
Example #17
Source File: GeoPackageExample.java    From geopackage-android with MIT License 5 votes vote down vote up
private static void createFeatures(GeoPackage geoPackage,
                                   SpatialReferenceSystem srs, String tableName, GeometryType type,
                                   Geometry geometry, String name) throws SQLException {

    List<Geometry> geometries = new ArrayList<>();
    geometries.add(geometry);
    List<String> names = new ArrayList<>();
    names.add(name);

    createFeatures(geoPackage, srs, tableName, type, geometries, names);
}
 
Example #18
Source File: FeatureIndexManagerUtils.java    From geopackage-android with 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 #19
Source File: GeoPackageValidate.java    From geopackage-core-java with MIT License 5 votes vote down vote up
/**
 * Validate the GeoPackage has the minimum required tables
 * 
 * @param geoPackage
 *            GeoPackage
 */
public static void validateMinimumTables(GeoPackageCore geoPackage) {
	if (!hasMinimumTables(geoPackage)) {
		throw new GeoPackageException(
				"Invalid GeoPackage. Does not contain required tables: "
						+ SpatialReferenceSystem.TABLE_NAME + " & "
						+ Contents.TABLE_NAME + ", GeoPackage Name: "
						+ geoPackage.getName());
	}
}
 
Example #20
Source File: CrsWktExtension.java    From geopackage-core-java with MIT License 5 votes vote down vote up
/**
 * Create the extension column
 */
private void createColumn() {

	AlterTable.addColumn(connection, SpatialReferenceSystem.TABLE_NAME,
			COLUMN_NAME, COLUMN_DEF);

	// Update the existing known SRS values
	updateDefinition(GeoPackageProperties.getIntegerProperty(
			PropertyConstants.WGS_84, PropertyConstants.SRS_ID),
			GeoPackageProperties.getProperty(PropertyConstants.WGS_84,
					PropertyConstants.DEFINITION_12_063));
	updateDefinition(
			GeoPackageProperties.getIntegerProperty(
					PropertyConstants.UNDEFINED_CARTESIAN,
					PropertyConstants.SRS_ID),
			GeoPackageProperties.getProperty(
					PropertyConstants.UNDEFINED_CARTESIAN,
					PropertyConstants.DEFINITION_12_063));
	updateDefinition(GeoPackageProperties.getIntegerProperty(
			PropertyConstants.UNDEFINED_GEOGRAPHIC,
			PropertyConstants.SRS_ID), GeoPackageProperties.getProperty(
			PropertyConstants.UNDEFINED_GEOGRAPHIC,
			PropertyConstants.DEFINITION_12_063));
	updateDefinition(GeoPackageProperties.getIntegerProperty(
			PropertyConstants.WEB_MERCATOR, PropertyConstants.SRS_ID),
			GeoPackageProperties.getProperty(
					PropertyConstants.WEB_MERCATOR,
					PropertyConstants.DEFINITION_12_063));
}
 
Example #21
Source File: GeometryColumnsSqlMm.java    From geopackage-core-java with MIT License 5 votes vote down vote up
public void setSrs(SpatialReferenceSystem srs) {
	this.srs = srs;
	if (srs != null) {
		srsId = srs.getId();
		srsName = srs.getSrsName();
	}
}
 
Example #22
Source File: FeatureInfoBuilder.java    From geopackage-android-map with MIT License 5 votes vote down vote up
/**
 * Project the geometry into the provided projection
 *
 * @param geometryData geometry data
 * @param projection   projection
 */
public void projectGeometry(GeoPackageGeometryData geometryData, Projection projection) {

    if (geometryData.getGeometry() != null) {

        try {
            SpatialReferenceSystemDao srsDao = DaoManager.createDao(featureDao.getDb().getConnectionSource(), SpatialReferenceSystem.class);
            int srsId = geometryData.getSrsId();
            SpatialReferenceSystem srs = srsDao.queryForId((long) srsId);

            if (!projection.equals(srs.getOrganization(), srs.getOrganizationCoordsysId())) {

                Projection geomProjection = srs.getProjection();
                ProjectionTransform transform = geomProjection.getTransformation(projection);

                Geometry projectedGeometry = transform.transform(geometryData.getGeometry());
                geometryData.setGeometry(projectedGeometry);
                SpatialReferenceSystem projectionSrs = srsDao.getOrCreateCode(projection.getAuthority(), Long.parseLong(projection.getCode()));
                geometryData.setSrsId((int) projectionSrs.getSrsId());
            }
        } catch (SQLException e) {
            throw new GeoPackageException("Failed to project geometry to projection with Authority: "
                    + projection.getAuthority() + ", Code: " + projection.getCode(), e);
        }
    }

}
 
Example #23
Source File: GeoPackageCoreImpl.java    From geopackage-core-java with MIT License 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public SpatialReferenceSystemDao getSpatialReferenceSystemDao() {
	SpatialReferenceSystemDao dao = createDao(SpatialReferenceSystem.class);
	dao.setCrsWktExtension(new CrsWktExtension(this));
	return dao;
}
 
Example #24
Source File: GeoPackageRepository.java    From geopackage-mapcache-android with MIT License 5 votes vote down vote up
/**
 * Add Spatial Reference System to the info
 *
 * @param info
 * @param srs
 */
private void addSrs(StringBuilder info, SpatialReferenceSystem srs) {
    info.append("\nSRS Name: ").append(srs.getSrsName());
    info.append("\nSRS ID: ").append(srs.getSrsId());
    info.append("\nOrganization: ").append(srs.getOrganization());
    info.append("\nCoordsys ID: ").append(srs.getOrganizationCoordsysId());
    info.append("\nDefinition: ").append(srs.getDefinition());
    info.append("\nDescription: ").append(srs.getDescription());
}
 
Example #25
Source File: GeoPackageTextOutput.java    From geopackage-java with MIT License 5 votes vote down vote up
/**
 * Text output from a SRS
 * 
 * @param srs
 *            spatial reference system
 * @return text
 */
public String textOutput(SpatialReferenceSystem srs) {
	StringBuilder output = new StringBuilder();
	output.append("\tSRS " + SpatialReferenceSystem.COLUMN_ORGANIZATION
			+ ": " + srs.getOrganization());
	output.append("\n\tSRS "
			+ SpatialReferenceSystem.COLUMN_ORGANIZATION_COORDSYS_ID + ": "
			+ srs.getOrganizationCoordsysId());
	output.append("\n\tSRS " + SpatialReferenceSystem.COLUMN_DEFINITION
			+ ": " + srs.getDefinition());
	return output.toString();
}
 
Example #26
Source File: FeatureIndexManagerUtils.java    From geopackage-java with MIT License 5 votes vote down vote up
/**
 * Test large index
 *
 * @param geoPackage
 *            GeoPackage
 * @param numFeatures
 *            num features
 * @param verbose
 *            verbose printing
 * @throws SQLException
 *             upon error
 */
public static void testLargeIndex(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(geoPackage, featureTable, true, verbose);
}
 
Example #27
Source File: GeoPackageExample.java    From geopackage-java with MIT License 5 votes vote down vote up
private static void createFeatures(GeoPackage geoPackage,
		SpatialReferenceSystem srs, String tableName, GeometryType type,
		Geometry geometry, String name) throws SQLException {

	List<Geometry> geometries = new ArrayList<>();
	geometries.add(geometry);
	List<String> names = new ArrayList<>();
	names.add(name);

	createFeatures(geoPackage, srs, tableName, type, geometries, names);
}
 
Example #28
Source File: GeoPackageExample.java    From geopackage-java with MIT License 5 votes vote down vote up
private static void createCrsWktExtension(GeoPackage geoPackage)
		throws SQLException {

	CrsWktExtension wktExtension = new CrsWktExtension(geoPackage);
	wktExtension.getOrCreate();

	SpatialReferenceSystemDao srsDao = geoPackage
			.getSpatialReferenceSystemDao();

	SpatialReferenceSystem srs = srsDao.queryForOrganizationCoordsysId(
			ProjectionConstants.AUTHORITY_EPSG,
			ProjectionConstants.EPSG_WORLD_GEODETIC_SYSTEM);

	SpatialReferenceSystem testSrs = new SpatialReferenceSystem();
	testSrs.setSrsName("test");
	testSrs.setSrsId(12345);
	testSrs.setOrganization("test_org");
	testSrs.setOrganizationCoordsysId(testSrs.getSrsId());
	testSrs.setDefinition(srs.getDefinition());
	testSrs.setDescription(srs.getDescription());
	testSrs.setDefinition_12_063(srs.getDefinition_12_063());
	srsDao.create(testSrs);

	SpatialReferenceSystem testSrs2 = new SpatialReferenceSystem();
	testSrs2.setSrsName("test2");
	testSrs2.setSrsId(54321);
	testSrs2.setOrganization("test_org");
	testSrs2.setOrganizationCoordsysId(testSrs2.getSrsId());
	testSrs2.setDefinition(srs.getDefinition());
	testSrs2.setDescription(srs.getDescription());
	srsDao.create(testSrs2);

}
 
Example #29
Source File: TransactionTest.java    From geopackage-java with MIT License 4 votes vote down vote up
/**
 * Test an ORMLite transaction
 * 
 * @param geoPackage
 *            GeoPackage
 * @param successful
 *            true for a successful transaction
 * @throws SQLException
 *             upon error
 */
private void testORMLite(final GeoPackage geoPackage,
		final boolean successful) throws SQLException {

	final String tableName = "test_table";

	final Contents contents = new Contents();
	contents.setTableName(tableName);
	contents.setDataType(ContentsDataType.ATTRIBUTES);

	if (!geoPackage.isTable(tableName)) {
		geoPackage.execSQL("CREATE TABLE " + tableName
				+ " (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL)");
	}

	final SpatialReferenceSystemDao srsDao = geoPackage
			.getSpatialReferenceSystemDao();
	final ContentsDao contentsDao = geoPackage.getContentsDao();

	long srsCount = srsDao.countOf();
	long contentsCount = contentsDao.countOf();

	Callable<Void> callable = new Callable<Void>() {
		public Void call() throws Exception {

			SpatialReferenceSystem srs = srsDao.createWgs84Geographical3D();

			contents.setSrs(srs);
			contentsDao.create(contents);

			if (!successful) {
				throw new SQLException();
			}

			return null;
		}
	};

	try {
		geoPackage.callInTransaction(callable);
	} catch (SQLException e) {
		if (successful) {
			TestCase.fail(e.getMessage());
		}
	}

	TestCase.assertEquals(successful ? srsCount + 1 : srsCount,
			srsDao.countOf());
	TestCase.assertEquals(successful ? contentsCount + 1 : contentsCount,
			contentsDao.countOf());

	TestCase.assertEquals(successful,
			geoPackage.isAttributeTable(tableName));

}
 
Example #30
Source File: GeometryColumnsUtils.java    From geopackage-android with MIT License 4 votes vote down vote up
/**
 * Test create
 *
 * @param geoPackage
 * @throws SQLException
 */
public static void testCreate(GeoPackage geoPackage) throws SQLException {

    SpatialReferenceSystemDao srsDao = geoPackage
            .getSpatialReferenceSystemDao();
    ContentsDao contentsDao = geoPackage.getContentsDao();
    GeometryColumnsDao dao = geoPackage.getGeometryColumnsDao();

    if (dao.isTableExists()) {

        // Get current count
        long count = dao.countOf();
        TestCase.assertEquals(count, dao.getFeatureTables().size());

        // Retrieve a random srs
        List<SpatialReferenceSystem> results = srsDao.queryForAll();
        SpatialReferenceSystem srs = null;
        if (!results.isEmpty()) {
            int random = (int) (Math.random() * results.size());
            srs = results.get(random);
        }

        // Create a new contents
        Contents contents = new Contents();
        contents.setTableName("test_contents");
        contents.setDataType(ContentsDataType.FEATURES);
        contents.setIdentifier("test_contents");
        contents.setDescription("");
        // contents.setLastChange(new Date());
        contents.setMinX(-180.0);
        contents.setMinY(-90.0);
        contents.setMaxX(180.0);
        contents.setMaxY(90.0);
        contents.setSrs(srs);

        // Create the feature table
        geoPackage.createFeatureTable(TestUtils.buildFeatureTable(
                contents.getTableName(), "geom", GeometryType.GEOMETRY));

        contentsDao.create(contents);

        String columnName = "TEST_COLUMN_NAME";
        GeometryType geometryType = GeometryType.POINT;
        byte z = 2;
        byte m = 2;

        // Create new geometry columns
        GeometryColumns geometryColumns = new GeometryColumns();
        geometryColumns.setContents(contents);
        geometryColumns.setColumnName(columnName);
        geometryColumns.setGeometryType(geometryType);
        geometryColumns.setSrs(contents.getSrs());
        geometryColumns.setZ(z);
        geometryColumns.setM(m);
        dao.create(geometryColumns);

        // Verify count
        long newCount = dao.countOf();
        TestCase.assertEquals(count + 1, newCount);
        TestCase.assertEquals(newCount, dao.getFeatureTables().size());
        TestCase.assertTrue(dao.getFeatureTables().contains(
                contents.getTableName()));

        // Verify saved geometry columns
        GeometryColumns queryGeometryColumns = dao
                .queryForId(geometryColumns.getId());
        TestCase.assertEquals(contents.getId(),
                queryGeometryColumns.getTableName());
        TestCase.assertEquals(columnName,
                queryGeometryColumns.getColumnName());
        TestCase.assertEquals(geometryType,
                queryGeometryColumns.getGeometryType());
        TestCase.assertEquals(contents.getSrsId().longValue(),
                queryGeometryColumns.getSrsId());
        TestCase.assertEquals(z, queryGeometryColumns.getZ());
        TestCase.assertEquals(m, queryGeometryColumns.getM());
        TestCase.assertEquals(contents.getId(), queryGeometryColumns
                .getContents().getId());
        TestCase.assertEquals(contents.getSrsId().longValue(),
                queryGeometryColumns.getSrs().getId());
    }
}