package ch.epfl.alpano.dem; import static java.lang.Math.toRadians; import java.awt.image.BufferedImage; import java.io.File; import java.util.ArrayList; import java.util.Arrays; import javax.imageio.ImageIO; import ch.epfl.alpano.GeoPoint; final class DrawElevationProfile { final static File HGT_FILE = new File("HGT"+File.separatorChar+"N46E006.hgt"); final static double MAX_ELEVATION = 1_500; final static int LENGTH = 111_000; final static double AZIMUTH = toRadians(27.97); final static double LONGITUDE = toRadians(6.15432); final static double LATITUDE = toRadians(46.20562); final static int WIDTH = 800, HEIGHT = 100; public static void main(String[] as) throws Exception { DiscreteElevationModel dDEM = new HgtDiscreteElevationModel(HGT_FILE); ContinuousElevationModel cDEM = new ContinuousElevationModel(dDEM); GeoPoint o = new GeoPoint(LONGITUDE, LATITUDE); ElevationProfile p1 = new ElevationProfile(cDEM, o, AZIMUTH, (int)(LENGTH/3)); GeoPoint gP1 = p1.positionAt((int)LENGTH/3); ElevationProfile p2 = new ElevationProfile(cDEM, p1.positionAt((int)LENGTH/3), AZIMUTH+toRadians(6.0),2*((int)LENGTH/3)); GeoPoint gP2 = p2.positionAt(2*((int)LENGTH/3)); ElevationProfile p3 = new ElevationProfile (cDEM,p2.positionAt(2*((int)LENGTH/3)), AZIMUTH, LENGTH); ArrayList trekkingSpots = new ArrayList(Arrays.asList(o,gP1,gP2)); ArrayList profiles= new ArrayList(); for (int index = 0; index < trekkingSpots.size()-1; index++){ GeoPoint current= trekkingSpots.get(index); GeoPoint next = trekkingSpots.get(index+1); ElevationProfile evP= new ElevationProfile(cDEM, current,current.azimuthTo(next), current.distanceTo(next)); profiles.add(evP); } CompositElevationProfile p = new CompositElevationProfile(profiles); int BLACK = 0x00_00_00, WHITE = 0xFF_FF_FF; BufferedImage i = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_RGB); for (int x = 0; x < WIDTH; ++x) { double pX = x * (double) LENGTH / (WIDTH - 1); double pY = p.elevationAt(pX); int yL = (int)((pY / MAX_ELEVATION) * (HEIGHT - 1)); for (int y = 0; y < HEIGHT; ++y) { int color = y < yL ? BLACK : WHITE; i.setRGB(x, HEIGHT - 1 - y, color); } } dDEM.close(); ImageIO.write(i, "png", new File("tests/ch/epfl/alpano/dem/profile.png")); } }