# GeoScript

## Monday, June 14, 2010

### Calculating Convex Hull and Minimum Bounding Circle with Groovy

The Java Topology Suite, which Groovy GeoScript wraps, contains spatial operators that act on a group of Features or Geometries. In this post, I collect all geometries from a shapefile to calculate the convex hull and minimum bounding circle. This post builds on previous blog entries where I use GeoScript to extract centroids and buffer Features.

Convex Hull
`// Import GeoScript modulesimport geoscript.layer.*import geoscript.feature.*import geoscript.geom.*// Get the shapefileShapefile shp = new Shapefile('states_centroids.shp');// Create a new SchemaSchema schema = new Schema('states_convex_hull', [['the_geom','Polygon','EPSG:4326']])// Create our new LayerLayer layer = shp.workspace.create(schema)// Collect the GeometriesList geoms = shp.features.collect{f->f.geom}// Create a GeometryCollection from the List of GeometriesGeometryCollection geomCol = new GeometryCollection(geoms)// Get the Convex Hull from the GeometryCollectionGeometry convexHullGeom = geomCol.convexHull// Add the Convex Hull Geometry as a Featurelayer.add(schema.feature([convexHullGeom]))` Minimum Bounding Circle
`// Import GeoScript modulesimport geoscript.layer.*import geoscript.feature.*import geoscript.geom.*// Get the ShapefileShapefile shp = new Shapefile('states_centroids.shp')// Create a new SchemaSchema schema = new Schema('states_minimum_bounding_circle', [['the_geom','Polygon','EPSG:4326']])// Create the new LayerLayer layer = shp.workspace.create(schema)// Collect Geometries from the ShapefileList geoms = shp.features.collect{f->f.geom}// Create a GeometryCollection from the List of GeometriesGeometryCollection geomCol = new GeometryCollection(geoms)// Get the Minimum Bounding Circle from the GeometryCollectionGeometry circleGeom = geomCol.minimumBoundingCircle// Add the Minimum Bounding Circle Geometry as a Featurelayer.add(schema.feature([circleGeom]))` #### 2 comments:

1. Jared (or anyone for that matter),

Are you aware of any implementations of the Douglas-Peucker or Lang Simplification algorithms in Groovy? Alternatively what about Java? I can port one over from C++ or other language but I'd hate to reinvent the wheel! TIA for any help.

2. Succeed! It could be one of the most useful blogs we have ever come across on the subject. Excellent info! I’m also an expert in this topic so I can understand your effort very well. Thanks for the huge help. バウンディング

## Introducing GeoScript

GeoScript adds geo capabilities to dynamic scripting languages such as JavaScript, Python, Scala and Groovy.