mil.nga.sf.proj.Projection Java Examples

The following examples show how to use mil.nga.sf.proj.Projection. 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: UrlTileGenerator.java    From geopackage-android with MIT License 6 votes vote down vote up
/**
 * Constructor
 *
 * @param context     app context
 * @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.3.0
 */
public UrlTileGenerator(Context context, GeoPackage geoPackage,
                        String tableName, String tileUrl, int minZoom, int maxZoom, BoundingBox boundingBox, Projection projection) {
    super(context, 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 #2
Source File: FeatureTiles.java    From geopackage-java with MIT License 6 votes vote down vote up
/**
 * Create an expanded bounding box to handle features outside the tile that
 * overlap
 * 
 * @param boundingBox
 *            bounding box
 * @param projection
 *            bounding box projection
 * @return bounding box
 * @since 3.2.0
 */
public BoundingBox expandBoundingBox(BoundingBox boundingBox,
		Projection projection) {

	BoundingBox expandedBoundingBox = boundingBox;

	ProjectionTransform toWebMercator = projection
			.getTransformation(ProjectionConstants.EPSG_WEB_MERCATOR);
	if (!toWebMercator.isSameProjection()) {
		expandedBoundingBox = expandedBoundingBox.transform(toWebMercator);
	}

	expandedBoundingBox = expandBoundingBox(expandedBoundingBox);

	if (!toWebMercator.isSameProjection()) {
		ProjectionTransform fromWebMercator = toWebMercator
				.getInverseTransformation();
		expandedBoundingBox = expandedBoundingBox
				.transform(fromWebMercator);
	}

	return expandedBoundingBox;
}
 
Example #3
Source File: GoogleMapShapeConverter.java    From geopackage-android-map with MIT License 6 votes vote down vote up
/**
 * Constructor with specified projection, see
 * {@link FeatureDao#getProjection}
 *
 * @param projection projection
 */
public GoogleMapShapeConverter(Projection projection) {
    this.projection = projection;
    if (projection != null) {
        toWgs84 = projection
                .getTransformation(ProjectionConstants.EPSG_WORLD_GEODETIC_SYSTEM);
        Projection wgs84 = toWgs84.getToProjection();
        fromWgs84 = wgs84.getTransformation(projection);
        toWebMercator = projection.getTransformation(ProjectionConstants.EPSG_WEB_MERCATOR);
        Projection webMercator = toWebMercator.getToProjection();
        fromWebMercator = webMercator.getTransformation(projection);
    } else {
        toWgs84 = null;
        fromWgs84 = null;
        toWebMercator = null;
        fromWebMercator = null;
    }
}
 
Example #4
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 #5
Source File: GeoPackageImpl.java    From geopackage-java with MIT License 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public BoundingBox getFeatureBoundingBox(Projection projection,
		String table, boolean manual) {

	BoundingBox boundingBox = null;

	FeatureIndexManager indexManager = new FeatureIndexManager(this, table);
	try {
		if (manual || indexManager.isIndexed()) {
			boundingBox = indexManager.getBoundingBox(projection);
		}
	} finally {
		indexManager.close();
	}

	return boundingBox;
}
 
Example #6
Source File: RTreeIndexTableDao.java    From geopackage-android with MIT License 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public BoundingBox getBoundingBox(Projection projection) {
    BoundingBox boundingBox = getBoundingBox();
    if (boundingBox != null && projection != null) {
        ProjectionTransform projectionTransform = featureDao
                .getProjection().getTransformation(projection);
        boundingBox = boundingBox.transform(projectionTransform);
    }
    return boundingBox;
}
 
Example #7
Source File: TileCreator.java    From geopackage-android with MIT License 5 votes vote down vote up
/**
 * Constructor, specified tile size and projection
 *
 * @param tileDao           tile dao
 * @param width             requested width
 * @param height            requested height
 * @param requestProjection requested projection
 */
public TileCreator(TileDao tileDao, Integer width, Integer height, Projection requestProjection) {
    this.tileDao = tileDao;
    this.width = width;
    this.height = height;
    this.requestProjection = requestProjection;

    tileMatrixSet = tileDao.getTileMatrixSet();
    tilesProjection = tileDao.getTileMatrixSet().getProjection();
    tileSetBoundingBox = tileMatrixSet.getBoundingBox();

    // Check if the projections have the same units
    sameProjection = (requestProjection.getUnit().name.equals(tilesProjection.getUnit().name));
}
 
Example #8
Source File: CoverageData.java    From geopackage-android with MIT License 5 votes vote down vote up
/**
 * 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 #9
Source File: FeatureOverlayQuery.java    From geopackage-android-map with MIT License 5 votes vote down vote up
/**
 * Perform a query based upon the map click location and build feature table data
 *
 * @param latLng      location
 * @param zoom        current zoom level
 * @param boundingBox click bounding box
 * @param tolerance   distance tolerance
 * @param projection  desired geometry projection
 * @return table data on what was clicked, or null
 */
private FeatureTableData buildMapClickTableData(LatLng latLng, double zoom, BoundingBox boundingBox, double tolerance, Projection projection) {
    FeatureTableData tableData = null;

    // Verify the features are indexed and we are getting information
    if (isIndexed() && (maxFeaturesInfo || featuresInfo)) {

        if (isOnAtCurrentZoom(zoom, latLng)) {

            // Get the number of features in the tile location
            long tileFeatureCount = tileFeatureCount(latLng, zoom);

            // If more than a configured max features to draw
            if (isMoreThanMaxFeatures(tileFeatureCount)) {

                // Build the max features message
                if (maxFeaturesInfo) {
                    tableData = new FeatureTableData(featureTiles.getFeatureDao().getTableName(), tileFeatureCount);
                }

            }
            // Else, query for the features near the click
            else if (featuresInfo) {

                // Query for results and build the message
                FeatureIndexResults results = queryFeatures(boundingBox, projection);
                tableData = featureInfoBuilder.buildTableDataAndClose(results, tolerance, latLng, projection);
            }

        }
    }

    return tableData;
}
 
Example #10
Source File: FeatureTableCoreIndex.java    From geopackage-core-java with MIT License 5 votes vote down vote up
/**
 * Query for the feature index bounds and return in the provided projection
 * 
 * @param projection
 *            desired projection
 * @return bounding box
 * @since 3.1.0
 */
public BoundingBox getBoundingBox(Projection projection) {
	BoundingBox boundingBox = getBoundingBox();
	if (boundingBox != null && projection != null) {
		ProjectionTransform projectionTransform = getProjection()
				.getTransformation(projection);
		boundingBox = boundingBox.transform(projectionTransform);
	}
	return boundingBox;
}
 
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: FeatureDao.java    From geopackage-android with MIT License 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public BoundingBox getBoundingBox(Projection projection) {
    Contents contents = geometryColumns.getContents();
    BoundingBox boundingBox = contents.getBoundingBox(projection);
    return boundingBox;
}
 
Example #13
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 #14
Source File: TileBoundingBoxUtils.java    From geopackage-core-java with MIT License 5 votes vote down vote up
/**
 * Get the Projected tile bounding box from the XYZ tile grid and zoom level
 *
 * @param projection
 *            projection
 * @param tileGrid
 *            tile grid
 * @param zoom
 *            zoom level
 * @return bounding box
 */
public static BoundingBox getProjectedBoundingBox(Projection projection,
		TileGrid tileGrid, int zoom) {

	BoundingBox boundingBox = getWebMercatorBoundingBox(tileGrid, zoom);

	if (projection != null) {
		ProjectionTransform transform = webMercator
				.getTransformation(projection);
		boundingBox = boundingBox.transform(transform);
	}

	return boundingBox;
}
 
Example #15
Source File: TileMatrixSet.java    From geopackage-core-java with MIT License 5 votes vote down vote up
/**
 * Get a bounding box in the provided projection
 * 
 * @param projection
 *            desired projection
 * 
 * @return bounding box
 * @since 3.1.0
 */
public BoundingBox getBoundingBox(Projection projection) {
	BoundingBox boundingBox = getBoundingBox();
	if (projection != null) {
		ProjectionTransform transform = getProjection().getTransformation(
				projection);
		if (!transform.isSameProjection()) {
			boundingBox = boundingBox.transform(transform);
		}
	}
	return boundingBox;
}
 
Example #16
Source File: OAPIFeatureCoreGenerator.java    From geopackage-core-java with MIT License 5 votes vote down vote up
/**
 * Get the CRS from the projection
 * 
 * @param projection
 *            projection
 * @return crs
 */
protected Crs getCrs(Projection projection) {
	String version = null;
	switch (projection.getAuthority()) {
	case ProjectionConstants.AUTHORITY_OGC:
		version = OGC_VERSION;
		break;
	default:
		version = EPSG_VERSION;
	}
	return new Crs(projection.getAuthority(), version,
			projection.getCode());
}
 
Example #17
Source File: AttributesDao.java    From geopackage-android with MIT License 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public BoundingBox getBoundingBox(Projection projection) {
    throw new GeoPackageException(
            "Bounding Box not supported for Attributes");
}
 
Example #18
Source File: GeoPackageGeometryDataUtils.java    From geopackage-android with MIT License 4 votes vote down vote up
/**
 * 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 #19
Source File: GeoPackageCoreImpl.java    From geopackage-core-java with MIT License 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public BoundingBox getBoundingBox(Projection projection, String table) {
	return getBoundingBox(projection, table, false);
}
 
Example #20
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 #21
Source File: MapFragment.java    From mage-android with Apache License 2.0 4 votes vote down vote up
/**
 * Add the GeoPackage Feature Table Cache Overlay
 * @param enabledCacheOverlays
 * @param featureTableCacheOverlay
 * @param geoPackage
 */
private void addGeoPackageFeatureCacheOverlay(Map<String, CacheOverlay> enabledCacheOverlays, GeoPackageFeatureTableCacheOverlay featureTableCacheOverlay, GeoPackage geoPackage){
	// Retrieve the cache overlay if it already exists (and remove from cache overlays)
	CacheOverlay cacheOverlay = cacheOverlays.remove(featureTableCacheOverlay.getCacheName());
	if(cacheOverlay != null){
		// If the existing cache overlay is being replaced, create a new cache overlay
		if(featureTableCacheOverlay.getParent().isAdded()){
			cacheOverlay = null;
		}
		for(GeoPackageTileTableCacheOverlay linkedTileTable: featureTableCacheOverlay.getLinkedTileTables()){
			cacheOverlays.remove(linkedTileTable.getCacheName());
		}
	}
	if(cacheOverlay == null) {
		// Add the features to the map
		FeatureDao featureDao = geoPackage.getFeatureDao(featureTableCacheOverlay.getName());

		// If indexed, add as a tile overlay
		if(featureTableCacheOverlay.isIndexed()){
			FeatureTiles featureTiles = new DefaultFeatureTiles(getActivity(), geoPackage, featureDao,
					getResources().getDisplayMetrics().density);
			Integer maxFeaturesPerTile = null;
			if(featureDao.getGeometryType() == GeometryType.POINT){
				maxFeaturesPerTile = getResources().getInteger(R.integer.geopackage_feature_tiles_max_points_per_tile);
			}else{
				maxFeaturesPerTile = getResources().getInteger(R.integer.geopackage_feature_tiles_max_features_per_tile);
			}
			featureTiles.setMaxFeaturesPerTile(maxFeaturesPerTile);
			NumberFeaturesTile numberFeaturesTile = new NumberFeaturesTile(getActivity());
			// Adjust the max features number tile draw paint attributes here as needed to
			// change how tiles are drawn when more than the max features exist in a tile
			featureTiles.setMaxFeaturesTileDraw(numberFeaturesTile);
			// Adjust the feature tiles draw paint attributes here as needed to change how
			// features are drawn on tiles
			FeatureOverlay featureOverlay = new FeatureOverlay(featureTiles);
			featureOverlay.setMinZoom(featureTableCacheOverlay.getMinZoom());

			// Get the tile linked overlay
			BoundedOverlay overlay = GeoPackageOverlayFactory.getLinkedFeatureOverlay(featureOverlay, geoPackage);

			FeatureOverlayQuery featureOverlayQuery = new FeatureOverlayQuery(getActivity(), overlay, featureTiles);
			featureTableCacheOverlay.setFeatureOverlayQuery(featureOverlayQuery);
			TileOverlayOptions overlayOptions = createFeatureTileOverlayOptions(overlay);
			TileOverlay tileOverlay = map.addTileOverlay(overlayOptions);
			featureTableCacheOverlay.setTileOverlay(tileOverlay);
		}
		// Not indexed, add the features to the map
		else {
			int maxFeaturesPerTable = 0;
			if(featureDao.getGeometryType() == GeometryType.POINT){
				maxFeaturesPerTable = getResources().getInteger(R.integer.geopackage_features_max_points_per_table);
			}else{
				maxFeaturesPerTable = getResources().getInteger(R.integer.geopackage_features_max_features_per_table);
			}
			Projection projection = featureDao.getProjection();
			GoogleMapShapeConverter shapeConverter = new GoogleMapShapeConverter(projection);
			FeatureCursor featureCursor = featureDao.queryForAll();
			try {
				final int totalCount = featureCursor.getCount();
				int count = 0;
				while (featureCursor.moveToNext()) {
					try {
						FeatureRow featureRow = featureCursor.getRow();
						GeoPackageGeometryData geometryData = featureRow.getGeometry();
						if (geometryData != null && !geometryData.isEmpty()) {
							Geometry geometry = geometryData.getGeometry();
							if (geometry != null) {
								GoogleMapShape shape = shapeConverter.toShape(geometry);
								// Set the Shape Marker, PolylineOptions, and PolygonOptions here if needed to change color and style
								featureTableCacheOverlay.addShapeToMap(featureRow.getId(), shape, map);

								if (++count >= maxFeaturesPerTable) {
									if (count < totalCount) {
										Toast.makeText(getActivity().getApplicationContext(), featureTableCacheOverlay.getCacheName()
												+ "- added " + count + " of " + totalCount, Toast.LENGTH_LONG).show();
									}
									break;
								}
							}
						}
					}catch(Exception e){
						Log.e(LOG_NAME, "Failed to display feature. GeoPackage: " + geoPackage.getName()
								+ ", Table: " + featureDao.getTableName() + ", Row: " + featureCursor.getPosition(), e);
					}
				}
			} finally {
				featureCursor.close();
			}
		}

		cacheOverlay = featureTableCacheOverlay;
	}

	// Add the cache overlay to the enabled cache overlays
	enabledCacheOverlays.put(cacheOverlay.getCacheName(), cacheOverlay);
}
 
Example #22
Source File: FeatureOverlayQuery.java    From geopackage-android-map with MIT License 4 votes vote down vote up
/**
 * Perform a query based upon the map click location and build feature table data
 *
 * @param latLng     location
 * @param view       view
 * @param map        Google Map
 * @param projection desired geometry projection
 * @return table data on what was clicked, or null
 * @since 1.2.7
 */
public FeatureTableData buildMapClickTableData(LatLng latLng, View view, GoogleMap map, Projection projection) {

    // Get the zoom level
    double zoom = MapUtils.getCurrentZoom(map);

    // Build a bounding box to represent the click location
    BoundingBox boundingBox = MapUtils.buildClickBoundingBox(latLng, view, map, screenClickPercentage);

    // Get the map click distance tolerance
    double tolerance = MapUtils.getToleranceDistance(latLng, view, map, screenClickPercentage);

    FeatureTableData tableData = buildMapClickTableData(latLng, zoom, boundingBox, tolerance, projection);

    return tableData;
}
 
Example #23
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 #24
Source File: FeatureTableIndex.java    From geopackage-android with MIT License 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public Projection getProjection() {
    return featureDao.getProjection();
}
 
Example #25
Source File: RTreeIndexTableDao.java    From geopackage-java with MIT License 3 votes vote down vote up
/**
 * Count the features within the bounding box in the provided projection
 * 
 * @param boundingBox
 *            bounding box
 * @param projection
 *            projection
 * @param fieldValues
 *            field values
 * @return count
 * @since 3.4.0
 */
public int countFeatures(BoundingBox boundingBox, Projection projection,
		Map<String, Object> fieldValues) {
	BoundingBox featureBoundingBox = projectBoundingBox(boundingBox,
			projection);
	return countFeatures(featureBoundingBox, fieldValues);
}
 
Example #26
Source File: FeatureIndexer.java    From geopackage-android with MIT License 3 votes vote down vote up
/**
 * Query for features within the bounding box in the provided projection
 *
 * @param columns     columns
 * @param boundingBox bounding box
 * @param projection  projection
 * @param where       where clause
 * @param whereArgs   where arguments
 * @return feature results
 * @since 3.5.0
 */
public FeatureCursor queryFeatures(String[] columns, BoundingBox boundingBox,
                                   Projection projection, String where, String[] whereArgs) {
    BoundingBox featureBoundingBox = getFeatureBoundingBox(boundingBox,
            projection);
    return queryFeatures(columns, featureBoundingBox, where, whereArgs);
}
 
Example #27
Source File: ManualFeatureQuery.java    From geopackage-android with MIT License 3 votes vote down vote up
/**
 * Manually query for rows within the bounding box in the provided
 * projection
 *
 * @param columns     columns
 * @param boundingBox bounding box
 * @param projection  projection
 * @return results
 * @since 3.5.0
 */
public ManualFeatureQueryResults query(String[] columns,
                                       BoundingBox boundingBox, Projection projection) {
    BoundingBox featureBoundingBox = featureDao
            .projectBoundingBox(boundingBox, projection);
    return query(columns, featureBoundingBox);
}
 
Example #28
Source File: FeatureIndexer.java    From geopackage-android with MIT License 3 votes vote down vote up
/**
 * Query for features within the bounding box in the provided projection
 *
 * @param columns     columns
 * @param boundingBox bounding box
 * @param projection  projection
 * @param fieldValues field values
 * @return feature results
 * @since 3.5.0
 */
public FeatureCursor queryFeatures(String[] columns, BoundingBox boundingBox,
                                   Projection projection, Map<String, Object> fieldValues) {
    BoundingBox featureBoundingBox = getFeatureBoundingBox(boundingBox,
            projection);
    return queryFeatures(columns, featureBoundingBox, fieldValues);
}
 
Example #29
Source File: TileBoundingBoxUtils.java    From geopackage-core-java with MIT License 3 votes vote down vote up
/**
 * Get the Projected tile bounding box from the XYZ tile coordinates and
 * zoom level
 *
 * @param projection
 *            projection
 * @param x
 *            x coordinate
 * @param y
 *            y coordinate
 * @param zoom
 *            zoom level
 * @return bounding box
 */
public static BoundingBox getProjectedBoundingBox(Projection projection,
		long x, long y, int zoom) {

	BoundingBox boundingBox = getWebMercatorBoundingBox(x, y, zoom);

	if (projection != null) {
		ProjectionTransform transform = webMercator
				.getTransformation(projection);
		boundingBox = boundingBox.transform(transform);
	}

	return boundingBox;
}
 
Example #30
Source File: RTreeIndexTableDao.java    From geopackage-android with MIT License 3 votes vote down vote up
/**
 * Count the features within the bounding box in the provided projection
 *
 * @param boundingBox bounding box
 * @param projection  projection
 * @param where       where clause
 * @param whereArgs   where arguments
 * @return count
 * @since 3.4.0
 */
public int countFeatures(BoundingBox boundingBox, Projection projection,
                         String where, String[] whereArgs) {
    BoundingBox featureBoundingBox = projectBoundingBox(boundingBox,
            projection);
    return countFeatures(featureBoundingBox, where, whereArgs);
}