Search in sources :

Example 41 with BaseCloseable

use of com.revolsys.io.BaseCloseable in project com.revolsys.open by revolsys.

the class RecordStoreLayer method getRecords.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public <R extends LayerRecord> List<R> getRecords(BoundingBox boundingBox) {
    if (hasGeometryField()) {
        boundingBox = convertBoundingBox(boundingBox);
        if (Property.hasValue(boundingBox)) {
            try (final BaseCloseable booleanValueCloseable = eventsDisabled()) {
                final BoundingBox queryBoundingBox = convertBoundingBox(boundingBox);
                boolean covers;
                synchronized (getSync()) {
                    covers = this.loadedBoundingBox.covers(queryBoundingBox);
                }
                if (covers) {
                    return getRecordsIndex(queryBoundingBox);
                } else {
                    final List<R> records = (List) getRecordsPersisted(queryBoundingBox);
                    return records;
                }
            }
        }
    }
    return Collections.emptyList();
}
Also used : BaseCloseable(com.revolsys.io.BaseCloseable) BoundingBox(com.revolsys.geometry.model.BoundingBox) List(java.util.List) ArrayList(java.util.ArrayList)

Example 42 with BaseCloseable

use of com.revolsys.io.BaseCloseable in project com.revolsys.open by revolsys.

the class MarkerStyleRenderer method renderMarker.

/**
 * Point must be in the same geometry factory as the view.
 *
 * @param viewport
 * @param graphics
 * @param point
 * @param style
 */
public static void renderMarker(final Viewport2D viewport, final Graphics2D graphics, Point point, final MarkerStyle style, final double orientation) {
    point = getGeometry(viewport, point);
    if (Property.hasValue(point)) {
        final Paint paint = graphics.getPaint();
        try (BaseCloseable transformClosable = viewport.setUseModelCoordinates(graphics, false)) {
            final Marker marker = style.getMarker();
            final double x = point.getX();
            final double y = point.getY();
            marker.render(viewport, graphics, style, x, y, orientation);
        } catch (final Throwable e) {
            Logs.debug(MarkerStyleRenderer.class, "Unable to render marker: " + style, e);
        } finally {
            graphics.setPaint(paint);
        }
    }
}
Also used : BaseCloseable(com.revolsys.io.BaseCloseable) Paint(java.awt.Paint) Marker(com.revolsys.swing.map.layer.record.style.marker.Marker)

Example 43 with BaseCloseable

use of com.revolsys.io.BaseCloseable in project com.revolsys.open by revolsys.

the class SvgMarker method render.

@Override
public void render(final Viewport2D viewport, final Graphics2D graphics, final MarkerStyle style, final double modelX, final double modelY, double orientation) {
    final TranscoderInput transcoderInput = this.transcoderInput;
    if (transcoderInput != null) {
        try (BaseCloseable transformCloseable = new CloseableAffineTransform(graphics)) {
            Viewport2D.setUseModelCoordinates(viewport, graphics, false);
            final Quantity<Length> markerWidth = style.getMarkerWidth();
            final double mapWidth = Viewport2D.toDisplayValue(viewport, markerWidth);
            final Quantity<Length> markerHeight = style.getMarkerHeight();
            final double mapHeight = Viewport2D.toDisplayValue(viewport, markerHeight);
            final String orientationType = style.getMarkerOrientationType();
            if ("none".equals(orientationType)) {
                orientation = 0;
            }
            Viewport2D.translateModelToViewCoordinates(viewport, graphics, modelX, modelY);
            final double markerOrientation = style.getMarkerOrientation();
            orientation = orientation + markerOrientation;
            if (orientation != 0) {
                graphics.rotate(Math.toRadians(orientation));
            }
            final Quantity<Length> deltaX = style.getMarkerDx();
            final Quantity<Length> deltaY = style.getMarkerDy();
            double dx = Viewport2D.toDisplayValue(viewport, deltaX);
            double dy = Viewport2D.toDisplayValue(viewport, deltaY);
            final String verticalAlignment = style.getMarkerVerticalAlignment();
            if ("bottom".equals(verticalAlignment)) {
                dy -= mapHeight;
            } else if ("middle".equals(verticalAlignment)) {
                dy -= mapHeight / 2;
            }
            final String horizontalAlignment = style.getMarkerHorizontalAlignment();
            if ("right".equals(horizontalAlignment)) {
                dx -= mapWidth;
            } else if ("center".equals(horizontalAlignment)) {
                dx -= mapWidth / 2;
            }
            graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
            graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
            graphics.translate(dx, dy);
            // changeAttribute(root, "stroke", "#ffffff",
            // WebColors.toHex(style.getMarkerLineColor()));
            // changeAttribute(root, "color", "#ffffff",
            // WebColors.toHex(style.getMarkerLineColor()));
            // changeAttribute(root, "fill", "#ffffff",
            // WebColors.toHex(style.getMarkerLineColor()));
            // 
            // changeAttribute(root, "stroke", "#000000",
            // WebColors.toHex(style.getMarkerFill()));
            // changeAttribute(root, "color", "#000000",
            // WebColors.toHex(style.getMarkerFill()));
            // changeAttribute(root, "fill", "#000000",
            // WebColors.toHex(style.getMarkerFill()));
            // changeAttribute(root, "stroke", "#444444",
            // WebColors.toHex(style.getMarkerFill()));
            // changeAttribute(root, "color", "#444444",
            // WebColors.toHex(style.getMarkerFill()));
            // changeAttribute(root, "fill", "#444444",
            // WebColors.toHex(style.getMarkerFill()));
            // shape.render(graphics);
            final Graphics2DTranscoder transcoder = new Graphics2DTranscoder(graphics);
            synchronized (transcoderInput) {
                transcoder.transcode(transcoderInput, null);
            }
        } catch (final Throwable e) {
            Logs.error(this, "Unable to render", e);
        }
    }
}
Also used : BaseCloseable(com.revolsys.io.BaseCloseable) TranscoderInput(org.apache.batik.transcoder.TranscoderInput) Length(javax.measure.quantity.Length) CloseableAffineTransform(com.revolsys.awt.CloseableAffineTransform)

Example 44 with BaseCloseable

use of com.revolsys.io.BaseCloseable in project com.revolsys.open by revolsys.

the class GeometryRecordReader method closeDo.

@Override
protected void closeDo() {
    final Iterator<Geometry> geometryIterator = this.geometryIterator;
    this.geometryIterator = null;
    if (geometryIterator instanceof BaseCloseable) {
        final BaseCloseable closeable = (BaseCloseable) geometryIterator;
        closeable.close();
    }
    final GeometryReader geometryReader = this.geometryReader;
    this.geometryReader = null;
    if (geometryReader != null) {
        geometryReader.close();
    }
    super.closeDo();
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) BaseCloseable(com.revolsys.io.BaseCloseable) GeometryReader(com.revolsys.geometry.io.GeometryReader)

Example 45 with BaseCloseable

use of com.revolsys.io.BaseCloseable in project com.revolsys.open by revolsys.

the class RecordReader method readRecordsById.

default Map<Identifier, Record> readRecordsById() {
    try (BaseCloseable closeable = this) {
        final Map<Identifier, Record> recordsById = new TreeMap<>(Identifier.comparator());
        for (final Record record : this) {
            final Identifier identifier = record.getIdentifier();
            recordsById.put(identifier, record);
        }
        return recordsById;
    }
}
Also used : BaseCloseable(com.revolsys.io.BaseCloseable) Identifier(com.revolsys.identifier.Identifier) Record(com.revolsys.record.Record) ArrayRecord(com.revolsys.record.ArrayRecord) TreeMap(java.util.TreeMap)

Aggregations

BaseCloseable (com.revolsys.io.BaseCloseable)46 Point (com.revolsys.geometry.model.Point)9 BoundingBox (com.revolsys.geometry.model.BoundingBox)8 Geometry (com.revolsys.geometry.model.Geometry)7 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)6 Polygon (com.revolsys.geometry.model.Polygon)6 Record (com.revolsys.record.Record)5 LineString (com.revolsys.geometry.model.LineString)4 Identifier (com.revolsys.identifier.Identifier)4 RecordReader (com.revolsys.record.io.RecordReader)4 Graphics2D (java.awt.Graphics2D)4 ArrayList (java.util.ArrayList)4 Vertex (com.revolsys.geometry.model.vertex.Vertex)3 RecordDefinition (com.revolsys.record.schema.RecordDefinition)3 CloseableAffineTransform (com.revolsys.awt.CloseableAffineTransform)2 GeoreferencedImage (com.revolsys.raster.GeoreferencedImage)2 ArrayRecord (com.revolsys.record.ArrayRecord)2 RecordStore (com.revolsys.record.schema.RecordStore)2 Resource (com.revolsys.spring.resource.Resource)2 MapPanel (com.revolsys.swing.map.MapPanel)2