dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #25799
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 12819: Impl method for getting coordinates of box shape based on a point and distance to edges
------------------------------------------------------------
revno: 12819
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2013-10-28 14:17:58 +0100
message:
Impl method for getting coordinates of box shape based on a point and distance to edges
modified:
dhis-2/dhis-services/dhis-service-mapgeneration/pom.xml
dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/MapUtils.java
dhis-2/dhis-services/dhis-service-mapgeneration/src/test/java/org/hisp/dhis/mapgenerator/MapUtilsTest.java
dhis-2/pom.xml
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-services/dhis-service-mapgeneration/pom.xml'
--- dhis-2/dhis-services/dhis-service-mapgeneration/pom.xml 2013-10-17 06:57:37 +0000
+++ dhis-2/dhis-services/dhis-service-mapgeneration/pom.xml 2013-10-28 13:17:58 +0000
@@ -47,6 +47,10 @@
<groupId>org.geotools</groupId>
<artifactId>gt-epsg-wkt</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.geotools</groupId>
+ <artifactId>gt-referencing</artifactId>
+ </dependency>
</dependencies>
<properties>
=== modified file 'dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/MapUtils.java'
--- dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/MapUtils.java 2013-08-23 16:05:01 +0000
+++ dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/MapUtils.java 2013-10-28 13:17:58 +0000
@@ -32,6 +32,7 @@
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.RenderingHints;
+import java.awt.geom.Point2D;
import java.awt.image.BufferedImage;
import org.geotools.feature.DefaultFeatureCollection;
@@ -40,6 +41,7 @@
import org.geotools.map.FeatureLayer;
import org.geotools.map.Layer;
import org.geotools.map.MapContent;
+import org.geotools.referencing.GeodeticCalculator;
import org.geotools.renderer.GTRenderer;
import org.geotools.renderer.lite.StreamingRenderer;
import org.geotools.styling.Style;
@@ -289,4 +291,50 @@
return image;
}
+
+ /**
+ * Returns boundaries of a box shape which centre is the point defined by the
+ * given longitude and latitude. The distance between the center point and the
+ * edges of the box is defined in meters by the given distance. Based on standard
+ * EPSG:4326 long/lat projection. The result is an array of length 4 where
+ * the values at each index are:
+ *
+ * <ul>
+ * <li>Index 0: Maximum latitude (north edge of box shape).</li>
+ * <li>Index 1: Maxium longitude (east edge of box shape).</li>
+ * <li>Index 2: Minimum latitude (south edge of box shape).</li>
+ * <li>Index 3: Minumum longitude (west edge of box shape).</li>
+ * </ul>
+ *
+ * @param longitude the longitude.
+ * @param latitude the latitude.
+ * @param distance the distance in meters to each box edge.
+ * @return an array of length 4.
+ */
+ public static double[] getBoxShape( double longitude, double latitude, double distance )
+ {
+ double[] box = new double[4];
+
+ GeodeticCalculator calc = new GeodeticCalculator();
+ calc.setStartingGeographicPoint( longitude, latitude );
+
+ calc.setDirection( 0, distance );
+ Point2D north = calc.getDestinationGeographicPoint();
+
+ calc.setDirection( 90, distance );
+ Point2D east = calc.getDestinationGeographicPoint();
+
+ calc.setDirection( 180, distance );
+ Point2D south = calc.getDestinationGeographicPoint();
+
+ calc.setDirection( -90, distance );
+ Point2D west = calc.getDestinationGeographicPoint();
+
+ box[0] = north.getY();
+ box[1] = east.getX();
+ box[2] = south.getY();
+ box[3] = west.getX();
+
+ return box;
+ }
}
=== modified file 'dhis-2/dhis-services/dhis-service-mapgeneration/src/test/java/org/hisp/dhis/mapgenerator/MapUtilsTest.java'
--- dhis-2/dhis-services/dhis-service-mapgeneration/src/test/java/org/hisp/dhis/mapgenerator/MapUtilsTest.java 2013-08-23 16:05:01 +0000
+++ dhis-2/dhis-services/dhis-service-mapgeneration/src/test/java/org/hisp/dhis/mapgenerator/MapUtilsTest.java 2013-10-28 13:17:58 +0000
@@ -28,13 +28,19 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import static org.hisp.dhis.mapgeneration.MapUtils.getBoxShape;
+import static org.hisp.dhis.mapgeneration.MapUtils.getWidthHeight;
+import static org.junit.Assert.assertEquals;
+
import org.junit.Test;
-import static org.junit.Assert.*;
-import static org.hisp.dhis.mapgeneration.MapUtils.*;
-
+/**
+ * Lars Helge Overland
+ */
public class MapUtilsTest
{
+ private static final double DELTA = 0.01;
+
@Test
public void testGetWidthHeight()
{
@@ -61,4 +67,26 @@
{
getWidthHeight( null, null, 0, 0, 0.5 );
}
+
+ @Test
+ public void testGetBoxShape()
+ {
+ // Equator
+
+ double[] box = getBoxShape( 0, 0, 110574.27 );
+
+ assertEquals( 1d, box[0], DELTA );
+ assertEquals( 1d, box[1], DELTA );
+ assertEquals( -1d, box[2], DELTA );
+ assertEquals( -1d, box[3], DELTA );
+
+ // Punta Arenas
+
+ box = getBoxShape( -71, -53, 67137.20 );
+
+ assertEquals( -52.4, box[0], DELTA );
+ assertEquals( -70d, box[1], DELTA );
+ assertEquals( -53.6, box[2], DELTA );
+ assertEquals( -72d, box[3], DELTA );
+ }
}
=== modified file 'dhis-2/pom.xml'
--- dhis-2/pom.xml 2013-10-17 06:57:37 +0000
+++ dhis-2/pom.xml 2013-10-28 13:17:58 +0000
@@ -885,6 +885,11 @@
</exclusion>
</exclusions>
</dependency>
+ <dependency>
+ <groupId>org.geotools</groupId>
+ <artifactId>gt-referencing</artifactId>
+ <version>${geotools.version}</version>
+ </dependency>
<!-- JAXB -->
<dependency>