Skip to content

Commit 8e46a52

Browse files
committed
Add getGeoBounds method in addition to the getBounds method. This changes the getBounds method which now returns a Bounds in the same Projection as the current Projection.
1 parent c30d75a commit 8e46a52

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

src/main/groovy/geoscript/proj/Projection.groovy

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,23 @@ class Projection {
7878
}
7979

8080
/**
81-
* Get the valid geographic area for this Projection
81+
* Get the extent for this Projection
8282
* @return A Bounds
8383
*/
8484
Bounds getBounds() {
85+
def extent = CRS.getEnvelope(crs)
86+
if (extent != null) {
87+
return new Bounds(extent.getMinimum(0), extent.getMinimum(1), extent.getMaximum(0), extent.getMaximum(1), this)
88+
} else {
89+
return null
90+
}
91+
}
92+
93+
/**
94+
* Get the valid geographic area for this Projection
95+
* @return A Bounds
96+
*/
97+
Bounds getGeoBounds() {
8598
def extent = CRS.getGeographicBoundingBox(crs)
8699
if (extent != null) {
87100
return new Bounds(extent.westBoundLongitude, extent.southBoundLatitude, extent.eastBoundLongitude, extent.northBoundLatitude, 'epsg:4326')

src/test/groovy/geoscript/proj/ProjectionTestCase.groovy

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,22 @@ class ProjectionTestCase {
5454
@Test void getBounds() {
5555
Bounds bounds = new Projection("EPSG:2927").bounds
5656
assertNotNull(bounds)
57+
assertEquals "EPSG:2927", bounds.proj.id
58+
assertEquals(641400.91, bounds.minX, 0.1)
59+
assertEquals(75407.62, bounds.minY, 0.1)
60+
assertEquals(2557520.70, bounds.maxX, 0.1)
61+
assertEquals(854063.65, bounds.maxY, 0.1)
62+
}
63+
64+
@Test void getGeoBounds() {
65+
Bounds bounds = new Projection("EPSG:2927").geoBounds
66+
assertNotNull(bounds)
5767
assertEquals "EPSG:4326", bounds.proj.id
5868
assertEquals(-124.5, bounds.minX, 0.1)
5969
assertEquals(45.55, bounds.minY, 0.1)
6070
assertEquals(-116.9, bounds.maxX, 0.1)
6171
assertEquals(47.6, bounds.maxY, 0.1)
6272
}
63-
6473

6574
@Test void transform() {
6675
Point point = new Point(1181199.82, 652100.72)

0 commit comments

Comments
 (0)