mil.nga.sf.proj.ProjectionConstants Java Examples

The following examples show how to use mil.nga.sf.proj.ProjectionConstants. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GeoPackageTestUtils.java    From geopackage-android with MIT License 6 votes vote down vote up
/**
 * 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 #2
Source File: TestUtils.java    From geopackage-java with MIT License 6 votes vote down vote up
/**
 * Create a random point
 * 
 * @param hasZ
 * @param hasM
 * @return point
 */
public static Point createPoint(boolean hasZ, boolean hasM) {

	double x = Math.random() * 180.0 * (Math.random() < .5 ? 1 : -1);
	double y = Math.random()
			* ProjectionConstants.WEB_MERCATOR_MIN_LAT_RANGE
			* (Math.random() < .5 ? 1 : -1);

	Point point = new Point(hasZ, hasM, x, y);

	if (hasZ) {
		double z = Math.random() * 1000.0;
		point.setZ(z);
	}

	if (hasM) {
		double m = Math.random() * 1000.0;
		point.setM(m);
	}

	return point;
}
 
Example #3
Source File: FeatureTiles.java    From geopackage-android 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 #4
Source File: FeatureTileGenerator.java    From geopackage-java with MIT License 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public BoundingBox getBoundingBox(int zoom) {

	ProjectionTransform projectionToWebMercator = projection
			.getTransformation(ProjectionConstants.EPSG_WEB_MERCATOR);
	BoundingBox webMercatorBoundingBox = boundingBox
			.transform(projectionToWebMercator);

	TileGrid tileGrid = TileBoundingBoxUtils.getTileGrid(
			webMercatorBoundingBox, zoom);
	BoundingBox tileBoundingBox = TileBoundingBoxUtils
			.getWebMercatorBoundingBox(tileGrid.getMinX(),
					tileGrid.getMinY(), zoom);

	BoundingBox expandedBoundingBox = featureTiles.expandBoundingBox(
			webMercatorBoundingBox, tileBoundingBox);

	BoundingBox zoomBoundingBox = expandedBoundingBox
			.transform(projectionToWebMercator.getInverseTransformation());

	return zoomBoundingBox;
}
 
Example #5
Source File: GeoPackageTestUtils.java    From geopackage-java with MIT License 6 votes vote down vote up
/**
 * 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 #6
Source File: FeatureTileGenerator.java    From geopackage-android with MIT License 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public BoundingBox getBoundingBox(int zoom) {

    ProjectionTransform projectionToWebMercator = projection
            .getTransformation(ProjectionConstants.EPSG_WEB_MERCATOR);
    BoundingBox webMercatorBoundingBox = boundingBox
            .transform(projectionToWebMercator);

    TileGrid tileGrid = TileBoundingBoxUtils.getTileGrid(webMercatorBoundingBox, zoom);
    BoundingBox tileBoundingBox = TileBoundingBoxUtils.getWebMercatorBoundingBox(
            tileGrid.getMinX(), tileGrid.getMinY(), zoom);

    BoundingBox expandedBoundingBox = featureTiles.expandBoundingBox(webMercatorBoundingBox, tileBoundingBox);

    BoundingBox zoomBoundingBox = expandedBoundingBox.transform(projectionToWebMercator.getInverseTransformation());

    return zoomBoundingBox;
}
 
Example #7
Source File: CoverageDataTiffImportTest.java    From geopackage-java with MIT License 6 votes vote down vote up
/**
 * Test a single location
 * 
 * @param latitude
 * @param longitude
 * @throws Exception
 */
private void testLocation(double latitude, double longitude)
		throws Exception {

	if (PRINT) {
		System.out.println("Latitude: " + latitude);
		System.out.println("Longitude: " + longitude);
	}

	for (CoverageDataAlgorithm algorithm : CoverageDataAlgorithm.values()) {
		Double value = CoverageDataTestUtils.getValue(geoPackage,
				algorithm, latitude, longitude,
				ProjectionConstants.EPSG_WORLD_GEODETIC_SYSTEM);
		if (PRINT) {
			System.out.println(algorithm.name() + ": " + value);
		}
	}
}
 
Example #8
Source File: GeoPackageTestUtils.java    From geopackage-java with MIT License 6 votes vote down vote up
/**
 * 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 #9
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 #10
Source File: GeoPackageRepository.java    From geopackage-mapcache-android with MIT License 6 votes vote down vote up
/**
 * Create feature table in the given geopackage
 */
public boolean createFeatureTable(String gpName, BoundingBox boundingBox, GeometryType geometryType, String tableName){
    GeometryColumns geometryColumns = new GeometryColumns();
    geometryColumns.setId(new TableColumnKey(tableName,
            "geom"));
    geometryColumns.setGeometryType(geometryType);
    geometryColumns.setZ((byte) 0);
    geometryColumns.setM((byte) 0);

    GeoPackage geoPackage = manager.open(gpName);
    try {
        GeometryColumns created = geoPackage.createFeatureTableWithMetadata(
                geometryColumns, boundingBox, ProjectionConstants.EPSG_WORLD_GEODETIC_SYSTEM);
        if(created != null) {
            return true;
        }
    } finally {
        geoPackage.close();
    }
    return false;
}
 
Example #11
Source File: TileBoundingBoxUtils.java    From geopackage-core-java with MIT License 6 votes vote down vote up
/**
 * Get the WGS84 tile bounding box from the tile grid and zoom level
 *
 * @param tileGrid
 *            tile grid
 * @param zoom
 *            zoom
 *
 * @return wgs84 bounding box
 * @since 1.2.0
 */
public static BoundingBox getWGS84BoundingBox(TileGrid tileGrid, int zoom) {

	int tilesPerLat = tilesPerWGS84LatSide(zoom);
	int tilesPerLon = tilesPerWGS84LonSide(zoom);

	double tileSizeLat = tileSizeLatPerWGS84Side(tilesPerLat);
	double tileSizeLon = tileSizeLonPerWGS84Side(tilesPerLon);

	double minLon = (-1 * ProjectionConstants.WGS84_HALF_WORLD_LON_WIDTH)
			+ (tileGrid.getMinX() * tileSizeLon);
	double maxLon = (-1 * ProjectionConstants.WGS84_HALF_WORLD_LON_WIDTH)
			+ ((tileGrid.getMaxX() + 1) * tileSizeLon);
	double minLat = ProjectionConstants.WGS84_HALF_WORLD_LAT_HEIGHT
			- ((tileGrid.getMaxY() + 1) * tileSizeLat);
	double maxLat = ProjectionConstants.WGS84_HALF_WORLD_LAT_HEIGHT
			- (tileGrid.getMinY() * tileSizeLat);

	BoundingBox box = new BoundingBox(minLon, minLat, maxLon, maxLat);

	return box;
}
 
Example #12
Source File: FeatureTileUtils.java    From geopackage-java with MIT License 6 votes vote down vote up
/**
 * Create feature dao
 *
 * @return feature dao
 */
public static FeatureDao createFeatureDao(GeoPackage geoPackage) {

	BoundingBox boundingBox = new BoundingBox();

	GeometryColumns geometryColumns = new GeometryColumns();
	geometryColumns.setId(new TableColumnKey(TABLE_NAME, "geom"));
	geometryColumns.setGeometryType(GeometryType.GEOMETRY);
	geometryColumns.setZ((byte) 0);
	geometryColumns.setM((byte) 0);

	geoPackage.createFeatureTableWithMetadata(geometryColumns, boundingBox,
			ProjectionConstants.EPSG_WORLD_GEODETIC_SYSTEM);

	FeatureDao featureDao = geoPackage.getFeatureDao(geometryColumns);

	return featureDao;
}
 
Example #13
Source File: CoverageDataTiffImportTest.java    From geopackage-android with MIT License 6 votes vote down vote up
/**
 * Test a single location
 *
 * @param latitude
 * @param longitude
 * @throws Exception
 */
private void testLocation(double latitude, double longitude)
        throws Exception {

    if (PRINT) {
        System.out.println("Latitude: " + latitude);
        System.out.println("Longitude: " + longitude);
    }

    for (CoverageDataAlgorithm algorithm : CoverageDataAlgorithm
            .values()) {
        Double value = CoverageDataTestUtils.getValue(
                geoPackage, algorithm, latitude, longitude,
                ProjectionConstants.EPSG_WORLD_GEODETIC_SYSTEM);
        if (PRINT) {
            System.out.println(algorithm.name() + ": " + value);
        }
    }
}
 
Example #14
Source File: GeoPackageTestUtils.java    From geopackage-java with MIT License 6 votes vote down vote up
/**
 * 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 #15
Source File: TileBoundingBoxUtils.java    From geopackage-core-java with MIT License 6 votes vote down vote up
/**
 * Get the Web Mercator tile bounding box from the XYZ tile grid and zoom
 * level
 *
 * @param tileGrid
 *            tile grid
 * @param zoom
 *            zoom level
 * @return bounding box
 */
public static BoundingBox getWebMercatorBoundingBox(TileGrid tileGrid,
		int zoom) {

	double tileSize = tileSizeWithZoom(zoom);

	double minLon = (-1 * ProjectionConstants.WEB_MERCATOR_HALF_WORLD_WIDTH)
			+ (tileGrid.getMinX() * tileSize);
	double maxLon = (-1 * ProjectionConstants.WEB_MERCATOR_HALF_WORLD_WIDTH)
			+ ((tileGrid.getMaxX() + 1) * tileSize);
	double minLat = ProjectionConstants.WEB_MERCATOR_HALF_WORLD_WIDTH
			- ((tileGrid.getMaxY() + 1) * tileSize);
	double maxLat = ProjectionConstants.WEB_MERCATOR_HALF_WORLD_WIDTH
			- (tileGrid.getMinY() * tileSize);

	BoundingBox box = new BoundingBox(minLon, minLat, maxLon, maxLat);

	return box;
}
 
Example #16
Source File: TileBoundingBoxUtils.java    From geopackage-core-java with MIT License 6 votes vote down vote up
/**
 * Get the Web Mercator tile bounding box from the XYZ tile coordinates and
 * zoom level
 *
 * @param x
 *            x coordinate
 * @param y
 *            y coordinate
 * @param zoom
 *            zoom level
 * @return bounding box
 */
public static BoundingBox getWebMercatorBoundingBox(long x, long y,
		int zoom) {

	double tileSize = tileSizeWithZoom(zoom);

	double minLon = (-1 * ProjectionConstants.WEB_MERCATOR_HALF_WORLD_WIDTH)
			+ (x * tileSize);
	double maxLon = (-1 * ProjectionConstants.WEB_MERCATOR_HALF_WORLD_WIDTH)
			+ ((x + 1) * tileSize);
	double minLat = ProjectionConstants.WEB_MERCATOR_HALF_WORLD_WIDTH
			- ((y + 1) * tileSize);
	double maxLat = ProjectionConstants.WEB_MERCATOR_HALF_WORLD_WIDTH
			- (y * tileSize);

	BoundingBox box = new BoundingBox(minLon, minLat, maxLon, maxLat);

	return box;
}
 
Example #17
Source File: UserCoreDao.java    From geopackage-core-java with MIT License 6 votes vote down vote up
/**
 * Get the approximate zoom level of where the bounding box of the user data
 * fits into the world
 * 
 * @return zoom level
 * @since 1.1.0
 */
public int getZoomLevel() {
	Projection projection = getProjection();
	if (projection == null) {
		throw new GeoPackageException(
				"No projection was set which is required to determine the zoom level");
	}
	int zoomLevel = 0;
	BoundingBox boundingBox = getBoundingBox();
	if (boundingBox != null) {
		if (projection.isUnit(Units.DEGREES)) {
			boundingBox = TileBoundingBoxUtils
					.boundDegreesBoundingBoxWithWebMercatorLimits(
							boundingBox);
		}
		ProjectionTransform webMercatorTransform = projection
				.getTransformation(ProjectionConstants.EPSG_WEB_MERCATOR);
		BoundingBox webMercatorBoundingBox = boundingBox
				.transform(webMercatorTransform);
		zoomLevel = TileBoundingBoxUtils
				.getZoomLevel(webMercatorBoundingBox);
	}
	return zoomLevel;
}
 
Example #18
Source File: GeoPackageTestUtils.java    From geopackage-android with MIT License 6 votes vote down vote up
/**
 * 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 #19
Source File: GeoPackageTestUtils.java    From geopackage-android with MIT License 6 votes vote down vote up
/**
 * 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 #20
Source File: FeatureTileUtils.java    From geopackage-android with MIT License 6 votes vote down vote up
public static long insertPolygon(FeatureDao featureDao, double[][]... points) {
    FeatureRow featureRow = featureDao.newRow();
    GeoPackageGeometryData geomData = new GeoPackageGeometryData(
            ProjectionConstants.EPSG_WORLD_GEODETIC_SYSTEM);
    Polygon polygon = new Polygon(false, false);
    for (double[][] ring : points) {
        LineString lineString = getLineString(ring);
        polygon.addRing(lineString);
    }
    geomData.setGeometry(polygon);
    featureRow.setGeometry(geomData);
    return featureDao.insert(featureRow);
}
 
Example #21
Source File: GeoPackageTestUtils.java    From geopackage-android with MIT License 6 votes vote down vote up
/**
 * 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 #22
Source File: TileBoundingBoxUtils.java    From geopackage-core-java with MIT License 6 votes vote down vote up
/**
 * Bound the upper and lower bounds of the degrees bounding box with web
 * mercator limits
 * 
 * @param boundingBox
 *            degrees bounding box
 * @return bounding box
 * @since 1.3.1
 */
public static BoundingBox boundDegreesBoundingBoxWithWebMercatorLimits(
		BoundingBox boundingBox) {
	BoundingBox bounded = new BoundingBox(boundingBox);
	if (bounded
			.getMinLatitude() < ProjectionConstants.WEB_MERCATOR_MIN_LAT_RANGE) {
		bounded.setMinLatitude(
				ProjectionConstants.WEB_MERCATOR_MIN_LAT_RANGE);
	}
	if (bounded
			.getMaxLatitude() < ProjectionConstants.WEB_MERCATOR_MIN_LAT_RANGE) {
		bounded.setMaxLatitude(
				ProjectionConstants.WEB_MERCATOR_MIN_LAT_RANGE);
	}
	if (bounded
			.getMaxLatitude() > ProjectionConstants.WEB_MERCATOR_MAX_LAT_RANGE) {
		bounded.setMaxLatitude(
				ProjectionConstants.WEB_MERCATOR_MAX_LAT_RANGE);
	}
	if (bounded
			.getMinLatitude() > ProjectionConstants.WEB_MERCATOR_MAX_LAT_RANGE) {
		bounded.setMinLatitude(
				ProjectionConstants.WEB_MERCATOR_MAX_LAT_RANGE);
	}
	return bounded;
}
 
Example #23
Source File: TileBoundingBoxUtils.java    From geopackage-core-java with MIT License 5 votes vote down vote up
/**
 * Bound the web mercator bounding box within the limits
 * 
 * @param boundingBox
 *            web mercator bounding box
 * @return bounding box
 * @since 3.5.0
 */
public static BoundingBox boundWebMercatorBoundingBox(
		BoundingBox boundingBox) {
	BoundingBox bounded = new BoundingBox(boundingBox);
	bounded.setMinLongitude(Math.max(bounded.getMinLongitude(),
			-1 * ProjectionConstants.WEB_MERCATOR_HALF_WORLD_WIDTH));
	bounded.setMaxLongitude(Math.min(bounded.getMaxLongitude(),
			ProjectionConstants.WEB_MERCATOR_HALF_WORLD_WIDTH));
	bounded.setMinLatitude(Math.max(bounded.getMinLatitude(),
			-1 * ProjectionConstants.WEB_MERCATOR_HALF_WORLD_WIDTH));
	bounded.setMaxLatitude(Math.min(bounded.getMaxLatitude(),
			ProjectionConstants.WEB_MERCATOR_HALF_WORLD_WIDTH));
	return bounded;
}
 
Example #24
Source File: TileBoundingBoxUtils.java    From geopackage-core-java with MIT License 5 votes vote down vote up
/**
 * Get the tile grid that includes the entire tile bounding box
 *
 * @param boundingBox
 *            wgs84 bounding box
 * @param zoom
 *            zoom level
 *
 * @return tile grid
 * @since 1.2.0
 */
public static TileGrid getTileGridWGS84(BoundingBox boundingBox, int zoom) {

	int tilesPerLat = tilesPerWGS84LatSide(zoom);
	int tilesPerLon = tilesPerWGS84LonSide(zoom);

	double tileSizeLat = tileSizeLatPerWGS84Side(tilesPerLat);
	double tileSizeLon = tileSizeLonPerWGS84Side(tilesPerLon);

	int minX = (int) ((boundingBox.getMinLongitude()
			+ ProjectionConstants.WGS84_HALF_WORLD_LON_WIDTH)
			/ tileSizeLon);
	double tempMaxX = (boundingBox.getMaxLongitude()
			+ ProjectionConstants.WGS84_HALF_WORLD_LON_WIDTH) / tileSizeLon;
	int maxX = (int) tempMaxX;
	if (tempMaxX % 1 == 0) {
		maxX--;
	}
	maxX = Math.min(maxX, tilesPerLon - 1);

	int minY = (int) (((boundingBox.getMaxLatitude()
			- ProjectionConstants.WGS84_HALF_WORLD_LAT_HEIGHT) * -1)
			/ tileSizeLat);
	double tempMaxY = ((boundingBox.getMinLatitude()
			- ProjectionConstants.WGS84_HALF_WORLD_LAT_HEIGHT) * -1)
			/ tileSizeLat;
	int maxY = (int) tempMaxY;
	if (tempMaxY % 1 == 0) {
		maxY--;
	}
	maxY = Math.min(maxY, tilesPerLat - 1);

	TileGrid grid = new TileGrid(minX, minY, maxX, maxY);

	return grid;
}
 
Example #25
Source File: BoundingBox.java    From geopackage-core-java with MIT License 5 votes vote down vote up
/**
 * Constructor
 */
public BoundingBox() {
	this(-ProjectionConstants.WGS84_HALF_WORLD_LON_WIDTH,
			-ProjectionConstants.WGS84_HALF_WORLD_LAT_HEIGHT,
			ProjectionConstants.WGS84_HALF_WORLD_LON_WIDTH,
			ProjectionConstants.WGS84_HALF_WORLD_LAT_HEIGHT);
}
 
Example #26
Source File: TileGenerator.java    From geopackage-java with MIT License 5 votes vote down vote up
/**
 * Get the tile count of tiles to be generated
 *
 * @return tile count
 */
public int getTileCount() {
	if (tileCount == null) {
		int count = 0;

		boolean degrees = projection.isUnit(Units.DEGREES);
		ProjectionTransform transformToWebMercator = null;
		if (!degrees) {
			transformToWebMercator = projection.getTransformation(
					ProjectionConstants.EPSG_WEB_MERCATOR);
		}

		for (int zoom = minZoom; zoom <= maxZoom; zoom++) {

			BoundingBox expandedBoundingBox = getBoundingBox(zoom);

			// Get the tile grid that includes the entire bounding box
			TileGrid tileGrid = null;
			if (degrees) {
				tileGrid = TileBoundingBoxUtils
						.getTileGridWGS84(expandedBoundingBox, zoom);
			} else {
				tileGrid = TileBoundingBoxUtils
						.getTileGrid(expandedBoundingBox
								.transform(transformToWebMercator), zoom);
			}

			count += tileGrid.count();
			tileGrids.put(zoom, tileGrid);
			tileBounds.put(zoom, expandedBoundingBox);
		}

		tileCount = count;
	}
	return tileCount;
}
 
Example #27
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 #28
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 #29
Source File: GeoPackageExample.java    From geopackage-java with MIT License 5 votes vote down vote up
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 #30
Source File: FeatureIndexManagerUtils.java    From geopackage-java with MIT License 5 votes vote down vote up
/**
 * 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);
}