Skip to content

Commit 32f531e

Browse files
committed
Add map cube command.
1 parent 2a13b59 commit 32f531e

File tree

5 files changed

+146
-1
lines changed

5 files changed

+146
-1
lines changed

examples/map_cube.txt

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
download --url https://www.naturalearthdata.com/http//www.naturalearthdata.com/download/110m/cultural/ne_110m_admin_0_countries.zip --file countries.zip --overwrite false
2+
3+
unzip --file countries.zip --directory countries
4+
5+
download --url https://www.naturalearthdata.com/http//www.naturalearthdata.com/download/110m/physical/ne_110m_ocean.zip --file ocean.zip --overwrite false
6+
7+
unzip --file ocean.zip --directory ocean
8+
9+
workspace open --name countries --params countries/ne_110m_admin_0_countries.shp
10+
11+
layer open --workspace countries --layer ne_110m_admin_0_countries
12+
13+
workspace open --name ocean --params ocean/ne_110m_ocean.shp
14+
15+
layer open --workspace ocean --layer ne_110m_ocean
16+
17+
style create --params "fill=#ffffff fill-opacity=1.0 stroke=#b2b2b2 stroke-width=0.5" --file countries.sld
18+
19+
style create --params "fill=#a5bfdd fill-opacity=1.0" --file ocean.sld
20+
21+
layer style set --name countries:ne_110m_admin_0_countries --style countries.sld
22+
23+
layer style set --name ocean:ne_110m_ocean --style ocean.sld
24+
25+
map open --name world
26+
27+
map add layer --name world --layer ocean:ne_110m_ocean
28+
29+
map add layer --name world --layer countries:ne_110m_admin_0_countries
30+
31+
map cube --name world --draw-tabs true --draw-outline true --title World --source "Natural Earth"
32+
33+
map close --name world
34+
35+
open --file image.png

src/main/docs/map.adoc

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,4 +388,44 @@ include::output/map_display_7_result.txt[]
388388
include::output/map_display_8_command.txt[]
389389
include::output/map_display_8_result.txt[]
390390

391-
image::map_display.png[]
391+
image::map_display.png[]
392+
393+
=== Map Cube
394+
395+
include::commands/map_cube_description.txt[]
396+
397+
include::output/map_cube_8_command.txt[]
398+
399+
include::commands/map_cube.txt[]
400+
401+
include::output/map_cube_0_command.txt[]
402+
include::output/map_cube_0_result.txt[]
403+
404+
include::output/map_cube_1_command.txt[]
405+
include::output/map_cube_1_result.txt[]
406+
407+
include::output/map_cube_2_command.txt[]
408+
include::output/map_cube_2_result.txt[]
409+
410+
include::output/map_cube_3_command.txt[]
411+
include::output/map_cube_3_result.txt[]
412+
413+
include::output/map_cube_4_command.txt[]
414+
include::output/map_cube_4_result.txt[]
415+
416+
include::output/map_cube_5_command.txt[]
417+
include::output/map_cube_5_result.txt[]
418+
419+
include::output/map_cube_6_command.txt[]
420+
include::output/map_cube_6_result.txt[]
421+
422+
include::output/map_cube_7_command.txt[]
423+
include::output/map_cube_7_result.txt[]
424+
425+
include::output/map_cube_8_command.txt[]
426+
include::output/map_cube_8_result.txt[]
427+
428+
include::output/map_cube_9_command.txt[]
429+
include::output/map_cube_9_result.txt[]
430+
431+
image::map_cube.png[]

src/main/groovy/org/geoshell/map/MapCommands.groovy

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package org.geoshell.map
22

33
import geoscript.geom.Bounds
44
import geoscript.proj.Projection
5+
import geoscript.render.MapCube
56
import geoscript.render.MapWindow
67
import geoscript.render.Window
78
import org.geoshell.Catalog
@@ -197,4 +198,33 @@ class MapCommands implements CommandMarker {
197198
"Unable to find Map ${name}"
198199
}
199200
}
201+
202+
@CliCommand(value = "map cube", help = "Draw a map cube.")
203+
String renderMapCube(
204+
@CliOption(key = "name", mandatory = true, help = "The map name") MapName name,
205+
@CliOption(key = "draw-outline", mandatory = false, specifiedDefaultValue = "false", unspecifiedDefaultValue = "false", help = "Whether to draw outline or now") boolean drawOutline,
206+
@CliOption(key = "draw-tabs", mandatory = false, specifiedDefaultValue = "false", unspecifiedDefaultValue = "false", help = "Whether to draw tabs or not") boolean drawTabs,
207+
@CliOption(key = "tab-size", mandatory = false, unspecifiedDefaultValue = "30", specifiedDefaultValue = "30", help = "The size of the tabs") int tabSize,
208+
@CliOption(key = "title", mandatory = false, unspecifiedDefaultValue = "", specifiedDefaultValue = "", help = "The map title") String title,
209+
@CliOption(key = "source", mandatory = false, unspecifiedDefaultValue = "", specifiedDefaultValue = "", help = "The map source") String source,
210+
@CliOption(key = "type", mandatory = false, unspecifiedDefaultValue = "png", specifiedDefaultValue = "png", help = "The type") String type,
211+
@CliOption(key = "file", mandatory = false, help = "The file") File file
212+
) throws Exception {
213+
org.geoshell.map.Map map = catalog.maps[name]
214+
if (map) {
215+
MapCube mapCube = new MapCube(
216+
drawOutline: drawOutline,
217+
drawTabs: drawTabs,
218+
tabSize: tabSize,
219+
title: title,
220+
source: source,
221+
imageType: type
222+
)
223+
file = file ? file : new File("image.${type}")
224+
mapCube.render(map.getLayers(), file)
225+
"Done drawing ${file.absolutePath}!"
226+
} else {
227+
"Unable to find Map ${name}"
228+
}
229+
}
200230
}

src/test/groovy/org/geoshell/docs/MapDocTest.groovy

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,4 +158,21 @@ class MapDocTest extends AbstractDocTest {
158158
copyFile(new File("examples/map_draw.png"), new File("src/main/docs/images"))
159159
}
160160

161+
@Test
162+
void mapCube() {
163+
run("map_cube", [
164+
"map open --name world",
165+
"workspace open --name naturalearth --params examples/naturalearth.gpkg",
166+
"layer open --workspace naturalearth --layer countries --name countries",
167+
"layer style set --name countries --style examples/countries.sld",
168+
"layer open --workspace naturalearth --layer ocean --name ocean",
169+
"layer style set --name ocean --style examples/ocean.sld",
170+
"map add layer --name world --layer ocean",
171+
"map add layer --name world --layer countries",
172+
"map cube --name world --file examples/map_cube.png --title World --source NaturalEarth --draw-tabs true --draw-outline true",
173+
"map close --name world"
174+
])
175+
copyFile(new File("examples/map_cube.png"), new File("src/main/docs/images"))
176+
}
177+
161178
}

src/test/groovy/org/geoshell/map/MapCommandsTest.groovy

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,4 +140,27 @@ class MapCommandsTest {
140140
assertTrue result.endsWith("map.png!")
141141
}
142142

143+
@Test void drawMapCube() {
144+
Layer layer = new Shapefile(new File(getClass().getClassLoader().getResource("grid.shp").toURI()))
145+
Catalog catalog = new Catalog()
146+
catalog.layers[new LayerName("grid")] = layer
147+
148+
MapCommands cmds = new MapCommands(catalog: catalog)
149+
cmds.open(new MapName("grid"))
150+
cmds.addLayer(new MapName("grid"), new LayerName("grid"), null)
151+
File file = new File(folder, "mapcube.png")
152+
String result = cmds.renderMapCube(
153+
new MapName("grid"),
154+
true,
155+
true,
156+
30,
157+
"World Grid",
158+
"Natural Earth",
159+
"png",
160+
file
161+
)
162+
assertTrue result.startsWith("Done drawing")
163+
assertTrue result.endsWith("mapcube.png!")
164+
}
165+
143166
}

0 commit comments

Comments
 (0)