Skip to content

Commit

Permalink
Updated memory raster implementation to use size proportionate to bou…
Browse files Browse the repository at this point in the history
…nds.

Also updated RasterApiBaseTest based on this implementation and updated
RasterDataset javadocs to specify this is the expected behaviour.
  • Loading branch information
jdeolive committed Aug 28, 2015
1 parent 98afa70 commit 195eb50
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 6 deletions.
8 changes: 7 additions & 1 deletion core/src/main/java/io/jeo/data/mem/MemRasterDataset.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,13 @@ public Raster read(RasterQuery query) throws IOException {

Dimension size = query.size();
if (size == null) {
size = size();
// use the size of the query bounds if that is set
if(query.bounds()!=null) {
size = new Dimension(r.width(), r.height());
}
else {
size = size();
}
}
raster.size(size);

Expand Down
3 changes: 2 additions & 1 deletion core/src/main/java/io/jeo/raster/RasterDataset.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ public interface RasterDataset extends Dataset {
* Reads data from the raster into a buffer.
* <p>
* Implementations must handle data type conversion specified by {@link RasterQuery#bands()}
* and image resampling specified by {@link RasterQuery#size()}.
* and image resampling specified by {@link RasterQuery#size()}. When no {@link RasterQuery#size()} is specified
* implementations should create a result proportionate to the size of the requested bounds.
* </p>
* <p>
* The returned buffer should always be in read mode.
Expand Down
32 changes: 28 additions & 4 deletions core/src/test/java/io/jeo/raster/RasterApiTestBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@
*/
public abstract class RasterApiTestBase {

RasterDataset dem;
RasterDataset rgb;
protected RasterDataset dem;
protected RasterDataset rgb;

@Before
public final void setUp() throws Exception {
Expand Down Expand Up @@ -124,8 +124,11 @@ public void testStats() throws IOException {
@Test
public void testRead() throws IOException {
// read all data

ByteBuffer buf = dem.read(new RasterQuery().datatype(DataType.FLOAT)
.bounds(new Envelope(589980.0, 609000.0, 4913700.0, 4928010.0))).data().buffer();
.bounds(new Envelope(589980.0, 609000.0, 4913700.0, 4928010.0)))
//.print(System.out)
.data().buffer();
assertNotNull(buf);

FloatBuffer fb = buf.asFloatBuffer();
Expand All @@ -137,7 +140,28 @@ public void testRead() throws IOException {

// read subset
buf = dem.read(new RasterQuery().datatype(DataType.FLOAT)
.bounds(new Envelope(589980.0, 599490.0, 4920855.0, 4928010.0))).data().buffer();
.bounds(new Envelope(589980.0, 599490.0, 4920855.0, 4928010.0)))
//.print(System.out)
.data().buffer();
assertNotNull(buf);

fb = buf.asFloatBuffer();
assertEquals(25, fb.limit());

assertEquals(1099.0, fb.get(0), 0.1);
assertEquals(1234.0, fb.get(1), 0.1);
assertEquals(1177.0, fb.get(2), 0.1);

assertEquals(1361.0, fb.get(22), 0.1);
assertEquals(1369.0, fb.get(23), 0.1);
assertEquals(1326.0, fb.get(24), 0.1);

// read subset scaled
buf = dem.read(new RasterQuery().datatype(DataType.FLOAT)
.bounds(new Envelope(589980.0, 599490.0, 4920855.0, 4928010.0))
.size(10, 10))
//.print(System.out)
.data().buffer();
assertNotNull(buf);

fb = buf.asFloatBuffer();
Expand Down

0 comments on commit 195eb50

Please sign in to comment.