use of gov.nasa.worldwind.layers.mercator.MercatorSector in project hortonmachine by TheHortonMachine.
the class MapsforgeNwwLayer method makeLevels.
private static LevelSet makeLevels(String layerName, OsmTilegenerator osmTilegenerator, Integer tileSize) throws MalformedURLException {
AVList params = new AVListImpl();
String cacheRelativePath = "mapsforge/" + layerName + "-tiles";
if (tileSize == null || tileSize < 256) {
tileSize = TILESIZE;
}
int finalTileSize = tileSize;
params.setValue(AVKey.URL, cacheRelativePath);
params.setValue(AVKey.TILE_WIDTH, finalTileSize);
params.setValue(AVKey.TILE_HEIGHT, finalTileSize);
params.setValue(AVKey.DATA_CACHE_NAME, cacheRelativePath);
params.setValue(AVKey.SERVICE, "*");
params.setValue(AVKey.DATASET_NAME, "*");
params.setValue(AVKey.FORMAT_SUFFIX, ".png");
params.setValue(AVKey.NUM_LEVELS, 22);
params.setValue(AVKey.NUM_EMPTY_LEVELS, 0);
params.setValue(AVKey.LEVEL_ZERO_TILE_DELTA, new LatLon(Angle.fromDegrees(22.5d), Angle.fromDegrees(45d)));
params.setValue(AVKey.SECTOR, new MercatorSector(-1.0, 1.0, Angle.NEG180, Angle.POS180));
File cacheRoot = CacheUtils.getCacheRoot();
final File cacheFolder = new File(cacheRoot, cacheRelativePath);
if (!cacheFolder.exists()) {
cacheFolder.mkdirs();
}
params.setValue(AVKey.TILE_URL_BUILDER, new TileUrlBuilder() {
public URL getURL(Tile tile, String altImageFormat) throws MalformedURLException {
int zoom = tile.getLevelNumber() + 3;
Sector sector = tile.getSector();
double north = sector.getMaxLatitude().degrees;
double south = sector.getMinLatitude().degrees;
double east = sector.getMaxLongitude().degrees;
double west = sector.getMinLongitude().degrees;
double centerX = west + (east - west) / 2.0;
double centerY = south + (north - south) / 2.0;
int[] tileNumber = NwwUtilities.getTileNumber(centerY, centerX, zoom);
int x = tileNumber[0];
int y = tileNumber[1];
File tileImageFolderFile = new File(cacheFolder, zoom + File.separator + x);
if (!tileImageFolderFile.exists()) {
tileImageFolderFile.mkdirs();
}
File imgFile = new File(tileImageFolderFile, y + ".png");
try {
if (!imgFile.exists()) {
BufferedImage bImg = osmTilegenerator.getImage(zoom, x, y);
// PrintUtilities.printRenderedImageData(bImg);
ImageIO.write(bImg, "png", imgFile);
}
return imgFile.toURI().toURL();
} catch (IOException e) {
return null;
}
}
});
return new LevelSet(params);
}
use of gov.nasa.worldwind.layers.mercator.MercatorSector in project hortonmachine by TheHortonMachine.
the class OSMMapnikLayer method makeLevels.
private static LevelSet makeLevels() {
AVList params = new AVListImpl();
params.setValue(AVKey.TILE_WIDTH, 256);
params.setValue(AVKey.TILE_HEIGHT, 256);
params.setValue(AVKey.DATA_CACHE_NAME, "Earth/OSM-Mercator/OpenStreetMap OpentopoMap");
params.setValue(AVKey.SERVICE, "https://tile.openstreetmap.org/");
params.setValue(AVKey.DATASET_NAME, "h");
params.setValue(AVKey.FORMAT_SUFFIX, ".png");
params.setValue(AVKey.NUM_LEVELS, 22);
params.setValue(AVKey.NUM_EMPTY_LEVELS, 0);
params.setValue(AVKey.LEVEL_ZERO_TILE_DELTA, new LatLon(Angle.fromDegrees(22.5d), Angle.fromDegrees(45d)));
params.setValue(AVKey.SECTOR, new MercatorSector(-1.0, 1.0, Angle.NEG180, Angle.POS180));
params.setValue(AVKey.TILE_URL_BUILDER, new URLBuilder());
return new LevelSet(params);
}
use of gov.nasa.worldwind.layers.mercator.MercatorSector in project hortonmachine by TheHortonMachine.
the class RasterizedSpatialiteLasLayer method makeLevels.
private static LevelSet makeLevels(String title, Integer tileSize, boolean transparentBackground, ASpatialDb db, boolean doIntensity) throws Exception {
String plus = doIntensity ? INTENSITY : ELEVATION;
String cacheRelativePath = "rasterized_spatialites/" + title + "_" + plus + "-tiles";
File cacheRoot = CacheUtils.getCacheRoot();
final File cacheFolder = new File(cacheRoot, cacheRelativePath);
if (!cacheFolder.exists()) {
cacheFolder.mkdirs();
}
CacheUtils.clearCacheBySourceName(cacheRelativePath);
AVList params = new AVListImpl();
if (tileSize == null || tileSize < 256) {
tileSize = TILESIZE;
}
int finalTileSize = tileSize;
GeometryColumn spatialiteGeometryColumns = db.getGeometryColumnsForTable(LasCellsTable.TABLENAME);
CoordinateReferenceSystem dataCrs = CRS.decode("EPSG:" + spatialiteGeometryColumns.srid);
CoordinateReferenceSystem nwwCRS = DefaultGeographicCRS.WGS84;
List<LasSource> lasSources = LasSourcesTable.getLasSources(db);
double min = Double.POSITIVE_INFINITY;
double max = Double.NEGATIVE_INFINITY;
List<Polygon> polList = new ArrayList<>();
ColorInterpolator colorInterp;
int lasLevels = 0;
if (!doIntensity) {
for (LasSource lasSource : lasSources) {
lasLevels = lasSource.levels;
polList.add(lasSource.polygon);
min = Math.min(min, lasSource.minElev);
max = Math.max(max, lasSource.maxElev);
}
colorInterp = new ColorInterpolator(EColorTables.elev.name(), min, max, null);
} else {
for (LasSource lasSource : lasSources) {
lasLevels = lasSource.levels;
polList.add(lasSource.polygon);
min = Math.min(min, lasSource.minIntens);
max = Math.max(max, lasSource.maxIntens);
}
colorInterp = new ColorInterpolator(EColorTables.rainbow.name(), 0, 255, null);
}
final int _lasLevels = lasLevels;
Geometry sourcesUnionData = CascadedPolygonUnion.union(polList);
PreparedGeometry preparedCoverage = PreparedGeometryFactory.prepare(sourcesUnionData);
MathTransform nww2DataTransform = CRS.findMathTransform(nwwCRS, dataCrs);
MathTransform data2NwwTransform = CRS.findMathTransform(dataCrs, nwwCRS);
// String urlString = folderFile.toURI().toURL().toExternalForm();
// params.setValue(AVKey.URL, urlString);
params.setValue(AVKey.TILE_WIDTH, finalTileSize);
params.setValue(AVKey.TILE_HEIGHT, finalTileSize);
params.setValue(AVKey.DATA_CACHE_NAME, cacheRelativePath);
params.setValue(AVKey.SERVICE, "*");
params.setValue(AVKey.DATASET_NAME, "*");
params.setValue(AVKey.FORMAT_SUFFIX, ".png");
params.setValue(AVKey.NUM_LEVELS, 22);
params.setValue(AVKey.NUM_EMPTY_LEVELS, 8);
params.setValue(AVKey.LEVEL_ZERO_TILE_DELTA, new LatLon(Angle.fromDegrees(22.5d), Angle.fromDegrees(45d)));
params.setValue(AVKey.SECTOR, new MercatorSector(-1.0, 1.0, Angle.NEG180, Angle.POS180));
params.setValue(AVKey.TILE_URL_BUILDER, new TileUrlBuilder() {
public URL getURL(Tile tile, String altImageFormat) throws MalformedURLException {
try {
int zoom = tile.getLevelNumber() + 3;
Sector sector = tile.getSector();
double north = sector.getMaxLatitude().degrees;
double south = sector.getMinLatitude().degrees;
double east = sector.getMaxLongitude().degrees;
double west = sector.getMinLongitude().degrees;
double centerX = west + (east - west) / 2.0;
double centerY = south + (north - south) / 2.0;
int[] tileNumber = NwwUtilities.getTileNumber(centerY, centerX, zoom);
int x = tileNumber[0];
int y = tileNumber[1];
Rectangle imageBounds = new Rectangle(0, 0, finalTileSize, finalTileSize);
ReferencedEnvelope tileEnvNww = new ReferencedEnvelope(west, east, south, north, DefaultGeographicCRS.WGS84);
AffineTransform worldToPixel = TransformationUtils.getWorldToPixel(tileEnvNww, imageBounds);
PointTransformation pointTransformation = new PointTransformation() {
@Override
public void transform(Coordinate src, Point2D dest) {
worldToPixel.transform(new Point2D.Double(src.x, src.y), dest);
}
};
Polygon polygonNww = GeometryUtilities.createPolygonFromEnvelope(tileEnvNww);
Geometry polygonData = JTS.transform(polygonNww, nww2DataTransform);
int imgType;
Color backgroundColor;
boolean intersects = preparedCoverage.intersects(polygonData);
if (transparentBackground || !intersects) {
imgType = BufferedImage.TYPE_INT_ARGB;
backgroundColor = new Color(Color.WHITE.getRed(), Color.WHITE.getGreen(), Color.WHITE.getBlue(), 0);
} else {
imgType = BufferedImage.TYPE_INT_RGB;
backgroundColor = Color.WHITE;
}
BufferedImage image = new BufferedImage(imageBounds.width, imageBounds.height, imgType);
Graphics2D gr = image.createGraphics();
gr.setPaint(backgroundColor);
gr.fill(imageBounds);
if (zoom < 12) {
Geometry sourcesUnionNww = JTS.transform(sourcesUnionData, data2NwwTransform);
drawSources(db, pointTransformation, sourcesUnionNww, gr, finalTileSize);
} else if (zoom < 14) {
drawLevels(db, colorInterp, pointTransformation, polygonData, gr, _lasLevels, data2NwwTransform, doIntensity, finalTileSize);
} else if (zoom < 15 && _lasLevels - 1 > 0) {
drawLevels(db, colorInterp, pointTransformation, polygonData, gr, _lasLevels - 1, data2NwwTransform, doIntensity, finalTileSize);
} else if (zoom < 17 && _lasLevels - 2 > 0) {
drawLevels(db, colorInterp, pointTransformation, polygonData, gr, _lasLevels - 2, data2NwwTransform, doIntensity, finalTileSize);
} else if (zoom > 18) {
drawPoints(db, colorInterp, pointTransformation, polygonData, gr, data2NwwTransform, doIntensity, finalTileSize);
} else {
drawCells(db, colorInterp, pointTransformation, polygonData, gr, data2NwwTransform, doIntensity, finalTileSize);
}
File tileImageFolderFile = new File(cacheFolder, zoom + File.separator + x);
if (!tileImageFolderFile.exists()) {
tileImageFolderFile.mkdirs();
}
File imgFile = new File(tileImageFolderFile, y + ".png");
if (!imgFile.exists()) {
ImageIO.write(image, "png", imgFile);
}
return imgFile.toURI().toURL();
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
});
return new LevelSet(params);
}
use of gov.nasa.worldwind.layers.mercator.MercatorSector in project hortonmachine by TheHortonMachine.
the class RasterizedFeatureCollectionLayer method makeLevels.
private static LevelSet makeLevels(String title, GTRenderer renderer, Integer tileSize, boolean transparentBackground) throws MalformedURLException {
AVList params = new AVListImpl();
if (tileSize == null || tileSize < 256) {
tileSize = TILESIZE;
}
int finalTileSize = tileSize;
String cacheRelativePath = "rasterized_featurecollections/" + title + "-tiles";
// String urlString = folderFile.toURI().toURL().toExternalForm();
// params.setValue(AVKey.URL, urlString);
params.setValue(AVKey.TILE_WIDTH, finalTileSize);
params.setValue(AVKey.TILE_HEIGHT, finalTileSize);
params.setValue(AVKey.DATA_CACHE_NAME, cacheRelativePath);
params.setValue(AVKey.SERVICE, "*");
params.setValue(AVKey.DATASET_NAME, "*");
params.setValue(AVKey.FORMAT_SUFFIX, ".png");
params.setValue(AVKey.NUM_LEVELS, 22);
params.setValue(AVKey.NUM_EMPTY_LEVELS, 0);
params.setValue(AVKey.LEVEL_ZERO_TILE_DELTA, new LatLon(Angle.fromDegrees(22.5d), Angle.fromDegrees(45d)));
params.setValue(AVKey.SECTOR, new MercatorSector(-1.0, 1.0, Angle.NEG180, Angle.POS180));
File cacheRoot = CacheUtils.getCacheRoot();
final File cacheFolder = new File(cacheRoot, cacheRelativePath);
if (!cacheFolder.exists()) {
cacheFolder.mkdirs();
}
params.setValue(AVKey.TILE_URL_BUILDER, new TileUrlBuilder() {
public URL getURL(Tile tile, String altImageFormat) throws MalformedURLException {
int zoom = tile.getLevelNumber() + 3;
Sector sector = tile.getSector();
double north = sector.getMaxLatitude().degrees;
double south = sector.getMinLatitude().degrees;
double east = sector.getMaxLongitude().degrees;
double west = sector.getMinLongitude().degrees;
double centerX = west + (east - west) / 2.0;
double centerY = south + (north - south) / 2.0;
int[] tileNumber = NwwUtilities.getTileNumber(centerY, centerX, zoom);
int x = tileNumber[0];
int y = tileNumber[1];
Rectangle imageBounds = new Rectangle(0, 0, finalTileSize, finalTileSize);
int imgType;
Color backgroundColor;
if (transparentBackground) {
imgType = BufferedImage.TYPE_INT_ARGB;
backgroundColor = new Color(Color.WHITE.getRed(), Color.WHITE.getGreen(), Color.WHITE.getBlue(), 0);
} else {
imgType = BufferedImage.TYPE_INT_RGB;
backgroundColor = Color.WHITE;
}
BufferedImage image = new BufferedImage(imageBounds.width, imageBounds.height, imgType);
Graphics2D gr = image.createGraphics();
gr.setPaint(backgroundColor);
gr.fill(imageBounds);
gr.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
try {
synchronized (renderer) {
renderer.paint(gr, imageBounds, new ReferencedEnvelope(west, east, south, north, DefaultGeographicCRS.WGS84));
File tileImageFolderFile = new File(cacheFolder, zoom + File.separator + x);
if (!tileImageFolderFile.exists()) {
tileImageFolderFile.mkdirs();
}
File imgFile = new File(tileImageFolderFile, y + ".png");
if (!imgFile.exists()) {
ImageIO.write(image, "png", imgFile);
}
return imgFile.toURI().toURL();
}
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
});
return new LevelSet(params);
}
use of gov.nasa.worldwind.layers.mercator.MercatorSector in project hortonmachine by TheHortonMachine.
the class RasterizedShapefilesFolderNwwLayer method makeLevels.
private static LevelSet makeLevels(String title, File folderFile, GTRenderer renderer, Integer tileSize, boolean transparentBackground) throws MalformedURLException {
AVList params = new AVListImpl();
if (tileSize == null || tileSize < 256) {
tileSize = TILESIZE;
}
int finalTileSize = tileSize;
String tileFolderName = title == null ? folderFile.getName() : title;
String cacheRelativePath = "shapefilefolders/" + tileFolderName + "-tiles";
// String urlString = folderFile.toURI().toURL().toExternalForm();
// params.setValue(AVKey.URL, urlString);
params.setValue(AVKey.TILE_WIDTH, finalTileSize);
params.setValue(AVKey.TILE_HEIGHT, finalTileSize);
params.setValue(AVKey.DATA_CACHE_NAME, cacheRelativePath);
params.setValue(AVKey.SERVICE, "*");
params.setValue(AVKey.DATASET_NAME, "*");
params.setValue(AVKey.FORMAT_SUFFIX, ".png");
params.setValue(AVKey.NUM_LEVELS, 22);
params.setValue(AVKey.NUM_EMPTY_LEVELS, 0);
params.setValue(AVKey.LEVEL_ZERO_TILE_DELTA, new LatLon(Angle.fromDegrees(22.5d), Angle.fromDegrees(45d)));
params.setValue(AVKey.SECTOR, new MercatorSector(-1.0, 1.0, Angle.NEG180, Angle.POS180));
File cacheRoot = CacheUtils.getCacheRoot();
final File cacheFolder = new File(cacheRoot, cacheRelativePath);
if (!cacheFolder.exists()) {
cacheFolder.mkdirs();
}
params.setValue(AVKey.TILE_URL_BUILDER, new TileUrlBuilder() {
public URL getURL(Tile tile, String altImageFormat) throws MalformedURLException {
int zoom = tile.getLevelNumber() + 3;
Sector sector = tile.getSector();
double north = sector.getMaxLatitude().degrees;
double south = sector.getMinLatitude().degrees;
double east = sector.getMaxLongitude().degrees;
double west = sector.getMinLongitude().degrees;
double centerX = west + (east - west) / 2.0;
double centerY = south + (north - south) / 2.0;
int[] tileNumber = NwwUtilities.getTileNumber(centerY, centerX, zoom);
int x = tileNumber[0];
int y = tileNumber[1];
Rectangle imageBounds = new Rectangle(0, 0, finalTileSize, finalTileSize);
int imgType;
Color backgroundColor;
if (transparentBackground) {
imgType = BufferedImage.TYPE_INT_ARGB;
backgroundColor = new Color(Color.WHITE.getRed(), Color.WHITE.getGreen(), Color.WHITE.getBlue(), 0);
} else {
imgType = BufferedImage.TYPE_INT_RGB;
backgroundColor = Color.WHITE;
}
BufferedImage image = new BufferedImage(imageBounds.width, imageBounds.height, imgType);
Graphics2D gr = image.createGraphics();
gr.setPaint(backgroundColor);
gr.fill(imageBounds);
gr.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
try {
synchronized (renderer) {
renderer.paint(gr, imageBounds, new ReferencedEnvelope(west, east, south, north, DefaultGeographicCRS.WGS84));
File tileImageFolderFile = new File(cacheFolder, zoom + File.separator + x);
if (!tileImageFolderFile.exists()) {
tileImageFolderFile.mkdirs();
}
File imgFile = new File(tileImageFolderFile, y + ".png");
if (!imgFile.exists()) {
ImageIO.write(image, "png", imgFile);
}
return imgFile.toURI().toURL();
}
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
});
return new LevelSet(params);
}
Aggregations