mil.nga.sf.proj.ProjectionFactory Java Examples

The following examples show how to use mil.nga.sf.proj.ProjectionFactory. 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: CoverageDataTestUtils.java    From geopackage-android with MIT License 6 votes vote down vote up
/**
 * Get the coverage data value at the coordinate
 *
 * @param geoPackage GeoPackage
 * @param algorithm  algorithm
 * @param latitude   latitude
 * @param longitude  longitude
 * @param epsg       epsg
 * @return coverage data value
 * @throws Exception
 */
public static Double getValue(GeoPackage geoPackage,
                              CoverageDataAlgorithm algorithm, double latitude,
                              double longitude, long epsg) throws Exception {

    Double value = 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);
        value = coverageData.getValue(latitude, longitude);
    }

    return value;
}
 
Example #2
Source File: GeoPackageRepository.java    From geopackage-mapcache-android with MIT License 6 votes vote down vote up
/**
 * 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 #3
Source File: BoundedOverlay.java    From geopackage-android-map with MIT License 5 votes vote down vote up
/**
 * 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 #4
Source File: UrlTileGeneratorUtils.java    From geopackage-java with MIT License 5 votes vote down vote up
private static BoundingBox getBoundingBox(BoundingBox boundingBox) {
	boundingBox = TileBoundingBoxUtils
			.boundWgs84BoundingBoxWithWebMercatorLimits(boundingBox);
	boundingBox = boundingBox.transform(ProjectionFactory.getProjection(
			ProjectionConstants.EPSG_WORLD_GEODETIC_SYSTEM)
			.getTransformation(ProjectionConstants.EPSG_WEB_MERCATOR));
	return boundingBox;
}
 
Example #5
Source File: GeoPackageExample.java    From geopackage-java with MIT License 5 votes vote down vote up
private static void createFeatureTileLinkExtension(GeoPackage geoPackage)
		throws SQLException, IOException {

	List<String> featureTables = geoPackage.getFeatureTables();
	for (String featureTable : featureTables) {

		FeatureDao featureDao = geoPackage.getFeatureDao(featureTable);
		FeatureTiles featureTiles = new DefaultFeatureTiles(geoPackage,
				featureDao);

		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(geoPackage,
				featureTable + "_tiles", featureTiles, minZoom, maxZoom,
				requestBoundingBox, requestProjection);

		tileGenerator.generateTiles();
	}
}
 
Example #6
Source File: CoverageDataTestUtils.java    From geopackage-java with MIT License 5 votes vote down vote up
/**
 * 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
 * @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 #7
Source File: CoverageDataTestUtils.java    From geopackage-java with MIT License 5 votes vote down vote up
/**
 * Get the coverage data value at the coordinate
 * 
 * @param geoPackage
 *            GeoPackage
 * @param algorithm
 *            algorithm
 * @param latitude
 *            latitude
 * @param longitude
 *            longitude
 * @param epsg
 *            epsg
 * @return coverage data value
 * @throws Exception
 */
public static Double getValue(GeoPackage geoPackage,
		CoverageDataAlgorithm algorithm, double latitude, double longitude,
		long epsg) throws Exception {

	Double value = 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);
		value = coverageData.getValue(latitude, longitude);
	}

	return value;
}
 
Example #8
Source File: FeaturePreview.java    From geopackage-java with MIT License 5 votes vote down vote up
/**
 * Draw a preview image
 * 
 * @return preview image
 */
public BufferedImage draw() {

	BufferedImage image = null;

	FeatureDao featureDao = featureTiles.getFeatureDao();
	String table = featureDao.getTableName();

	Projection webMercator = ProjectionFactory
			.getProjection(ProjectionConstants.EPSG_WEB_MERCATOR);

	BoundingBox boundingBox = geoPackage.getFeatureBoundingBox(webMercator,
			table, false);
	if (boundingBox == null) {
		boundingBox = geoPackage.getContentsBoundingBox(webMercator, table);
	}
	if (boundingBox == null && manual) {
		boundingBox = geoPackage.getFeatureBoundingBox(webMercator, table,
				manual);
	}
	if (boundingBox != null) {
		boundingBox = TileBoundingBoxUtils
				.boundWebMercatorBoundingBox(boundingBox);
		BoundingBox expandedBoundingBox = boundingBox
				.squareExpand(bufferPercentage);
		expandedBoundingBox = TileBoundingBoxUtils
				.boundWebMercatorBoundingBox(expandedBoundingBox);
		int zoom = TileBoundingBoxUtils.getZoomLevel(expandedBoundingBox);

		FeatureResultSet results = featureDao.query(
				columns.toArray(new String[] {}), where, whereArgs, null,
				null, null, limit != null ? limit.toString() : null);
		image = featureTiles.drawTile(zoom, expandedBoundingBox, results);
	}

	return image;
}
 
Example #9
Source File: TileGenerator.java    From geopackage-java with MIT License 5 votes vote down vote up
/**
 * 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 #10
Source File: SpatialReferenceSystem.java    From geopackage-core-java with MIT License 5 votes vote down vote up
/**
 * Get the projection for the Spatial Reference System
 * 
 * @return projection
 * @since 3.0.0
 */
public Projection getProjection() {

	String authority = getOrganization();
	long code = getOrganizationCoordsysId();
	String definition = getDefinition_12_063();
	if (definition == null) {
		definition = getDefinition();
	}

	Projection projection = ProjectionFactory.getProjection(authority,
			code, null, definition);

	return projection;
}
 
Example #11
Source File: FeatureCoreGenerator.java    From geopackage-core-java with MIT License 5 votes vote down vote up
/**
 * Create a projection
 * 
 * @param authority
 *            authority
 * @param code
 *            code
 * @return projection
 */
protected Projection createProjection(String authority, String code) {

	Projection projection = null;

	try {
		projection = ProjectionFactory.getProjection(authority, code);
	} catch (Exception e) {
		LOGGER.log(Level.WARNING, "Unable to create projection. Authority: "
				+ authority + ", Code: " + code);
	}

	return projection;
}
 
Example #12
Source File: GeoPackageExample.java    From geopackage-android with MIT License 5 votes vote down vote up
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 #13
Source File: CoverageDataTestUtils.java    From geopackage-android with MIT License 5 votes vote down vote up
/**
 * 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 #14
Source File: FeaturePreview.java    From geopackage-android with MIT License 5 votes vote down vote up
/**
 * Draw a preview image
 *
 * @return preview image
 */
public Bitmap draw() {

    Bitmap image = null;

    FeatureDao featureDao = featureTiles.getFeatureDao();
    String table = featureDao.getTableName();

    Projection webMercator = ProjectionFactory
            .getProjection(ProjectionConstants.EPSG_WEB_MERCATOR);

    BoundingBox boundingBox = geoPackage.getFeatureBoundingBox(webMercator,
            table, false);
    if (boundingBox == null) {
        boundingBox = geoPackage.getContentsBoundingBox(webMercator, table);
    }
    if (boundingBox == null && manual) {
        boundingBox = geoPackage.getFeatureBoundingBox(webMercator, table,
                manual);
    }
    if (boundingBox != null) {
        boundingBox = TileBoundingBoxUtils
                .boundWebMercatorBoundingBox(boundingBox);
        BoundingBox expandedBoundingBox = boundingBox
                .squareExpand(bufferPercentage);
        expandedBoundingBox = TileBoundingBoxUtils
                .boundWebMercatorBoundingBox(expandedBoundingBox);
        int zoom = TileBoundingBoxUtils.getZoomLevel(expandedBoundingBox);

        FeatureCursor results = featureDao.query(
                columns.toArray(new String[]{}), where, whereArgs, null,
                null, null, limit != null ? limit.toString() : null);
        image = featureTiles.drawTile(zoom, expandedBoundingBox, results);
    }

    return image;
}
 
Example #15
Source File: TileGenerator.java    From geopackage-android with MIT License 5 votes vote down vote up
/**
 * 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 #16
Source File: FeatureOverlayQuery.java    From geopackage-android-map with MIT License 5 votes vote down vote up
/**
 * Query for features in the bounding box
 *
 * @param columns     columns
 * @param boundingBox query bounding box
 * @param projection  bounding box projection
 * @return feature index results, must be closed
 * @since 3.5.0
 */
public FeatureIndexResults queryFeatures(String[] columns, BoundingBox boundingBox, Projection projection) {

    if (projection == null) {
        projection = ProjectionFactory.getProjection(ProjectionConstants.EPSG_WORLD_GEODETIC_SYSTEM);
    }

    // Query for features
    FeatureIndexManager indexManager = featureTiles.getIndexManager();
    if (indexManager == null) {
        throw new GeoPackageException("Index Manager is not set on the Feature Tiles and is required to query indexed features");
    }
    FeatureIndexResults results = indexManager.query(columns, boundingBox, projection);
    return results;
}
 
Example #17
Source File: CoverageDataTiffImportTest.java    From geopackage-android with MIT License 4 votes vote down vote up
/**
 * Test 10 random locations and optionally print
 *
 * @throws Exception
 */
@Test
public void testRandomLocations() throws Exception {

    BoundingBox projectedBoundingBox = null;

    List<String> coverageDataTables = CoverageDataTiff.getTables(geoPackage);
    TileMatrixSetDao dao = geoPackage.getTileMatrixSetDao();

    for (String coverageTable : coverageDataTables) {

        TileMatrixSet tileMatrixSet = dao.queryForId(coverageTable);

        BoundingBox boundingBox = tileMatrixSet.getBoundingBox();
        if (PRINT) {
            System.out.println("Min Latitude: "
                    + boundingBox.getMinLatitude());
            System.out.println("Max Latitude: "
                    + boundingBox.getMaxLatitude());
            System.out.println("Min Longitude: "
                    + boundingBox.getMinLongitude());
            System.out.println("Max Longitude: "
                    + boundingBox.getMaxLongitude());
            System.out.println();
        }
        SpatialReferenceSystemDao srsDao = geoPackage
                .getSpatialReferenceSystemDao();
        long srsId = tileMatrixSet.getSrsId();
        SpatialReferenceSystem srs = srsDao.queryForId(srsId);
        Projection projection = srs.getProjection();
        Projection requestProjection = ProjectionFactory
                .getProjection(ProjectionConstants.EPSG_WORLD_GEODETIC_SYSTEM);
        ProjectionTransform coverageToRequest = projection
                .getTransformation(requestProjection);
        projectedBoundingBox = boundingBox.transform(coverageToRequest);

    }
    if (PRINT) {
        System.out.println("Min Latitude: "
                + projectedBoundingBox.getMinLatitude());
        System.out.println("Max Latitude: "
                + projectedBoundingBox.getMaxLatitude());
        System.out.println("Min Longitude: "
                + projectedBoundingBox.getMinLongitude());
        System.out.println("Max Longitude: "
                + projectedBoundingBox.getMaxLongitude());
        System.out.println();
    }

    double latDistance = projectedBoundingBox.getMaxLatitude()
            - projectedBoundingBox.getMinLatitude();
    double lonDistance = projectedBoundingBox.getMaxLongitude()
            - projectedBoundingBox.getMinLongitude();

    for (int i = 0; i < 10; i++) {

        // Get a random coordinate
        double latitude = latDistance * .9 * Math.random()
                + projectedBoundingBox.getMinLatitude()
                + (.05 * latDistance);
        double longitude = lonDistance * .9 * Math.random()
                + projectedBoundingBox.getMinLongitude()
                + (.05 * lonDistance);
        testLocation(latitude, longitude);
        if (PRINT) {
            System.out.println();
        }
    }
}
 
Example #18
Source File: LoadTilesTask.java    From geopackage-mapcache-android with MIT License 4 votes vote down vote up
/**
 * Load tiles from a URL
 *
 * @param activity
 * @param callback
 * @param active
 * @param database
 * @param tableName
 * @param tileUrl
 * @param minZoom
 * @param maxZoom
 * @param compressFormat
 * @param compressQuality
 * @param googleTiles
 * @param boundingBox
 * @param scaling
 * @param authority
 * @param code
 */
public static void loadTiles(Activity activity, ILoadTilesTask callback,
                             GeoPackageDatabases active, String database, String tableName,
                             String tileUrl, int minZoom, int maxZoom,
                             CompressFormat compressFormat, Integer compressQuality,
                             boolean googleTiles, BoundingBox boundingBox, TileScaling scaling, String authority, String code) {

    GeoPackageManager manager = GeoPackageFactory.getManager(activity);
    GeoPackage geoPackage = manager.open(database);

    Projection projection = ProjectionFactory.getProjection(authority, code);
    BoundingBox bbox = transform(boundingBox, projection);

    TileGenerator tileGenerator = new UrlTileGenerator(activity, geoPackage,
            tableName, tileUrl, minZoom, maxZoom, bbox, projection);
    setTileGenerator(activity, tileGenerator, minZoom, maxZoom, compressFormat, compressQuality, googleTiles, boundingBox, scaling);

    loadTiles(activity, callback, active, geoPackage, tableName, tileGenerator);
}
 
Example #19
Source File: LoadTilesTask.java    From geopackage-mapcache-android with MIT License 4 votes vote down vote up
/**
 * Load tiles from features
 *
 * @param activity
 * @param callback
 * @param active
 * @param geoPackage
 * @param tableName
 * @param featureTiles
 * @param minZoom
 * @param maxZoom
 * @param compressFormat
 * @param compressQuality
 * @param googleTiles
 * @param boundingBox
 * @param scaling
 * @param authority
 * @param code
 */
public static void loadTiles(Activity activity, ILoadTilesTask callback,
                             GeoPackageDatabases active, GeoPackage geoPackage, String tableName,
                             FeatureTiles featureTiles, int minZoom, int maxZoom,
                             CompressFormat compressFormat, Integer compressQuality,
                             boolean googleTiles, BoundingBox boundingBox, TileScaling scaling, String authority, String code) {

    GeoPackageUtils.prepareFeatureTiles(featureTiles);

    Projection projection = ProjectionFactory.getProjection(authority, code);
    BoundingBox bbox = transform(boundingBox, projection);

    TileGenerator tileGenerator = new FeatureTileGenerator(activity, geoPackage,
            tableName, featureTiles, minZoom, maxZoom, bbox, projection);
    setTileGenerator(activity, tileGenerator, minZoom, maxZoom, compressFormat, compressQuality, googleTiles, boundingBox, scaling);

    loadTiles(activity, callback, active, geoPackage, tableName, tileGenerator);
}
 
Example #20
Source File: CoverageDataPngImportTest.java    From geopackage-android with MIT License 4 votes vote down vote up
/**
 * Test 10 random locations and optionally print
 *
 * @throws Exception
 */
@Test
public void testRandomLocations() throws Exception {

    BoundingBox projectedBoundingBox = null;

    List<String> coverageDataTables = CoverageDataPng.getTables(geoPackage);
    TileMatrixSetDao dao = geoPackage.getTileMatrixSetDao();

    for (String coverageTable : coverageDataTables) {

        TileMatrixSet tileMatrixSet = dao.queryForId(coverageTable);

        BoundingBox boundingBox = tileMatrixSet.getBoundingBox();
        if (PRINT) {
            System.out.println("Min Latitude: "
                    + boundingBox.getMinLatitude());
            System.out.println("Max Latitude: "
                    + boundingBox.getMaxLatitude());
            System.out.println("Min Longitude: "
                    + boundingBox.getMinLongitude());
            System.out.println("Max Longitude: "
                    + boundingBox.getMaxLongitude());
            System.out.println();
        }
        SpatialReferenceSystemDao srsDao = geoPackage
                .getSpatialReferenceSystemDao();
        long srsId = tileMatrixSet.getSrsId();
        SpatialReferenceSystem srs = srsDao.queryForId(srsId);
        Projection projection = srs.getProjection();
        Projection requestProjection = ProjectionFactory
                .getProjection(ProjectionConstants.EPSG_WORLD_GEODETIC_SYSTEM);
        ProjectionTransform coverageToRequest = projection
                .getTransformation(requestProjection);
        projectedBoundingBox = boundingBox.transform(coverageToRequest);

    }
    if (PRINT) {
        System.out.println("Min Latitude: "
                + projectedBoundingBox.getMinLatitude());
        System.out.println("Max Latitude: "
                + projectedBoundingBox.getMaxLatitude());
        System.out.println("Min Longitude: "
                + projectedBoundingBox.getMinLongitude());
        System.out.println("Max Longitude: "
                + projectedBoundingBox.getMaxLongitude());
        System.out.println();
    }

    double latDistance = projectedBoundingBox.getMaxLatitude()
            - projectedBoundingBox.getMinLatitude();
    double lonDistance = projectedBoundingBox.getMaxLongitude()
            - projectedBoundingBox.getMinLongitude();

    for (int i = 0; i < 10; i++) {

        // Get a random coordinate
        double latitude = latDistance * .9 * Math.random()
                + projectedBoundingBox.getMinLatitude()
                + (.05 * latDistance);
        double longitude = lonDistance * .9 * Math.random()
                + projectedBoundingBox.getMinLongitude()
                + (.05 * lonDistance);
        testLocation(latitude, longitude);
        if (PRINT) {
            System.out.println();
        }
    }
}
 
Example #21
Source File: CoverageDataPngImportTest.java    From geopackage-java with MIT License 4 votes vote down vote up
/**
 * Test 10 random locations and optionally print
 * 
 * @throws Exception
 */
@Test
public void testRandomLocations() throws Exception {

	BoundingBox projectedBoundingBox = null;

	List<String> coverageDataTables = CoverageDataPng.getTables(geoPackage);
	TileMatrixSetDao dao = geoPackage.getTileMatrixSetDao();

	for (String coverageTable : coverageDataTables) {

		TileMatrixSet tileMatrixSet = dao.queryForId(coverageTable);

		BoundingBox boundingBox = tileMatrixSet.getBoundingBox();
		if (PRINT) {
			System.out.println("Min Latitude: "
					+ boundingBox.getMinLatitude());
			System.out.println("Max Latitude: "
					+ boundingBox.getMaxLatitude());
			System.out.println("Min Longitude: "
					+ boundingBox.getMinLongitude());
			System.out.println("Max Longitude: "
					+ boundingBox.getMaxLongitude());
			System.out.println();
		}
		SpatialReferenceSystemDao srsDao = geoPackage
				.getSpatialReferenceSystemDao();
		long srsId = tileMatrixSet.getSrsId();
		SpatialReferenceSystem srs = srsDao.queryForId(srsId);
		Projection projection = srs.getProjection();
		Projection requestProjection = ProjectionFactory
				.getProjection(ProjectionConstants.EPSG_WORLD_GEODETIC_SYSTEM);
		ProjectionTransform coverageToRequest = projection
				.getTransformation(requestProjection);
		projectedBoundingBox = boundingBox.transform(coverageToRequest);

	}
	if (PRINT) {
		System.out.println("Min Latitude: "
				+ projectedBoundingBox.getMinLatitude());
		System.out.println("Max Latitude: "
				+ projectedBoundingBox.getMaxLatitude());
		System.out.println("Min Longitude: "
				+ projectedBoundingBox.getMinLongitude());
		System.out.println("Max Longitude: "
				+ projectedBoundingBox.getMaxLongitude());
		System.out.println();
	}

	double latDistance = projectedBoundingBox.getMaxLatitude()
			- projectedBoundingBox.getMinLatitude();
	double lonDistance = projectedBoundingBox.getMaxLongitude()
			- projectedBoundingBox.getMinLongitude();

	for (int i = 0; i < 10; i++) {

		// Get a random coordinate
		double latitude = latDistance * .9 * Math.random()
				+ projectedBoundingBox.getMinLatitude()
				+ (.05 * latDistance);
		double longitude = lonDistance * .9 * Math.random()
				+ projectedBoundingBox.getMinLongitude()
				+ (.05 * lonDistance);
		testLocation(latitude, longitude);
		if (PRINT) {
			System.out.println();
		}
	}
}
 
Example #22
Source File: CoverageDataTiffImportTest.java    From geopackage-java with MIT License 4 votes vote down vote up
/**
 * Test 10 random locations and optionally print
 * 
 * @throws Exception
 */
@Test
public void testRandomLocations() throws Exception {

	BoundingBox projectedBoundingBox = null;

	List<String> coverageDataTables = CoverageDataTiff
			.getTables(geoPackage);
	TileMatrixSetDao dao = geoPackage.getTileMatrixSetDao();

	for (String coverageTable : coverageDataTables) {

		TileMatrixSet tileMatrixSet = dao.queryForId(coverageTable);

		BoundingBox boundingBox = tileMatrixSet.getBoundingBox();
		if (PRINT) {
			System.out.println("Min Latitude: "
					+ boundingBox.getMinLatitude());
			System.out.println("Max Latitude: "
					+ boundingBox.getMaxLatitude());
			System.out.println("Min Longitude: "
					+ boundingBox.getMinLongitude());
			System.out.println("Max Longitude: "
					+ boundingBox.getMaxLongitude());
			System.out.println();
		}
		SpatialReferenceSystemDao srsDao = geoPackage
				.getSpatialReferenceSystemDao();
		long srsId = tileMatrixSet.getSrsId();
		SpatialReferenceSystem srs = srsDao.queryForId(srsId);
		Projection projection = srs.getProjection();
		Projection requestProjection = ProjectionFactory
				.getProjection(ProjectionConstants.EPSG_WORLD_GEODETIC_SYSTEM);
		ProjectionTransform coverageToRequest = projection
				.getTransformation(requestProjection);
		projectedBoundingBox = boundingBox.transform(coverageToRequest);

	}
	if (PRINT) {
		System.out.println("Min Latitude: "
				+ projectedBoundingBox.getMinLatitude());
		System.out.println("Max Latitude: "
				+ projectedBoundingBox.getMaxLatitude());
		System.out.println("Min Longitude: "
				+ projectedBoundingBox.getMinLongitude());
		System.out.println("Max Longitude: "
				+ projectedBoundingBox.getMaxLongitude());
		System.out.println();
	}

	double latDistance = projectedBoundingBox.getMaxLatitude()
			- projectedBoundingBox.getMinLatitude();
	double lonDistance = projectedBoundingBox.getMaxLongitude()
			- projectedBoundingBox.getMinLongitude();

	for (int i = 0; i < 10; i++) {

		// Get a random coordinate
		double latitude = latDistance * .9 * Math.random()
				+ projectedBoundingBox.getMinLatitude()
				+ (.05 * latDistance);
		double longitude = lonDistance * .9 * Math.random()
				+ projectedBoundingBox.getMinLongitude()
				+ (.05 * lonDistance);
		testLocation(latitude, longitude);
		if (PRINT) {
			System.out.println();
		}
	}
}
 
Example #23
Source File: UrlTileGeneratorUtils.java    From geopackage-java with MIT License 4 votes vote down vote up
private static Projection getProjection() {
	return ProjectionFactory
			.getProjection(ProjectionConstants.EPSG_WEB_MERCATOR);
}
 
Example #24
Source File: GeoPackageTileRetriever.java    From geopackage-java with MIT License 3 votes vote down vote up
/**
 * Constructor with specified tile size
 *
 * @param tileDao
 *            tile dao
 * @param width
 *            width
 * @param height
 *            height
 * @param imageFormat
 *            image format
 */
public GeoPackageTileRetriever(TileDao tileDao, Integer width,
		Integer height, String imageFormat) {

	tileDao.adjustTileMatrixLengths();

	Projection webMercator = ProjectionFactory
			.getProjection(ProjectionConstants.EPSG_WEB_MERCATOR);

	tileCreator = new TileCreator(tileDao, width, height, webMercator,
			imageFormat);
}
 
Example #25
Source File: GeoPackageTileRetriever.java    From geopackage-android with MIT License 3 votes vote down vote up
/**
 * Constructor with specified tile size
 *
 * @param tileDao tile dao
 * @param width   width
 * @param height  height
 */
public GeoPackageTileRetriever(TileDao tileDao, Integer width, Integer height) {

    tileDao.adjustTileMatrixLengths();

    Projection webMercator = ProjectionFactory
            .getProjection(ProjectionConstants.EPSG_WEB_MERCATOR);

    tileCreator = new TileCreator(tileDao, width, height, webMercator);
}
 
Example #26
Source File: TileBoundingBoxUtils.java    From geopackage-core-java with MIT License 2 votes vote down vote up
/**
 * Get the tile grid for the location specified as WGS84
 * 
 * @param point
 *            point
 * @param zoom
 *            zoom level
 * @return tile grid
 * @since 1.1.0
 */
public static TileGrid getTileGridFromWGS84(Point point, int zoom) {
	Projection projection = ProjectionFactory
			.getProjection(ProjectionConstants.EPSG_WORLD_GEODETIC_SYSTEM);
	return getTileGrid(point, zoom, projection);
}