Skip to content

Commit d05ec98

Browse files
committed
Add Raster reprojection method
1 parent 7e609dd commit d05ec98

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

doc/api/raster.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,11 @@ Methods
131131

132132
Crop the current Raster to only include data in the given Geometry.
133133

134+
.. function:: Raster.reproject(projection)
135+
136+
:arg projection: :class:`proj.Projection` The target Projection
137+
138+
Reproject a Raster from one Projection to anothet Projection.
134139

135140
:class:`raster.Band`
136141
====================

src/main/java/org/geoscript/js/raster/Raster.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,16 @@ public Raster crop(Object boundsOrGeometry) {
156156
return new Raster(this.getParentScope(), newCoverage);
157157
}
158158

159+
@JSFunction
160+
public Raster reproject(Projection projection) {
161+
CoverageProcessor processor = new CoverageProcessor();
162+
ParameterValueGroup params = processor.getOperation("Resample").getParameters();
163+
params.parameter("Source").setValue(coverage);
164+
params.parameter("CoordinateReferenceSystem").setValue(projection.unwrap());
165+
GridCoverage2D newCoverage = (GridCoverage2D) processor.doOperation(params);
166+
return new Raster(this.getParentScope(), newCoverage);
167+
}
168+
159169
@Override
160170
public String toString() {
161171
return this.getName();

src/test/resources/org/geoscript/js/tests/geoscript/raster/test_raster.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ exports["test: get raster point from pixel"] = function() {
7171
assert.strictEqual("81.8", pt.y.toFixed(1), "Point y should be 81.8");
7272
};
7373

74-
7574
exports["test: get raster point from pixel"] = function() {
7675
var format = new raster.Format({source: admin.raster.source});
7776
var tif = format.read({});
@@ -107,4 +106,12 @@ exports["test: crop a raster with a geometry"] = function() {
107106
assert.strictEqual(-4, Math.round(bounds.minY), "Min Y should be -4");
108107
assert.strictEqual(4, Math.round(bounds.maxX), "Max X should be 4");
109108
assert.strictEqual(4, Math.round(bounds.maxY), "Max Y should be 4");
109+
};
110+
111+
exports["test: reproject a raster"] = function() {
112+
var format = new raster.Format({source: admin.raster.source});
113+
var tif = format.read({}).crop(new geom.Point([0, 0]).buffer(4));
114+
var reprojectedTif = tif.reproject(new proj.Projection("EPSG:3857"));
115+
assert.strictEqual("EPSG:4326", tif.proj.id, "Original raster should be EPSG:4326");
116+
assert.strictEqual("EPSG:3857", reprojectedTif.proj.id, "Original raster should be EPSG:3857");
110117
};

0 commit comments

Comments
 (0)