diff --git a/pom.xml b/pom.xml index 9851925c3..b42405144 100644 --- a/pom.xml +++ b/pom.xml @@ -154,12 +154,6 @@ - - com.jhlabs - javaproj - 1.0 - - org.hsqldb diff --git a/src/main/java/org/auscope/portal/server/web/controllers/ReprojectionController.java b/src/main/java/org/auscope/portal/server/web/controllers/ReprojectionController.java deleted file mode 100644 index de7927ee2..000000000 --- a/src/main/java/org/auscope/portal/server/web/controllers/ReprojectionController.java +++ /dev/null @@ -1,137 +0,0 @@ -package org.auscope.portal.server.web.controllers; - -import java.awt.geom.Rectangle2D; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.auscope.portal.core.server.controllers.BasePortalController; -import org.springframework.stereotype.Controller; -import org.springframework.ui.ModelMap; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.servlet.ModelAndView; - -import com.jhlabs.map.proj.Projection; -import com.jhlabs.map.proj.ProjectionFactory; - -/** - * Controller for performing simplistic BBox reprojection - * @author Josh Vote - * - */ -@Controller -public class ReprojectionController extends BasePortalController { - protected final Log logger = LogFactory.getLog(getClass()); - - public ReprojectionController() { - - } - - /** - * Utility for calculating the best Mga zone for a given point - * (Inherited from VEGL - should be revised) - */ - private int calculateIdealMgaZone(double northBoundLatitude, double southBoundLatitude, double eastBoundLongitude, double westBoundLongitude) { - double lngDiff = eastBoundLongitude - westBoundLongitude; - double lngCenter = westBoundLongitude + (lngDiff/2); - double latDiff = northBoundLatitude - southBoundLatitude; - double latCenter = southBoundLatitude + (latDiff/2); - - return calculateIdealMgaZone(latCenter, lngCenter); - } - - /** - * Utility for calculating the best Mga zone for a given point - * (Inherited from VEGL - should be revised) - */ - private int calculateIdealMgaZone(double latitude, double longitude) { - if (longitude >= 108 && longitude < 114){ - return 49; - } else if (longitude >= 114 && longitude < 120){ - return 50; - } else if (longitude >= 120 && longitude < 126){ - return 51; - } else if (longitude >= 126 && longitude < 132){ - return 52; - } else if (longitude >= 132 && longitude < 138){ - return 53; - } else if (longitude >= 138 && longitude < 144){ - return 54; - } else if (longitude >= 144 && longitude < 150){ - return 55; - } else if (longitude >= 150 && longitude < 156){ - return 56; - } - - logger.error("could not calculate MGA zone"); - return-1; - } - - /** - * Calculates the likely MGA zone that the user should use. This zone is determined by finding what zone - * the center of the selected region is in. - * @return - */ - @RequestMapping("/calculateMgaZoneForBBox.do") - public ModelAndView calculateMgaZoneForBBox(@RequestParam("northBoundLatitude") final double northBoundLatitude, - @RequestParam("southBoundLatitude") final double southBoundLatitude, - @RequestParam("eastBoundLongitude") final double eastBoundLongitude, - @RequestParam("westBoundLongitude") final double westBoundLongitude) { - - // calculate likely MGA zone - int mgaZone = calculateIdealMgaZone(northBoundLatitude, southBoundLatitude, eastBoundLongitude, westBoundLongitude); - if (mgaZone < 0) { - logger.error("could not calculate MGA zone"); - return generateJSONResponseMAV(false, null, "Could not calculate MGA zone"); - } - - return generateJSONResponseMAV(true, mgaZone, ""); - } - - /** - * Projects the lat/lng co-ordinates to UTM. If mga zone is not specified it will be estimated - * - * @return - * @throws Exception - */ - @RequestMapping("/projectBBoxToUtm.do") - public ModelAndView projectBBoxToUtm(@RequestParam("northBoundLatitude") double northBoundLatitude, - @RequestParam("southBoundLatitude") double southBoundLatitude, - @RequestParam("eastBoundLongitude") double eastBoundLongitude, - @RequestParam("westBoundLongitude") double westBoundLongitude, - @RequestParam(required=false, value="mgaZone") Integer mgaZone) { - - if (mgaZone == null) { - mgaZone = calculateIdealMgaZone(northBoundLatitude, southBoundLatitude, eastBoundLongitude, westBoundLongitude); - if (mgaZone < 0) { - logger.error("could not calculate MGA zone"); - return generateJSONResponseMAV(false, null, "Could not calculate MGA zone"); - } - } - - // create new projection object - Projection projection = ProjectionFactory.fromPROJ4Specification( - new String[] { - "+proj=utm", // Projection name - "+zone=" + mgaZone, //UTM zone - "+ellps=WGS84", // Ellipsoid name - "+x_0=500000", // False easting - "+y_0=10000000", // False northing - "+k_0=0.99960000" // Scaling factor (new name) - } - ); - - // project the selected region into appropriate UTM projection - Rectangle2D rect = new Rectangle2D.Double(eastBoundLongitude, southBoundLatitude, (westBoundLongitude - eastBoundLongitude), (northBoundLatitude - southBoundLatitude)); - Rectangle2D approxAreaMga = projection.transform(rect); - - // Calculate bounding box which fully encompasses this polygon - ModelMap data = new ModelMap(); - data.put("minNorthing", (int)Math.floor(approxAreaMga.getMinY())); - data.put("maxNorthing", (int)Math.ceil(approxAreaMga.getMaxY())); - data.put("minEasting", (int)Math.floor(approxAreaMga.getMinX())); - data.put("maxEasting", (int)Math.ceil(approxAreaMga.getMaxX())); - data.put("mgaZone", mgaZone); - return generateJSONResponseMAV(true, data, ""); - } -} diff --git a/src/test/java/org/auscope/portal/server/web/controllers/TestReprojectionController.java b/src/test/java/org/auscope/portal/server/web/controllers/TestReprojectionController.java deleted file mode 100644 index cddce2a9c..000000000 --- a/src/test/java/org/auscope/portal/server/web/controllers/TestReprojectionController.java +++ /dev/null @@ -1,204 +0,0 @@ -package org.auscope.portal.server.web.controllers; - -import org.auscope.portal.core.test.PortalTestClass; -import org.junit.Assert; -import org.junit.Test; -import org.springframework.ui.ModelMap; -import org.springframework.web.servlet.ModelAndView; - -public class TestReprojectionController extends PortalTestClass { - ReprojectionController cont = new ReprojectionController(); - - /** - * Simple test with dataset that will return MGA Zone of 49. - */ - @Test - public void testCalculateMgaZoneForBBox_MGAZone_49() { - double north = -30; - double south = -32; - double east = 125; - double west = 100; - - ModelAndView mav = cont.calculateMgaZoneForBBox(north, south, east, west); - Assert.assertNotNull(mav); - Assert.assertTrue((Boolean) mav.getModel().get("success")); - int result = (Integer)mav.getModel().get("data"); - Assert.assertEquals(49, result); - } - - /** - * Simple test with dataset that will return MGA Zone of 50. - */ - @Test - public void testCalculateMgaZoneForBBox_MGAZone_50() { - double north = -30; - double south = -32; - double east = 125; - double west = 110; - - ModelAndView mav = cont.calculateMgaZoneForBBox(north, south, east, west); - Assert.assertNotNull(mav); - Assert.assertTrue((Boolean) mav.getModel().get("success")); - int result = (Integer)mav.getModel().get("data"); - Assert.assertEquals(50, result); - } - - /** - * Simple test with dataset that will return MGA Zone of 51. - */ - @Test - public void testCalculateMgaZoneForBBox_MGAZone_51() { - double north = -30; - double south = -32; - double east = 150; - double west = 100; - - ModelAndView mav = cont.calculateMgaZoneForBBox(north, south, east, west); - Assert.assertNotNull(mav); - Assert.assertTrue((Boolean) mav.getModel().get("success")); - int result = (Integer)mav.getModel().get("data"); - Assert.assertEquals(51, result); - } - - /** - * Simple test with dataset that will return MGA Zone of 52. - */ - @Test - public void testCalculateMgaZoneForBBox_MGAZone_52() { - double north = -30; - double south = -32; - double east = 150; - double west = 110; - - ModelAndView mav = cont.calculateMgaZoneForBBox(north, south, east, west); - Assert.assertNotNull(mav); - Assert.assertTrue((Boolean) mav.getModel().get("success")); - int result = (Integer)mav.getModel().get("data"); - Assert.assertEquals(52, result); - } - - /** - * Simple test with dataset that will return MGA Zone of 53. - */ - @Test - public void testCalculateMgaZoneForBBox_MGAZone_53() { - double north = -30; - double south = -32; - double east = 170; - double west = 100; - - ModelAndView mav = cont.calculateMgaZoneForBBox(north, south, east, west); - Assert.assertNotNull(mav); - Assert.assertTrue((Boolean) mav.getModel().get("success")); - int result = (Integer)mav.getModel().get("data"); - Assert.assertEquals(53, result); - } - - /** - * Simple test with dataset that will return MGA Zone of 54. - */ - @Test - public void testCalculateMgaZoneForBBox_MGAZone_54() { - double north = -30; - double south = -32; - double east = 180; - double west = 100; - - ModelAndView mav = cont.calculateMgaZoneForBBox(north, south, east, west); - Assert.assertNotNull(mav); - Assert.assertTrue((Boolean) mav.getModel().get("success")); - int result = (Integer)mav.getModel().get("data"); - Assert.assertEquals(54, result); - } - - /** - * Simple test with dataset that will return MGA Zone of 55. - */ - @Test - public void testCalculateMgaZoneForBBox_MGAZone_55() { - double north = -30; - double south = -32; - double east = 190; - double west = 100; - - ModelAndView mav = cont.calculateMgaZoneForBBox(north, south, east, west); - Assert.assertNotNull(mav); - Assert.assertTrue((Boolean) mav.getModel().get("success")); - int result = (Integer)mav.getModel().get("data"); - Assert.assertEquals(55, result); - } - - /** - * Simple test with dataset that will return MGA Zone of 56. - */ - @Test - public void testCalculateMgaZoneForBBox_MGAZone_56() { - double north = -30; - double south = -32; - double east = 200; - double west = 100; - - ModelAndView mav = cont.calculateMgaZoneForBBox(north, south, east, west); - Assert.assertNotNull(mav); - Assert.assertTrue((Boolean) mav.getModel().get("success")); - int result = (Integer)mav.getModel().get("data"); - Assert.assertEquals(56, result); - } - - /** - * Simple test with dataset that will fail. - */ - @Test - public void testCalculateMgaZoneForBBox_MGAZoneSmallerThanZero() { - // The following dataset will yield -1 MGA zone - double north = -30; - double south = -32; - double east = 100; - double west = 50; - - ModelAndView mav = cont.calculateMgaZoneForBBox(north, south, east, west); - Assert.assertNotNull(mav); - Assert.assertFalse((Boolean) mav.getModel().get("success")); - Assert.assertNull(mav.getModel().get("data")); - } - - /** - * Simple test to ensure no errors (no validity of conversion is tested) - */ - @Test - public void testBBoxReproject() { - double north = -30; - double south = -32; - double east = 125; - double west = 110; - - ModelAndView mav = cont.projectBBoxToUtm(north, south, east, west, null); - Assert.assertNotNull(mav); - Assert.assertTrue((Boolean) mav.getModel().get("success")); - Assert.assertNotNull(mav.getModel().get("data")); - - ModelMap data = (ModelMap) mav.getModel().get("data"); - data.containsKey("mgaZone"); - data.containsKey("minNorthing"); - data.containsKey("maxNorthing"); - data.containsKey("minEasting"); - data.containsKey("maxEasting"); - } - - /** - * Simple test with dataset that will fail. - */ - @Test - public void testBBoxReproject_MGAZoneSmallerThanZero() { - // The following dataset will yield -1 MGA zone - double north = -30; - double south = -32; - double east = 100; - double west = 50; - - ModelAndView mav = cont.projectBBoxToUtm(north, south, east, west, null); - Assert.assertNotNull(mav); - Assert.assertFalse((Boolean) mav.getModel().get("success")); - Assert.assertNull(mav.getModel().get("data")); - } -} \ No newline at end of file