You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
MapViewmv = MainApplication.getMap().mapView;
// The area to take the image from.MapViewState.MapViewRectangleselectedArea = mv.getState().getViewArea(r);
// The area in east/north coordinatesProjectionBoundsselectedInEastNorth = selectedArea.getProjectionBounds();
Optional<Layer> layerOpt = MainApplication.getLayerManager().getLayers().stream()
.filter(l -> l.isBackgroundLayer() && l.isVisible())
.findFirst();
if (layerOpt.isPresent()) {
Layerlayer = layerOpt.get();
MainLayerManagerlayersToRender = newMainLayerManager();
layersToRender.addLayer(layer);
MapViewfakeMapView = newMapView(layersToRender, null) {
{
setBounds(0, 0, 1024, 1024); // < max rendering sizeupdateLocationState();
}
@OverrideprotectedbooleanisVisibleOnScreen() {
returntrue;
}
@OverridepublicPointgetLocationOnScreen() {
returnnewPoint(0, 0);
}
};
Runnablereset = () -> {};
// Dirty hack. This should be fixed in JOSM.if (layerinstanceofAbstractTileSourceLayer) {
try {
FieldcoordinateConverterField = AbstractTileSourceLayer.class.getDeclaredField("coordinateConverter");
coordinateConverterField.setAccessible(true);
FieldtileSourceField = TileCoordinateConverter.class.getDeclaredField("tileSource");
FieldsettingsField = TileCoordinateConverter.class.getDeclaredField("settings");
TileCoordinateConverteroldConverter = (TileCoordinateConverter) coordinateConverterField.get(layer);
tileSourceField.setAccessible(true);
settingsField.setAccessible(true);
TileCoordinateConverternewConverter = newTileCoordinateConverter(fakeMapView,
(TileSource) tileSourceField.get(oldConverter),
(TileSourceDisplaySettings) settingsField.get(oldConverter));
coordinateConverterField.set(layer, newConverter);
reset = () -> {
try {
coordinateConverterField.set(layer, oldConverter);
} catch (IllegalAccessExceptionex) {
Logging.warn(ex);
}
};
} catch (NoSuchFieldException | IllegalAccessExceptionex) {
// TODO: Show errorLogging.error(ex);
}
}
MapViewPaintable.LayerPainterpainter = layer.attachToMapView(newMapViewPaintable.MapViewEvent(fakeMapView, false));
// Mind that this will not exactly zoom to that area, but instead to an area close to it depending on the native scale of the background layer.fakeMapView.zoomTo(selectedArea.getCornerBounds());
// Now we need to find out the selected are in faked map view spaceMapViewState.MapViewRectangletoPaint = fakeMapView.getState().getPointFor(selectedInEastNorth.getMin())
.rectTo(fakeMapView.getState().getPointFor(selectedInEastNorth.getMax()));
// Actual drawingBufferedImageimage = newBufferedImage((int) toPaint.getInView().getWidth(), (int) toPaint.getInView().getHeight(),
BufferedImage.TYPE_BYTE_INDEXED);
Graphics2Dgraphics = image.createGraphics();
// Move so that the image matches the region we are painting.graphics.translate(-toPaint.getInView().getMinX(), -toPaint.getInView().getMinY());
painter.paint(newMapViewGraphics(fakeMapView, graphics, toPaint));
// Dispose the painter, release resources.graphics.dispose();
painter.detachFromMapView(newMapViewPaintable.MapViewEvent(fakeMapView, false));
/* TODO: We could dispose layers. But this will make some global state of JOSM inconsistent. * So we just let GC reclaim as many resources as possible. */reset.run();
// Good for debugging / scaling: How many meters are in 100 pixel for your image// I don't know if your training model will improve if you normalize the images by using this, any way you should store it just in case we need it later.fakeMapView.getDist100Pixel();
try {
ImageIO.write(image, "png", newFile("whatever.png"));
} catch (IOExceptionex) {
//TODO: Show error
}
} else {
JOptionPane.showMessageDialog(
MainApplication.getMainFrame(),
tr("No imagery layer found."),
tr("Warning"),
JOptionPane.WARNING_MESSAGE);
}
Mind the copyright issues: Before publishing (parts of) satellite images online, you should check if that source allows them to be published. Bing does not allow it.
The text was updated successfully, but these errors were encountered:
Every time the above code snippet is run, the imagery in the map view pixellates and becomes normal. I moved the downloader to the separate thread so that the user will be able to perform other operations when this download is happening.
Not the nicest code, but it works
Mind the copyright issues: Before publishing (parts of) satellite images online, you should check if that source allows them to be published. Bing does not allow it.
The text was updated successfully, but these errors were encountered: