2. What is GeoScript?
• Geospatial Scripting on the JVM
• One API Four Languages
• Python
• JavaScript
• Scala
• Groovy
• Built on the shoulders of giants (GeoTools, JTS)
Friday, September 21, 2012
5. Styling
• geoscript.style module
• Symbolizer and Composite
• Symbolizer
• where: Filter
• range: min and max scale
• zindex: drawing order
• Composite:Two or more Symbolizers
Friday, September 21, 2012
6. Rendering
• geoscript.render module
• Draw and Plot shortcuts
• draw/plot to image, gui, or file
• Map for complicate rendering
• Image, PDF, SVG, GUI outputs
Friday, September 21, 2012
7. Stroke
• Symbolizer for Linear geometries
• color, width, opacity, dash, cap, join, hatch,
shape
1 import geoscript.layer.Shapefile
2 import geoscript.style.Stroke
3 import static geoscript.render.Draw.*
4
5 shp = new Shapefile("states.shp")
6 shp.style = new Stroke("#999999",0.1)
7 draw(shp)
Friday, September 21, 2012
8. Fill
• Symbolizer for Polygon geometries
• color, opacity,hatch,icon
1 import geoscript.layer.Shapefile
2 import geoscript.style.Fill
3 import static geoscript.render.Draw.*
4
5 shp = new Shapefile("states.shp")
6 shp.style = new Fill("wheat",0.5)
7 draw(shp, out: "fill.png")
Friday, September 21, 2012
9. Shape
• Symbolizer for Point geometries
• type, color, size, opacity, rotation, stroke
1 import geoscript.layer.Shapefile
2 import geoscript.style.Shape
3 import static geoscript.render.Draw.*
4
5 shp = new Shapefile("states_centroids.shp")
6 shp.style = new Shape("#008080", 8, "circle", 0.55)
7 draw(shp, out: "shape.png")
Friday, September 21, 2012
10. Icon
• Symbolizer using external files
• url, format (svg, png, gif, jpeg), size
1 import geoscript.layer.Shapefile
2 import geoscript.style.Icon
3 import static geoscript.render.Draw.*
4
5 shp = new Shapefile("states_centroids.shp")
6 shp.style = new Icon("library.svg", "image/svg", 12)
7 draw(shp, out: "icon.png")
Friday, September 21, 2012
11. Composite
• Two or more Symbolizers
• Used to create complicated styles
1 import geoscript.layer.Shapefile
2 import geoscript.style.*
3 import static geoscript.render.Draw.*
4
5 shp = new Shapefile("states.shp")
6 shp.style = new Fill("wheat",0.5) + new Stroke("black",0.2)
7 draw(shp, out: "composite.png")
Friday, September 21, 2012
12. Where
• Apply Symbolizers to some features
• Uses CQL or Common Query Language
1 import geoscript.layer.Shapefile
2 import geoscript.style.*
3 import static geoscript.render.Draw.*
4
5 shp = new Shapefile("states.shp")
6 shp.style = new Stroke("black",0.1) + new Label(property:
"STATE_ABBR", font: new Font(size: 14, family: "Serif"))
7 shp.style += new Fill("#4DFF4D", 0.7).where("PERSONS < 2000000")
8 shp.style += new Fill("#FF4D4D", 0.7).where("PERSONS BETWEEN
2000000 AND 4000000")
9 shp.style += new Fill("#4D4DFF", 0.7).where("PERSONS > 4000000")
10 draw(shp, out: "where.png")
Friday, September 21, 2012
13. Z-index
• Order Symbolizers
1 import geoscript.layer.Shapefile
2 import geoscript.style.Stroke
3 import static geoscript.render.Draw.*
4
5 shp = new Shapefile("states.shp")
6 shp.style = new Stroke("black",2.0).zindex(0) +
new Stroke("white", 0.1).zindex(1)
7 draw(shp, out: "zindex.png")
Friday, September 21, 2012
14. Scale
• Scale dependent styles
1 import geoscript.geom.Bounds
2 import geoscript.layer.Shapefile
3 import geoscript.style.*
4 import static geoscript.render.Draw.*
5
6 shp = new Shapefile("states.shp")
7 shp.style = (new Fill("wheat",0.5) + new Stroke("black",0.2)) + new
Label("STATE_ABBR").font(size:24).range(max: 16000000)
8 draw(shp, out: "scale1.png")
9 draw(shp, out: "scale2.png", bounds: new Bounds(-105, 35, -95, 45))
Friday, September 21, 2012
15. Transform
• Dynamically transform values
• String/Date formatting
1 import geoscript.layer.Shapefile
2 import geoscript.style.*
3 import static geoscript.render.Draw.*
4
5 shp = new Shapefile("states.shp")
6 shp.style = (new Fill("#E6E6E6") + new Stroke("#4C4C4C",0.5)) +
7 (new Shape("#66CCff", 6, "circle").stroke("#004080") + new
Transform("centroid(the_geom)")).zindex(1) +
8 (new Label("STATE_ABBR").font(new Font("normal", "bold", 10,
"serif")).fill(new Fill("#004080")))
9
10 draw(shp, out: "function.png")
Friday, September 21, 2012
16. Expressions
• geoscript.filter module
• Most style properties are Expressions
• Expression, Property, Function, Color
1 import geoscript.layer.Shapefile
2 import geoscript.style.*
3 import geoscript.filter.Function
4 import static geoscript.render.Draw.*
5
6 shp = new Shapefile("states.shp")
7 shp.style = (new Fill("#E6E6E6") + new Stroke("#4C4C4C",0.5)) +
8 (new Label(new Function("strToLowerCase(STATE_ABBR)")).font
(new Font("normal", "bold", 20, "serif")).fill(new Fill("#004080")))
9
10 draw(shp, out: "expression.png")
Friday, September 21, 2012
17. Gradient
1 import geoscript.layer.Shapefile
2 import geoscript.style.*
3 import geoscript.filter.Expression
4 import static geoscript.render.Draw.*
5
6 shp = new Shapefile("states.shp")
7 shp.style = new Gradient(
8 new Expression("PERSONS / LAND_KM"),
9 [0,200],
10 [new Fill("#000066") + new Stroke("black",0.1),
11 new Fill("red") + new Stroke("black", 0.1)],
12 10,
13 "exponential")
14
15 draw(shp, out: "gradient.png")
Friday, September 21, 2012
18. Another Gradient
1 import geoscript.layer.Shapefile
2 import geoscript.style.*
3 import static geoscript.render.Draw.*
4
5 shp = new Shapefile("states.shp")
6 shp.style = new Gradient(shp, "WORKERS", "Quantile", 5, "Greens")
7 draw(shp, out: "gradient2.png")
• Color brewer: geoscript.filter.Color
• getPaletteNames(String type = “all”)
• getPaletteColors(String name, int count = -1)
Friday, September 21, 2012
19. UniqueValues
• Symbolizer for unique values
• colors can be palette name, closure, or list
1 import geoscript.layer.Shapefile
2 import geoscript.style.UniqueValues
3 import static geoscript.render.Draw.*
4
5 shp = new Shapefile("states.shp")
6 shp.style = new UniqueValues(shp, "STATE_ABBR", "Greens")
7 draw(shp, out: "uniquevalues.png")
Friday, September 21, 2012
20. SLD
• The standard way of styling GIS data
• Kind of verbose
• geoscript.style.io module can read and
write SLD
1 import geoscript.layer.Shapefile
2 import geoscript.style.*
3 import geoscript.style.io.*
4 import static geoscript.render.Draw.*
5
6 def style = new Fill("#E6E6E6") + new Stroke("#4C4C4C",0.5)
7 new SLDWriter().write(style, new File("states.sld"))
8
9 shp = new Shapefile("states.shp")
10 shp.style = new SLDReader().read(new File("states.sld"))
11 draw(shp, out: "sld.png")
Friday, September 21, 2012
24. Map
1 import geoscript.layer.Shapefile
2 import geoscript.layer.io.CsvReader
3 import geoscript.style.*
4 import geoscript.render.Map
5
6 def dir = "/Users/jericks/Projects/NaturalEarth/SmallScale"
7
8 def ocean = new Shapefile("${dir}/110m_Physical/110m_ocean.shp")
9 ocean.style = new Fill("#66CCFF")
10
11 def countries = new Shapefile("${dir}/110m_Cultural/110m_admin_0_countries.shp")
12 countries.style = new Stroke("#666666",0.5) + new Fill("#E6E6E6")
13
14 def graticlues = new Shapefile("${dir}/110m_physical/110m_graticules_all/
110m_graticules_30.shp")
15 graticlues.style = new Stroke("#CCCCCC",0.1)
16
17 def bbox = new Shapefile("${dir}/110m_physical/110m_graticules_all/
110m_wgs84_bounding_box.shp")
18 bbox.style = new Stroke("#4C4C4C",0.8)
19
20 def pplaces = new Shapefile("${dir}/110m_cultural/110m_populated_places.shp")
21 pplaces.style = new Shape("#CCCCCC",3,"circle",0.55).stroke("#B3B3B3")
22
Friday, September 21, 2012
25. 23 def earthquakes = new CsvReader("Lon","Lat").read(
24 new URL("http://earthquake.usgs.gov/earthquakes/catalogs/eqs7day-
M2.5.txt").text
25 )
26 earthquakes.style = (new Shape("#FF6666", 4, "circle").stroke("#8000000",
0.1)).where("Magnitude < 3")
27 earthquakes.style += (new Shape("#FF6666", 6, "circle").stroke("#8000000",
0.1)).where("Magnitude BETWEEN 3 AND 6")
28 earthquakes.style += (new Shape("#FF6666", 10, "circle").stroke("#8000000",
0.1)).where("Magnitude > 6")
29
30 def map = new Map(layers: [ocean,countries,graticlues,bbox,pplaces,earthquakes])
31 map.render(new File("map.png"))
Map...
Friday, September 21, 2012
26. PDF
1 import geoscript.layer.Shapefile
2 import geoscript.style.*
3 import geoscript.render.*
4
5 shp = new Shapefile("states.shp")
6 shp.style = new Fill("wheat",0.5) + new Stroke("black",0.2)
7 Map map = new Map(layers:[shp])
8 Pdf pdf = new Pdf()
9 pdf.render(map, new FileOutputStream(new File("map.pdf")))
Friday, September 21, 2012
27. SVG
1 import geoscript.layer.Shapefile
2 import geoscript.style.*
3 import static geoscript.render.Draw.*
4
5 shp = new Shapefile("states.shp")
6 shp.style = new Fill("wheat",0.5) + new Stroke("black",
0.2)
7 draw(shp, out: "map.svg", format: "svg")
Friday, September 21, 2012
28. Uses
• Quickly view results of analysis
• Preview & Create SLD
• Creating map series
• Simple WMS/TMS/WMST services
• UTF-8, MBTiless
Friday, September 21, 2012