You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sis.apache.org by de...@apache.org on 2013/07/01 18:32:59 UTC
svn commit: r1498553 - in /sis/branches/JDK7/core/sis-referencing/src:
main/java/org/apache/sis/core/ test/java/org/apache/sis/core/
Author: desruisseaux
Date: Mon Jul 1 16:32:59 2013
New Revision: 1498553
URL: http://svn.apache.org/r1498553
Log:
Refactor LatLon, LatLonRadius and LatLonRect as subclasses of DirectPosition and Envelope implementations (SIS-68, SIS-69).
Modified:
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/core/LatLon.java
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/core/LatLonPointRadius.java
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/core/LatLonRect.java
sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/core/TestLatLon.java
sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/core/TestLatLonPointRadius.java
sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/core/TestLatLonRect.java
Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/core/LatLon.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/core/LatLon.java?rev=1498553&r1=1498552&r2=1498553&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/core/LatLon.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/core/LatLon.java [UTF-8] Mon Jul 1 16:32:59 2013
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
@@ -17,74 +17,72 @@
package org.apache.sis.core;
+import org.apache.sis.geometry.DirectPosition2D;
+
/**
* Represents 2D point on earth surface by latitude and longitude.
- *
- *
+ *
+ *
*/
-public class LatLon {
-
- private double lat;
- private double lon;
+public class LatLon extends DirectPosition2D {
/**
* LatLon to represent geo point.
- *
+ *
* @param lat
* the latitude
* @param lon
* the longitude
*/
public LatLon(double lat, double lon) {
- this.lat = lat;
- this.lon = lon;
+ super(lon, lat);
}
/**
* Shifts the latitude by +90.0 so that all latitude lies in the positive
* coordinate. Used mainly for Java 2D geometry.
- *
+ *
* @return latitude shifted by +90.0
*/
public double getShiftedLat() {
- return this.lat + 90.0;
+ return this.y + 90.0;
}
/**
* Shifts the longitude by +180.0 so that all longitude lies in the positive
* coordinate. Used mainly for Java 2D geometry.
- *
+ *
* @return longitude shifted by +180.0
*/
public double getShiftedLon() {
- return this.lon + 180.0;
+ return this.x + 180.0;
}
/**
* Returns the latitude.
- *
+ *
* @return latitude
*/
public double getLat() {
- return this.lat;
+ return this.y;
}
/**
* Returns the longitude.
- *
+ *
* @return longitude
*/
public double getLon() {
- return this.lon;
+ return this.x;
}
/**
* Normalizes the longitude values to be between -180.0 and 180.0
- *
+ *
* @return longitude value that is between -180.0 and 180.0 inclusive
*/
public double getNormLon() {
- double normLon = this.lon;
+ double normLon = this.x;
if (normLon > 180.0) {
while (normLon > 180.0) {
normLon -= 360.0;
@@ -99,6 +97,6 @@ public class LatLon {
@Override
public String toString() {
- return this.lat + "," + this.lon;
+ return this.y + "," + this.x;
}
}
Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/core/LatLonPointRadius.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/core/LatLonPointRadius.java?rev=1498553&r1=1498552&r2=1498553&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/core/LatLonPointRadius.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/core/LatLonPointRadius.java [UTF-8] Mon Jul 1 16:32:59 2013
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
@@ -24,41 +24,38 @@ import java.awt.geom.Rectangle2D;
//SIS imports
import org.apache.sis.distance.DistanceUtils;
+import org.apache.sis.geometry.GeneralDirectPosition;
/**
* Represents a 2D point associated with a radius to enable great circle
* estimation on earth surface.
- *
+ *
*/
-public class LatLonPointRadius {
-
- private LatLon center;
- private double radius;
+public class LatLonPointRadius extends GeneralDirectPosition {
/**
* Creates a representation of point-radius search region.
- *
+ *
* @param center
* the center of the search region
* @param radius
* the radius of the search region
*/
public LatLonPointRadius(LatLon center, double radius) {
- this.center = center;
- this.radius = radius;
+ super(center.x, center.y, radius);
}
/**
* Gets the circular region approximation on the earth surface using haversine
* formula.
- *
+ *
* @param numberOfPoints
* the number of points used to estimate the circular region
* @return an array of LatLon representing the points that estimate the
* circular region
*/
public LatLon[] getCircularRegionApproximation(int numberOfPoints) {
- if (this.radius >= DistanceUtils.HALF_EARTH_CIRCUMFERENCE) {
+ if (super.getOrdinate(2) >= DistanceUtils.HALF_EARTH_CIRCUMFERENCE) {
LatLon[] points = new LatLon[5];
points[0] = new LatLon(-90.0, -180.0);
points[1] = new LatLon(90.0, -180.0);
@@ -69,14 +66,14 @@ public class LatLonPointRadius {
}
// plus one to add closing point
LatLon[] points = new LatLon[numberOfPoints + 1];
-
+
double bearingIncrement = 0;
if (numberOfPoints > 0) { bearingIncrement = 360/numberOfPoints; }
- for (int i = 0; i < numberOfPoints; i++)
+ for (int i = 0; i < numberOfPoints; i++)
{
- points[i] = DistanceUtils.getPointOnGreatCircle(this.center.getLat(),
- this.center.getLon(), radius, i * bearingIncrement);
+ points[i] = DistanceUtils.getPointOnGreatCircle(super.getOrdinate(1),
+ super.getOrdinate(0), super.getOrdinate(2), i * bearingIncrement);
}
points[numberOfPoints] = points[0];
@@ -86,27 +83,27 @@ public class LatLonPointRadius {
/**
* Calculates the rectangular region enclosing the circular search region.
- *
+ *
* @param numberOfPoints
* the number of points used to estimate the circular search region
* @return Java Rectangle2D object that bounds the circlar search region
*/
public Rectangle2D getRectangularRegionApproximation(int numberOfPoints) {
- if (this.radius >= DistanceUtils.HALF_EARTH_CIRCUMFERENCE) {
+ if (super.getOrdinate(2) >= DistanceUtils.HALF_EARTH_CIRCUMFERENCE) {
return new Rectangle2D.Double(0.0, 0.0, 360.0, 180.0);
}
int numberOfCrossOvers = 0;
Path2D path = new Path2D.Double();
- LatLon initPT = DistanceUtils.getPointOnGreatCircle(this.center.getLat(),
- this.center.getLon(), this.radius, 0);
+ LatLon initPT = DistanceUtils.getPointOnGreatCircle(super.getOrdinate(1),
+ super.getOrdinate(0), super.getOrdinate(2), 0);
path.moveTo(initPT.getShiftedLon(), initPT.getShiftedLat());
LatLon currPT = initPT;
for (int i = 1; i < 360; i++) {
- LatLon pt = DistanceUtils.getPointOnGreatCircle(this.center.getLat(),
- this.center.getLon(), this.radius, i);
+ LatLon pt = DistanceUtils.getPointOnGreatCircle(super.getOrdinate(1),
+ super.getOrdinate(0), super.getOrdinate(2), i);
path.lineTo(pt.getShiftedLon(), pt.getShiftedLat());
if (dateLineCrossOver(currPT.getNormLon(), pt.getNormLon())) {
@@ -126,8 +123,7 @@ public class LatLonPointRadius {
Rectangle2D r = path.getBounds2D();
Rectangle2D lowerHalf = new Rectangle2D.Double(0.0, 0.0, 360.0, r
.getMaxY());
- if (lowerHalf.contains(this.center.getShiftedLon(), this.center
- .getShiftedLat())) {
+ if (lowerHalf.contains(super.getOrdinate(0) + 180, super.getOrdinate(1) + 90)) {
return lowerHalf;
} else {
return new Rectangle2D.Double(0.0, r.getMinY(), 360.0, 180.0 - r
@@ -135,7 +131,7 @@ public class LatLonPointRadius {
}
}
- if (path.contains(this.center.getShiftedLon(), this.center.getShiftedLat())) {
+ if (path.contains(super.getOrdinate(0) + 180, super.getOrdinate(1) + 90)) {
Rectangle2D r = path.getBounds2D();
if ((r.getMaxX() - r.getMinX()) > 359.0) {
return new Rectangle2D.Double(0.0, 0.0, 360.0, 180.0);
@@ -160,7 +156,7 @@ public class LatLonPointRadius {
/**
* Returns true if the line segment connecting the two specified longitudes
* crosses the international dateline.
- *
+ *
* @param longitude1
* first longitude
* @param longitude2
Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/core/LatLonRect.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/core/LatLonRect.java?rev=1498553&r1=1498552&r2=1498553&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/core/LatLonRect.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/core/LatLonRect.java [UTF-8] Mon Jul 1 16:32:59 2013
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
@@ -20,47 +20,43 @@ package org.apache.sis.core;
//JDK imports
import java.awt.geom.Rectangle2D;
+//SIS imports
+import org.apache.sis.geometry.Envelope2D;
+
/**
* Represents a 2D rectangle on earth surface specified by lower left and upper
* right coordinates.
- *
+ *
*/
-public class LatLonRect {
- private LatLon lowerLeft;
- private LatLon upperRight;
+public class LatLonRect extends Envelope2D {
/**
* Creates representation of 2D rectangle.
- *
+ *
* @param lowerLeft
* lower left coordinatee of rectangle
* @param upperRight
* upper right coordinate of rectangle
*/
public LatLonRect(LatLon lowerLeft, LatLon upperRight) {
- this.lowerLeft = lowerLeft;
- this.upperRight = upperRight;
+ super(lowerLeft, upperRight);
}
/**
* Returns true if the rectangle crosses the international dateline.
- *
+ *
* @return true if the rectangle crosses the international dateline, false
* otherwise
*/
private boolean crossesDateLine() {
- if (lowerLeft.getLon() > upperRight.getLon()) {
- return true;
- } else {
- return false;
- }
+ return width < 0;
}
/**
* Calculates the rectangles that makes up this rectangle. Need to do some
* calculation because rectangular region can cross the dateline and will need
* to be represented as two separate rectangles
- *
+ *
* @return an array of Java Rectangle2D representing this rectangular region
* on the earth surface
*/
@@ -69,11 +65,10 @@ public class LatLonRect {
if (crossesDateLine()) {
rect = new Rectangle2D[2];
- LatLonRect west = new LatLonRect(new LatLon(this.lowerLeft.getLat(),
- -180.0), new LatLon(this.upperRight.getLat(), this.upperRight
- .getLon()));
- LatLonRect east = new LatLonRect(new LatLon(this.lowerLeft.getLat(),
- this.lowerLeft.getLon()), new LatLon(this.upperRight.getLat(), 180.0));
+ LatLonRect west = new LatLonRect(new LatLon(y,
+ -180.0), new LatLon(y + height, x + width));
+ LatLonRect east = new LatLonRect(new LatLon(y,
+ x), new LatLon(y + height, 180.0));
rect[0] = getJavaRectangle(west);
rect[1] = getJavaRectangle(east);
} else {
@@ -85,15 +80,13 @@ public class LatLonRect {
/**
* Creates a Java Rectangle2D of the specified LatLonRect.
- *
+ *
* @param rect
* specified LatLonRect
* @return Java Rectangle2D
*/
private Rectangle2D getJavaRectangle(LatLonRect rect) {
- return new Rectangle2D.Double(rect.lowerLeft.getShiftedLon(),
- rect.lowerLeft.getShiftedLat(), rect.upperRight.getShiftedLon()
- - rect.lowerLeft.getShiftedLon(), rect.upperRight.getShiftedLat()
- - rect.lowerLeft.getShiftedLat());
+ return new Rectangle2D.Double(rect.x + 180,
+ rect.y + 90, rect.width, rect.height);
}
}
Modified: sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/core/TestLatLon.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/core/TestLatLon.java?rev=1498553&r1=1498552&r2=1498553&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/core/TestLatLon.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/core/TestLatLon.java [UTF-8] Mon Jul 1 16:32:59 2013
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
@@ -21,14 +21,14 @@ import junit.framework.TestCase;
/**
* Tests methods from the {@link LatLon} class.
- *
+ *
* @author rlaidlaw
*/
public class TestLatLon extends TestCase
{
private static final double EPSILON = 0.000001;
private LatLon point;
-
+
/**
* Set up objects prior to tests.
*/
@@ -36,7 +36,7 @@ public class TestLatLon extends TestCase
{
point = new LatLon(-75.0, -145.0);
}
-
+
/**
* Clear up objects after testing.
*/
@@ -52,7 +52,7 @@ public class TestLatLon extends TestCase
{
assertNotNull(point);
}
-
+
/**
* Tests the getLat() method.
*/
@@ -60,7 +60,7 @@ public class TestLatLon extends TestCase
{
assertEquals(-75.0, point.getLat(), EPSILON);
}
-
+
/**
* Tests the getLon() method.
*/
@@ -68,7 +68,7 @@ public class TestLatLon extends TestCase
{
assertEquals(-145.0, point.getLon(), EPSILON);
}
-
+
/**
* Tests the getShiftedLat() method.
*/
@@ -90,11 +90,11 @@ public class TestLatLon extends TestCase
*/
public void testGetNormLon()
{
- LatLon pointHighLon = new LatLon(0.0, 545.0);
+ LatLon pointHighLon = new LatLon(0.0, 545.0);
assertEquals(-175.0, pointHighLon.getNormLon(), EPSILON);
-
+
LatLon pointLowLon = new LatLon(0.0, -545.0);
- assertEquals(175.0, pointLowLon.getNormLon(), EPSILON);
+ assertEquals(175.0, pointLowLon.getNormLon(), EPSILON);
}
/**
Modified: sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/core/TestLatLonPointRadius.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/core/TestLatLonPointRadius.java?rev=1498553&r1=1498552&r2=1498553&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/core/TestLatLonPointRadius.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/core/TestLatLonPointRadius.java [UTF-8] Mon Jul 1 16:32:59 2013
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
@@ -24,7 +24,7 @@ import java.awt.geom.Rectangle2D;
/**
* Tests methods from the {@link LatLonPointRadius} class.
- *
+ *
* @author rlaidlaw
*/
public class TestLatLonPointRadius extends TestCase
@@ -58,7 +58,7 @@ public class TestLatLonPointRadius exten
assertEquals(180.0, pts1[3].getLon(), EPSILON);
assertEquals(-90.0, pts1[4].getLat(), EPSILON);
assertEquals(-180.0, pts1[4].getLon(), EPSILON);
-
+
LatLonPointRadius pr2 = new LatLonPointRadius(new LatLon(0.0, 0.0), 1000.0);
LatLon pts2[] = pr2.getCircularRegionApproximation(6);
assertEquals(7, pts2.length);
@@ -67,7 +67,7 @@ public class TestLatLonPointRadius exten
/**
* Tests the getRectangularRegionApproximation() method.
*/
- public void testGetRectangularRegionApproximation()
+ public void testGetRectangularRegionApproximation()
{
LatLonPointRadius pr1 = new LatLonPointRadius(new LatLon(0.0, 0.0), 25000.0);
Rectangle2D r1 = pr1.getRectangularRegionApproximation(10);
Modified: sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/core/TestLatLonRect.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/core/TestLatLonRect.java?rev=1498553&r1=1498552&r2=1498553&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/core/TestLatLonRect.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/core/TestLatLonRect.java [UTF-8] Mon Jul 1 16:32:59 2013
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
@@ -24,31 +24,31 @@ import java.awt.geom.Rectangle2D;
/**
* Tests methods from the {@link LatLonRect} class.
- *
+ *
* @author rlaidlaw
*/
public class TestLatLonRect extends TestCase
{
private static final double EPSILON = 0.000001;
-
+
/**
* Tests the LatLonRect constructor.
*/
public void testCreateLatLonRect()
{
- LatLonRect rect = new LatLonRect(new LatLon(-50.0, -150.0),
+ LatLonRect rect = new LatLonRect(new LatLon(-50.0, -150.0),
new LatLon(50.0, 150.0));
- assertNotNull(rect);
+ assertNotNull(rect);
}
-
+
/**
* Tests the getJavaRectangles() method.
*/
public void testGetJavaRectangles()
{
- LatLonRect r1 = new LatLonRect(new LatLon(0.0, 0.0),
+ LatLonRect r1 = new LatLonRect(new LatLon(0.0, 0.0),
new LatLon(50.0, 50.0));
-
+
Rectangle2D[] rects1 = r1.getJavaRectangles();
assertEquals(1, rects1.length);
assertEquals(180.0, rects1[0].getX(), EPSILON);
@@ -56,8 +56,8 @@ public class TestLatLonRect extends Test
assertEquals(50.0, rects1[0].getWidth(), EPSILON);
assertEquals(50.0, rects1[0].getHeight(), EPSILON);
-
- LatLonRect r2 = new LatLonRect(new LatLon(0.0, 155.0),
+
+ LatLonRect r2 = new LatLonRect(new LatLon(0.0, 155.0),
new LatLon(50.0, -155.0));
Rectangle2D[] rects2 = r2.getJavaRectangles();