Search in sources :

Example 1 with SpatialReferenceSystem

use of mil.nga.geopackage.srs.SpatialReferenceSystem in project geopackage-android-map by ngageoint.

the class FeatureInfoBuilder method projectGeometry.

/**
 * 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) {
        SpatialReferenceSystemDao srsDao = SpatialReferenceSystemDao.create(featureDao.getDb());
        try {
            int srsId = geometryData.getSrsId();
            SpatialReferenceSystem srs = srsDao.queryForId((long) srsId);
            if (!projection.equals(srs.getOrganization(), srs.getOrganizationCoordsysId())) {
                Projection geomProjection = srs.getProjection();
                GeometryTransform transform = GeometryTransform.create(geomProjection, 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);
        }
    }
}
Also used : GeometryTransform(mil.nga.sf.proj.GeometryTransform) Geometry(mil.nga.sf.Geometry) SpatialReferenceSystemDao(mil.nga.geopackage.srs.SpatialReferenceSystemDao) SQLException(java.sql.SQLException) SpatialReferenceSystem(mil.nga.geopackage.srs.SpatialReferenceSystem) Projection(mil.nga.proj.Projection) GeoPackageException(mil.nga.geopackage.GeoPackageException) Point(mil.nga.sf.Point)

Example 2 with SpatialReferenceSystem

use of mil.nga.geopackage.srs.SpatialReferenceSystem in project geopackage-android-map by ngageoint.

the class TestSetupTeardown method setUpCreateTiles.

/**
 * Set up create for tiles test
 *
 * @param testContext
 * @param geoPackage
 * @throws SQLException
 * @throws IOException
 */
private static void setUpCreateTiles(Context testContext, GeoPackage geoPackage) throws SQLException, IOException {
    // Get existing SRS objects
    SpatialReferenceSystemDao srsDao = geoPackage.getSpatialReferenceSystemDao();
    SpatialReferenceSystem epsgSrs = srsDao.queryForId(4326l);
    TestCase.assertNotNull(epsgSrs);
    // Create the Tile Matrix Set and Tile Matrix tables
    geoPackage.createTileMatrixSetTable();
    geoPackage.createTileMatrixTable();
    // Create new Contents
    ContentsDao contentsDao = geoPackage.getContentsDao();
    Contents contents = new Contents();
    contents.setTableName("test_tiles");
    contents.setDataType(ContentsDataType.TILES);
    contents.setIdentifier("test_tiles");
    // contents.setDescription("");
    // contents.setLastChange(new Date());
    contents.setMinX(-180.0);
    contents.setMinY(-90.0);
    contents.setMaxX(180.0);
    contents.setMaxY(90.0);
    contents.setSrs(epsgSrs);
    // Create the user tile table
    TileTable tileTable = TestUtils.buildTileTable(contents.getTableName());
    geoPackage.createTileTable(tileTable);
    // Create the contents
    contentsDao.create(contents);
    // Create new Tile Matrix Set
    TileMatrixSetDao tileMatrixSetDao = geoPackage.getTileMatrixSetDao();
    TileMatrixSet tileMatrixSet = new TileMatrixSet();
    tileMatrixSet.setContents(contents);
    tileMatrixSet.setSrs(contents.getSrs());
    tileMatrixSet.setMinX(contents.getMinX());
    tileMatrixSet.setMinY(contents.getMinY());
    tileMatrixSet.setMaxX(contents.getMaxX());
    tileMatrixSet.setMaxY(contents.getMaxY());
    tileMatrixSetDao.create(tileMatrixSet);
    // Create new Tile Matrix rows
    TileMatrixDao tileMatrixDao = geoPackage.getTileMatrixDao();
    int matrixWidthAndHeight = 2;
    double pixelXSize = 69237.2;
    double pixelYSize = 68412.1;
    // Read the asset tile to bytes and convert to bitmap
    byte[] assetTileData = TestUtils.getAssetFileBytes(testContext, TestConstants.TILE_FILE_NAME);
    Bitmap bitmap = BitmapConverter.toBitmap(assetTileData);
    // Get the width and height of the bitmap
    final int tileWidth = bitmap.getWidth();
    final int tileHeight = bitmap.getHeight();
    // Compress the bitmap back to bytes and use those for the test
    byte[] tileData = BitmapConverter.toBytes(bitmap, CompressFormat.valueOf(TestConstants.TILE_FILE_NAME_EXTENSION.toUpperCase()));
    for (int zoom = 0; zoom < CREATE_TILE_MATRIX_COUNT; zoom++) {
        TileMatrix tileMatrix = new TileMatrix();
        tileMatrix.setContents(contents);
        tileMatrix.setZoomLevel(zoom);
        tileMatrix.setMatrixWidth(matrixWidthAndHeight);
        tileMatrix.setMatrixHeight(matrixWidthAndHeight);
        tileMatrix.setTileWidth(tileWidth);
        tileMatrix.setTileHeight(tileHeight);
        tileMatrix.setPixelXSize(pixelXSize);
        tileMatrix.setPixelYSize(pixelYSize);
        tileMatrixDao.create(tileMatrix);
        matrixWidthAndHeight *= 2;
        pixelXSize /= 2.0;
        pixelYSize /= 2.0;
        // Populate the tile table with rows
        TestUtils.addRowsToTileTable(geoPackage, tileMatrix, tileData);
    }
}
Also used : TileMatrixSet(mil.nga.geopackage.tiles.matrixset.TileMatrixSet) SpatialReferenceSystemDao(mil.nga.geopackage.srs.SpatialReferenceSystemDao) TileMatrixDao(mil.nga.geopackage.tiles.matrix.TileMatrixDao) Bitmap(android.graphics.Bitmap) Contents(mil.nga.geopackage.contents.Contents) SpatialReferenceSystem(mil.nga.geopackage.srs.SpatialReferenceSystem) TileTable(mil.nga.geopackage.tiles.user.TileTable) TileMatrixSetDao(mil.nga.geopackage.tiles.matrixset.TileMatrixSetDao) ContentsDao(mil.nga.geopackage.contents.ContentsDao) TileMatrix(mil.nga.geopackage.tiles.matrix.TileMatrix)

Example 3 with SpatialReferenceSystem

use of mil.nga.geopackage.srs.SpatialReferenceSystem in project geopackage-android-map by ngageoint.

the class TestSetupTeardown method setUpCreateFeatures.

/**
 * Set up create for features test
 *
 * @param geoPackage
 * @param allowEmptyFeatures
 * @throws SQLException
 */
private static void setUpCreateFeatures(GeoPackage geoPackage, boolean allowEmptyFeatures) throws SQLException {
    // Get existing SRS objects
    SpatialReferenceSystemDao srsDao = geoPackage.getSpatialReferenceSystemDao();
    SpatialReferenceSystem epsgSrs = srsDao.queryForId(4326l);
    SpatialReferenceSystem undefinedCartesianSrs = srsDao.queryForId(-1l);
    SpatialReferenceSystem undefinedGeographicSrs = srsDao.queryForId(0l);
    TestCase.assertNotNull(epsgSrs);
    TestCase.assertNotNull(undefinedCartesianSrs);
    TestCase.assertNotNull(undefinedGeographicSrs);
    // Create the Geometry Columns table
    geoPackage.createGeometryColumnsTable();
    // Create new Contents
    ContentsDao contentsDao = geoPackage.getContentsDao();
    Contents point2dContents = new Contents();
    point2dContents.setTableName("point2d");
    point2dContents.setDataType(ContentsDataType.FEATURES);
    point2dContents.setIdentifier("point2d");
    // point2dContents.setDescription("");
    // point2dContents.setLastChange(new Date());
    point2dContents.setMinX(-180.0);
    point2dContents.setMinY(-90.0);
    point2dContents.setMaxX(180.0);
    point2dContents.setMaxY(90.0);
    point2dContents.setSrs(epsgSrs);
    Contents polygon2dContents = new Contents();
    polygon2dContents.setTableName("polygon2d");
    polygon2dContents.setDataType(ContentsDataType.FEATURES);
    polygon2dContents.setIdentifier("polygon2d");
    // polygon2dContents.setDescription("");
    // polygon2dContents.setLastChange(new Date());
    polygon2dContents.setMinX(0.0);
    polygon2dContents.setMinY(0.0);
    polygon2dContents.setMaxX(10.0);
    polygon2dContents.setMaxY(10.0);
    polygon2dContents.setSrs(undefinedGeographicSrs);
    Contents point3dContents = new Contents();
    point3dContents.setTableName("point3d");
    point3dContents.setDataType(ContentsDataType.FEATURES);
    point3dContents.setIdentifier("point3d");
    // point3dContents.setDescription("");
    // point3dContents.setLastChange(new Date());
    point3dContents.setMinX(-180.0);
    point3dContents.setMinY(-90.0);
    point3dContents.setMaxX(180.0);
    point3dContents.setMaxY(90.0);
    point3dContents.setSrs(undefinedCartesianSrs);
    Contents lineString3dMContents = new Contents();
    lineString3dMContents.setTableName("lineString3dM");
    lineString3dMContents.setDataType(ContentsDataType.FEATURES);
    lineString3dMContents.setIdentifier("lineString3dM");
    // lineString3dMContents.setDescription("");
    // lineString3dMContents.setLastChange(new Date());
    lineString3dMContents.setMinX(-180.0);
    lineString3dMContents.setMinY(-90.0);
    lineString3dMContents.setMaxX(180.0);
    lineString3dMContents.setMaxY(90.0);
    lineString3dMContents.setSrs(undefinedCartesianSrs);
    // Create Data Column Constraints table and rows
    TestUtils.createConstraints(geoPackage);
    // Create data columns table
    (new SchemaExtension(geoPackage)).createDataColumnsTable();
    String geometryColumn = "geometry";
    // Create the feature tables
    FeatureTable point2dTable = TestUtils.createFeatureTable(geoPackage, point2dContents, geometryColumn, GeometryType.POINT);
    FeatureTable polygon2dTable = TestUtils.createFeatureTable(geoPackage, polygon2dContents, geometryColumn, GeometryType.POLYGON);
    FeatureTable point3dTable = TestUtils.createFeatureTable(geoPackage, point3dContents, geometryColumn, GeometryType.POINT);
    FeatureTable lineString3dMTable = TestUtils.createFeatureTable(geoPackage, lineString3dMContents, geometryColumn, GeometryType.LINESTRING);
    // Create the contents
    contentsDao.create(point2dContents);
    contentsDao.create(polygon2dContents);
    contentsDao.create(point3dContents);
    contentsDao.create(lineString3dMContents);
    // Create new Geometry Columns
    GeometryColumnsDao geometryColumnsDao = geoPackage.getGeometryColumnsDao();
    GeometryColumns point2dGeometryColumns = new GeometryColumns();
    point2dGeometryColumns.setContents(point2dContents);
    point2dGeometryColumns.setColumnName(geometryColumn);
    point2dGeometryColumns.setGeometryType(GeometryType.POINT);
    point2dGeometryColumns.setSrs(point2dContents.getSrs());
    point2dGeometryColumns.setZ((byte) 0);
    point2dGeometryColumns.setM((byte) 0);
    geometryColumnsDao.create(point2dGeometryColumns);
    GeometryColumns polygon2dGeometryColumns = new GeometryColumns();
    polygon2dGeometryColumns.setContents(polygon2dContents);
    polygon2dGeometryColumns.setColumnName(geometryColumn);
    polygon2dGeometryColumns.setGeometryType(GeometryType.POLYGON);
    polygon2dGeometryColumns.setSrs(polygon2dContents.getSrs());
    polygon2dGeometryColumns.setZ((byte) 0);
    polygon2dGeometryColumns.setM((byte) 0);
    geometryColumnsDao.create(polygon2dGeometryColumns);
    GeometryColumns point3dGeometryColumns = new GeometryColumns();
    point3dGeometryColumns.setContents(point3dContents);
    point3dGeometryColumns.setColumnName(geometryColumn);
    point3dGeometryColumns.setGeometryType(GeometryType.POINT);
    point3dGeometryColumns.setSrs(point3dContents.getSrs());
    point3dGeometryColumns.setZ((byte) 1);
    point3dGeometryColumns.setM((byte) 0);
    geometryColumnsDao.create(point3dGeometryColumns);
    GeometryColumns lineString3dMGeometryColumns = new GeometryColumns();
    lineString3dMGeometryColumns.setContents(lineString3dMContents);
    lineString3dMGeometryColumns.setColumnName(geometryColumn);
    lineString3dMGeometryColumns.setGeometryType(GeometryType.LINESTRING);
    lineString3dMGeometryColumns.setSrs(lineString3dMContents.getSrs());
    lineString3dMGeometryColumns.setZ((byte) 1);
    lineString3dMGeometryColumns.setM((byte) 1);
    geometryColumnsDao.create(lineString3dMGeometryColumns);
    // Populate the feature tables with rows
    TestUtils.addRowsToFeatureTable(geoPackage, point2dGeometryColumns, point2dTable, 3, false, false, allowEmptyFeatures);
    TestUtils.addRowsToFeatureTable(geoPackage, polygon2dGeometryColumns, polygon2dTable, 3, false, false, allowEmptyFeatures);
    TestUtils.addRowsToFeatureTable(geoPackage, point3dGeometryColumns, point3dTable, 3, true, false, allowEmptyFeatures);
    TestUtils.addRowsToFeatureTable(geoPackage, lineString3dMGeometryColumns, lineString3dMTable, 3, true, true, allowEmptyFeatures);
}
Also used : GeometryColumns(mil.nga.geopackage.features.columns.GeometryColumns) SpatialReferenceSystemDao(mil.nga.geopackage.srs.SpatialReferenceSystemDao) SchemaExtension(mil.nga.geopackage.extension.schema.SchemaExtension) FeatureTable(mil.nga.geopackage.features.user.FeatureTable) Contents(mil.nga.geopackage.contents.Contents) SpatialReferenceSystem(mil.nga.geopackage.srs.SpatialReferenceSystem) ContentsDao(mil.nga.geopackage.contents.ContentsDao) GeometryColumnsDao(mil.nga.geopackage.features.columns.GeometryColumnsDao)

Aggregations

SpatialReferenceSystem (mil.nga.geopackage.srs.SpatialReferenceSystem)3 SpatialReferenceSystemDao (mil.nga.geopackage.srs.SpatialReferenceSystemDao)3 Contents (mil.nga.geopackage.contents.Contents)2 ContentsDao (mil.nga.geopackage.contents.ContentsDao)2 Bitmap (android.graphics.Bitmap)1 SQLException (java.sql.SQLException)1 GeoPackageException (mil.nga.geopackage.GeoPackageException)1 SchemaExtension (mil.nga.geopackage.extension.schema.SchemaExtension)1 GeometryColumns (mil.nga.geopackage.features.columns.GeometryColumns)1 GeometryColumnsDao (mil.nga.geopackage.features.columns.GeometryColumnsDao)1 FeatureTable (mil.nga.geopackage.features.user.FeatureTable)1 TileMatrix (mil.nga.geopackage.tiles.matrix.TileMatrix)1 TileMatrixDao (mil.nga.geopackage.tiles.matrix.TileMatrixDao)1 TileMatrixSet (mil.nga.geopackage.tiles.matrixset.TileMatrixSet)1 TileMatrixSetDao (mil.nga.geopackage.tiles.matrixset.TileMatrixSetDao)1 TileTable (mil.nga.geopackage.tiles.user.TileTable)1 Projection (mil.nga.proj.Projection)1 Geometry (mil.nga.sf.Geometry)1 Point (mil.nga.sf.Point)1 GeometryTransform (mil.nga.sf.proj.GeometryTransform)1