mil.nga.geopackage.GeoPackage Java Examples
The following examples show how to use
mil.nga.geopackage.GeoPackage.
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 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 #2
Source File: GeoPackageExample.java From geopackage-java with MIT License | 6 votes |
private void validateNGAExtensions(GeoPackage geoPackage, boolean has) throws SQLException { ExtensionsDao extensionsDao = geoPackage.getExtensionsDao(); TestCase.assertEquals(has && GEOMETRY_INDEX, extensionsDao.isTableExists() && !extensionsDao .queryByExtension(FeatureTableIndex.EXTENSION_NAME) .isEmpty()); TestCase.assertEquals(has && FEATURE_TILE_LINK, new FeatureTileTableLinker(geoPackage).has()); TestCase.assertEquals(has && TILE_SCALING, extensionsDao.isTableExists() && !extensionsDao .queryByExtension(TileTableScaling.EXTENSION_NAME) .isEmpty()); TestCase.assertEquals(has && PROPERTIES, new PropertiesExtension(geoPackage).has()); TestCase.assertEquals(has && CONTENTS_ID, new ContentsIdExtension(geoPackage).has()); TestCase.assertEquals(has && FEATURE_STYLE, new FeatureStyleExtension(geoPackage).has()); }
Example #3
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 #4
Source File: GeoPackageExample.java From geopackage-android with MIT License | 6 votes |
private static void createRelatedTablesFeaturesExtension( GeoPackage geoPackage, String tableName1, String tableName2) { RelatedTablesExtension relatedTables = new RelatedTablesExtension( geoPackage); List<UserCustomColumn> additionalMappingColumns = RelatedTablesUtils .createAdditionalUserColumns(); UserMappingTable userMappingTable = UserMappingTable.create(tableName1 + "_" + tableName2, additionalMappingColumns); ExtendedRelation relation = relatedTables.addFeaturesRelationship( tableName1, tableName2, userMappingTable); insertRelatedTablesFeaturesExtensionRows(geoPackage, relation); }
Example #5
Source File: ImportCoverageDataTiffGeoPackageTestCase.java From geopackage-android with MIT License | 6 votes |
@Override protected GeoPackage getGeoPackage() throws Exception { GeoPackageManager manager = GeoPackageFactory.getManager(activity); // Delete manager.delete(TestConstants.IMPORT_COVERAGE_DATA_TIFF_DB_NAME); // Copy the test db file from assets to the internal storage TestUtils.copyAssetFileToInternalStorage(activity, testContext, TestConstants.IMPORT_COVERAGE_DATA_TIFF_DB_FILE_NAME); // Import String importLocation = TestUtils.getAssetFileInternalStorageLocation( activity, TestConstants.IMPORT_COVERAGE_DATA_TIFF_DB_FILE_NAME); manager.importGeoPackage(new File(importLocation)); // Open GeoPackage geoPackage = manager.open(TestConstants.IMPORT_COVERAGE_DATA_TIFF_DB_NAME); if (geoPackage == null) { throw new GeoPackageException("Failed to open database"); } return geoPackage; }
Example #6
Source File: UrlTileGenerator.java From geopackage-java with MIT License | 6 votes |
/** * Constructor * * @param geoPackage * GeoPackage * @param tableName * table name * @param tileUrl * tile url * @param minZoom * min zoom * @param maxZoom * max zoom * @param boundingBox * tiles bounding box * @param projection * tiles projection * @since 1.2.0 */ public UrlTileGenerator(GeoPackage geoPackage, String tableName, String tileUrl, int minZoom, int maxZoom, BoundingBox boundingBox, Projection projection) { super(geoPackage, tableName, minZoom, maxZoom, boundingBox, projection); try { this.tileUrl = URLDecoder.decode(tileUrl, "UTF-8"); } catch (UnsupportedEncodingException e) { throw new GeoPackageException( "Failed to decode tile url: " + tileUrl, e); } this.urlHasXYZ = hasXYZ(tileUrl); this.urlHasBoundingBox = hasBoundingBox(tileUrl); if (!this.urlHasXYZ && !this.urlHasBoundingBox) { throw new GeoPackageException( "URL does not contain x,y,z or bounding box variables: " + tileUrl); } }
Example #7
Source File: GeoPackageOverlayFactory.java From geopackage-android-map with MIT License | 6 votes |
/** * Create a composite overlay linking the feature overly with * * @param featureOverlay feature overlay * @param geoPackage GeoPackage * @return linked bounded overlay */ public static BoundedOverlay getLinkedFeatureOverlay(FeatureOverlay featureOverlay, GeoPackage geoPackage) { BoundedOverlay overlay; // Get the linked tile daos FeatureTileTableLinker linker = new FeatureTileTableLinker(geoPackage); List<TileDao> tileDaos = linker.getTileDaosForFeatureTable(featureOverlay.getFeatureTiles().getFeatureDao().getTableName()); if (!tileDaos.isEmpty()) { // Create a composite overlay to search for existing tiles before drawing from features overlay = getCompositeOverlay(tileDaos, featureOverlay); } else { overlay = featureOverlay; } return overlay; }
Example #8
Source File: PropertiesManagerTest.java From geopackage-android with MIT License | 6 votes |
private void addProperties(GeoPackage geoPackage, int i) { PropertiesExtension properties = new PropertiesExtension(geoPackage); properties.addValue(PropertyNames.TITLE, GEOPACKAGE_NAME + (i + 1)); properties.addValue(PropertyNames.IDENTIFIER, Integer.toString(i)); properties.addValue(EVEN_PROPERTY, i % 2 == 0 ? Boolean.TRUE.toString() : Boolean.FALSE.toString()); if (i % 2 == 1) { properties.addValue(ODD_PROPERTY, Boolean.TRUE.toString()); } if (i % COLOR_RED_FREQUENCY == 0) { properties.addValue(PropertyNames.TAG, COLOR_RED); } if (i % COLOR_GREEN_FREQUENCY == 0) { properties.addValue(PropertyNames.TAG, COLOR_GREEN); } if (i % COLOR_BLUE_FREQUENCY == 0) { properties.addValue(PropertyNames.TAG, COLOR_BLUE); } }
Example #9
Source File: SQLExec.java From geopackage-java with MIT License | 6 votes |
/** * Execute the SQL on the GeoPackage database * * @param database * open database * @param sql * SQL statement * @param maxRows * max rows * @return results * @throws SQLException * upon SQL error */ public static SQLExecResult executeSQL(GeoPackage database, String sql, Integer maxRows) throws SQLException { // If no max number of results, use the default if (maxRows == null) { maxRows = DEFAULT_MAX_ROWS; } sql = sql.trim(); RTreeIndexExtension rtree = new RTreeIndexExtension(database); if (rtree.has()) { rtree.createAllFunctions(); } SQLExecResult result = SQLExecAlterTable.alterTable(database, sql); if (result == null) { result = executeQuery(database, sql, maxRows); } return result; }
Example #10
Source File: GeoPackageRepository.java From geopackage-mapcache-android with MIT License | 6 votes |
/** * Get table Contents object */ public Contents getTableContents(String gpName, String tableName) { GeoPackage geo = null; try{ geo = manager.open(gpName); if(geo != null) { ContentsDao contentsDao = geo.getContentsDao(); Contents contents = contentsDao.queryForId(tableName); return contents; } } catch (Exception e){ } finally { if(geo != null){ geo.close(); } } return null; }
Example #11
Source File: GeoPackageExample.java From geopackage-android with MIT License | 5 votes |
private static void createPropertiesExtension(GeoPackage geoPackage) { PropertiesExtension properties = new PropertiesExtension(geoPackage); String dateTime = DateConverter.dateTimeConverter().stringValue( new Date()); properties.addValue(PropertyNames.TITLE, "GeoPackage Android Example"); properties.addValue(PropertyNames.VERSION, "3.2.0"); properties.addValue(PropertyNames.CREATOR, "NGA"); properties.addValue(PropertyNames.PUBLISHER, "NGA"); properties.addValue(PropertyNames.CONTRIBUTOR, "Brian Osborn"); properties.addValue(PropertyNames.CONTRIBUTOR, "Dan Barela"); properties.addValue(PropertyNames.CREATED, dateTime); properties.addValue(PropertyNames.DATE, dateTime); properties.addValue(PropertyNames.MODIFIED, dateTime); properties .addValue( PropertyNames.DESCRIPTION, "GeoPackage example created by https://github.com/ngageoint/geopackage-android/blob/master/geopackage-sdk/src/androidTest/java/mil/nga/geopackage/test/GeoPackageExample.java"); properties.addValue(PropertyNames.IDENTIFIER, "geopackage-android"); properties.addValue(PropertyNames.LICENSE, "MIT"); properties .addValue( PropertyNames.SOURCE, "http://github.com/ngageoint/GeoPackage/blob/master/docs/examples/android/example.gpkg"); properties.addValue(PropertyNames.SUBJECT, "Examples"); properties.addValue(PropertyNames.TYPE, "Examples"); properties.addValue(PropertyNames.URI, "http://github.com/ngageoint/geopackage-android"); properties.addValue(PropertyNames.TAG, "NGA"); properties.addValue(PropertyNames.TAG, "Example"); properties.addValue(PropertyNames.TAG, "BIT Systems"); }
Example #12
Source File: CoverageData.java From geopackage-java with MIT License | 5 votes |
/** * Create the coverage data tile table with metadata and extension * * @param geoPackage * GeoPackage * @param tableName * table name * @param contentsBoundingBox * contents bounding box * @param contentsSrsId * contents srs id * @param tileMatrixSetBoundingBox * tile matrix set bounding box * @param tileMatrixSetSrsId * tile matrix set srs id * @param dataType * gridded coverage data type * @return coverage data */ public static CoverageData<?> createTileTableWithMetadata( GeoPackage geoPackage, String tableName, BoundingBox contentsBoundingBox, long contentsSrsId, BoundingBox tileMatrixSetBoundingBox, long tileMatrixSetSrsId, GriddedCoverageDataType dataType) { TileMatrixSet tileMatrixSet = CoverageDataCore .createTileTableWithMetadata(geoPackage, tableName, contentsBoundingBox, contentsSrsId, tileMatrixSetBoundingBox, tileMatrixSetSrsId); TileDao tileDao = geoPackage.getTileDao(tileMatrixSet); CoverageData<?> coverageData = null; switch (dataType) { case INTEGER: coverageData = new CoverageDataPng(geoPackage, tileDao); break; case FLOAT: coverageData = new CoverageDataTiff(geoPackage, tileDao); break; default: throw new GeoPackageException( "Unsupported Gridded Coverage Data Type: " + dataType); } coverageData.getOrCreate(); return coverageData; }
Example #13
Source File: TestSetupTeardown.java From geopackage-java with MIT License | 5 votes |
/** * Tear down the create database * * @param geoPackage */ public static void tearDownCreate(GeoPackage geoPackage) { // Close if (geoPackage != null) { geoPackage.close(); } }
Example #14
Source File: CoverageData.java From geopackage-java with MIT License | 5 votes |
/** * Get a Tiled Gridded Coverage Data * * @param geoPackage * GeoPackage * @param tileDao * tile dao * @param width * coverage data response width * @param height * coverage data response height * @param requestProjection * request projection * @return coverage data */ public static CoverageData<?> getCoverageData(GeoPackage geoPackage, TileDao tileDao, Integer width, Integer height, Projection requestProjection) { TileMatrixSet tileMatrixSet = tileDao.getTileMatrixSet(); GriddedCoverageDao griddedCoverageDao = geoPackage .getGriddedCoverageDao(); GriddedCoverage griddedCoverage = null; try { if (griddedCoverageDao.isTableExists()) { griddedCoverage = griddedCoverageDao.query(tileMatrixSet); } } catch (SQLException e) { throw new GeoPackageException( "Failed to get Gridded Coverage for table name: " + tileMatrixSet.getTableName(), e); } CoverageData<?> coverageData = null; GriddedCoverageDataType dataType = griddedCoverage.getDataType(); switch (dataType) { case INTEGER: coverageData = new CoverageDataPng(geoPackage, tileDao, width, height, requestProjection); break; case FLOAT: coverageData = new CoverageDataTiff(geoPackage, tileDao, width, height, requestProjection); break; default: throw new GeoPackageException( "Unsupported Gridded Coverage Data Type: " + dataType); } return coverageData; }
Example #15
Source File: FeatureIndexManagerUtils.java From geopackage-java with MIT License | 5 votes |
private static void testTimedIndex(GeoPackage geoPackage, FeatureIndexType type, FeatureDao featureDao, List<FeatureIndexTestEnvelope> envelopes, double precision, boolean compareProjectionCounts, double projectionPrecision, boolean verbose) { testTimedIndex(geoPackage, type, featureDao, envelopes, precision, precision, compareProjectionCounts, projectionPrecision, verbose); }
Example #16
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 #17
Source File: GeopackageFeatureTilesOverlay.java From osmdroid with Apache License 2.0 | 5 votes |
public List<String> getFeatureTable(String database) throws Exception { GeoPackage open = null; List<String> featureTables = new ArrayList<>(); try { open = manager.open(database); featureTables = open.getFeatureTables(); } catch (Exception ex) { throw ex; } finally { if (open != null) open.close(); } return featureTables; }
Example #18
Source File: GeoPackageExample.java From geopackage-android with MIT License | 5 votes |
private void validateExtensions(GeoPackage geoPackage, boolean has) throws SQLException { ExtensionsDao extensionsDao = geoPackage.getExtensionsDao(); TestCase.assertEquals(has && RTREE_SPATIAL_INDEX, new RTreeIndexExtension(geoPackage).has()); TestCase.assertEquals( has && (RELATED_TABLES_FEATURES || RELATED_TABLES_MEDIA || RELATED_TABLES_SIMPLE_ATTRIBUTES), new RelatedTablesExtension(geoPackage).has()); TestCase.assertEquals( has && COVERAGE_DATA, extensionsDao.isTableExists() && !extensionsDao.queryByExtension( CoverageData.EXTENSION_NAME).isEmpty()); TestCase.assertEquals(has && SCHEMA, new SchemaExtension(geoPackage).has()); TestCase.assertEquals(has && METADATA, new MetadataExtension(geoPackage).has()); TestCase.assertEquals( has && NON_LINEAR_GEOMETRY_TYPES, extensionsDao.isTableExists() && !extensionsDao .queryByExtension( GeometryExtensions .getExtensionName(GeometryType.CIRCULARSTRING)) .isEmpty()); TestCase.assertEquals(has && WEBP, extensionsDao.isTableExists() && !extensionsDao .queryByExtension(WebPExtension.EXTENSION_NAME) .isEmpty()); TestCase.assertEquals(has && CRS_WKT, new CrsWktExtension(geoPackage).has()); }
Example #19
Source File: GeoPackageExample.java From geopackage-android with MIT License | 5 votes |
private static void createFeatureTileLinkExtension(Context context, GeoPackage geoPackage) throws SQLException, IOException { List<String> featureTables = geoPackage.getFeatureTables(); for (String featureTable : featureTables) { FeatureDao featureDao = geoPackage.getFeatureDao(featureTable); FeatureTiles featureTiles = new DefaultFeatureTiles(context, geoPackage, featureDao, context.getResources().getDisplayMetrics().density); BoundingBox boundingBox = featureDao.getBoundingBox(); Projection projection = featureDao.getProjection(); Projection requestProjection = ProjectionFactory .getProjection(ProjectionConstants.EPSG_WEB_MERCATOR); ProjectionTransform transform = projection .getTransformation(requestProjection); BoundingBox requestBoundingBox = boundingBox.transform(transform); int zoomLevel = TileBoundingBoxUtils .getZoomLevel(requestBoundingBox); zoomLevel = Math.max(zoomLevel, 8); zoomLevel = Math.min(zoomLevel, 19); int minZoom = zoomLevel - 8; int maxZoom = zoomLevel + 2; TileGenerator tileGenerator = new FeatureTileGenerator(context, geoPackage, featureTable + "_tiles", featureTiles, minZoom, maxZoom, requestBoundingBox, requestProjection); tileGenerator.generateTiles(); featureTiles.close(); } }
Example #20
Source File: TestSetupTeardown.java From geopackage-android with MIT License | 5 votes |
/** * Tear down the import database * * @param activity * @param geoPackage */ public static void tearDownImport(Activity activity, GeoPackage geoPackage) { // Close if (geoPackage != null) { geoPackage.close(); } // Delete GeoPackageManager manager = GeoPackageFactory.getManager(activity); manager.delete(TestConstants.IMPORT_DB_NAME); }
Example #21
Source File: TransactionTest.java From geopackage-android with MIT License | 4 votes |
/** * 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 #22
Source File: GeoPackageExample.java From geopackage-java with MIT License | 4 votes |
private static void createFeatures(GeoPackage geoPackage) throws SQLException { SpatialReferenceSystemDao srsDao = geoPackage .getSpatialReferenceSystemDao(); SpatialReferenceSystem srs = srsDao.getOrCreateCode( ProjectionConstants.AUTHORITY_EPSG, (long) ProjectionConstants.EPSG_WORLD_GEODETIC_SYSTEM); geoPackage.createGeometryColumnsTable(); createFeatures1(geoPackage, srs); createFeatures2(geoPackage, srs); }
Example #23
Source File: GeoPackageUtils.java From geopackage-mapcache-android with MIT License | 4 votes |
/** * Prepare the feature draw limits and defaults * * @param context * @param geoPackage * @param featureTable * @param pointAlpha * @param lineAlpha * @param polygonAlpha * @param polygonFillAlpha * @param pointColor * @param lineColor * @param pointRadius * @param lineStroke * @param polygonColor * @param polygonStroke * @param polygonFill * @param polygonFillColor */ public static void prepareFeatureDraw(Context context, GeoPackage geoPackage, String featureTable, EditText pointAlpha, EditText lineAlpha, EditText polygonAlpha, EditText polygonFillAlpha, EditText pointColor, EditText lineColor, EditText pointRadius, EditText lineStroke, EditText polygonColor, EditText polygonStroke, CheckBox polygonFill, EditText polygonFillColor) { FeatureTableStyles featureTableStyles = new FeatureTableStyles(geoPackage, featureTable); // Set feature limits pointAlpha.setFilters(new InputFilter[]{new InputFilterMinMax( 0, 255)}); lineAlpha.setFilters(new InputFilter[]{new InputFilterMinMax( 0, 255)}); polygonAlpha.setFilters(new InputFilter[]{new InputFilterMinMax( 0, 255)}); polygonFillAlpha.setFilters(new InputFilter[]{new InputFilterMinMax( 0, 255)}); // Set default feature attributes FeatureTiles featureTiles = new DefaultFeatureTiles(context); String defaultColor = "#000000"; StyleRow pointStyle = featureTableStyles.getTableStyle(GeometryType.POINT); if(pointStyle != null){ mil.nga.geopackage.style.Color pointStyleColor = pointStyle.getColorOrDefault(); pointColor.setText(pointStyleColor.getColorHex()); pointAlpha.setText(String.valueOf(pointStyleColor.getAlpha())); pointRadius.setText(new DecimalFormat("0.0#").format(pointStyle.getWidthOrDefault() / 2.0)); }else{ Paint pointPaint = featureTiles.getPointPaint(); pointColor.setText(defaultColor); pointAlpha.setText(String.valueOf(pointPaint.getAlpha())); pointRadius.setText(String.valueOf(featureTiles.getPointRadius())); } StyleRow lineStyle = featureTableStyles.getTableStyle(GeometryType.LINESTRING); if(lineStyle != null){ mil.nga.geopackage.style.Color lineStyleColor = lineStyle.getColorOrDefault(); lineColor.setText(lineStyleColor.getColorHex()); lineAlpha.setText(String.valueOf(lineStyleColor.getAlpha())); lineStroke.setText(new DecimalFormat("0.0#").format(lineStyle.getWidthOrDefault())); }else{ Paint linePaint = featureTiles.getLinePaintCopy(); lineColor.setText(defaultColor); lineAlpha.setText(String.valueOf(linePaint.getAlpha())); lineStroke.setText(String.valueOf(linePaint.getStrokeWidth())); } StyleRow polygonStyle = featureTableStyles.getTableStyle(GeometryType.POLYGON); if(polygonStyle != null){ mil.nga.geopackage.style.Color polygonStyleColor = polygonStyle.getColorOrDefault(); polygonColor.setText(polygonStyleColor.getColorHex()); polygonAlpha.setText(String.valueOf(polygonStyleColor.getAlpha())); polygonStroke.setText(new DecimalFormat("0.0#").format(polygonStyle.getWidthOrDefault())); mil.nga.geopackage.style.Color polygonStyleFillColor = polygonStyle.getFillColor(); polygonFill.setChecked(polygonStyleFillColor != null); if(polygonStyleFillColor != null){ polygonFillColor.setText(polygonStyleFillColor.getColorHex()); polygonFillAlpha.setText(String.valueOf(polygonStyleFillColor.getAlpha())); }else{ polygonFillColor.setText(defaultColor); polygonFillAlpha.setText(String.valueOf(255)); } }else{ Paint polygonPaint = featureTiles.getPolygonPaintCopy(); polygonColor.setText(defaultColor); polygonAlpha.setText(String.valueOf(polygonPaint.getAlpha())); polygonStroke.setText(String.valueOf(polygonPaint.getStrokeWidth())); polygonFill.setChecked(featureTiles.isFillPolygon()); Paint polygonFillPaint = featureTiles.getPolygonFillPaintCopy(); polygonFillColor.setText(defaultColor); polygonFillAlpha.setText(String.valueOf(polygonFillPaint.getAlpha())); } }
Example #24
Source File: TileMatrixSetUtils.java From geopackage-android with MIT License | 4 votes |
/** * Test create * * @param geoPackage * @throws SQLException */ public static void testCreate(GeoPackage geoPackage) throws SQLException { SpatialReferenceSystemDao srsDao = geoPackage .getSpatialReferenceSystemDao(); ContentsDao contentsDao = geoPackage.getContentsDao(); TileMatrixSetDao dao = geoPackage.getTileMatrixSetDao(); if (dao.isTableExists()) { // Get current count long count = dao.countOf(); TestCase.assertEquals(count, dao.getTileTables().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.TILES); 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 user tile table geoPackage.createTileTable(TestUtils.buildTileTable(contents .getTableName())); contentsDao.create(contents); // Create new matrix tile set 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()); dao.create(tileMatrixSet); // Verify count long newCount = dao.countOf(); TestCase.assertEquals(count + 1, newCount); TestCase.assertEquals(newCount, dao.getTileTables().size()); TestCase.assertTrue(dao.getTileTables().contains( contents.getTableName())); // Verify saved matrix tile set TileMatrixSet queryTileMatrixSet = dao.queryForId(tileMatrixSet .getId()); TestCase.assertEquals(contents.getId(), queryTileMatrixSet.getTableName()); TestCase.assertEquals(contents.getSrsId().longValue(), queryTileMatrixSet.getSrsId()); TestCase.assertEquals(contents.getMinX(), queryTileMatrixSet.getMinX()); TestCase.assertEquals(contents.getMinY(), queryTileMatrixSet.getMinY()); TestCase.assertEquals(contents.getMaxX(), queryTileMatrixSet.getMaxX()); TestCase.assertEquals(contents.getMaxY(), queryTileMatrixSet.getMaxY()); TestCase.assertEquals(contents.getId(), queryTileMatrixSet .getContents().getId()); TestCase.assertEquals(contents.getSrsId().longValue(), queryTileMatrixSet.getSrs().getId()); } }
Example #25
Source File: GeoPackageExample.java From geopackage-android with MIT License | 4 votes |
private static void insertRelatedTablesMediaExtensionRows(Activity activity, Context testContext, GeoPackage geoPackage, ExtendedRelation relation, String query, String name, String file, String contentType, String description, String source) throws IOException { RelatedTablesExtension relatedTables = new RelatedTablesExtension( geoPackage); FeatureDao featureDao = geoPackage.getFeatureDao(relation .getBaseTableName()); MediaDao mediaDao = relatedTables.getMediaDao(relation); UserMappingDao userMappingDao = relatedTables.getMappingDao(relation); MediaRow mediaRow = mediaDao.newRow(); TestUtils.copyAssetFileToInternalStorage(activity, testContext, file); String mediaImageName = TestUtils.getAssetFileInternalStorageLocation(activity, file); Bitmap mediaImage = BitmapFactory.decodeFile(mediaImageName); mediaRow.setData(mediaImage, Bitmap.CompressFormat.PNG); mediaRow.setContentType(contentType); RelatedTablesUtils.populateUserRow(mediaDao.getTable(), mediaRow, MediaTable.requiredColumns()); DublinCoreMetadata.setValue(mediaRow, DublinCoreType.TITLE, name); DublinCoreMetadata.setValue(mediaRow, DublinCoreType.DESCRIPTION, description); DublinCoreMetadata.setValue(mediaRow, DublinCoreType.SOURCE, source); long mediaRowId = mediaDao.create(mediaRow); FeatureCursor featureCursor = featureDao.queryForLike( TEXT_COLUMN, query); while (featureCursor.moveToNext()) { FeatureRow featureRow = featureCursor.getRow(); UserMappingRow userMappingRow = userMappingDao.newRow(); userMappingRow.setBaseId(featureRow.getId()); userMappingRow.setRelatedId(mediaRowId); RelatedTablesUtils.populateUserRow(userMappingDao.getTable(), userMappingRow, UserMappingTable.requiredColumns()); String featureName = featureRow.getValue(TEXT_COLUMN).toString(); DublinCoreMetadata.setValue(userMappingRow, DublinCoreType.TITLE, featureName + " - " + name); DublinCoreMetadata.setValue(userMappingRow, DublinCoreType.DESCRIPTION, featureName + " - " + description); DublinCoreMetadata.setValue(userMappingRow, DublinCoreType.SOURCE, source); userMappingDao.create(userMappingRow); } featureCursor.close(); }
Example #26
Source File: GeoPackageExample.java From geopackage-android with MIT License | 4 votes |
private static void createFeatures(GeoPackage geoPackage) throws SQLException { SpatialReferenceSystemDao srsDao = geoPackage .getSpatialReferenceSystemDao(); SpatialReferenceSystem srs = srsDao.getOrCreateCode( ProjectionConstants.AUTHORITY_EPSG, (long) ProjectionConstants.EPSG_WORLD_GEODETIC_SYSTEM); geoPackage.createGeometryColumnsTable(); createFeatures1(geoPackage, srs); createFeatures2(geoPackage, srs); }
Example #27
Source File: TileMatrixUtils.java From geopackage-android with MIT License | 4 votes |
/** * Test delete * * @param geoPackage * @throws SQLException */ public static void testDelete(GeoPackage geoPackage) throws SQLException { TileMatrixDao dao = geoPackage.getTileMatrixDao(); if (dao.isTableExists()) { List<TileMatrix> results = dao.queryForAll(); if (!results.isEmpty()) { // Choose random tile matrix int random = (int) (Math.random() * results.size()); TileMatrix tileMatrix = results.get(random); // Delete the tile matrix dao.delete(tileMatrix); // Verify deleted TileMatrix queryTileMatrix = dao.queryForId(tileMatrix.getId()); TestCase.assertNull(queryTileMatrix); // Prepared deleted results = dao.queryForAll(); if (!results.isEmpty()) { // Choose random tile matrix random = (int) (Math.random() * results.size()); tileMatrix = results.get(random); // Find which tile matrix to delete QueryBuilder<TileMatrix, TileMatrixKey> qb = dao .queryBuilder(); qb.where().eq(TileMatrix.COLUMN_ZOOM_LEVEL, tileMatrix.getZoomLevel()); PreparedQuery<TileMatrix> query = qb.prepare(); List<TileMatrix> queryResults = dao.query(query); int count = queryResults.size(); // Delete DeleteBuilder<TileMatrix, TileMatrixKey> db = dao .deleteBuilder(); db.where().eq(TileMatrix.COLUMN_ZOOM_LEVEL, tileMatrix.getZoomLevel()); PreparedDelete<TileMatrix> deleteQuery = db.prepare(); int deleted = dao.delete(deleteQuery); TestCase.assertEquals(count, deleted); } } } }
Example #28
Source File: FeatureTileUtils.java From geopackage-android with MIT License | 4 votes |
public static void updateLastChange(GeoPackage geoPackage, FeatureDao featureDao) throws SQLException { Contents contents = featureDao.getGeometryColumns().getContents(); contents.setLastChange(new Date()); ContentsDao contentsDao = geoPackage.getContentsDao(); contentsDao.update(contents); }
Example #29
Source File: GeoPackageExample.java From geopackage-java with MIT License | 4 votes |
private static void createRelatedTablesTilesExtension( GeoPackage geoPackage) { String featureTable = "point2"; String tileTable = "nga"; RelatedTablesExtension relatedTables = new RelatedTablesExtension( geoPackage); List<UserCustomColumn> additionalMappingColumns = RelatedTablesUtils .createAdditionalUserColumns(); UserMappingTable userMappingTable = UserMappingTable.create( featureTable + "_" + tileTable, additionalMappingColumns); ExtendedRelation relation = relatedTables.addTilesRelationship( featureTable, tileTable, userMappingTable); UserMappingDao userMappingDao = relatedTables.getMappingDao(relation); FeatureDao featureDao = geoPackage .getFeatureDao(relation.getBaseTableName()); TileDao tileDao = geoPackage.getTileDao(relation.getRelatedTableName()); FeatureResultSet featureResultSet = featureDao.queryForAll(); while (featureResultSet.moveToNext()) { FeatureRow featureRow = featureResultSet.getRow(); String featureName = featureRow.getValue(TEXT_COLUMN).toString(); TileResultSet tileResultSet = tileDao .queryForTile(tileDao.getMinZoom()); while (tileResultSet.moveToNext()) { TileRow tileRow = tileResultSet.getRow(); UserMappingRow userMappingRow = userMappingDao.newRow(); userMappingRow.setBaseId(featureRow.getId()); userMappingRow.setRelatedId(tileRow.getId()); RelatedTablesUtils.populateUserRow(userMappingDao.getTable(), userMappingRow, UserMappingTable.requiredColumns()); DublinCoreMetadata.setValue(userMappingRow, DublinCoreType.TITLE, featureName); DublinCoreMetadata.setValue(userMappingRow, DublinCoreType.DESCRIPTION, featureName); DublinCoreMetadata.setValue(userMappingRow, DublinCoreType.SOURCE, featureName); userMappingDao.create(userMappingRow); } tileResultSet.close(); } featureResultSet.close(); }
Example #30
Source File: GeoPackageExample.java From geopackage-java with MIT License | 4 votes |
private static void createFeatureStyleExtension(GeoPackage geoPackage) throws IOException { List<StyleRow> styles = new ArrayList<>(); StyleRow style1 = new StyleRow(); style1.setName("Green"); style1.setDescription("Green Style"); style1.setColor(ColorConstants.GREEN); style1.setWidth(2.0); styles.add(style1); StyleRow style2 = new StyleRow(); style2.setName("Blue with Red Fill"); style2.setDescription("Blue with Red Fill Style"); style2.setColor(new Color(ColorConstants.BLUE)); style2.setFillColor(new Color(255, 0, 0, .4f)); styles.add(style2); StyleRow style3 = new StyleRow(); style3.setName("Orange"); style3.setDescription("Orange Style"); style3.setColor(new Color(0xFFA500)); style3.setWidth(6.5); styles.add(style3); StyleRow style4 = new StyleRow(); style4.setName("Violet with Yellow Fill"); style4.setDescription("Violet with Yellow Fill Style"); style4.setColor(new Color(138, 43, 226)); style4.setWidth(4.1); style4.setFillColor(new Color(new float[] { 61, .89f, .72f }, .3f)); styles.add(style4); List<IconRow> icons = new ArrayList<>(); IconRow icon1 = new IconRow(); icon1.setName("Building"); icon1.setDescription("Building Icon"); icon1.setData(GeoPackageIOUtils .fileBytes(TestUtils.getTestFile("building.png"))); icon1.setContentType("image/png"); icon1.setWidth(32.0); icon1.setAnchorU(0.5); icon1.setAnchorV(1.0); icons.add(icon1); IconRow icon2 = new IconRow(); icon2.setName("College"); icon2.setDescription("College Icon"); icon2.setData(GeoPackageIOUtils .fileBytes(TestUtils.getTestFile("college.png"))); icon2.setContentType("image/png"); icon2.setWidth(32.0); icon2.setHeight(44.0); icons.add(icon2); IconRow icon3 = new IconRow(); icon3.setName("Tractor"); icon3.setDescription("Tractor Icon"); icon3.setData(GeoPackageIOUtils .fileBytes(TestUtils.getTestFile("tractor.png"))); icon3.setContentType("image/png"); icon3.setAnchorV(1.0); icons.add(icon3); createFeatureStylesGeometry1(geoPackage, styles, icons); createFeatureStylesGeometry2(geoPackage, styles, icons); }