bbloggsbott / autobound Goto Github PK
View Code? Open in Web Editor NEWRepository for Google Summer of Code 2019 project
Repository for Google Summer of Code 2019 project
Not the nicest code, but it works
MapView mv = MainApplication.getMap().mapView;
// The area to take the image from.
MapViewState.MapViewRectangle selectedArea = mv.getState().getViewArea(r);
// The area in east/north coordinates
ProjectionBounds selectedInEastNorth = selectedArea.getProjectionBounds();
Optional<Layer> layerOpt = MainApplication.getLayerManager().getLayers().stream()
.filter(l -> l.isBackgroundLayer() && l.isVisible())
.findFirst();
if (layerOpt.isPresent()) {
Layer layer = layerOpt.get();
MainLayerManager layersToRender = new MainLayerManager();
layersToRender.addLayer(layer);
MapView fakeMapView = new MapView(layersToRender, null) {
{
setBounds(0, 0, 1024, 1024); // < max rendering size
updateLocationState();
}
@Override
protected boolean isVisibleOnScreen() {
return true;
}
@Override
public Point getLocationOnScreen() {
return new Point(0, 0);
}
};
Runnable reset = () -> {};
// Dirty hack. This should be fixed in JOSM.
if (layer instanceof AbstractTileSourceLayer) {
try {
Field coordinateConverterField = AbstractTileSourceLayer.class.getDeclaredField("coordinateConverter");
coordinateConverterField.setAccessible(true);
Field tileSourceField = TileCoordinateConverter.class.getDeclaredField("tileSource");
Field settingsField = TileCoordinateConverter.class.getDeclaredField("settings");
TileCoordinateConverter oldConverter = (TileCoordinateConverter) coordinateConverterField.get(layer);
tileSourceField.setAccessible(true);
settingsField.setAccessible(true);
TileCoordinateConverter newConverter = new TileCoordinateConverter(fakeMapView,
(TileSource) tileSourceField.get(oldConverter),
(TileSourceDisplaySettings) settingsField.get(oldConverter));
coordinateConverterField.set(layer, newConverter);
reset = () -> {
try {
coordinateConverterField.set(layer, oldConverter);
} catch (IllegalAccessException ex) {
Logging.warn(ex);
}
};
} catch (NoSuchFieldException | IllegalAccessException ex) {
// TODO: Show error
Logging.error(ex);
}
}
MapViewPaintable.LayerPainter painter = layer.attachToMapView(new MapViewPaintable.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 space
MapViewState.MapViewRectangle toPaint = fakeMapView.getState().getPointFor(selectedInEastNorth.getMin())
.rectTo(fakeMapView.getState().getPointFor(selectedInEastNorth.getMax()));
// Actual drawing
BufferedImage image = new BufferedImage((int) toPaint.getInView().getWidth(), (int) toPaint.getInView().getHeight(),
BufferedImage.TYPE_BYTE_INDEXED);
Graphics2D graphics = image.createGraphics();
// Move so that the image matches the region we are painting.
graphics.translate(-toPaint.getInView().getMinX(), -toPaint.getInView().getMinY());
painter.paint(new MapViewGraphics(fakeMapView, graphics, toPaint));
// Dispose the painter, release resources.
graphics.dispose();
painter.detachFromMapView(new MapViewPaintable.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", new File("whatever.png"));
} catch (IOException ex) {
//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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.