use of org.geotoolkit.storage.multires.TiledResource in project geotoolkit by Geomatys.
the class WMTSClientDemo method createContext.
public static MapLayers createContext() throws Exception {
final MapLayers context = MapBuilder.createContext(CommonCRS.WGS84.normalizedGeographic());
final WebMapTileClient server = new WebMapTileClient(new URL("http://localhost:8080/constellation/WS/wmts/test"), WMTSVersion.v100);
for (final Resource ref : DataStores.flatten(server, false)) {
final GenericName n = ref.getIdentifier().get();
System.out.println(n);
final MapLayer layer = MapBuilder.createCoverageLayer(ref, new DefaultStyleFactory().style(StyleConstants.DEFAULT_RASTER_SYMBOLIZER));
TiledResource model = (TiledResource) ref;
System.out.println(model);
layer.setTitle(n.tip().toString());
context.getComponents().add(layer);
}
return context;
}
use of org.geotoolkit.storage.multires.TiledResource in project geotoolkit by Geomatys.
the class TileDebugSymbolizerRenderer method presentations.
@Override
public Stream<Presentation> presentations(MapLayer layer, Resource resource) {
if (!(resource instanceof TiledResource)) {
return Stream.empty();
}
final TiledResource mrm = (TiledResource) resource;
final List<Presentation> presentations = new ArrayList<>();
final Graphics2D graphics = renderingContext.getGraphics();
final Color textColor = Color.YELLOW;
final Color bgColor = new Color(0, 0, 0, 150);
final Stroke stroke = new BasicStroke(1);
final Font font = new Font("Dialog", Font.BOLD, 12);
final FontMetrics fontMetrics = graphics.getFontMetrics(font);
try {
final Map.Entry<Envelope, List<TileMatrix>> intersect = TileMatrixSetCoverageReader.intersect(mrm, getRenderingContext().getGridGeometry());
final List<TileMatrix> mosaics = intersect.getValue();
final Envelope wantedEnv = intersect.getKey();
for (TileMatrix m : mosaics) {
final CoordinateReferenceSystem crs = m.getUpperLeftCorner().getCoordinateReferenceSystem();
final CoordinateReferenceSystem crs2d = CRS.getHorizontalComponent(crs);
final Rectangle rectangle;
try {
rectangle = TileMatrices.getTilesInEnvelope(m, wantedEnv);
} catch (NoSuchDataException ex) {
continue;
}
for (int x = 0; x < rectangle.width; x++) {
for (int y = 0; y < rectangle.height; y++) {
final GridGeometry gridgeom = TileMatrices.getTileGridGeometry2D(m, new Point(rectangle.x + x, rectangle.y + y), crs2d);
Geometry geom = GeometricUtilities.toJTSGeometry(gridgeom.getEnvelope(), GeometricUtilities.WrapResolution.NONE);
geom.setUserData(crs2d);
geom = org.apache.sis.internal.feature.jts.JTS.transform(geom, renderingContext.getDisplayCRS());
Shape shp = new JTSGeometryJ2D(geom);
final ShapePresentation border = new ShapePresentation(layer, resource, null);
border.stroke = stroke;
border.strokePaint = Color.BLACK;
border.shape = shp;
presentations.add(border);
final Rectangle bounds = shp.getBounds();
final double centerX = bounds.getCenterX();
final double centerY = bounds.getCenterY();
String mid = m.getIdentifier();
if (mid.length() > 10) {
mid = mid.substring(0, 9) + "..";
}
final String mosaicId = "Z: " + mid;
final String mosaicScale = "S: " + new DecimalFormat("#0.00000").format(m.getScale());
final String strX = "X: " + (rectangle.x + x);
final String strY = "Y: " + (rectangle.y + y);
String longest = mosaicId;
if (mosaicScale.length() > longest.length())
longest = mosaicScale;
if (strX.length() > longest.length())
longest = strX;
if (strY.length() > longest.length())
longest = strY;
Font ft = font;
FontMetrics fm = fontMetrics;
while (fm.stringWidth(longest) > bounds.width && ft.getSize() > 8) {
ft = new Font(ft.getFamily(), ft.getStyle(), ft.getSize() - 1);
fm = graphics.getFontMetrics(ft);
}
graphics.setFont(ft);
final double fntHeight = fm.getHeight();
Rectangle2D txtbbox = fm.getStringBounds(mosaicId, g2d);
{
final AttributedString as = new AttributedString(mosaicId);
as.addAttribute(TextAttribute.FONT, ft);
as.addAttribute(TextAttribute.BACKGROUND, bgColor);
final TextPresentation2 tp = new TextPresentation2(layer, resource, null);
tp.forGrid(renderingContext);
tp.text = as;
tp.paint = textColor;
tp.x = (float) (centerX - txtbbox.getWidth() / 2.0);
tp.y = (float) (centerY - fntHeight);
presentations.add(tp);
}
{
final AttributedString as = new AttributedString(mosaicScale);
as.addAttribute(TextAttribute.FONT, ft);
as.addAttribute(TextAttribute.BACKGROUND, bgColor);
txtbbox = fm.getStringBounds(mosaicScale, g2d);
final TextPresentation2 tp = new TextPresentation2(layer, resource, null);
tp.forGrid(renderingContext);
tp.text = as;
tp.paint = textColor;
tp.x = (float) (centerX - txtbbox.getWidth() / 2.0);
tp.y = (float) (centerY);
presentations.add(tp);
}
{
final AttributedString as = new AttributedString(strX);
as.addAttribute(TextAttribute.FONT, ft);
as.addAttribute(TextAttribute.BACKGROUND, bgColor);
txtbbox = fm.getStringBounds(strX, g2d);
final TextPresentation2 tp = new TextPresentation2(layer, resource, null);
tp.forGrid(renderingContext);
tp.text = as;
tp.paint = textColor;
tp.x = (float) (centerX - txtbbox.getWidth() / 2.0);
tp.y = (float) (centerY + fntHeight);
presentations.add(tp);
}
{
final AttributedString as = new AttributedString(strY);
as.addAttribute(TextAttribute.FONT, ft);
as.addAttribute(TextAttribute.BACKGROUND, bgColor);
txtbbox = fm.getStringBounds(strY, g2d);
final TextPresentation2 tp = new TextPresentation2(layer, resource, null);
tp.forGrid(renderingContext);
tp.text = as;
tp.paint = textColor;
tp.x = (float) (centerX - txtbbox.getWidth() / 2.0);
tp.y = (float) (centerY + 2 * fntHeight);
presentations.add(tp);
}
}
}
}
} catch (DataStoreException | TransformException | FactoryException ex) {
ExceptionPresentation ep = new ExceptionPresentation(ex);
ep.setLayer(layer);
ep.setResource(resource);
presentations.add(ep);
}
return presentations.stream();
}
use of org.geotoolkit.storage.multires.TiledResource in project geotoolkit by Geomatys.
the class DataStores method toRawModel.
private static String toRawModel(Resource rs) {
final Map<String, Object> mp = new LinkedHashMap<>();
try {
final GenericName identifier = rs.getIdentifier().orElse(null);
if (identifier != null) {
mp.put("identifier", identifier.toString());
}
} catch (DataStoreException ex) {
mp.put("identifier", "ERROR (" + ex.getMessage() + ")");
}
if (rs instanceof FeatureSet) {
final FeatureSet cdt = (FeatureSet) rs;
final Map<String, Object> map = new LinkedHashMap<>();
mp.put("FeatureSet", map);
try {
final FeatureType type = cdt.getType();
map.put("type name", type.getName().toString());
if (cdt instanceof WritableFeatureSet) {
map.put("writable", Boolean.TRUE);
} else {
map.put("writable", Boolean.FALSE);
}
map.put("type", type.toString());
} catch (DataStoreException ex) {
map.put("type", "ERROR (" + ex.getMessage() + ")");
}
}
if (rs instanceof GridCoverageResource) {
final GridCoverageResource cdt = (GridCoverageResource) rs;
final Map<String, Object> map = new LinkedHashMap<>();
mp.put("GridCoverageResource", map);
try {
final GridGeometry gridGeometry = cdt.getGridGeometry();
map.put("grid geometry", gridGeometry);
} catch (DataStoreException ex) {
map.put("grid geometry", "ERROR (" + ex.getMessage() + ")");
}
try {
final List<SampleDimension> sampleDimensions = cdt.getSampleDimensions();
final List<Map> sds = new ArrayList<>();
for (SampleDimension sd : sampleDimensions) {
final Map<String, Object> tf = new LinkedHashMap<>();
tf.put("name", String.valueOf(sd.getName()));
tf.put("unit", String.valueOf(sd.getUnits().orElse(Units.UNITY).getSymbol()));
tf.put("background", String.valueOf(sd.getBackground().orElse(null)));
final List<Map> cats = new ArrayList<>();
for (Category cat : sd.getCategories()) {
final Map<String, Object> cf = new LinkedHashMap<>();
cf.put("name", cat.getName().toString());
cf.put("quantitative", cat.isQuantitative());
cats.add(cf);
}
tf.put("categories", cats);
sds.add(tf);
}
map.put("sample dimensions", StringUtilities.toStringTree("", sampleDimensions));
} catch (DataStoreException ex) {
map.put("sample dimensions", "ERROR (" + ex.getMessage() + ")");
}
}
if (rs instanceof TiledResource) {
final TiledResource cdt = (TiledResource) rs;
final TileFormat tileFormat = cdt.getTileFormat();
final Map<String, Object> map = new LinkedHashMap<>();
mp.put("MultiResolutionResource", map);
if (tileFormat != null) {
final Map<String, Object> tf = new LinkedHashMap<>();
map.put("tile format", tf);
tf.put("mime type", tileFormat.getMimeType());
tf.put("provider id", tileFormat.getProviderId());
tf.put("compression", tileFormat.getCompression().name());
}
try {
final Collection<? extends TileMatrixSet> models = cdt.getTileMatrixSets();
final List<String> mms = new ArrayList<>();
for (TileMatrixSet mrm : models) {
mms.add(mrm.toString());
}
map.put("models", StringUtilities.toStringTree("", mms));
} catch (DataStoreException ex) {
map.put("models", "ERROR (" + ex.getMessage() + ")");
}
}
if (rs instanceof Aggregate) {
final Aggregate cdt = (Aggregate) rs;
final Map<String, Object> map = new LinkedHashMap<>();
mp.put("Aggregate", map);
if (cdt instanceof WritableAggregate) {
map.put("writable", Boolean.TRUE);
} else {
map.put("writable", Boolean.FALSE);
}
try {
final Collection<? extends Resource> components = cdt.components();
map.put("nb components", components.size());
int i = 0;
for (Resource r : components) {
map.put("component[" + i++ + "]", toRawModel(r));
}
} catch (DataStoreException ex) {
map.put("models", "ERROR (" + ex.getMessage() + ")");
}
}
if (rs instanceof ProgressiveResource) {
final ProgressiveResource pr = (ProgressiveResource) rs;
mp.put("ProgressiveResource", pr.toString());
}
return StringUtilities.toStringTree(Classes.getShortClassName(rs), toList(mp));
}
use of org.geotoolkit.storage.multires.TiledResource in project geotoolkit by Geomatys.
the class InMemoryAggregate method add.
@Override
public synchronized Resource add(Resource resource) throws DataStoreException {
Resource newr;
if (resource instanceof FeatureSet) {
final FeatureSet fs = (FeatureSet) resource;
final InMemoryFeatureSet newres = new InMemoryFeatureSet(fs.getType());
try (Stream<Feature> stream = fs.features(false)) {
newres.add(stream.iterator());
}
newr = newres;
} else if (resource instanceof DefiningTiledGridCoverageResource) {
final DefiningTiledGridCoverageResource cr = (DefiningTiledGridCoverageResource) resource;
final GenericName name = cr.getIdentifier().orElse(null);
newr = new InMemoryTiledGridCoverageResource(name);
} else if (resource instanceof GridCoverageResource && resource instanceof TiledResource) {
final GridCoverageResource cr = (GridCoverageResource) resource;
final GenericName name = cr.getIdentifier().orElse(null);
newr = new InMemoryTiledGridCoverageResource(name);
} else if (resource instanceof GridCoverageResource) {
final GridCoverageResource cr = (GridCoverageResource) resource;
final GenericName name = cr.getIdentifier().orElse(null);
final InMemoryGridCoverageResource newres = new InMemoryGridCoverageResource(name);
newres.write(cr.read(null));
newr = newres;
} else if (resource instanceof DefiningGridCoverageResource) {
final DefiningGridCoverageResource cr = (DefiningGridCoverageResource) resource;
final GenericName name = cr.getIdentifier().orElse(null);
newr = new InMemoryGridCoverageResource(name);
} else if (resource instanceof Aggregate) {
final Aggregate agg = (Aggregate) resource;
final InMemoryAggregate newres = new InMemoryAggregate(agg.getIdentifier().orElse(null));
for (Resource r : agg.components()) {
newres.add(r);
}
newr = newres;
} else {
throw new DataStoreException("Unsupported resource type " + resource);
}
resources.add(newr);
listeners.fire(new AggregationEvent(this, AggregationEvent.TYPE_ADD, newr), AggregationEvent.class);
return newr;
}
use of org.geotoolkit.storage.multires.TiledResource in project geotoolkit by Geomatys.
the class MathCalcProcess method execute.
@Override
protected void execute() throws ProcessException {
final GridCoverage[] inCoverages = inputParameters.getValue(MathCalcDescriptor.IN_COVERAGES);
final String inFormula = inputParameters.getValue(MathCalcDescriptor.IN_FORMULA);
final String[] inMapping = inputParameters.getValue(MathCalcDescriptor.IN_MAPPING);
final WritableGridCoverageResource outRef = inputParameters.getValue(MathCalcDescriptor.IN_RESULT_COVERAGE);
final GridGeometry gg;
try {
gg = outRef.getGridGeometry();
} catch (DataStoreException ex) {
throw new ProcessException(ex.getMessage(), this, ex);
}
// create expression
final FilterFactory2 ff = FilterUtilities.FF;
final Expression exp;
try {
exp = CQL.parseExpression(inFormula, ff);
} catch (CQLException ex) {
throw new ProcessException(ex.getMessage(), this, ex);
}
// prepare dynamic pick object
final MathCalcCoverageEvaluator evaluator;
try {
evaluator = new MathCalcCoverageEvaluator(inCoverages, inMapping, exp, gg.getCoordinateReferenceSystem());
} catch (FactoryException ex) {
throw new ProcessException(ex.getMessage(), this, ex);
}
final FillCoverage filler = new FillCoverage();
try {
if (outRef instanceof TiledResource) {
filler.fill((TiledResource) outRef, evaluator);
} else {
filler.fill(outRef, evaluator, null);
}
} catch (DataStoreException ex) {
throw new ProcessException(ex.getMessage(), this, ex);
} catch (TransformException ex) {
throw new ProcessException(ex.getMessage(), this, ex);
} catch (FactoryException ex) {
throw new ProcessException(ex.getMessage(), this, ex);
}
}
Aggregations