Skip to content

Commit f134f6a

Browse files
committed
Add a few Raster examples.
1 parent b9ab8b8 commit f134f6a

File tree

4 files changed

+64
-0
lines changed

4 files changed

+64
-0
lines changed

examples/raster_crop.groovy

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import geoscript.layer.*
2+
import geoscript.geom.Bounds
3+
import geoscript.proj.Projection
4+
5+
// Read
6+
def geoTiffFormat = new GeoTIFF()
7+
def raster = geoTiffFormat.read(new File("raster.tif"), new Projection("urn:ogc:def:crs:EPSG::EPSG:4326"))
8+
9+
// Crop
10+
def croppedRaster = raster.crop(new Bounds(-10, -10, 10, 10, raster.proj))
11+
println croppedRaster.bounds
12+
println croppedRaster.proj.id
13+
println croppedRaster.size
14+
15+
// Write
16+
geoTiffFormat.write(croppedRaster, new File("raster_cropped.tif"))

examples/raster_getvalue.groovy

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import geoscript.geom.Geometry
2+
import geoscript.layer.*
3+
import geoscript.geom.Bounds
4+
import geoscript.proj.Projection
5+
6+
// Read
7+
def geoTiffFormat = new GeoTIFF()
8+
def raster = geoTiffFormat.read(new File("raster.tif"), new Projection("urn:ogc:def:crs:EPSG::EPSG:4326"))
9+
10+
def multiPoint = Geometry.createRandomPoints(new Bounds(-180,-90,180,80).geometry, 10)
11+
multiPoint.points.eachWithIndex{pt,i ->
12+
def value = raster.getValue(pt)
13+
println "${i}). ${value} at ${pt}"
14+
}

examples/raster_info.groovy

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import geoscript.layer.*
2+
3+
// Read a GeoTIFF
4+
def format = new GeoTIFF()
5+
def raster = format.read(new File("raster.tif"))
6+
7+
// Print some information
8+
println "Format = ${raster.format}"
9+
println "Proj EPSG = ${raster.proj.id}"
10+
println "Proj WKT = ${raster.proj.wkt}"
11+
println "Bounds = ${raster.bounds.geometry.wkt}"
12+
println "Size = ${raster.size}"
13+
println "Block Size = ${raster.blockSize}"
14+
println "Pixel Size = ${raster.pixelSize}"
15+
println "Band:"
16+
raster.bands.eachWithIndex{b,i ->
17+
println " ${i}). ${b}"
18+
}
19+
20+
21+

examples/raster_read_write.groovy

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import geoscript.layer.*
2+
3+
// Read
4+
def geoTiffFormat = new GeoTIFF()
5+
def raster = geoTiffFormat.read(new File("raster.tif"))
6+
7+
// Write
8+
def pngFormat = new WorldImage()
9+
pngFormat.write(raster, new File("raster.png"))
10+
11+
// Read
12+
def pngRaster = pngFormat.read(new File("raster.png"))
13+
println pngRaster.format

0 commit comments

Comments
 (0)