Search in sources :

Example 1 with GeoreferencedImageLayer

use of com.revolsys.swing.map.layer.raster.GeoreferencedImageLayer in project com.revolsys.open by revolsys.

the class EditGeoreferencedImageOverlay method setLayer.

public void setLayer(final GeoreferencedImageLayer layer) {
    final GeoreferencedImageLayer oldLayer = this.layer;
    if (oldLayer != layer) {
        clear();
        this.layer = layer;
        final Viewport2D viewport = getViewport();
        setGeometryFactory(viewport.getGeometryFactory());
        setEnabled(layer != null);
        if (layer != null) {
            this.image = layer.getImage();
            setImageBoundingBox(layer.getBoundingBox());
        }
        if (oldLayer != null) {
            oldLayer.setEditable(false);
        }
    }
    firePropertyChange("layer", oldLayer, layer);
}
Also used : Viewport2D(com.revolsys.swing.map.Viewport2D) GeoreferencedImageLayer(com.revolsys.swing.map.layer.raster.GeoreferencedImageLayer)

Example 2 with GeoreferencedImageLayer

use of com.revolsys.swing.map.layer.raster.GeoreferencedImageLayer in project com.revolsys.open by revolsys.

the class EditGeoreferencedImageOverlay method paintComponent.

@Override
protected void paintComponent(final Viewport2D viewport, final Graphics2D graphics) {
    super.paintComponent(viewport, graphics);
    final GeoreferencedImageLayer layer = this.layer;
    final GeoreferencedImage image = this.image;
    final BoundingBox moveImageBoundingBox = this.moveImageBoundingBox;
    if (layer != null && layer.isVisible() && layer.isExists() && image != null) {
        try (BaseCloseable transformCloseable = viewport.setUseModelCoordinates(graphics, true)) {
            final GeometryFactory viewportGeometryFactory = viewport.getGeometryFactory();
            final boolean showOriginalImage = layer.isShowOriginalImage();
            final BoundingBox imageBoundingBox = getImageBoundingBox();
            BoundingBox boundingBox = imageBoundingBox;
            BoundingBox outlineBoundingBox = boundingBox;
            if (moveImageBoundingBox != null) {
                if (showOriginalImage) {
                    boundingBox = moveImageBoundingBox;
                }
                outlineBoundingBox = moveImageBoundingBox;
            }
            final GeoreferencedImage cachedImage = getCachedImage(boundingBox);
            GeoreferencedImageLayerRenderer.renderAlpha(viewport, graphics, cachedImage, false, layer.getOpacity() / 255.0, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
            GeoreferencedImageLayerRenderer.renderDifferentCoordinateSystem(viewport, graphics, imageBoundingBox);
            if (outlineBoundingBox != null && !outlineBoundingBox.isEmpty()) {
                final Polygon imageBoundary = outlineBoundingBox.convert(getViewportGeometryFactory()).toPolygon(1);
                graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
                viewport.drawGeometryOutline(imageBoundary, STYLE_BOX_OUTLINE);
                MarkerStyleRenderer.renderMarkerVertices(viewport, graphics, imageBoundary, STYLE_BOX_CORNER);
                final List<MappedLocation> tiePoints = image.getTiePoints();
                final int tiePointCount = tiePoints.size();
                final GeometryFactory viewGeometryFactory = getGeometryFactory();
                if (tiePointCount > 0) {
                    for (final MappedLocation mappedLocation : tiePoints) {
                        LineString line = mappedLocation.getSourceToTargetLine(image, boundingBox, !showOriginalImage);
                        if (line != null) {
                            line = line.convertGeometry(viewportGeometryFactory);
                            try (BaseCloseable transformCloseable1 = viewport.setUseModelCoordinates(graphics, true)) {
                                TIE_POINT_RENDERER.paintSelected(viewport, graphics, viewportGeometryFactory, line);
                            }
                        }
                    }
                    for (final MappedLocation mappedLocation : tiePoints) {
                        LineString line = mappedLocation.getSourceToTargetLine(image, boundingBox, !showOriginalImage);
                        if (line != null) {
                            line = line.convertGeometry(viewportGeometryFactory);
                            TIE_POINT_VERTEX_RENDERER.paintSelected(viewport, graphics, viewportGeometryFactory, line);
                        }
                    }
                }
                if (!showOriginalImage) {
                    final double width = image.getImageWidth() - 1;
                    final double height = image.getImageHeight() - 1;
                    final double[] targetCoordinates = MappedLocation.toModelCoordinates(image, boundingBox, true, 0, height, width, height, width, 0, 0, 0, 0, height);
                    final LineString line = viewGeometryFactory.lineString(2, targetCoordinates);
                    GeometryStyleRenderer.renderLineString(viewport, graphics, line, STYLE_IMAGE_LINE);
                }
            }
            final MappedLocation moveTiePoint = getMoveTiePoint();
            if (moveTiePoint != null) {
                final LineString line = moveTiePoint.getSourceToTargetLine(image, boundingBox, !showOriginalImage);
                Vertex vertex;
                if (this.moveTiePointSource) {
                    vertex = line.getVertex(0);
                } else {
                    vertex = line.getToVertex(0);
                }
                TIE_POINT_CLOSE_VERTEX_RENDERER.paintSelected(viewport, graphics, viewportGeometryFactory, vertex);
            }
        }
    }
    drawXorGeometry(graphics);
}
Also used : Vertex(com.revolsys.geometry.model.vertex.Vertex) BaseCloseable(com.revolsys.io.BaseCloseable) GeometryFactory(com.revolsys.geometry.model.GeometryFactory) BufferedGeoreferencedImage(com.revolsys.raster.BufferedGeoreferencedImage) GeoreferencedImage(com.revolsys.raster.GeoreferencedImage) MappedLocation(com.revolsys.raster.MappedLocation) GeoreferencedImageLayer(com.revolsys.swing.map.layer.raster.GeoreferencedImageLayer) Point(com.revolsys.geometry.model.Point) LineString(com.revolsys.geometry.model.LineString) BoundingBox(com.revolsys.geometry.model.BoundingBox) Polygon(com.revolsys.geometry.model.Polygon)

Example 3 with GeoreferencedImageLayer

use of com.revolsys.swing.map.layer.raster.GeoreferencedImageLayer in project com.revolsys.open by revolsys.

the class LayerGroup method openFile.

public int openFile(int index, final URL url) {
    final String urlString = url.toString();
    final Map<String, Object> properties = new HashMap<>();
    properties.put("url", urlString);
    String name = UrlUtil.getFileBaseName(url);
    name = FileUtil.fromSafeName(name);
    properties.put("name", name);
    Layer layer;
    if (IoFactory.hasFactory(TriangulatedIrregularNetworkReadFactory.class, url)) {
        layer = new TriangulatedIrregularNetworkLayer(properties);
    } else if (IoFactory.hasFactory(GriddedElevationModelReadFactory.class, url)) {
        layer = new GriddedElevationModelLayer(properties);
    } else if (IoFactory.hasFactory(GeoreferencedImageReadFactory.class, url)) {
        layer = new GeoreferencedImageLayer(properties);
    } else if (IoFactory.hasFactory(PointCloudReadFactory.class, url)) {
        layer = new PointCloudLayer(properties);
    } else if (IoFactory.hasFactory(RecordReaderFactory.class, url)) {
        final FileRecordLayer recordLayer = new FileRecordLayer(properties);
        final GeometryStyleRenderer renderer = recordLayer.getRenderer();
        renderer.setStyle(GeometryStyle.newStyle());
        layer = recordLayer;
    } else {
        layer = null;
    }
    if (layer != null) {
        layer.setProperty("showTableView", isShowNewLayerTableView());
        if (index == -1) {
            addLayer(layer);
        } else {
            addLayer(index++, layer);
        }
    }
    return index;
}
Also used : HashMap(java.util.HashMap) FileRecordLayer(com.revolsys.swing.map.layer.record.FileRecordLayer) FileRecordLayer(com.revolsys.swing.map.layer.record.FileRecordLayer) TriangulatedIrregularNetworkLayer(com.revolsys.swing.map.layer.elevation.tin.TriangulatedIrregularNetworkLayer) PointCloudLayer(com.revolsys.swing.map.layer.pointcloud.PointCloudLayer) GriddedElevationModelLayer(com.revolsys.swing.map.layer.elevation.gridded.GriddedElevationModelLayer) GeoreferencedImageLayer(com.revolsys.swing.map.layer.raster.GeoreferencedImageLayer) GeoreferencedImageLayer(com.revolsys.swing.map.layer.raster.GeoreferencedImageLayer) PointCloudLayer(com.revolsys.swing.map.layer.pointcloud.PointCloudLayer) GeometryStyleRenderer(com.revolsys.swing.map.layer.record.renderer.GeometryStyleRenderer) TriangulatedIrregularNetworkLayer(com.revolsys.swing.map.layer.elevation.tin.TriangulatedIrregularNetworkLayer) GriddedElevationModelReadFactory(com.revolsys.elevation.gridded.GriddedElevationModelReadFactory) GriddedElevationModelLayer(com.revolsys.swing.map.layer.elevation.gridded.GriddedElevationModelLayer) PointCloudReadFactory(com.revolsys.elevation.cloud.PointCloudReadFactory)

Example 4 with GeoreferencedImageLayer

use of com.revolsys.swing.map.layer.raster.GeoreferencedImageLayer in project com.revolsys.open by revolsys.

the class LayerGroup method openFile.

public int openFile(final Class<? extends IoFactory> factoryClass, int index, final URL url) {
    final String urlString = url.toString();
    final Map<String, Object> properties = new HashMap<>();
    properties.put("url", urlString);
    String name = UrlUtil.getFileBaseName(url);
    name = FileUtil.fromSafeName(name);
    properties.put("name", name);
    Layer layer;
    if (factoryClass == TriangulatedIrregularNetworkReadFactory.class) {
        layer = new TriangulatedIrregularNetworkLayer(properties);
    } else if (factoryClass == GriddedElevationModelReadFactory.class) {
        layer = new GriddedElevationModelLayer(properties);
    } else if (factoryClass == GeoreferencedImageReadFactory.class) {
        layer = new GeoreferencedImageLayer(properties);
    } else if (factoryClass == PointCloudReadFactory.class) {
        layer = new PointCloudLayer(properties);
    } else if (factoryClass == RecordReaderFactory.class) {
        final FileRecordLayer recordLayer = new FileRecordLayer(properties);
        final GeometryStyleRenderer renderer = recordLayer.getRenderer();
        renderer.setStyle(GeometryStyle.newStyle());
        layer = recordLayer;
    } else {
        layer = null;
    }
    if (layer != null) {
        layer.setProperty("showTableView", isShowNewLayerTableView());
        if (index == -1) {
            addLayer(layer);
        } else {
            addLayer(index++, layer);
        }
    }
    return index;
}
Also used : HashMap(java.util.HashMap) FileRecordLayer(com.revolsys.swing.map.layer.record.FileRecordLayer) FileRecordLayer(com.revolsys.swing.map.layer.record.FileRecordLayer) TriangulatedIrregularNetworkLayer(com.revolsys.swing.map.layer.elevation.tin.TriangulatedIrregularNetworkLayer) PointCloudLayer(com.revolsys.swing.map.layer.pointcloud.PointCloudLayer) GriddedElevationModelLayer(com.revolsys.swing.map.layer.elevation.gridded.GriddedElevationModelLayer) GeoreferencedImageLayer(com.revolsys.swing.map.layer.raster.GeoreferencedImageLayer) GeoreferencedImageLayer(com.revolsys.swing.map.layer.raster.GeoreferencedImageLayer) PointCloudLayer(com.revolsys.swing.map.layer.pointcloud.PointCloudLayer) GeometryStyleRenderer(com.revolsys.swing.map.layer.record.renderer.GeometryStyleRenderer) TriangulatedIrregularNetworkLayer(com.revolsys.swing.map.layer.elevation.tin.TriangulatedIrregularNetworkLayer) GriddedElevationModelReadFactory(com.revolsys.elevation.gridded.GriddedElevationModelReadFactory) GriddedElevationModelLayer(com.revolsys.swing.map.layer.elevation.gridded.GriddedElevationModelLayer) PointCloudReadFactory(com.revolsys.elevation.cloud.PointCloudReadFactory)

Example 5 with GeoreferencedImageLayer

use of com.revolsys.swing.map.layer.raster.GeoreferencedImageLayer in project com.revolsys.open by revolsys.

the class EditGeoreferencedImageOverlay method propertyChange.

@Override
public void propertyChange(final PropertyChangeEvent event) {
    super.propertyChange(event);
    final Object source = event.getSource();
    final String propertyName = event.getPropertyName();
    if (source instanceof GeoreferencedImageLayer) {
        final GeoreferencedImageLayer layer = (GeoreferencedImageLayer) source;
        if ("editable".equals(propertyName)) {
            if (!Booleans.getBoolean(event.getNewValue())) {
                if (this.layer == layer) {
                    setLayer(null);
                }
            } else {
                setLayer(layer);
            }
        } else if (this.layer == layer) {
            clearCachedImage();
            if ("boundingBox".equals(propertyName)) {
                final BoundingBox boundingBox = layer.getBoundingBox();
                setImageBoundingBox(boundingBox);
            } else if ("hasChanges".equals(propertyName)) {
                clear();
                setLayer(layer);
            } else if ("deleted".equals(propertyName)) {
                clear();
            }
        }
    } else if (source == this.image) {
        clearCachedImage();
    } else if ("scale".equals(propertyName)) {
        clearCachedImage();
    }
}
Also used : BoundingBox(com.revolsys.geometry.model.BoundingBox) LineString(com.revolsys.geometry.model.LineString) GeoreferencedImageLayer(com.revolsys.swing.map.layer.raster.GeoreferencedImageLayer)

Aggregations

GeoreferencedImageLayer (com.revolsys.swing.map.layer.raster.GeoreferencedImageLayer)5 PointCloudReadFactory (com.revolsys.elevation.cloud.PointCloudReadFactory)2 GriddedElevationModelReadFactory (com.revolsys.elevation.gridded.GriddedElevationModelReadFactory)2 BoundingBox (com.revolsys.geometry.model.BoundingBox)2 LineString (com.revolsys.geometry.model.LineString)2 GriddedElevationModelLayer (com.revolsys.swing.map.layer.elevation.gridded.GriddedElevationModelLayer)2 TriangulatedIrregularNetworkLayer (com.revolsys.swing.map.layer.elevation.tin.TriangulatedIrregularNetworkLayer)2 PointCloudLayer (com.revolsys.swing.map.layer.pointcloud.PointCloudLayer)2 FileRecordLayer (com.revolsys.swing.map.layer.record.FileRecordLayer)2 GeometryStyleRenderer (com.revolsys.swing.map.layer.record.renderer.GeometryStyleRenderer)2 HashMap (java.util.HashMap)2 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)1 Point (com.revolsys.geometry.model.Point)1 Polygon (com.revolsys.geometry.model.Polygon)1 Vertex (com.revolsys.geometry.model.vertex.Vertex)1 BaseCloseable (com.revolsys.io.BaseCloseable)1 BufferedGeoreferencedImage (com.revolsys.raster.BufferedGeoreferencedImage)1 GeoreferencedImage (com.revolsys.raster.GeoreferencedImage)1 MappedLocation (com.revolsys.raster.MappedLocation)1 Viewport2D (com.revolsys.swing.map.Viewport2D)1