Skip to content

Commit

Permalink
Add raster crop with geometry recipe
Browse files Browse the repository at this point in the history
  • Loading branch information
jericks committed Sep 17, 2023
1 parent 09b23a6 commit 5a4f6ee
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
17 changes: 14 additions & 3 deletions src/main/docs/raster.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,9 @@ include::output/geoc_raster_contour_command.txt[]
[.thumb]
image::geoc_raster_contour_command.png[]

=== Crop
=== Crop with Bounds

Crop a Raster.
Crop a Raster with Bounds.

include::output/geoc_raster_crop_options.txt[]

Expand All @@ -195,8 +195,19 @@ include::output/geoc_raster_crop_options.txt[]
include::output/geoc_raster_crop_command.txt[]
----

=== Crop with Geometry

Crop a Raster with Geometry.

include::output/geoc_raster_crop_with_geometry_options.txt[]

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

[.thumb]
image::geoc_raster_crop_command.png[]
image::geoc_raster_crop_with_geometry_command.png[]

=== Envelope

Expand Down
27 changes: 26 additions & 1 deletion src/test/groovy/org/geocommands/doc/RasterTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class RasterTest extends DocTest {
}

@Test
void crop() {
void cropWithBounds() {
String command = "geoc raster crop -i src/test/resources/earth.tif -b -160.927734,6.751896,-34.716797,57.279043 -o target/earth_cropped.tif"
String result = runApp(command, "")
writeTextFile("geoc_raster_crop_command", command)
Expand All @@ -138,6 +138,31 @@ class RasterTest extends DocTest {
drawOnBasemap("geoc_raster_crop_command", [raster])
}

@Test
void cropWithGeometry() {
List commands = [
"raster",
"crop",
"with",
"geometry",
"-i",
"src/test/resources/earth.tif",
"-g",
"POLYGON ((-120.06886118446164 54.657570186377484, -131.4744345802818 40.88641840854305, -120.66873293244274 27.841500134049014, -91.23852896646747 22.376168381822453, -75.66538001484537 23.99772020337508, -54.66444615739175 45.994788780815526, -91.94198075352523 53.20175611636799, -120.06886118446164 54.657570186377484))",
"-o",
"target/earth_cropped.tif"
]
String command = "geoc " + commands.collect{
it.startsWith("POLYGON") ? '"' + it + '"' : it
}.join(" ")
String result = runApp(commands, "")
writeTextFile("geoc_raster_crop_with_geometry_command", command)
writeTextFile("geoc_raster_crop_with_geometry_command_output", result)

Raster raster = new GeoTIFF(new File("target/earth_cropped.tif")).read()
drawOnBasemap("geoc_raster_crop_with_geometry_command", [raster])
}

@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 5a4f6ee

Please sign in to comment.