File tree Expand file tree Collapse file tree 3 files changed +23
-1
lines changed
main/java/org/geoscript/js/raster
test/resources/org/geoscript/js/tests/geoscript/raster Expand file tree Collapse file tree 3 files changed +23
-1
lines changed Original file line number Diff line number Diff 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====================
Original file line number Diff line number Diff 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 ();
Original file line number Diff line number Diff 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-
7574exports [ "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} ;
You can’t perform that action at this time.
0 commit comments