Skip to content

Commit

Permalink
Add raster crop with layer recipe
Browse files Browse the repository at this point in the history
  • Loading branch information
jericks committed Sep 19, 2023
1 parent 5a4f6ee commit 4fb0f96
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/main/docs/raster.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,30 @@ include::output/geoc_raster_crop_with_geometry_command.txt[]
[.thumb]
image::geoc_raster_crop_with_geometry_command.png[]

=== Crop with Layer

Crop a Raster with a Layer.

include::output/geoc_raster_crop_with_layer_options.txt[]

[source,bash]
----
include::output/geoc_raster_crop_with_layer_random_points_command.txt[]
----

[source,bash]
----
include::output/geoc_raster_crop_with_layer_buffer_command.txt[]
----

[source,bash]
----
include::output/geoc_raster_crop_with_layer_command.txt[]
----

[.thumb]
image::geoc_raster_crop_with_layer_command.png[]

=== Envelope

Get the Envelope of a Raster as a Vector Layer.
Expand Down
29 changes: 29 additions & 0 deletions src/test/groovy/org/geocommands/doc/RasterTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import geoscript.style.ColorMap
import geoscript.style.Label
import geoscript.style.Stroke
import geoscript.style.Style
import geoscript.style.io.SimpleStyleReader
import org.junit.jupiter.api.Test

class RasterTest extends DocTest {
Expand Down Expand Up @@ -163,6 +164,34 @@ class RasterTest extends DocTest {
drawOnBasemap("geoc_raster_crop_with_geometry_command", [raster])
}

@Test
void cropWithLayer() {

// Random Points
String randomCommand = "geoc vector randompoints -n 10 -g -180,-90,180,90 -o target/locations.shp"
println runApp(randomCommand, "")
writeTextFile("geoc_raster_crop_with_layer_random_points_command", randomCommand)

// Buffer Points
String bufferCommand = "geoc vector buffer -d 10 -i target/locations.shp -o target/buffers.shp"
println runApp(bufferCommand, "")
writeTextFile("geoc_raster_crop_with_layer_buffer_command", bufferCommand)

// Crop
String command = "geoc raster crop with layer -i src/test/resources/earth.tif -o target/earth_cropped.tif -w target/buffers.shp"
String result = runApp(command, "")
writeTextFile("geoc_raster_crop_with_layer_command", command)
writeTextFile("geoc_raster_crop_with_layer_command_output", result)

// Create Map
Raster raster = new GeoTIFF(new File("target/earth_cropped.tif")).read()
Layer pointsLayer = new Shapefile("target/locations.shp")
pointsLayer.style = new SimpleStyleReader().read("shape-type=circle shape-size=6 shape=red")
Layer bufferLayer = new Shapefile("target/buffers.shp")
bufferLayer.style = new SimpleStyleReader().read("stroke=red stroke-width=2.5")
drawOnBasemap("geoc_raster_crop_with_layer_command", [bufferLayer, raster, pointsLayer])
}

@Test
void contour() {
String command = "geoc raster contour -i src/test/resources/pc.tif -b 0 -v 300 -s -m -o target/contours.shp"
Expand Down

0 comments on commit 4fb0f96

Please sign in to comment.