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 Project: geopackage-android Author: ngageoint File: FeatureDao.java License: MIT License | 6 votes |
/** * 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 #2
Source Project: geopackage-android Author: ngageoint File: GeoPackageTestUtils.java License: MIT License | 6 votes |
/** * 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 Project: geopackage-android Author: ngageoint File: GeoPackageTestUtils.java License: MIT License | 6 votes |
/** * 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 Project: geopackage-android Author: ngageoint File: GeoPackageTestUtils.java License: 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 #5
Source Project: geopackage-android Author: ngageoint File: GeoPackageTestUtils.java License: 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_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 #6
Source Project: geopackage-core-java Author: ngageoint File: GeoPackageCoreImpl.java License: MIT License | 6 votes |
/** * 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 #7
Source Project: geopackage-core-java Author: ngageoint File: GeoPackageTableCreator.java License: MIT License | 6 votes |
/** * 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 #8
Source Project: geopackage-core-java Author: ngageoint File: GeoPackageDaoManager.java License: MIT License | 6 votes |
/** * 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 #9
Source Project: geopackage-mapcache-android Author: ngageoint File: GeoPackageRepository.java License: MIT License | 6 votes |
/** * 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 #10
Source Project: geopackage-java Author: ngageoint File: FeatureDao.java License: MIT License | 6 votes |
/** * 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 Project: geopackage-java Author: ngageoint File: GeoPackageTestUtils.java License: MIT License | 6 votes |
/** * 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 Project: geopackage-java Author: ngageoint File: GeoPackageTestUtils.java License: MIT License | 6 votes |
/** * 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 Project: geopackage-java Author: ngageoint File: GeoPackageTestUtils.java License: 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 #14
Source Project: geopackage-java Author: ngageoint File: GeoPackageTestUtils.java License: 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 #15
Source Project: geopackage-android-map Author: ngageoint File: FeatureInfoBuilder.java License: MIT License | 5 votes |
/** * 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 #16
Source Project: geopackage-android Author: ngageoint File: FeatureIndexManagerUtils.java License: MIT License | 5 votes |
/** * 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 #17
Source Project: geopackage-android Author: ngageoint File: GeoPackageExample.java License: MIT License | 5 votes |
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 Project: geopackage-android Author: ngageoint File: GeoPackageExample.java License: MIT License | 5 votes |
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 #19
Source Project: geopackage-core-java Author: ngageoint File: CrsWktExtension.java License: MIT License | 5 votes |
/** * 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 #20
Source Project: geopackage-core-java Author: ngageoint File: CrsWktExtension.java License: MIT License | 5 votes |
/** * 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 Project: geopackage-core-java Author: ngageoint File: GeometryColumnsSqlMm.java License: MIT License | 5 votes |
public void setSrs(SpatialReferenceSystem srs) { this.srs = srs; if (srs != null) { srsId = srs.getId(); srsName = srs.getSrsName(); } }
Example #22
Source Project: geopackage-core-java Author: ngageoint File: GeoPackageCoreImpl.java License: MIT License | 5 votes |
/** * {@inheritDoc} */ @Override public SpatialReferenceSystemDao getSpatialReferenceSystemDao() { SpatialReferenceSystemDao dao = createDao(SpatialReferenceSystem.class); dao.setCrsWktExtension(new CrsWktExtension(this)); return dao; }
Example #23
Source Project: geopackage-core-java Author: ngageoint File: GeoPackageValidate.java License: MIT License | 5 votes |
/** * 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 #24
Source Project: geopackage-mapcache-android Author: ngageoint File: GeoPackageRepository.java License: MIT License | 5 votes |
/** * 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 Project: geopackage-java Author: ngageoint File: GeoPackageTextOutput.java License: MIT License | 5 votes |
/** * 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 Project: geopackage-java Author: ngageoint File: FeatureIndexManagerUtils.java License: MIT License | 5 votes |
/** * 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 Project: geopackage-java Author: ngageoint File: GeoPackageExample.java License: MIT License | 5 votes |
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 Project: geopackage-java Author: ngageoint File: GeoPackageExample.java License: MIT License | 5 votes |
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 Project: geopackage-android-map Author: ngageoint File: TestSetupTeardown.java License: MIT License | 4 votes |
/** * 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); } }
Example #30
Source Project: geopackage-android Author: ngageoint File: TileDao.java License: MIT License | 4 votes |
/** * Constructor * * @param database database name * @param db GeoPackage connection * @param tileMatrixSet tile matrix set * @param tileMatrices tile matrices * @param table tile table */ public TileDao(String database, GeoPackageConnection db, TileMatrixSet tileMatrixSet, List<TileMatrix> tileMatrices, TileTable table) { super(database, db, new TileConnection(db), table); this.tileDb = (TileConnection) getUserDb(); this.tileMatrixSet = tileMatrixSet; this.tileMatrices = tileMatrices; this.widths = new double[tileMatrices.size()]; this.heights = new double[tileMatrices.size()]; projection = tileMatrixSet.getProjection(); // Set the min and max zoom levels if (!tileMatrices.isEmpty()) { minZoom = tileMatrices.get(0).getZoomLevel(); maxZoom = tileMatrices.get(tileMatrices.size() - 1).getZoomLevel(); } else { minZoom = 0; maxZoom = 0; } // Populate the zoom level to tile matrix and the sorted tile widths and // heights for (int i = 0; i < tileMatrices.size(); i++) { TileMatrix tileMatrix = tileMatrices.get(i); zoomLevelToTileMatrix.put(tileMatrix.getZoomLevel(), tileMatrix); widths[tileMatrices.size() - i - 1] = tileMatrix.getPixelXSize() * tileMatrix.getTileWidth(); heights[tileMatrices.size() - i - 1] = tileMatrix.getPixelYSize() * tileMatrix.getTileHeight(); } if (tileMatrixSet.getContents() == null) { throw new GeoPackageException(TileMatrixSet.class.getSimpleName() + " " + tileMatrixSet.getId() + " has null " + Contents.class.getSimpleName()); } if (tileMatrixSet.getSrs() == null) { throw new GeoPackageException(TileMatrixSet.class.getSimpleName() + " " + tileMatrixSet.getId() + " has null " + SpatialReferenceSystem.class.getSimpleName()); } }