Skip to content

Commit afbd450

Browse files
committed
Add Projection.toMeters method to convert a distance in the projection's native units to meters.
1 parent bcfd973 commit afbd450

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import geoscript.geom.Bounds
55
import org.geotools.geometry.jts.GeometryCoordinateSequenceTransformer
66
import org.geotools.metadata.iso.citation.Citations
77
import org.geotools.referencing.CRS
8+
import org.geotools.renderer.lite.RendererUtilities
89
import org.opengis.referencing.crs.CoordinateReferenceSystem
910
import org.opengis.referencing.operation.MathTransform
1011

@@ -128,6 +129,15 @@ class Projection {
128129
}
129130
}
130131

132+
/**
133+
* Convert a distance in the Projection's native units to meters.
134+
* @param distance A distance in the Projection's native units
135+
* @return The distance in meters
136+
*/
137+
double toMeters(double distance) {
138+
RendererUtilities.toMeters(distance, crs)
139+
}
140+
131141
/**
132142
* Transform the Geometry to another Projection
133143
* @param geom The Geometry

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,5 +166,12 @@ class ProjectionTestCase {
166166
@Test void hasEpsgExtension() {
167167
assertNotNull new Projection("EPSG:104905")
168168
}
169+
170+
@Test void toMeters() {
171+
Projection p = new Projection("EPSG:2927")
172+
double meters = p.toMeters(5280)
173+
assertEquals(1609.3472, meters, 0.001)
174+
}
175+
169176
}
170177

0 commit comments

Comments
 (0)