use of org.hortonmachine.gears.io.las.databases.LasSource 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 org.hortonmachine.gears.io.las.databases.LasSource in project hortonmachine by TheHortonMachine.
the class DatabaseLasDataManager method getOverallEnvelope.
@Override
public synchronized ReferencedEnvelope getOverallEnvelope() throws Exception {
if (referencedEnvelope2D == null) {
checkOpen();
List<LasSource> lasSources = LasSourcesTable.getLasSources(spatialDb);
ReferencedEnvelope total = new ReferencedEnvelope(crs);
for (LasSource lasSource : lasSources) {
Envelope envelopeInternal = lasSource.polygon.getEnvelopeInternal();
total.expandToInclude(envelopeInternal);
}
referencedEnvelope2D = total;
referencedEnvelope2DList.add(referencedEnvelope2D);
}
return referencedEnvelope2D;
}
use of org.hortonmachine.gears.io.las.databases.LasSource in project hortonmachine by TheHortonMachine.
the class DatabaseLasDataManager method getEnvelope3D.
@Override
public synchronized ReferencedEnvelope3D getEnvelope3D() throws Exception {
if (referencedEnvelope3D == null) {
checkOpen();
List<LasSource> lasSources = LasSourcesTable.getLasSources(spatialDb);
ReferencedEnvelope total = new ReferencedEnvelope(crs);
double minZ = Double.POSITIVE_INFINITY;
double maxZ = Double.NEGATIVE_INFINITY;
for (LasSource lasSource : lasSources) {
Envelope envelopeInternal = lasSource.polygon.getEnvelopeInternal();
total.expandToInclude(envelopeInternal);
minZ = Math.min(minZ, lasSource.minElev);
maxZ = Math.max(maxZ, lasSource.maxElev);
}
referencedEnvelope3D = new ReferencedEnvelope3D(total.getMinX(), total.getMaxX(), total.getMinY(), total.getMaxY(), minZ, maxZ, crs);
}
return referencedEnvelope3D;
}
use of org.hortonmachine.gears.io.las.databases.LasSource in project hortonmachine by TheHortonMachine.
the class DatabaseLasDataManager method getOverviewFeatures.
@Override
public synchronized SimpleFeatureCollection getOverviewFeatures() throws Exception {
if (overviewFeatures == null) {
SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
b.setName("overview");
b.setCRS(crs);
b.add("the_geom", Polygon.class);
b.add("name", String.class);
SimpleFeatureType type = b.buildFeatureType();
SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type);
overviewFeatures = new DefaultFeatureCollection();
List<LasSource> lasSources = LasSourcesTable.getLasSources(spatialDb);
for (int i = 0; i < lasSources.size(); i++) {
LasSource lasSource = lasSources.get(i);
String name = lasSource.name;
Object[] objs = new Object[] { lasSource.polygon, name };
builder.addAll(objs);
SimpleFeature feature = builder.buildFeature(null);
((DefaultFeatureCollection) overviewFeatures).add(feature);
}
}
return overviewFeatures;
}
Aggregations