Skip to content

Commit

Permalink
Moved printRaster to Raster class for better availability.
Browse files Browse the repository at this point in the history
  • Loading branch information
jdeolive committed Aug 28, 2015
1 parent d1d02aa commit 98afa70
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 20 deletions.
27 changes: 27 additions & 0 deletions core/src/main/java/io/jeo/raster/Raster.java
Expand Up @@ -18,6 +18,7 @@
import io.jeo.util.Dimension;
import org.osgeo.proj4j.CoordinateReferenceSystem;

import java.io.PrintStream;
import java.util.List;

/**
Expand Down Expand Up @@ -147,4 +148,30 @@ public Raster nodata(NoData nodata) {
this.nodata = nodata;
return this;
}

/**
* Prints out the values of the raster in column row order.
* <p>
* This method is meant for debugging purposes and really only suitable for very
* small rasters.
* </p>
*/
public Raster print(PrintStream out) {
int idx = 0;
int w = size().width();
int h = size().height();

DataBuffer data = data();
for(int x=0; x<w; x++) {
out.print( x+"> \t");
for(int y=0; y<h; y++) {
Object v = data.get(idx++);
out.print( v + "\t");
}
out.println();
}

data.buffer().rewind();
return this;
}
}
22 changes: 2 additions & 20 deletions format/gdal/src/test/java/io/jeo/gdal/GDALTest.java
Expand Up @@ -76,23 +76,6 @@ public void testReadRaster() throws Exception {
ds.ReadRaster_Direct(0, 0, 1, 1, 1, 1, gdalconst.GDT_Float32, buf, null);
}

/**
* I'm not sure what the right X,Y order is... for the sample square image, it does not matter :)
*/
private void printRaster(Raster out) {
int idx = 0;
int w = out.size().width();
int h = out.size().height();
for(int x=0; x<w; x++) {
System.out.print( x+"> \t");
for(int y=0; y<h; y++) {
Object v = out.data().get(idx++);
System.out.print( v + "\t");
}
System.out.println();
}
}

@Test
public void testQuerySmallerRaster() throws Exception {

Expand All @@ -101,7 +84,7 @@ public void testQuerySmallerRaster() throws Exception {
Raster wholeimage = ds.read(new RasterQuery());
int count = wholeimage.data().size();
assertEquals(count, (ds.size().width()*ds.size().height()));
//printRaster(wholeimage);
//wholeimage.print(System.out);

// This is a smaller area
Bounds smaller = ds.bounds().scale(0.5);
Expand All @@ -118,7 +101,6 @@ public void testQuerySmallerRaster() throws Exception {
assertEquals("should be half",
(Integer)new Double(wholeimage.size().width()*.5).intValue(),
(Integer)halfsize.size().width());

//printRaster(halfsize);
//halfsize.print(System.out);
}
}

0 comments on commit 98afa70

Please sign in to comment.