use of mil.nga.proj.Projection 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);
}
}
}
use of mil.nga.proj.Projection in project geopackage-android-map by ngageoint.
the class FeatureOverlayQueryTest method testTileBounds.
/**
* Test Tile Bounds
*/
@Test
public void testTileBounds() {
double longitude = -77.196785;
double latitude = 38.753195;
int zoom = 6;
LatLng coordinate = new LatLng(latitude, longitude);
BoundingBox boundingBox = FeatureOverlayQuery.tileBounds(coordinate, zoom);
TestCase.assertEquals(-78.75000000000001, boundingBox.getMinLongitude(), 0.0);
TestCase.assertEquals(36.597889133070204, boundingBox.getMinLatitude(), 0.0);
TestCase.assertEquals(-73.125, boundingBox.getMaxLongitude(), 0.0);
TestCase.assertEquals(40.97989806962014, boundingBox.getMaxLatitude(), 0.0);
Point point = new Point(longitude, latitude);
BoundingBox boundingBox2 = FeatureOverlayQuery.tileBounds(point, zoom);
TestCase.assertEquals(boundingBox, boundingBox2);
Projection projection = ProjectionFactory.getProjection(ProjectionConstants.EPSG_WEB_MERCATOR);
GeometryTransform transform = GeometryTransform.create(ProjectionConstants.EPSG_WORLD_GEODETIC_SYSTEM, projection);
point = transform.transform(point);
boundingBox = FeatureOverlayQuery.tileBounds(projection, point, zoom);
TestCase.assertEquals(-8766409.899970295, boundingBox.getMinLongitude(), 0.0);
TestCase.assertEquals(4383204.9499851465, boundingBox.getMinLatitude(), 0.0);
TestCase.assertEquals(-8140237.7642581295, boundingBox.getMaxLongitude(), 0.0);
TestCase.assertEquals(5009377.085697312, boundingBox.getMaxLatitude(), 0.0);
longitude = 151.215026;
latitude = -33.856686;
zoom = 15;
coordinate = new LatLng(latitude, longitude);
boundingBox = FeatureOverlayQuery.tileBounds(coordinate, zoom);
TestCase.assertEquals(151.20483398437506, boundingBox.getMinLongitude(), 0.0);
TestCase.assertEquals(-33.86129311351553, boundingBox.getMinLatitude(), 0.0);
TestCase.assertEquals(151.21582031250003, boundingBox.getMaxLongitude(), 0.0);
TestCase.assertEquals(-33.852169701407426, boundingBox.getMaxLatitude(), 0.0);
point = new Point(longitude, latitude);
boundingBox2 = FeatureOverlayQuery.tileBounds(point, zoom);
TestCase.assertEquals(boundingBox, boundingBox2);
point = transform.transform(point);
boundingBox = FeatureOverlayQuery.tileBounds(projection, point, zoom);
TestCase.assertEquals(16832045.124622095, boundingBox.getMinLongitude(), 0.0);
TestCase.assertEquals(-4010192.2519534864, boundingBox.getMinLatitude(), 0.0);
TestCase.assertEquals(16833268.117074657, boundingBox.getMaxLongitude(), 0.0);
TestCase.assertEquals(-4008969.2595009245, boundingBox.getMaxLatitude(), 0.0);
}
use of mil.nga.proj.Projection in project geopackage-android-map by ngageoint.
the class ReadmeTest method testGeoPackage.
/**
* Test GeoPackage
*
* @param context context
* @param geoPackageFile GeoPackage file
* @param map Google map
* @throws IOException upon error
* @throws SQLException upon error
*/
private void testGeoPackage(Context context, File geoPackageFile, GoogleMap map) throws IOException, SQLException {
// Context context = ...;
// File geoPackageFile = ...;
// GoogleMap map = ...;
// Get a manager
GeoPackageManager manager = GeoPackageFactory.getManager(context);
// Import database
boolean imported = manager.importGeoPackage(geoPackageFile);
// Available databases
List<String> databases = manager.databases();
// Open database
GeoPackage geoPackage = manager.open(databases.get(0));
// GeoPackage Table DAOs
SpatialReferenceSystemDao srsDao = geoPackage.getSpatialReferenceSystemDao();
ContentsDao contentsDao = geoPackage.getContentsDao();
GeometryColumnsDao geomColumnsDao = geoPackage.getGeometryColumnsDao();
TileMatrixSetDao tileMatrixSetDao = geoPackage.getTileMatrixSetDao();
TileMatrixDao tileMatrixDao = geoPackage.getTileMatrixDao();
SchemaExtension schemaExtension = new SchemaExtension(geoPackage);
DataColumnsDao dao = schemaExtension.getDataColumnsDao();
DataColumnConstraintsDao dataColumnConstraintsDao = schemaExtension.getDataColumnConstraintsDao();
MetadataExtension metadataExtension = new MetadataExtension(geoPackage);
MetadataDao metadataDao = metadataExtension.getMetadataDao();
MetadataReferenceDao metadataReferenceDao = metadataExtension.getMetadataReferenceDao();
ExtensionsDao extensionsDao = geoPackage.getExtensionsDao();
// Feature and tile tables
List<String> features = geoPackage.getFeatureTables();
List<String> tiles = geoPackage.getTileTables();
// Query Features
String featureTable = features.get(0);
FeatureDao featureDao = geoPackage.getFeatureDao(featureTable);
GoogleMapShapeConverter converter = new GoogleMapShapeConverter(featureDao.getProjection());
FeatureCursor featureCursor = featureDao.queryForAll();
try {
for (FeatureRow featureRow : featureCursor) {
GeoPackageGeometryData geometryData = featureRow.getGeometry();
if (geometryData != null && !geometryData.isEmpty()) {
Geometry geometry = geometryData.getGeometry();
GoogleMapShape shape = converter.toShape(geometry);
GoogleMapShape mapShape = GoogleMapShapeConverter.addShapeToMap(map, shape);
// ...
}
}
} finally {
featureCursor.close();
}
// Query Tiles
String tileTable = tiles.get(0);
TileDao tileDao = geoPackage.getTileDao(tileTable);
TileCursor tileCursor = tileDao.queryForAll();
try {
for (TileRow tileRow : tileCursor) {
byte[] tileBytes = tileRow.getTileData();
Bitmap tileBitmap = tileRow.getTileDataBitmap();
// ...
}
} finally {
tileCursor.close();
}
// Retrieve Tiles by XYZ
GeoPackageTileRetriever retriever = new GeoPackageTileRetriever(tileDao);
GeoPackageTile geoPackageTile = retriever.getTile(2, 2, 2);
if (geoPackageTile != null) {
byte[] tileBytes = geoPackageTile.getData();
Bitmap tileBitmap = geoPackageTile.getBitmap();
// ...
}
// Retrieve Tiles by Bounding Box
TileCreator tileCreator = new TileCreator(tileDao, ProjectionFactory.getProjection(ProjectionConstants.EPSG_WORLD_GEODETIC_SYSTEM));
GeoPackageTile geoPackageTile2 = tileCreator.getTile(new BoundingBox(-90.0, 0.0, 0.0, 66.513260));
if (geoPackageTile2 != null) {
byte[] tileBytes = geoPackageTile2.getData();
Bitmap tileBitmap = geoPackageTile2.getBitmap();
// ...
}
// Tile Provider (GeoPackage or Google API)
TileProvider overlay = GeoPackageOverlayFactory.getTileProvider(tileDao);
TileOverlayOptions overlayOptions = new TileOverlayOptions();
overlayOptions.tileProvider(overlay);
overlayOptions.zIndex(-1);
map.addTileOverlay(overlayOptions);
BoundingBox boundingBox = BoundingBox.worldWebMercator();
Projection projection = ProjectionFactory.getProjection(ProjectionConstants.EPSG_WEB_MERCATOR);
// Index Features
FeatureIndexManager indexer = new FeatureIndexManager(context, geoPackage, featureDao);
indexer.setIndexLocation(FeatureIndexType.GEOPACKAGE);
int indexedCount = indexer.index();
// Query Indexed Features in paginated chunks
FeatureIndexResults indexResults = indexer.queryForChunk(boundingBox, projection, 50);
FeaturePaginatedCursor paginatedCursor = indexer.paginate(indexResults);
for (FeatureRow featureRow : paginatedCursor) {
GeoPackageGeometryData geometryData = featureRow.getGeometry();
if (geometryData != null && !geometryData.isEmpty()) {
Geometry geometry = geometryData.getGeometry();
// ...
}
}
// Feature Tile Provider (dynamically draw tiles from features)
FeatureTiles featureTiles = new DefaultFeatureTiles(context, featureDao, context.getResources().getDisplayMetrics().density);
// Set max features to draw per tile
featureTiles.setMaxFeaturesPerTile(1000);
// Custom feature tile implementation
NumberFeaturesTile numberFeaturesTile = new NumberFeaturesTile(context);
// Draw feature count tiles when max features passed
featureTiles.setMaxFeaturesTileDraw(numberFeaturesTile);
// Set index manager to query feature indices
featureTiles.setIndexManager(indexer);
FeatureOverlay featureOverlay = new FeatureOverlay(featureTiles);
// Set zoom level to start showing tiles
featureOverlay.setMinZoom(featureDao.getZoomLevel());
TileOverlayOptions featureOverlayOptions = new TileOverlayOptions();
featureOverlayOptions.tileProvider(featureOverlay);
// Draw the feature tiles behind map markers
featureOverlayOptions.zIndex(-1);
map.addTileOverlay(featureOverlayOptions);
// URL Tile Generator (generate tiles from a URL)
TileGenerator urlTileGenerator = new UrlTileGenerator(context, geoPackage, "url_tile_table", "http://url/{z}/{x}/{y}.png", 0, 0, boundingBox, projection);
int urlTileCount = urlTileGenerator.generateTiles();
// Feature Tile Generator (generate tiles from features)
TileGenerator featureTileGenerator = new FeatureTileGenerator(context, geoPackage, "tiles_" + featureTable, featureTiles, 1, 2, boundingBox, projection);
int featureTileCount = featureTileGenerator.generateTiles();
// Close feature tiles (and indexer)
featureTiles.close();
// Close database when done
geoPackage.close();
}
Aggregations