This document summarizes GeoScript, an open source library that provides spatial capabilities for scripting languages like Groovy, JavaScript, Python, Scala, and others. GeoScript allows users to work with geospatial data and perform operations like geometry processing, styling, projections, and data access in a scripting language of their choice. It builds on the GeoTools library but aims to be easier to use for rapid script development. The document outlines GeoScript modules for geometry, projections, data access layers, styling, and includes code examples in various languages.
18. Geometry - Visualization js> var geom = require("geoscript/geom") js> require("geoscript/viewer").bind() js> var poly1 = geom.Point([0, 0]).buffer(1) js> var poly2 = poly1.transform({dx: 0.5, dy: 0.5}) js> poly1.difference(poly2) <Polygon [[[0.9095298326166407, -0.409529...>
19.
20. Projection js> var proj = require("geoscript/proj"); js> var p = proj.Projection("epsg:4326"); js> p.wkt GEOGCS["WGS 84", DATUM["World Geodetic System 1984", ...
21. Projection >>> from geoscript import geom >>> from geoscript.proj import Projection >>> p = Projection('epsg:4326') >>> p.transform((-111, 45.7), 'epsg:26912') (500000.0, 5060716.313515949) >>> g = geom.Point(0, 0).buffer(4) >>> g = reduce(lambda x,y:x.union(y),[geom.transform(g,dx=x,dy=y) for x,y in [(3,0),(0,3),(-3,0),(0,-3)]]) >>> p.transform(g, 'epsg:26912') >>> p.transform(g, 'epsg:3005') Reprojection WGS 84 UTM Albers
22.
23. Data Access - Workspace js> var ws = require("geoscript/workspace"); js> var dir = ws.Directory("data"); js> dir <Directory ["states"]> js> var states = dir.get("states"); js> states <Layer name: states, count: 49>
24. Data Access - Workspace >> from geoscript.workspace import PostGIS >> pg = PostGIS('spearfish') >> pg.layers() ['archsites', 'bugsites', ..., 'streams'] >> l = pg['archsites']
25. Data Access - Workspace >>> import geoscript.workspace.H2 >>> import geoscript.geom.Point >>> import geoscript.feature.Feature >>> h2 = new H2("name", "path") >>> layer = h2.create("points", [ new Field("geom","Point"), new Field("name","String") ]) >>> layer.add([new Point[1,1],"one"])
26. Data Access - Layers >>> from geoscript.layer import Shapefile >>> states = Shapefile('states.shp') >>> states = states.reproject('epsg:3005')
31. Styling - Fill >>> import geoscript.style.Fill >>> new Fill("gray") >>> new Fill("gray", 0.5)) >>> new Fill("gray").hatch("backslash") >>> new Stroke("red",2) + new Fill("gray").hatch("times")
49. Geometry Web Services Open Layers function centroid() { var features = vectorLayer.features; if (features.length == 0) { alert("Please add some features!"); } else { OpenLayers.loadURL('centroid', { geom: wktFormat.write(features) }, this, function(request) { var wkt = request.responseText; var features = wktFormat.read(wkt); if (features) vectorLayer.addFeatures(features); }, function() { alert("Error calculating centroids!"); } ); } }
50.
51. WMS Server... import geoscript.map.Map import geoscript.style.* import geoscript.layer.Shapefile import geoscript.geom.Bounds def file = new File("states.shp") def shp = new Shapefile(file) shp.style = new Fill("steelblue") + new Stroke("wheat", 0.1) def map = new Map( width: 256, height: 256, layers: [shp], proj: shp.proj, fixAspectRatio: false ) def bbox = request.getParameter("BBOX").split(",") def bounds = new Bounds(bbox[0] as double, bbox[1] as double, bbox[2] as double, bbox[3] as double) map.bounds = bounds response.contentType = "image/png" map.render(response.outputStream) map.close()