Skip to content

Commit 210d1dd

Browse files
committed
Changed meter conversion
1 parent 4312cf9 commit 210d1dd

3 files changed

Lines changed: 41 additions & 15 deletions

File tree

bboxdb-commons/src/main/java/org/bboxdb/commons/math/Hyperrectangle.java

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -320,28 +320,35 @@ public Hyperrectangle enlargeByAmount(final double amount) {
320320
*/
321321
public Hyperrectangle enlargeByMeters(final double meterLat, final double meterLon) {
322322

323-
// The equatorial radius as defined by WGS84
324-
final double EQUATORIAL_RADIUS = 6378137.0;
325-
326323
final int dimension = getDimension();
327324

328325
if(dimension != 2) {
329326
throw new IllegalArgumentException("Bounding box has the wrong dimension: " + dimension);
330327
}
331-
328+
332329
final double latitudeLow = getCoordinateLow(0);
333330
final double lonitudeLow = getCoordinateLow(1);
334331
final double latitudeHigh = getCoordinateHigh(0);
335332
final double lonitudeHigh = getCoordinateHigh(1);
336333

337-
final double latChange = (180.0/Math.PI) * (meterLat / EQUATORIAL_RADIUS);
338-
final double longChange = (180.0/Math.PI) * (meterLon / EQUATORIAL_RADIUS) / Math.cos(Math.toRadians(latitudeLow));
334+
//final double lat0 = Math.toRadians(latitudeLow);
335+
final double lat0=(latitudeLow * (Math.PI) / 180);
336+
337+
// The radius as defined by WGS84
338+
final double equator_circumference = 6371000.0;
339+
final double polar_circumference = 6356800.0;
340+
341+
final double m_per_deg_long = 360 / polar_circumference;
342+
final double m_per_deg_lat = Math.abs(360 / (Math.cos(lat0) * equator_circumference));
343+
344+
final double deg_diff_lat = meterLat * m_per_deg_lat;
345+
final double deg_diff_long = meterLon * m_per_deg_long;
339346

340347
return new Hyperrectangle(
341-
latitudeLow - (latChange / 2.0),
342-
latitudeHigh + (latChange / 2.0),
343-
lonitudeLow - (longChange / 2.0),
344-
lonitudeHigh + (longChange / 2.0));
348+
latitudeLow - (deg_diff_lat / 2.0),
349+
latitudeHigh + (deg_diff_lat / 2.0),
350+
lonitudeLow - (deg_diff_long / 2.0),
351+
lonitudeHigh + (deg_diff_long / 2.0));
345352
}
346353

347354
/**

bboxdb-commons/src/test/java/org/bboxdb/math/TestHyperrectangle.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,5 +701,19 @@ public void testEnlargeByFactor() {
701701
Assert.assertEquals(new Hyperrectangle(-50d, 50d, -250d, 250d), bb2.enlargeByFactor(5));
702702
Assert.assertEquals(new Hyperrectangle(-20.0d, 30.0d, -250d, 250d, -320.0d, 230.0d), bb3.enlargeByFactor(5));
703703
}
704+
705+
706+
/**
707+
* Test the enlarge function
708+
*/
709+
@Test(timeout=60000)
710+
public void testEnlargeByMeters() {
711+
final Hyperrectangle bb0 = new Hyperrectangle(176.451691, 176.451691, 24.48522, 24.48522);
712+
final Hyperrectangle enlargedBox0 = bb0.enlargeByMeters(50, 60);
713+
Assert.assertEquals(enlargedBox0, new Hyperrectangle(176.4502756356295700, 176.4531063643704600, 24.4835210319657720, 24.4869189680342300));
704714

715+
final Hyperrectangle bb1 = new Hyperrectangle(239.848892, 239.848892, -131.3928222, -131.392822);
716+
final Hyperrectangle enlargedBox1 = bb1.enlargeByMeters(50, 60);
717+
Assert.assertEquals(enlargedBox1, new Hyperrectangle(239.8460795353730600, 239.8517044646269500, -131.3945211680342300, -131.3911230319657800));
718+
}
705719
}

bboxdb-server/src/test/java/org/bboxdb/test/distribution/TestContinuousQueryEnlargement.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public class TestContinuousQueryEnlargement {
3030
/**
3131
* The name of the cluster for this test
3232
*/
33-
private static final String CLUSTER_NAME = "testcluster";
33+
private static final String DISTRIBUTION_GROUP = "testgroupenlagement";
3434

3535
/**
3636
* The delta for the asserts
@@ -44,7 +44,7 @@ public static void init() throws Exception {
4444

4545
@Test(timeout=60_000)
4646
public void testQueryRegister0() {
47-
final ContinuousQueryRegisterer registerer = new ContinuousQueryRegisterer(CLUSTER_NAME, "abc1");
47+
final ContinuousQueryRegisterer registerer = new ContinuousQueryRegisterer(DISTRIBUTION_GROUP, "abc1");
4848
final QueryEnlagement enlargement = registerer.getMaxEnlagementFactorForTable();
4949
Assert.assertEquals(0, enlargement.getMaxAbsoluteEnlargement(), DELTA);
5050
Assert.assertEquals(1, enlargement.getMaxEnlargementFactor(), DELTA);
@@ -54,7 +54,7 @@ public void testQueryRegister0() {
5454

5555
@Test(timeout=60_000)
5656
public void testQueryRegister1() throws ZookeeperException {
57-
final ContinuousQueryRegisterer registerer = new ContinuousQueryRegisterer(CLUSTER_NAME, "abc2");
57+
final ContinuousQueryRegisterer registerer = new ContinuousQueryRegisterer(DISTRIBUTION_GROUP, "abc2");
5858
registerer.updateQueryOnTable(10, 20, 30, 40);
5959

6060
final QueryEnlagement enlargement = registerer.getMaxEnlagementFactorForTable();
@@ -67,7 +67,7 @@ public void testQueryRegister1() throws ZookeeperException {
6767

6868
@Test(timeout=60_000)
6969
public void testQueryRegister2() throws ZookeeperException {
70-
final ContinuousQueryRegisterer registerer = new ContinuousQueryRegisterer(CLUSTER_NAME, "abc3");
70+
final ContinuousQueryRegisterer registerer = new ContinuousQueryRegisterer(DISTRIBUTION_GROUP, "abc3");
7171
registerer.updateQueryOnTable(30, 40, 50, 60);
7272

7373
final QueryEnlagement enlargement = registerer.getMaxEnlagementFactorForTable();
@@ -79,7 +79,7 @@ public void testQueryRegister2() throws ZookeeperException {
7979

8080
@Test(timeout=60_000)
8181
public void testQueryUnRegister0() throws ZookeeperException, InterruptedException {
82-
final ContinuousQueryRegisterer registerer = new ContinuousQueryRegisterer(CLUSTER_NAME, "abc4");
82+
final ContinuousQueryRegisterer registerer = new ContinuousQueryRegisterer(DISTRIBUTION_GROUP, "abc4");
8383
registerer.updateQueryOnTable(30, 40, 50, 60);
8484

8585
final QueryEnlagement enlargement = registerer.getMaxEnlagementFactorForTable();
@@ -97,4 +97,9 @@ public void testQueryUnRegister0() throws ZookeeperException, InterruptedExcepti
9797
Assert.assertEquals(0, enlargement.getMaxEnlargementLon(), DELTA);
9898
}
9999

100+
public static void main(String[] args) throws ZookeeperException {
101+
final ContinuousQueryRegisterer registerer = new ContinuousQueryRegisterer("mydgroup", "table1");
102+
registerer.updateQueryOnTable(30, 40, 50, 60);
103+
}
104+
100105
}

0 commit comments

Comments
 (0)