This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# use JTS to find the linear distance along a line a given point falls | |
@Grab(group='com.vividsolutions',module='jts',version='1.12') | |
import com.vividsolutions.jts.io.WKTReader | |
import com.vividsolutions.jts.geom.Geometry | |
import com.vividsolutions.jts.linearref.LengthIndexedLine | |
import com.vividsolutions.jts.geom.Coordinate | |
WKTReader reader = new WKTReader() | |
Geometry geom = reader.read('LINESTRING(10 10, 30 10)') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# densify a line, adding vertices at a specified interval | |
@Grab(group='com.vividsolutions',module='jts',version='1.12') | |
import com.vividsolutions.jts.io.WKTReader | |
import com.vividsolutions.jts.geom.Geometry | |
import com.vividsolutions.jts.densify.Densifier | |
import com.vividsolutions.jts.geom.GeometryFactory | |
import com.vividsolutions.jts.geom.PrecisionModel | |
PrecisionModel precisionModel = new PrecisionModel(PrecisionModel.FIXED) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* calculates the distance between two points using the Spherical Law of Cosines. | |
* returned distance in miles, input points expected to be in signed decimal | |
* degrees. | |
* WARNING: returns incorrect values if longitudes in different hemispheres | |
*/ | |
f8unction geographicalDistance(lon1,lat1,lon2,lat2) { | |
//convert to radians | |
var ct = Math.PI/180.0; | |
lon1 *= ct; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env groovy | |
import javax.mail.internet.MimeBodyPart | |
import javax.mail.internet.MimeMultipart | |
import javax.activation.URLDataSource | |
def address = "http://example.com/cgi-bin/public/ms/gcv4/F16_2010_blended.lzw.tif?request=GetCoverage&service=WCS&version=1.1.1&COVERAGE=F16_2010_blended.lzw.tif&crs=EPSG:4326&format=geotiff&resx=0.0083333333&resy=0.0083333333&bbox=-95,25,-75,40" | |
def url = address.toURL() | |
HttpURLConnection connection = url.openConnection() | |
URLDataSource dataSource = new URLDataSource(url) | |
MimeMultipart multipart = new MimeMultipart(dataSource) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def roundDown(Double value, Integer interval) { | |
if (interval == null || interval <= 0) { | |
throw new IllegalArgumentException("Interval must be > 0") | |
} | |
return Math.floor(value/interval)*interval | |
} | |
def Integer roundUp(Double value, Integer interval) { | |
if (interval == null || interval <= 0) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.vividsolutions.jts.geom.Geometry | |
import com.vividsolutions.jts.io.WKTReader | |
def WKTReader wktReader = new WKTReader() | |
def clip = wktReader.read("POLYGON((-10 -10, 10 -10, 10 10, -10 10,-10 -10))") | |
def line = wktReader.read("MULTILINESTRING((-15 -20, 15 20),(9 -30, 9 30))") | |
//def line = wktReader.read("MULTILINESTRING((-15 -20, 15 20))") | |
//def line = wktReader.read("MULTILINESTRING((0 -20, 0 20),(2 -30, 2 30))") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def String getWmsUrl(url) { | |
def parser = new org.cyberneko.html.parsers.SAXParser() | |
parser.setFeature('http://xml.org/sax/features/namespaces', false) | |
def page = new XmlParser(parser).parse("${url}/MapServer?f=html") | |
def data = page.depthFirst().A.'@href'.grep{ it != null && it.endsWith('WMS') } | |
if (data) { | |
return data[0] | |
} else { | |
return null | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ucar.nc2.dataset.NetcdfDataset | |
import ucar.nc2.dt.GridCoordSystem | |
//import org.apache.log4j.* | |
//Logger log = Logger.getInstance("netcdf") | |
String filename = "http://motherlode.ucar.edu:8080/thredds/dodsC/fmrc/NCEP/GFS/CONUS_80km/runs/NCEP-GFS-CONUS_80km_RUN_2011-03-20T18:00:00Z.nc" | |
//http://motherlode.ucar.edu:8080/thredds/dodsC/model/NCEP/GFS/CONUS_80km/GFS_CONUS_80km_20061019_0000.grib1"; | |
NetcdfDataset ncd = null; | |
try { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ucar.nc2.NetcdfFile | |
import ucar.nc2.dataset.NetcdfDataset | |
String filename = "/Users/jcc/testme.grd"; | |
def NetcdfFile ncfile = null; | |
try { | |
ncfile = NetcdfFile.open(filename) | |
def minZ = ncfile.findVariable("z").findAttribute("actual_range").getValue(0) | |
def maxZ = ncfile.findVariable("z").findAttribute("actual_range").getValue(1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.vividsolutions.jts.linearref.LengthIndexedLine | |
import com.vividsolutions.jts.io.WKTReader | |
def reader = new WKTReader() | |
def line = reader.read("LINESTRING(10 10, -10 -10)") | |
def lil = new LengthIndexedLine(line) | |
def increment = 2 |
OlderNewer