Java Code Examples for mil.nga.sf.proj.ProjectionConstants#EPSG_WEB_MERCATOR
The following examples show how to use
mil.nga.sf.proj.ProjectionConstants#EPSG_WEB_MERCATOR .
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: GeoPackageExample.java From geopackage-android 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); }
Example 2
Source File: GeoPackageGeometryDataUtils.java From geopackage-android with MIT License | 4 votes |
/** * Test transforming geometries between projections * * @param geoPackage * @throws SQLException * @throws IOException */ public static void testGeometryProjectionTransform(GeoPackage geoPackage) throws SQLException, IOException { GeometryColumnsDao geometryColumnsDao = geoPackage .getGeometryColumnsDao(); if (geometryColumnsDao.isTableExists()) { List<GeometryColumns> results = geometryColumnsDao.queryForAll(); for (GeometryColumns geometryColumns : results) { FeatureDao dao = geoPackage.getFeatureDao(geometryColumns); TestCase.assertNotNull(dao); FeatureCursor cursor = dao.queryForAll(); while (cursor.moveToNext()) { GeoPackageGeometryData geometryData = cursor.getGeometry(); if (geometryData != null) { Geometry geometry = geometryData.getGeometry(); if (geometry != null) { SpatialReferenceSystemDao srsDao = geoPackage .getSpatialReferenceSystemDao(); long srsId = geometryData.getSrsId(); SpatialReferenceSystem srs = srsDao .queryForId(srsId); long epsg = srs.getOrganizationCoordsysId(); Projection projection = srs.getProjection(); long toEpsg = -1; if (epsg == ProjectionConstants.EPSG_WORLD_GEODETIC_SYSTEM) { toEpsg = ProjectionConstants.EPSG_WEB_MERCATOR; } else { toEpsg = ProjectionConstants.EPSG_WORLD_GEODETIC_SYSTEM; } ProjectionTransform transformTo = projection .getTransformation(toEpsg); ProjectionTransform transformFrom = srs.getTransformation(transformTo .getToProjection()); byte[] bytes = geometryData.getWkbBytes(); Geometry projectedGeometry = transformTo .transform(geometry); GeoPackageGeometryData projectedGeometryData = new GeoPackageGeometryData( -1); projectedGeometryData .setGeometry(projectedGeometry); projectedGeometryData.toBytes(); byte[] projectedBytes = projectedGeometryData .getWkbBytes(); if (epsg > 0) { TestCase.assertFalse(equalByteArrays(bytes, projectedBytes)); } Geometry restoredGeometry = transformFrom .transform(projectedGeometry); compareGeometries(geometry, restoredGeometry, .001); } } } cursor.close(); } } }
Example 3
Source File: SpatialReferenceSystemDao.java From geopackage-core-java with MIT License | 4 votes |
/** * Create the srs if needed * * @param srs * srs if exists or null * @param organization * organization * @param id * coordinate id * @return srs * @throws SQLException */ private SpatialReferenceSystem createIfNeeded(SpatialReferenceSystem srs, String organization, long id) throws SQLException { if (srs == null) { if (organization .equalsIgnoreCase(ProjectionConstants.AUTHORITY_EPSG)) { switch ((int) id) { case ProjectionConstants.EPSG_WORLD_GEODETIC_SYSTEM: srs = createWgs84(); break; case ProjectionConstants.EPSG_WEB_MERCATOR: srs = createWebMercator(); break; case ProjectionConstants.EPSG_WORLD_GEODETIC_SYSTEM_GEOGRAPHICAL_3D: srs = createWgs84Geographical3D(); break; default: throw new GeoPackageException( "Spatial Reference System not supported for metadata creation. Organization: " + organization + ", id: " + id); } } else if (organization .equalsIgnoreCase(ProjectionConstants.AUTHORITY_NONE)) { switch ((int) id) { case ProjectionConstants.UNDEFINED_CARTESIAN: srs = createUndefinedCartesian(); break; case ProjectionConstants.UNDEFINED_GEOGRAPHIC: srs = createUndefinedGeographic(); break; default: throw new GeoPackageException( "Spatial Reference System not supported for metadata creation. Organization: " + organization + ", id: " + id); } } else { throw new GeoPackageException( "Spatial Reference System not supported for metadata creation. Organization: " + organization + ", id: " + id); } } else { setDefinition_12_063(srs); } return srs; }
Example 4
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); }
Example 5
Source File: GeoPackageGeometryDataUtils.java From geopackage-java with MIT License | 4 votes |
/** * Test transforming geometries between projections * * @param geoPackage * @throws SQLException * @throws IOException */ public static void testGeometryProjectionTransform(GeoPackage geoPackage) throws SQLException, IOException { GeometryColumnsDao geometryColumnsDao = geoPackage .getGeometryColumnsDao(); if (geometryColumnsDao.isTableExists()) { List<GeometryColumns> results = geometryColumnsDao.queryForAll(); for (GeometryColumns geometryColumns : results) { FeatureDao dao = geoPackage.getFeatureDao(geometryColumns); TestCase.assertNotNull(dao); FeatureResultSet cursor = dao.queryForAll(); while (cursor.moveToNext()) { GeoPackageGeometryData geometryData = cursor.getGeometry(); if (geometryData != null) { Geometry geometry = geometryData.getGeometry(); if (geometry != null) { SpatialReferenceSystemDao srsDao = geoPackage .getSpatialReferenceSystemDao(); long srsId = geometryData.getSrsId(); SpatialReferenceSystem srs = srsDao .queryForId(srsId); long epsg = srs.getOrganizationCoordsysId(); Projection projection = srs.getProjection(); long toEpsg = -1; if (epsg == ProjectionConstants.EPSG_WORLD_GEODETIC_SYSTEM) { toEpsg = ProjectionConstants.EPSG_WEB_MERCATOR; } else { toEpsg = ProjectionConstants.EPSG_WORLD_GEODETIC_SYSTEM; } ProjectionTransform transformTo = projection .getTransformation(toEpsg); ProjectionTransform transformFrom = srs .getTransformation(transformTo .getToProjection()); byte[] bytes = geometryData.getWkbBytes(); Geometry projectedGeometry = transformTo .transform(geometry); GeoPackageGeometryData projectedGeometryData = new GeoPackageGeometryData( -1); projectedGeometryData .setGeometry(projectedGeometry); projectedGeometryData.toBytes(); byte[] projectedBytes = projectedGeometryData .getWkbBytes(); if (epsg > 0) { TestCase.assertFalse(equalByteArrays(bytes, projectedBytes)); } Geometry restoredGeometry = transformFrom .transform(projectedGeometry); compareGeometries(geometry, restoredGeometry, .001); } } } cursor.close(); } } }