No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

PlateCarreProjection.java 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. package org.insa.graphics.drawing;
  2. import org.insa.graph.GraphStatistics.BoundingBox;
  3. public class PlateCarreProjection implements Projection {
  4. // Bounding box
  5. private final float minLatitude, minLongitude, maxLatitude, maxLongitude;
  6. // Dimension of the image
  7. private final double width, height;
  8. /**
  9. * Create a new PlateCarreProjection corresponding to the given BoundingBox and
  10. * maxSize.
  11. *
  12. * @param boundingBox Box for this projection.
  13. * @param maxSize Maximum size of any side (width / height) of the image to
  14. * which this projection should draw.
  15. */
  16. public PlateCarreProjection(BoundingBox boundingBox, int maxSize) {
  17. // Find minimum/maximum longitude and latitude.
  18. this.minLongitude = boundingBox.getTopLeftPoint().getLongitude();
  19. this.maxLongitude = boundingBox.getBottomRightPoint().getLongitude();
  20. this.minLatitude = boundingBox.getBottomRightPoint().getLatitude();
  21. this.maxLatitude = boundingBox.getTopLeftPoint().getLatitude();
  22. float diffLon = maxLongitude - minLongitude, diffLat = maxLatitude - minLatitude;
  23. this.width = diffLon < diffLat ? (int) (maxSize * diffLon / diffLat) : maxSize;
  24. this.height = diffLon < diffLat ? maxSize : (int) (maxSize * diffLat / diffLon);
  25. }
  26. @Override
  27. public double getImageWidth() {
  28. return this.width;
  29. }
  30. @Override
  31. public double getImageHeight() {
  32. return this.height;
  33. }
  34. @Override
  35. public int latitudeToPixelY(float latitude) {
  36. return (int) (this.height * (this.maxLatitude - latitude)
  37. / (this.maxLatitude - this.minLatitude));
  38. }
  39. @Override
  40. public int longitudeToPixelX(float longitude) {
  41. return (int) (this.width * (longitude - this.minLongitude)
  42. / (this.maxLongitude - this.minLongitude));
  43. }
  44. @Override
  45. public float pixelYToLatitude(double py) {
  46. return (float) (this.maxLatitude
  47. - py / this.height * (this.maxLatitude - this.minLatitude));
  48. }
  49. @Override
  50. public float pixelXToLongitude(double px) {
  51. return (float) (px / this.width * (this.maxLongitude - this.minLongitude)
  52. + this.minLongitude);
  53. }
  54. }