mil.nga.geopackage.BoundingBox Java Examples
The following examples show how to use
mil.nga.geopackage.BoundingBox.
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 |
/** * 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: UrlTileGeneratorUtils.java From geopackage-java with MIT License | 6 votes |
/** * Test generating tiles with random bounds and zoomss * * @param geoPackage * @throws SQLException * @throws IOException */ public static void testGenerateTilesRandom(GeoPackage geoPackage) throws SQLException, IOException { for (int i = 0; i < 10; i++) { int minZoom = (int) (Math.random() * 3.0); int maxZoom = minZoom + ((int) (Math.random() * 3.0)); Point point1 = TestUtils.createPoint(false, false); Point point2 = TestUtils.createPoint(false, false); BoundingBox boundingBox = new BoundingBox(Math.min(point1.getX(), point2.getX()), Math.min(point1.getY(), point2.getY()), Math.max(point1.getX(), point2.getX()), Math.max( point1.getY(), point2.getY())); UrlTileGenerator tileGenerator = new UrlTileGenerator(geoPackage, TABLE_NAME + i, URL, minZoom, maxZoom, boundingBox, getProjection()); testGenerateTiles(tileGenerator); } }
Example #3
Source File: TileCreator.java From geopackage-android with MIT License | 6 votes |
/** * Get the tile row results of tiles needed to draw the requested bounding box tile * * @param projectedRequestBoundingBox bounding box projected to the tiles * @param tileMatrix * @return tile cursor results or null */ private TileCursor retrieveTileResults(BoundingBox projectedRequestBoundingBox, TileMatrix tileMatrix) { TileCursor tileResults = null; if (tileMatrix != null) { // Get the tile grid TileGrid tileGrid = TileBoundingBoxUtils.getTileGrid( tileSetBoundingBox, tileMatrix.getMatrixWidth(), tileMatrix.getMatrixHeight(), projectedRequestBoundingBox); // Query for matching tiles in the tile grid tileResults = tileDao.queryByTileGrid(tileGrid, tileMatrix.getZoomLevel()); } return tileResults; }
Example #4
Source File: UrlTileGenerator.java From geopackage-android with MIT License | 6 votes |
/** * Replace the url parts with the bounding box * * @param url * @param boundingBox * @return */ private String replaceBoundingBox(String url, BoundingBox boundingBox) { url = url.replaceAll( context.getString(R.string.tile_generator_variable_min_lat), String.valueOf(boundingBox.getMinLatitude())); url = url.replaceAll( context.getString(R.string.tile_generator_variable_max_lat), String.valueOf(boundingBox.getMaxLatitude())); url = url.replaceAll( context.getString(R.string.tile_generator_variable_min_lon), String.valueOf(boundingBox.getMinLongitude())); url = url.replaceAll( context.getString(R.string.tile_generator_variable_max_lon), String.valueOf(boundingBox.getMaxLongitude())); return url; }
Example #5
Source File: CoverageData.java From geopackage-android with MIT License | 6 votes |
/** * Get the tile row results of coverage data tiles needed to create the * requested bounding box coverage data, sorted by row and then column * * @param projectedRequestBoundingBox bounding box projected to the coverage data * @param tileMatrix tile matrix * @return tile results or null */ private TileCursor retrieveSortedTileResults( BoundingBox projectedRequestBoundingBox, TileMatrix tileMatrix) { TileCursor tileResults = null; if (tileMatrix != null) { // Get the tile grid TileGrid tileGrid = TileBoundingBoxUtils.getTileGrid( coverageBoundingBox, tileMatrix.getMatrixWidth(), tileMatrix.getMatrixHeight(), projectedRequestBoundingBox); // Query for matching tiles in the tile grid tileResults = tileDao.queryByTileGrid(tileGrid, tileMatrix.getZoomLevel(), TileTable.COLUMN_TILE_ROW + "," + TileTable.COLUMN_TILE_COLUMN); } return tileResults; }
Example #6
Source File: FeatureTiles.java From geopackage-android with MIT License | 6 votes |
/** * Create an expanded bounding box to handle features outside the tile that * overlap * * @param boundingBox bounding box * @param projection bounding box projection * @return bounding box * @since 3.2.0 */ public BoundingBox expandBoundingBox(BoundingBox boundingBox, Projection projection) { BoundingBox expandedBoundingBox = boundingBox; ProjectionTransform toWebMercator = projection .getTransformation(ProjectionConstants.EPSG_WEB_MERCATOR); if (!toWebMercator.isSameProjection()) { expandedBoundingBox = expandedBoundingBox.transform(toWebMercator); } expandedBoundingBox = expandBoundingBox(expandedBoundingBox); if (!toWebMercator.isSameProjection()) { ProjectionTransform fromWebMercator = toWebMercator .getInverseTransformation(); expandedBoundingBox = expandedBoundingBox .transform(fromWebMercator); } return expandedBoundingBox; }
Example #7
Source File: DefaultFeatureTiles.java From geopackage-java with MIT License | 6 votes |
/** * Get the area of the polygon * * @param simplifyTolerance * simplify tolerance in meters * @param boundingBox * @param transform * @param lineString */ private Area getArea(double simplifyTolerance, BoundingBox boundingBox, ProjectionTransform transform, Polygon polygon) { Area area = null; for (LineString ring : polygon.getRings()) { Path2D path = getPath(simplifyTolerance, boundingBox, transform, ring); Area ringArea = new Area(path); if (area == null) { area = ringArea; } else { area.subtract(ringArea); } } return area; }
Example #8
Source File: GeoPackageTestUtils.java From geopackage-android with MIT License | 6 votes |
/** * 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 #9
Source File: FeatureTileGenerator.java From geopackage-java with MIT License | 6 votes |
/** * {@inheritDoc} */ @Override public BoundingBox getBoundingBox(int zoom) { ProjectionTransform projectionToWebMercator = projection .getTransformation(ProjectionConstants.EPSG_WEB_MERCATOR); BoundingBox webMercatorBoundingBox = boundingBox .transform(projectionToWebMercator); TileGrid tileGrid = TileBoundingBoxUtils.getTileGrid( webMercatorBoundingBox, zoom); BoundingBox tileBoundingBox = TileBoundingBoxUtils .getWebMercatorBoundingBox(tileGrid.getMinX(), tileGrid.getMinY(), zoom); BoundingBox expandedBoundingBox = featureTiles.expandBoundingBox( webMercatorBoundingBox, tileBoundingBox); BoundingBox zoomBoundingBox = expandedBoundingBox .transform(projectionToWebMercator.getInverseTransformation()); return zoomBoundingBox; }
Example #10
Source File: CoverageData.java From geopackage-java with MIT License | 6 votes |
/** * Get the coverage data tile results by zooming in or out as needed from * the provided tile matrix to find values * * @param requestProjectedBoundingBox * request projected bounding box * @param tileMatrix * tile matrix * @param overlappingPixels * overlapping request pixels * @return tile matrix results */ private CoverageDataTileMatrixResults getResultsZoom( BoundingBox requestProjectedBoundingBox, TileMatrix tileMatrix, int overlappingPixels) { CoverageDataTileMatrixResults results = null; if (zoomIn && zoomInBeforeOut) { results = getResultsZoomIn(requestProjectedBoundingBox, tileMatrix, overlappingPixels); } if (results == null && zoomOut) { results = getResultsZoomOut(requestProjectedBoundingBox, tileMatrix, overlappingPixels); } if (results == null && zoomIn && !zoomInBeforeOut) { results = getResultsZoomIn(requestProjectedBoundingBox, tileMatrix, overlappingPixels); } return results; }
Example #11
Source File: FeatureTileGenerator.java From geopackage-android with MIT License | 6 votes |
/** * Get the bounding box for the feature tile generator, from the provided * and from the feature table * * @param geoPackage GeoPackage * @param featureTiles feature tiles * @param boundingBox bounding box * @param projection projection * @return bounding box */ private static BoundingBox getBoundingBox(GeoPackage geoPackage, FeatureTiles featureTiles, BoundingBox boundingBox, Projection projection) { String tableName = featureTiles.getFeatureDao().getTableName(); boolean manualQuery = boundingBox == null; BoundingBox featureBoundingBox = geoPackage.getBoundingBox(projection, tableName, manualQuery); if (featureBoundingBox != null) { if (boundingBox == null) { boundingBox = featureBoundingBox; } else { boundingBox = boundingBox.overlap(featureBoundingBox); } } if (boundingBox != null) { boundingBox = featureTiles.expandBoundingBox(boundingBox, projection); } return boundingBox; }
Example #12
Source File: DefaultFeatureTiles.java From geopackage-android with MIT License | 6 votes |
/** * Add the linestring to the path * * @param simplifyTolerance simplify tolerance in meters * @param boundingBox bounding box * @param transform projection transform * @param path path * @param lineString line string */ private void addLineString(double simplifyTolerance, BoundingBox boundingBox, ProjectionTransform transform, Path path, LineString lineString) { List<Point> points = lineString.getPoints(); if (points.size() >= 2) { // Try to simplify the number of points in the LineString points = simplifyPoints(simplifyTolerance, points); for (int i = 0; i < points.size(); i++) { Point point = points.get(i); Point webMercatorPoint = transform.transform(point); float x = TileBoundingBoxUtils.getXPixel(tileWidth, boundingBox, webMercatorPoint.getX()); float y = TileBoundingBoxUtils.getYPixel(tileHeight, boundingBox, webMercatorPoint.getY()); if (i == 0) { path.moveTo(x, y); } else { path.lineTo(x, y); } } } }
Example #13
Source File: RTreeIndexTableDao.java From geopackage-java with MIT License | 5 votes |
/** * {@inheritDoc} */ @Override public BoundingBox getBoundingBox(Projection projection) { BoundingBox boundingBox = getBoundingBox(); if (boundingBox != null && projection != null) { ProjectionTransform projectionTransform = featureDao.getProjection() .getTransformation(projection); boundingBox = boundingBox.transform(projectionTransform); } return boundingBox; }
Example #14
Source File: GeoPackageExample.java From geopackage-android with MIT License | 5 votes |
private static void createTiles(Context context, GeoPackage geoPackage) throws IOException, SQLException { geoPackage.createTileMatrixSetTable(); geoPackage.createTileMatrixTable(); BoundingBox bitsBoundingBox = new BoundingBox(-11667347.997449303, 4824705.2253603265, -11666125.00499674, 4825928.217812888); createTiles(context, geoPackage, "bit_systems", bitsBoundingBox, 15, 17, "png"); BoundingBox ngaBoundingBox = new BoundingBox(-8593967.964158937, 4685284.085768163, -8592744.971706374, 4687730.070673289); createTiles(context, geoPackage, "nga", ngaBoundingBox, 15, 16, "png"); }
Example #15
Source File: BoundedOverlay.java From geopackage-android-map with MIT License | 5 votes |
/** * Get the bounding box as the provided projection * * @param projection projection */ public BoundingBox getBoundingBox(Projection projection) { ProjectionTransform webMercatorToProjection = ProjectionFactory .getProjection(ProjectionConstants.EPSG_WEB_MERCATOR) .getTransformation(projection); return webMercatorBoundingBox .transform(webMercatorToProjection); }
Example #16
Source File: GeoPackageTextOutput.java From geopackage-java with MIT License | 5 votes |
/** * Text output from a bounding box * * @param boundingBox * bounding box * @return text */ public String textOutput(BoundingBox boundingBox) { StringBuilder output = new StringBuilder(); output.append("\tMin Longitude: " + boundingBox.getMinLongitude()); output.append("\n\tMin Latitude: " + boundingBox.getMinLatitude()); output.append("\n\tMax Longitude: " + boundingBox.getMaxLongitude()); output.append("\n\tMax Latitude: " + boundingBox.getMaxLatitude()); return output.toString(); }
Example #17
Source File: CoverageDataTestUtils.java From geopackage-android with MIT License | 5 votes |
/** * Get the coverage data for the bounding box * * @param geoPackage GeoPackage * @param algorithm algorithm * @param boundingBox bounding box * @param width results width * @param height results height * @param epsg epsg code * @return coverage data results * @throws Exception */ public static CoverageDataResults getValues(GeoPackage geoPackage, CoverageDataAlgorithm algorithm, BoundingBox boundingBox, int width, int height, long epsg) throws Exception { CoverageDataResults values = null; List<String> coverageDataTables = CoverageData.getTables(geoPackage); TileMatrixSetDao dao = geoPackage.getTileMatrixSetDao(); for (String coverageTable : coverageDataTables) { TileMatrixSet tileMatrixSet = dao.queryForId(coverageTable); TileDao tileDao = geoPackage.getTileDao(tileMatrixSet); Projection requestProjection = ProjectionFactory .getProjection(epsg); // Test getting the coverage data value of a single coordinate CoverageData<?> coverageData = CoverageData.getCoverageData(geoPackage, tileDao, requestProjection); coverageData.setAlgorithm(algorithm); coverageData.setWidth(width); coverageData.setHeight(height); values = coverageData.getValues(boundingBox); } return values; }
Example #18
Source File: FeatureTiles.java From geopackage-java with MIT License | 5 votes |
/** * Query for feature result count in the x, y, and zoom * * @param x * x coordinate * @param y * y coordinate * @param zoom * zoom level * @return feature count */ public long queryIndexedFeaturesCount(int x, int y, int zoom) { // Get the web mercator bounding box BoundingBox webMercatorBoundingBox = TileBoundingBoxUtils .getWebMercatorBoundingBox(x, y, zoom); // Query for the count of geometries matching the bounds in the index long count = queryIndexedFeaturesCount(webMercatorBoundingBox); return count; }
Example #19
Source File: TileBoundingBoxUtils.java From geopackage-core-java with MIT License | 5 votes |
/** * Get the Y pixel for where the latitude fits into the bounding box * * @param height * height * @param boundingBox * bounding box * @param latitude * latitude * @return y pixel */ public static float getYPixel(long height, BoundingBox boundingBox, double latitude) { double boxHeight = boundingBox.getMaxLatitude() - boundingBox.getMinLatitude(); double offset = boundingBox.getMaxLatitude() - latitude; double percentage = offset / boxHeight; float pixel = (float) (percentage * height); return pixel; }
Example #20
Source File: Contents.java From geopackage-core-java with MIT License | 5 votes |
/** * Get a bounding box in the provided projection * * @param projection * desired projection * * @return bounding box * @since 3.1.0 */ public BoundingBox getBoundingBox(Projection projection) { BoundingBox boundingBox = getBoundingBox(); if (boundingBox != null && projection != null) { ProjectionTransform transform = getProjection().getTransformation( projection); if (!transform.isSameProjection()) { boundingBox = boundingBox.transform(transform); } } return boundingBox; }
Example #21
Source File: TileGenerator.java From geopackage-android with MIT License | 5 votes |
/** * Adjust the tile matrix set and web mercator bounds for XYZ tile format */ private void adjustXYZBounds() { // Set the tile matrix set bounding box to be the world BoundingBox standardWgs84Box = new BoundingBox(-ProjectionConstants.WGS84_HALF_WORLD_LON_WIDTH, ProjectionConstants.WEB_MERCATOR_MIN_LAT_RANGE, ProjectionConstants.WGS84_HALF_WORLD_LON_WIDTH, ProjectionConstants.WEB_MERCATOR_MAX_LAT_RANGE); ProjectionTransform wgs84ToWebMercatorTransform = ProjectionFactory.getProjection(ProjectionConstants.EPSG_WORLD_GEODETIC_SYSTEM) .getTransformation(ProjectionConstants.EPSG_WEB_MERCATOR); tileGridBoundingBox = standardWgs84Box.transform(wgs84ToWebMercatorTransform); }
Example #22
Source File: GoogleMapShapeConverter.java From geopackage-android-map with MIT License | 5 votes |
/** * Transform the bounding box in the feature projection to WGS84 * * @param boundingBox bounding box in feature projection * @return bounding box in WGS84 */ public BoundingBox boundingBoxToWgs84(BoundingBox boundingBox) { if (projection == null) { throw new GeoPackageException("Shape Converter projection is null"); } return boundingBox.transform(toWgs84); }
Example #23
Source File: TileDao.java From geopackage-java with MIT License | 5 votes |
/** * Determine if the tiles are in the XYZ tile coordinate format * * @return true if XYZ tile format * @since 3.5.0 */ public boolean isXYZTiles() { // Convert the bounding box to wgs84 BoundingBox boundingBox = tileMatrixSet.getBoundingBox(); BoundingBox wgs84BoundingBox = boundingBox .transform(projection.getTransformation( ProjectionConstants.EPSG_WORLD_GEODETIC_SYSTEM)); boolean xyzTiles = false; // Verify the bounds are the entire world if (wgs84BoundingBox .getMinLatitude() <= ProjectionConstants.WEB_MERCATOR_MIN_LAT_RANGE && wgs84BoundingBox .getMaxLatitude() >= ProjectionConstants.WEB_MERCATOR_MAX_LAT_RANGE && wgs84BoundingBox .getMinLongitude() <= -ProjectionConstants.WGS84_HALF_WORLD_LON_WIDTH && wgs84BoundingBox .getMaxLongitude() >= ProjectionConstants.WGS84_HALF_WORLD_LON_WIDTH) { xyzTiles = true; // Verify each tile matrix is the correct width and height for (TileMatrix tileMatrix : tileMatrices) { long zoomLevel = tileMatrix.getZoomLevel(); long tilesPerSide = TileBoundingBoxUtils .tilesPerSide((int) zoomLevel); if (tileMatrix.getMatrixWidth() != tilesPerSide || tileMatrix.getMatrixHeight() != tilesPerSide) { xyzTiles = false; break; } } } return xyzTiles; }
Example #24
Source File: FeatureIndexer.java From geopackage-android with MIT License | 5 votes |
/** * Query for Geometry Metadata ids within the bounding box in * the provided projection * * @param boundingBox bounding box * @param projection projection of the provided bounding box * @return geometry metadata cursor * @since 3.4.0 */ public Cursor queryIds(BoundingBox boundingBox, Projection projection) { BoundingBox featureBoundingBox = getFeatureBoundingBox(boundingBox, projection); Cursor cursor = queryIds(featureBoundingBox); return cursor; }
Example #25
Source File: FeatureDao.java From geopackage-java with MIT License | 4 votes |
/** * {@inheritDoc} */ @Override public BoundingBox getBoundingBox() { return getBoundingBox(projection); }
Example #26
Source File: OAPIFeatureGeneratorTest.java From geopackage-android with MIT License | 4 votes |
/** * Test a WFS server and create a GeoPackage * * @param server server url * @param collection collection name * @param name geoPackage and table name * @param limit request limit * @param totalLimit total limit * @param boundingBox bounding box * @param time time * @param period period or end time * @throws SQLException upon error */ private void testServer(String server, String collection, String name, Integer limit, Integer totalLimit, BoundingBox boundingBox, String time, String period) throws SQLException { GeoPackageManager geoPackageManager = GeoPackageFactory.getManager(activity); geoPackageManager.delete(collection); geoPackageManager.create(collection); GeoPackage geoPackage = geoPackageManager.open(collection); OAPIFeatureGenerator generator = new OAPIFeatureGenerator( geoPackage, name, server, collection); generator.setLimit(limit); generator.setTotalLimit(totalLimit); generator.setBoundingBox(boundingBox); generator.setTime(time); generator.setPeriod(period); generator.setDownloadAttempts(3); int count = generator.generateFeatures(); if (totalLimit != null) { TestCase.assertEquals(totalLimit.intValue(), count); } FeatureDao featureDao = generator.getFeatureDao(); if (totalLimit != null) { TestCase.assertEquals(totalLimit.intValue(), featureDao.count()); } FeatureIndexManager indexer = new FeatureIndexManager(activity, geoPackage, featureDao); indexer.setIndexLocation(FeatureIndexType.GEOPACKAGE); indexer.index(); indexer.close(); BoundingBox dataBounds = geoPackage .getBoundingBox(featureDao.getTableName()); Contents contents = featureDao.getContents(); contents.setBoundingBox(dataBounds); geoPackage.getContentsDao().update(contents); geoPackage.close(); }
Example #27
Source File: MapUtils.java From geopackage-android-map with MIT License | 4 votes |
/** * Get the tolerance distance meters in the current region of the map * * @param view view * @param map google map * @return tolerance distance in meters */ public static double getToleranceDistance(View view, GoogleMap map) { BoundingBox boundingBox = getBoundingBox(map); double boundingBoxWidth = TileBoundingBoxMapUtils.getLongitudeDistance(boundingBox); double boundingBoxHeight = TileBoundingBoxMapUtils.getLatitudeDistance(boundingBox); int viewWidth = view.getWidth(); int viewHeight = view.getHeight(); double meters = 0; if (viewWidth > 0 && viewHeight > 0) { double widthMeters = boundingBoxWidth / viewWidth; double heightMeters = boundingBoxHeight / viewHeight; meters = Math.min(widthMeters, heightMeters); } return meters; }
Example #28
Source File: AttributesDao.java From geopackage-java with MIT License | 4 votes |
/** * {@inheritDoc} * * Not supported for Attributes */ @Override public BoundingBox getBoundingBox() { throw new GeoPackageException( "Bounding Box not supported for Attributes"); }
Example #29
Source File: FeaturePreviewUtils.java From geopackage-android with MIT License | 4 votes |
/** * Test the GeoPackage draw feature preview * * @param activity activity * @param geoPackage GeoPackage * @throws IOException upon error */ public static void testDraw(Activity activity, GeoPackage geoPackage) throws IOException { for (String featureTable : geoPackage.getFeatureTables()) { FeatureDao featureDao = geoPackage.getFeatureDao(featureTable); int count = featureDao.count( CoreSQLUtils.quoteWrap(featureDao.getGeometryColumnName()) + " IS NOT NULL"); BoundingBox contentsBoundingBox = geoPackage .getContentsBoundingBox(featureTable); BoundingBox indexedBoundingBox = geoPackage .getBoundingBox(featureTable); boolean expectImage = (contentsBoundingBox != null || indexedBoundingBox != null) && count > 0; boolean epsg = featureDao.getProjection().getAuthority() .equalsIgnoreCase(ProjectionConstants.AUTHORITY_EPSG); FeaturePreview preview = new FeaturePreview(activity, geoPackage, featureDao); Bitmap image = preview.draw(); if (epsg) { assertEquals(expectImage, image != null); } preview.setBufferPercentage(0.4); preview.setLimit((int) Math.ceil(count / 2.0)); Bitmap imageLimit = preview.draw(); if (epsg) { assertEquals(expectImage, imageLimit != null); } preview.setManual(true); preview.setBufferPercentage(0.05); preview.setLimit(null); FeatureTiles featureTiles = preview.getFeatureTiles(); featureTiles.setTileWidth(TileUtils.TILE_PIXELS_DEFAULT); featureTiles.setTileHeight(TileUtils.TILE_PIXELS_DEFAULT); featureTiles.setDensity( TileUtils.density(TileUtils.TILE_PIXELS_DEFAULT)); featureTiles.clearIconCache(); Bitmap imageManual = preview.draw(); if (epsg) { assertNotNull(imageManual); } preview.setBufferPercentage(0.35); preview.setLimit(Math.max(count - 1, 1)); Bitmap imageManualLimit = preview.draw(); if (epsg) { assertNotNull(imageManualLimit); } preview.setBufferPercentage(0.15); preview.setLimit(null); preview.appendWhere( CoreSQLUtils.quoteWrap(featureDao.getIdColumnName()) + " > " + ((int) Math.floor(count / 2.0))); Bitmap imageManualWhere = preview.draw(); if (epsg) { assertNotNull(imageManualWhere); } if(image != null) { image.recycle(); } if(imageLimit != null) { imageLimit.recycle(); } if(imageManual != null) { imageManual.recycle(); } if(imageManualLimit != null) { imageManualLimit.recycle(); } if(imageManualWhere != null) { imageManualWhere.recycle(); } preview.close(); } }
Example #30
Source File: GeoPackageExample.java From geopackage-java with MIT License | 4 votes |
private static void createCoverageDataPngExtension(GeoPackage geoPackage) throws SQLException { BoundingBox bbox = new BoundingBox(-11667347.997449303, 4824705.2253603265, -11666125.00499674, 4825928.217812888); int contentsEpsg = ProjectionConstants.EPSG_WEB_MERCATOR; int tileMatrixSetEpsg = ProjectionConstants.EPSG_WEB_MERCATOR; SpatialReferenceSystemDao srsDao = geoPackage .getSpatialReferenceSystemDao(); srsDao.getOrCreateFromEpsg( ProjectionConstants.EPSG_WORLD_GEODETIC_SYSTEM_GEOGRAPHICAL_3D); SpatialReferenceSystem contentsSrs = srsDao .getOrCreateFromEpsg(contentsEpsg); SpatialReferenceSystem tileMatrixSetSrs = srsDao .getOrCreateFromEpsg(tileMatrixSetEpsg); ProjectionTransform transform = tileMatrixSetSrs.getProjection() .getTransformation(contentsSrs.getProjection()); BoundingBox contentsBoundingBox = bbox; if (!transform.isSameProjection()) { contentsBoundingBox = bbox.transform(transform); } CoverageDataPng coverageData = CoverageDataPng .createTileTableWithMetadata(geoPackage, "coverage_png", contentsBoundingBox, contentsSrs.getId(), bbox, tileMatrixSetSrs.getId()); TileDao tileDao = coverageData.getTileDao(); TileMatrixSet tileMatrixSet = coverageData.getTileMatrixSet(); GriddedCoverageDao griddedCoverageDao = coverageData .getGriddedCoverageDao(); GriddedCoverage griddedCoverage = new GriddedCoverage(); griddedCoverage.setTileMatrixSet(tileMatrixSet); griddedCoverage.setDataType(GriddedCoverageDataType.INTEGER); griddedCoverage .setDataNull(new Double(Short.MAX_VALUE - Short.MIN_VALUE)); griddedCoverage .setGridCellEncodingType(GriddedCoverageEncodingType.CENTER); griddedCoverageDao.create(griddedCoverage); GriddedTileDao griddedTileDao = coverageData.getGriddedTileDao(); int width = 1; int height = 1; int tileWidth = 3; int tileHeight = 3; short[][] tilePixels = new short[tileHeight][tileWidth]; tilePixels[0][0] = (short) 1661.95; tilePixels[0][1] = (short) 1665.40; tilePixels[0][2] = (short) 1668.19; tilePixels[1][0] = (short) 1657.18; tilePixels[1][1] = (short) 1663.39; tilePixels[1][2] = (short) 1669.65; tilePixels[2][0] = (short) 1654.78; tilePixels[2][1] = (short) 1660.31; tilePixels[2][2] = (short) 1666.44; byte[] imageBytes = coverageData.drawTileData(tilePixels); TileMatrixDao tileMatrixDao = geoPackage.getTileMatrixDao(); TileMatrix tileMatrix = new TileMatrix(); tileMatrix.setContents(tileMatrixSet.getContents()); tileMatrix.setMatrixHeight(height); tileMatrix.setMatrixWidth(width); tileMatrix.setTileHeight(tileHeight); tileMatrix.setTileWidth(tileWidth); tileMatrix .setPixelXSize((bbox.getMaxLongitude() - bbox.getMinLongitude()) / width / tileWidth); tileMatrix.setPixelYSize((bbox.getMaxLatitude() - bbox.getMinLatitude()) / height / tileHeight); tileMatrix.setZoomLevel(15); tileMatrixDao.create(tileMatrix); TileRow tileRow = tileDao.newRow(); tileRow.setTileColumn(0); tileRow.setTileRow(0); tileRow.setZoomLevel(tileMatrix.getZoomLevel()); tileRow.setTileData(imageBytes); long tileId = tileDao.create(tileRow); GriddedTile griddedTile = new GriddedTile(); griddedTile.setContents(tileMatrixSet.getContents()); griddedTile.setTableId(tileId); griddedTileDao.create(griddedTile); }