Skip to content

Instantly share code, notes, and snippets.

@jericks
jericks / Function.groovy
Created November 13, 2010 22:20
A GeoScript Function implementation in Groovy
import geoscript.feature.Field
import org.geotools.factory.CommonFactoryFinder
import org.opengis.filter.expression.Function as GtFunction
import org.geotools.filter.FunctionImpl
import org.opengis.filter.expression.Expression
/**
* A GeoScript Function either wraps an existing GeoTools Function or
* can easily create a new Function by passing in a Closure.
* @author Jared Erickson
@jericks
jericks / GeoScript Groovy Building Geometry Transformations
Created December 9, 2010 04:53
GeoScript Groovy Building Style Geometry Transformations
import geoscript.geom.Bounds
import geoscript.map.Map
import geoscript.workspace.Directory
import geoscript.style.*
import geoscript.filter.Function
def dir = new Directory("/Users/jericks/Downloads/OpenGeo Workshop/data/shp-gs")
def layer = dir.get("nyc_buildings")
layer.style = new Style([
new PolygonSymbolizer(
@jericks
jericks / GeoScript Groovy Geometry Transformation and Formatting
Created December 9, 2010 04:55
GeoScript Groovy Style Geometry Transformation and Formatting
import geoscript.layer.*
import geoscript.proj.*
import geoscript.style.*
import geoscript.map.*
import geoscript.filter.Function
def statesShp = new Shapefile("states.shp")
statesShp.style = new Style([
new PolygonSymbolizer(
@jericks
jericks / transform_clean.groovy
Created March 11, 2012 19:48
layer transformation and cleaning
import geoscript.layer.Shapefile
import geoscript.proj.Projection
import geoscript.feature.Field
def shp = new Shapefile("test_uk.shp")
def out = shp.workspace.create(shp.schema.reproject("EPSG:27700", "test_uk_valid"))
out.add(shp.cursor.collect{f ->
f.geom = Projection.transform(f.geom, "EPSG:4326", "EPSG:27700")
if (!f.geom.isValid()) {
f.geom = f.geom.buffer(0)
@jericks
jericks / BatchWriter.groovy
Created September 23, 2013 03:05
Write batches of Feature to a Layer.
import geoscript.layer.*
import geoscript.feature.*
import geoscript.workspace.*
import org.geotools.data.Transaction
import org.geotools.data.DefaultTransaction
import org.geotools.data.FeatureStore
import org.geotools.data.DataUtilities
/**
@jericks
jericks / FeatureWriter.groovy
Created September 23, 2013 03:06
Write batches of Features using a GeoTools FeatureWriter
import geoscript.layer.*
import geoscript.feature.*
import geoscript.workspace.*
import org.geotools.data.Transaction
import org.geotools.data.DefaultTransaction
import org.geotools.data.FeatureStore
import org.geotools.data.DataUtilities
import org.geotools.data.FeatureWriter as GtFeatureWriter
@jericks
jericks / Writer.groovy
Created October 1, 2013 02:17
geoscript.layer.Writer
package geoscript.layer
import geoscript.feature.Feature
import geoscript.workspace.Directory
import geoscript.workspace.Memory
import org.geotools.data.DataUtilities
import org.geotools.data.DefaultTransaction
import org.geotools.data.FeatureStore
import org.geotools.data.Transaction
import org.geotools.data.collection.ListFeatureCollection
@jericks
jericks / MBTilesFiles.java
Created April 20, 2014 19:28
Auto increment min and max zoom levels when adding tiles to MBTilesFiles
/**
* Store a tile
*
* @throws IOException
*/
public void saveTile(MBTilesTile entry) throws IOException {
try {
Connection cx = connPool.getConnection();
try {
PreparedStatement ps;
import javax.imageio.ImageIO
import java.awt.*
import java.awt.image.*
if (args.length < 2) {
println "Usage: groovy tabs.groovy input.png output.png"
System.exit(-1)
}
String inputFile = args[0]
import geoscript.layer.*
import geoscript.geom.Bounds
import geoscript.proj.Projection
import javax.imageio.ImageIO
MBTiles mbtiles = new MBTiles(new File("geography-class.mbtiles"))
Raster raster = mbtiles.getRaster(mbtiles.tiles(4)).reproject(new Projection("EPSG:4326")).resample(bbox: new Bounds(-180,-90,180,90,"EPSG:4326"), size: [800,400])
ImageIO.write(raster.image, "png", new File("geography-class.png"))