/** * Created by IntelliJ IDEA. * User: sbortman * Date: Jun 12, 2008 * Time: 1:48:33 PM * To change this template use File | Settings | File Templates. */ import java.text.SimpleDateFormat; import org.hibernate.criterion.Restrictions import org.hibernate.criterion.Criterion import joms.oms.CoordinateUtility import joms.oms.Init; import joms.oms.WktUtility; import joms.oms.ossimUnitType; import joms.oms.ossimGpt; class VideoDataSetQuery { public static final String RADIUS_SEARCH = "RADIUS" public static final String BBOX_SEARCH = "BBOX" String searchMethod = RasterEntryQuery.BBOX_SEARCH String aoiMaxLat String aoiMinLon String aoiMinLat String aoiMaxLon Date startDate Date endDate String centerLon String centerLat String viewMaxLat String viewMinLon String viewMinLat String viewMaxLon String aoiRadius List searchTagNames = ["", "", "", "", "", "", "", ""] List searchTagValues = ["", "", "", "", "", "", "", ""] CoordinateUtility coordUtil = new CoordinateUtility() WktUtility wktUtil = new WktUtility() def createClause() { IntersectsExpression intersects = createIntersection() Criterion range = createDateRange() def clause = null if ( intersects && range ) { clause = Restrictions.and(intersects, range) } else { if ( intersects ) { clause = intersects } else if ( range ) { clause = range } } return clause } private def createDateRange() { def range = null // Change the time portion of the end date // to be the end of the day. 23:59:59.999 if ( endDate ) { def cal = Calendar.instance cal.time = endDate cal.set(Calendar.HOUR, 23) cal.set(Calendar.MINUTE, 59) cal.set(Calendar.SECOND, 59) cal.set(Calendar.MILLISECOND, 999) endDate = cal.time } if ( startDate && endDate ) { range = Restrictions.or( Restrictions.between("startDate", startDate, endDate), Restrictions.between("endDate", startDate, endDate) ) } else { if ( startDate ) { range = Restrictions.ge("endDate", startDate) } else if ( endDate ) { range = Restrictions.le("startDate", endDate) } } return range } private IntersectsExpression createIntersection() { def intersects = null def srs = "4326" def wkt = null def bounds = null switch ( searchMethod ) { case BBOX_SEARCH: if ( aoiMaxLat && aoiMinLon && aoiMinLat && aoiMaxLon ) { aoiMaxLat = convertToDecimalDegrees(aoiMaxLat) aoiMaxLon = convertToDecimalDegrees(aoiMaxLon) aoiMinLat = convertToDecimalDegrees(aoiMinLat) aoiMinLon = convertToDecimalDegrees(aoiMinLon) wkt = Geometry.createPolygon( aoiMinLon, aoiMinLat, aoiMaxLon, aoiMaxLat ) } break case RADIUS_SEARCH: if ( centerLon && centerLat && aoiRadius ) { centerLat = convertToDecimalDegrees(centerLat) centerLon = convertToDecimalDegrees(centerLon) def centerGpt = new ossimGpt(Double.valueOf(centerLat), Double.valueOf(centerLon)); double radius = Double.valueOf(aoiRadius); def unitType = ossimUnitType.OSSIM_METERS wkt = wktUtil.toWktPolygonGivenCenterRadius(centerGpt, radius, unitType, 360, -1) } break } if ( wkt ) { //println wkt bounds = Geometry.fromString("SRID=${srs};${wkt}") //println bounds intersects = new IntersectsExpression("groundGeom", bounds) } return intersects } String convertToDecimalDegrees(String input) { def dms = ~/\d{1,3}\s*\d{2}\s*\d{2}(\.\d+)?\s*[NnSsEeWw]$/ def dd = ~/^-?\d{1,3}(\.\d+)?$/ String output = null //println "convertToDecimalDegrees -> input: ${input}" switch ( input ) { case dms: def parseDMS = /^(\d{1,3})\s*(\d{2})\s*(\d{2}(\.\d+)?)\s*([NnSsEeWw])$/ def match = input =~ parseDMS def degrees = match[0][1] def minutes = match[0][2] def seconds = match[0][3] def hemisphere = match[0][5] def newInput = "${degrees} ${minutes} ${seconds} ${hemisphere}" //println newInput output = coordUtil.dmsToDegrees(newInput) break case dd: //println "DD" output = input break default: output = null } //println "convertToDecimalDegrees <- output: ${output}" return output } def toMap() { SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss"); String startDateText = (startDate) ? formatter.format(startDate) : ""; String endDateText = (endDate) ? formatter.format(endDate) : ""; def data = [ aoiMaxLat: aoiMaxLat, aoiMinLon: aoiMinLon, aoiMinLat: aoiMinLat, aoiMaxLon: aoiMaxLon, startDate: startDateText, endDate: endDateText, centerLat: centerLat, centerLon: centerLon, aoiRadius: aoiRadius, searchMethod: searchMethod, viewMaxLat: viewMaxLat, viewMinLon: viewMinLon, viewMinLat: viewMinLat, viewMaxLon: viewMaxLon ] (0.. if ( !v ) { map[k] = "" } } return map } }