def createHazardEvents(self, eventSet, polygon, fcstDict, key, baseVal, topVal): poly = GeometryFactory.createPolygon(polygon) poly = AdvancedGeometry.createShapelyWrapper(poly, 0) #create hazard event currentTime = datetime.datetime.now() startTime = datetime.datetime.utcfromtimestamp(int(key)) endTime = datetime.datetime.utcfromtimestamp(int(fcstDict[key]['endTime'])) sessionAttributes = eventSet.getAttributes() caveMode = sessionAttributes.get('runMode','PRACTICE').upper() practice = True if caveMode == 'OPERATIONAL': practice = False hazardEvent = EventFactory.createEvent(practice) hazardEvent.setCreationTime(currentTime) hazardEvent.setStartTime(startTime) hazardEvent.setEndTime(endTime) hazardEvent.setHazardStatus("pending") hazardEvent.setPhenomenon(fcstDict[key]['phenomenon']) #set metadata top and bottom based on top/bottom grid hazardEvent.set(fcstDict[key]['baseMetaID'], baseVal) hazardEvent.set(fcstDict[key]['topMetaID'], topVal) hazardEvent.setGeometry(poly) eventSet.add(hazardEvent) return
def setGeometry(self, geometry): # Convert any shapely geometries to AdvancedGeometry. if issubclass(type(geometry), BaseGeometry): geometry = AdvancedGeometry.createShapelyWrapper(geometry, 0) # Use the advanced geometry's wrapped Java object. if isinstance(geometry, AdvancedGeometry.AdvancedGeometry): geometry = geometry.getWrappedJavaObject() self.jobj.setGeometry(geometry)
def makeHazardEvent(self, ID, values): #print '\tMaking New Event?', ID if values.get('belowThreshold'): #print '\t\tBelow Threshold', self.lowThreshold, 'returning None' return None try: polygon = loads(values.get('polygons')) except: print '\t\tPOLYPOLYPOLY Unable to load polygons. Returning None. POLYPOLYPOLY' return None sys.stdout.flush() probSevereTime = values.get('startTime', self.dataLayerTime) hazardEvent = EventFactory.createEvent(self.practice) hazardEvent.setCreationTime(probSevereTime) self.setEventTimes(hazardEvent, values) hazardEvent.setHazardStatus("pending") hazardEvent.setPhenomenon("Prob_Severe") hazardEvent.setGeometry(polygon) hazardEvent.set('convectiveObjectDir', values.get('wdir')) hazardEvent.set('convectiveObjectSpdKts', values.get('wspd')) hazardEvent.set('probSeverAttrs', values) hazardEvent.set('objectID', ID) hazardEvent.set('visibleGeometry', 'highResolutionGeometryIsVisible') hazardEvent.setStatus('ISSUED') hazardEvent.set('statusForHiddenField', 'ISSUED') # fill in the fields for newly created event hazardEvent.set('convectiveObjectDirUnc', 12) hazardEvent.set('convectiveObjectSpdKtsUnc', 4) self.storeLastEvent(hazardEvent) hazardEvent.set( 'probSevereGeomList', [(AdvancedGeometry.createShapelyWrapper(polygon, 0), long(TimeUtils.datetimeToEpochTimeMillis(self.latestDLTDT)))]) hazardEvent.set('manuallyCreated', False) hazardEvent.set('geometryAutomated', True) hazardEvent.set('motionAutomated', True) hazardEvent.set('durationAutomated', True) hazardEvent.set('probTrendAutomated', True) graphProbs = self.probUtils.getGraphProbs( hazardEvent, int(probSevereTime.strftime('%s')) * 1000) hazardEvent.set('convectiveProbTrendGraph', graphProbs) return hazardEvent
def storeNextGeometry(self, event, recommendedDict): geomList = deque(event.get('probSevereGeomList', []), maxlen=5) st = long(TimeUtils.datetimeToEpochTimeMillis(self.latestDLTDT)) geom = AdvancedGeometry.createShapelyWrapper( loads(recommendedDict.get('polygons')), 0) ### Only want to store if new startTime times = sorted([t[1] for t in geomList]) if len(times) == 0: geomList.append((geom, st)) elif st > times[-1]: geomList.append((geom, st)) event.set('probSevereGeomList', list(geomList))
def polygonToLine(self, geometry): newGeometry = [] for x in range(0,3,2): lat1 = geometry[x][1] lon1 = geometry[x][0] lat2 = geometry[x+1][1] lon2 = geometry[x+1][0] newLat = (lat1+lat2)/2 newLon = (lon1+lon2)/2 newVertex = (newLon, newLat) newGeometry.append(newVertex) poly = GeometryFactory.createLineString(newGeometry) poly = AdvancedGeometry.createShapelyWrapper(poly, 0) return poly
def createSwathVisualFeatures(self, hazardEvent, currentSwathPoly, fcstSwathPoly, visualFeatureGeomDict): startTime = hazardEvent.getStartTime().replace(second=0, microsecond=0) startTime = startTime - datetime.timedelta(hours=2) endTime = TimeUtils.roundDatetime(hazardEvent.getEndTime()) eventID = hazardEvent.getEventID() selectedFeatures = self.addPreviousVisualFeatures( hazardEvent, visualFeatureGeomDict) currentSwathPoly = AdvancedGeometry.createShapelyWrapper( currentSwathPoly, 0) fcstSwathPoly = AdvancedGeometry.createShapelyWrapper(fcstSwathPoly, 0) currentSwathPoly = { "identifier": "currentSwathPoly_" + eventID, "visibilityConstraints": "selected", "diameter": "eventType", "borderColor": { "red": 128 / 255.0, "green": 0 / 255.0, "blue": 128 / 255.0, "alpha": 1.0 }, "fillColor": { "red": 128 / 255.0, "green": 0 / 255.0, "blue": 128 / 255.0, "alpha": 0.4 }, "label": "Current Swath", "geometry": { (TimeUtils.datetimeToEpochTimeMillis(startTime), TimeUtils.datetimeToEpochTimeMillis(endTime) + 1000): currentSwathPoly } } fcstSwathPoly = { "identifier": "fcstSwathPoly_" + eventID, "visibilityConstraints": "selected", "diameter": "eventType", "borderColor": { "red": 255 / 255.0, "green": 0 / 255.0, "blue": 0 / 255.0, "alpha": 1.0 }, "fillColor": { "red": 255 / 255.0, "green": 0 / 255.0, "blue": 0 / 255.0, "alpha": 0.0 }, "label": "Forecast Swath", "geometry": { (TimeUtils.datetimeToEpochTimeMillis(startTime), TimeUtils.datetimeToEpochTimeMillis(endTime) + 1000): fcstSwathPoly } } selectedFeatures.append(currentSwathPoly) selectedFeatures.append(fcstSwathPoly) hazardEvent.setVisualFeatures(VisualFeatures(selectedFeatures)) return True
def execute(self, eventSet, dialogInputMap, visualFeatures): ''' Runs the Paste MetaData Tool @param eventSet: A set of events which include session attributes @param dialogInputMap: A map of information retrieved from a user's interaction with a dialog. @param spatialInputMap: A map of information retrieved from the user's interaction with the spatial display. @return: A list of potential probabilistic hazard events. ''' caveMode = eventSet.getAttributes().get('runMode', 'PRACTICE').upper() practice = True if caveMode == 'OPERATIONAL': practice = False import sys sys.stderr.write("Running Paste MetaData Tool.\n") sys.stderr.flush() with open('/scratch/copyBuffer.txt') as openFile: eventDict = json.load(openFile) currentTime = datetime.datetime.now() startTime = eventDict['startTime'] startTime = datetime.datetime.strptime(startTime, '%Y-%m-%d %H:%M:%S') endTime = eventDict['endTime'] endTime = datetime.datetime.strptime(endTime, '%Y-%m-%d %H:%M:%S') hazardEvent = EventFactory.createEvent(practice) hazardEvent.setCreationTime(currentTime) hazardEvent.setStartTime(startTime) hazardEvent.setEndTime(endTime) hazardEvent.setHazardStatus("pending") hazardEvent.setPhenomenon("SIGMET") hazardEvent.setSignificance("Convective") hazardEvent.set('originalGeomType', eventDict['geomType']) for key in eventDict: hazardEvent.set(str(key), eventDict.get(key)) hazardEvent.set('generated', False) self._geomType = eventDict['geomType'] vertices = eventDict['geometry'] vertices = vertices.pop() newVerticesList = [] for vertex in vertices: newVert = [] for vert in vertex: vert = vert - 1.5 newVert.append(vert) newVerticesList.append(newVert) if self._geomType == 'Polygon': poly = GeometryFactory.createPolygon(newVerticesList) elif self._geomType == 'LineString': poly = GeometryFactory.createLineString(newVerticesList) elif self._geomType == 'Point': newVerticesList = newVerticesList[0] poly = GeometryFactory.createPoint(newVerticesList) poly = AdvancedGeometry.createShapelyWrapper(poly, 0) hazardEvent.setGeometry(poly) eventSet.add(hazardEvent) return eventSet
def updateVisualFeatures(self, event, vertices, polyPoints): startTime = event.getStartTime().replace(second=0, microsecond=0) startTime = startTime - datetime.timedelta(hours=2) endTime = TimeUtils.roundDatetime(event.getEndTime()) self._originalGeomType = event.get('originalGeomType') self._width = event.get('convectiveSigmetWidth') polygonArea = self.polygonArea(event, self._originalGeomType, self._width) label = self.createLabel(event, polygonArea) eventID = event.getEventID() selectedFeatures = [] VOR_points = event.getHazardAttributes().get('VOR_points') if self._originalGeomType != 'Polygon': poly = GeometryFactory.createPolygon(polyPoints) basePoly = vertices if self._originalGeomType == 'Point': basePoly = GeometryFactory.createPoint(basePoly) elif self._originalGeomType == 'LineString': basePoly = GeometryFactory.createLineString(basePoly) basePoly = AdvancedGeometry.createShapelyWrapper(basePoly, 0) else: poly = GeometryFactory.createPolygon(VOR_points) try: basePoly = AdvancedGeometry.createShapelyWrapper( GeometryFactory.createPolygon(vertices), 0) except ValueError: basePoly = event.getGeometry() event.setGeometry(basePoly) poly = AdvancedGeometry.createShapelyWrapper(poly, 0) if self._originalGeomType != 'Polygon': borderColorHazard = { "red": 255 / 255.0, "green": 255 / 255.0, "blue": 0 / 255.0, "alpha": 1.0 } #yellow fillColorHazard = {"red": 1, "green": 1, "blue": 1, "alpha": 0} borderColorBase = { "red": 255 / 255.0, "green": 255 / 255.0, "blue": 255 / 255.0, "alpha": 1.0 } #white fillColorBase = { "red": 255 / 255.0, "green": 255 / 255.0, "blue": 0 / 255.0, "alpha": 0.0 } hazardPolyVisibility = "always" basePolyVisibility = "selected" hazardPolyLabel = label basePolyLabel = "" else: borderColorHazard = "eventType" fillColorHazard = { "red": 255 / 255.0, "green": 255 / 255.0, "blue": 0 / 255.0, "alpha": 0.0 } borderColorBase = { "red": 255 / 255.0, "green": 255 / 255.0, "blue": 0 / 255.0, "alpha": 1.0 } #yellow fillColorBase = {"red": 1, "green": 1, "blue": 1, "alpha": 0} hazardPolyVisibility = "selected" basePolyVisibility = "always" hazardPolyLabel = "" basePolyLabel = label hazardEventPoly = { "identifier": "hazardEventPolygon_" + eventID, "visibilityConstraints": hazardPolyVisibility, "diameter": "eventType", "borderColor": borderColorHazard, "fillColor": fillColorHazard, "label": hazardPolyLabel, "geometry": { (TimeUtils.datetimeToEpochTimeMillis(startTime), TimeUtils.datetimeToEpochTimeMillis(endTime) + 1000): poly } } basePoly = { "identifier": "basePreview_" + eventID, "visibilityConstraints": basePolyVisibility, "dragCapability": "all", "borderThickness": "eventType", "diameter": "eventType", "borderColor": borderColorBase, "fillColor": fillColorBase, "label": basePolyLabel, "geometry": { (TimeUtils.datetimeToEpochTimeMillis(startTime), TimeUtils.datetimeToEpochTimeMillis(endTime) + 1000): basePoly } } visualFeatures = event.getVisualFeatures() for feature in visualFeatures: if 'base' in feature['identifier'] or 'hazardEvent' in feature[ 'identifier'] or 'VOR' in feature['identifier']: pass else: selectedFeatures.append(feature) selectedFeatures.append(basePoly) selectedFeatures.append(hazardEventPoly) event.setVisualFeatures(VisualFeatures(selectedFeatures)) return True
def addVAForecastVisualFeatures(self, hazardEvent, numFcstLayers, numObsLayers): startTime = hazardEvent.getStartTime().replace(second=0, microsecond=0) startTime = startTime - datetime.timedelta(hours=2) endTime = TimeUtils.roundDatetime(hazardEvent.getEndTime()) vertices = hazardEvent.getFlattenedGeometry() vertices = shapely.geometry.base.dump_coords(vertices) vertices = vertices.pop() fcstVerticesDict = {} obsVerticesDict = {} for i in range(0,numObsLayers): i = i+1 newObsVerticesList = [] for vertex in vertices: newVert = [] for vert in vertex: vert = vert+1.5*i newVert.append(vert) newObsVerticesList.append(newVert) newObsVerticesTuple = tuple(newObsVerticesList) obsVerticesDict['vaObsPoly'+str(i)] = newObsVerticesTuple for i in range(0,numFcstLayers): i = i+1 newFcstVerticesList = [] for vertex in vertices: newVert = [] for vert in vertex: vert = vert - 1.5*i newVert.append(vert) newFcstVerticesList.append(newVert) newFcstVerticesTuple = tuple(newFcstVerticesList) fcstVerticesDict['vaFcstPoly'+str(i)] = newFcstVerticesTuple for key, value in fcstVerticesDict.iteritems(): hazardEvent.set(key, value) for key, value in obsVerticesDict.iteritems(): hazardEvent.set(key, value) eventID = hazardEvent.getEventID() selectedFeatures = [] basePoly = hazardEvent.getGeometry() basePoly = { "identifier": "basePreview_" + eventID, "visibilityConstraints": "always", "dragCapability": "all", "borderColor": "eventType", "fillColor": {"red": 1, "green": 1, "blue": 1, "alpha": 0}, "label": "Observed Layer 1", "geometry": { (TimeUtils.datetimeToEpochTimeMillis(startTime), TimeUtils.datetimeToEpochTimeMillis(endTime)): basePoly } } selectedFeatures.append(basePoly) for i in range(0, numFcstLayers): poly = AdvancedGeometry.createShapelyWrapper(GeometryFactory.createPolygon(fcstVerticesDict['vaFcstPoly'+str(i+1)]), 0) featureName = 'vaFcstPoly'+str(i+1) featureName = { "identifier": "vaFcstPoly"+str(i+1)+"_" + eventID, "dragCapability": "all", "borderColor": {"red": 255 / 255.0, "green": 255 / 255.0, "blue": 0 / 255.0, "alpha": 1.0 }, "fillColor": {"red": 1, "green": 1, "blue": 1, "alpha": 0}, "label": "Forecast Layer" + str(i+1), "geometry": { (TimeUtils.datetimeToEpochTimeMillis(startTime), TimeUtils.datetimeToEpochTimeMillis(endTime)): poly } } selectedFeatures.append(featureName) for i in range(0, numObsLayers): poly = AdvancedGeometry.createShapelyWrapper(GeometryFactory.createPolygon(obsVerticesDict['vaObsPoly'+str(i+1)]), 0) featureName = 'vaObsPoly'+str(i+1) featureName = { "identifier": "vaObsPoly"+str(i+1)+"_" + eventID, "dragCapability": "all", "borderColor": {"red": 255 / 255.0, "green": 255 / 255.0, "blue": 255 / 255.0, "alpha": 1.0 }, "fillColor": {"red": 1, "green": 1, "blue": 1, "alpha": 0}, "label": "Observed Layer" + str(i+2), "geometry": { (TimeUtils.datetimeToEpochTimeMillis(startTime), TimeUtils.datetimeToEpochTimeMillis(endTime)): poly } } selectedFeatures.append(featureName) hazardEvent.setVisualFeatures(VisualFeatures(selectedFeatures)) return True
def addForecastLayersVisualFeatures(self, hazardEvent, layerDict): startTime = hazardEvent.getStartTime().replace(second=0, microsecond=0) startTime = startTime - datetime.timedelta(hours=2) endTime = TimeUtils.roundDatetime(hazardEvent.getEndTime()) vertices = hazardEvent.getFlattenedGeometry() vertices = shapely.geometry.base.dump_coords(vertices) vertices = vertices.pop() fcstVerticesDict = {} for key in layerDict: for i in range(0,layerDict[key]+1): newVerticesList = [] for vertex in vertices: newVert = [] newLat = vertex[1] - 1.5*(int(key)-1) newLon = vertex[0] + 1.5*i newVert.append(newLon) newVert.append(newLat) newVerticesList.append(newVert) newVerticesTuple = tuple(newVerticesList) fcstVerticesDict["Layer"+str(key)+'fcst'+str(i)] = newVerticesTuple for key, value in fcstVerticesDict.iteritems(): hazardEvent.set(key, value) eventID = hazardEvent.getEventID() selectedFeatures = [] basePoly = hazardEvent.getGeometry() basePoly = { "identifier": "basePreview_" + eventID, "visibilityConstraints": "always", "dragCapability": "all", "borderColor": "eventType", "fillColor": {"red": 1, "green": 1, "blue": 1, "alpha": 0}, "geometry": { (TimeUtils.datetimeToEpochTimeMillis(startTime), TimeUtils.datetimeToEpochTimeMillis(endTime)): basePoly } } selectedFeatures.append(basePoly) borderColorDict = {1: {0: {"red": 255 / 255.0, "green": 0 / 255.0, "blue": 127 / 255.0, "alpha": 1.0 }, 4: {"red": 255 / 255.0, "green": 0 / 255.0, "blue": 127 / 255.0, "alpha": 1.0 }, 3: {"red": 255 / 255.0, "green": 51 / 255.0, "blue": 153 / 255.0, "alpha": 1.0 }, 2: {"red": 255 / 255.0, "green": 102 / 255.0, "blue": 178 / 255.0, "alpha": 1.0 }, 1: {"red": 255 / 255.0, "green": 153 / 255.0, "blue": 204 / 255.0, "alpha": 1.0 }}, 2: {0: {"red": 229 / 255.0, "green": 204 / 255.0, "blue": 255 / 255.0, "alpha": 1.0 }, 4: {"red": 127 / 255.0, "green": 0 / 255.0, "blue": 255 / 255.0, "alpha": 1.0 }, 3: {"red": 153 / 255.0, "green": 51 / 255.0, "blue": 255 / 255.0, "alpha": 1.0 }, 2: {"red": 178 / 255.0, "green": 102 / 255.0, "blue": 255 / 255.0, "alpha": 1.0 }, 1: {"red": 204 / 255.0, "green": 153 / 255.0, "blue": 255 / 255.0, "alpha": 1.0 }}, 3: {0: {"red": 204 / 255.0, "green": 204 / 255.0, "blue": 255 / 255.0, "alpha": 1.0 }, 4: {"red": 0 / 255.0, "green": 0 / 255.0, "blue": 255 / 255.0, "alpha": 1.0 }, 3: {"red": 51 / 255.0, "green": 51 / 255.0, "blue": 255 / 255.0, "alpha": 1.0 }, 2: {"red": 102 / 255.0, "green": 102 / 255.0, "blue": 255 / 255.0, "alpha": 1.0 }, 1: {"red": 153 / 255.0, "green": 153 / 255.0, "blue": 255 / 255.0, "alpha": 1.0 }}} labelDict = {1: {0: 'Layer1', 1: 't+6', 2: 't+12', 3: 't+18', 4: 't+24'}, 2: {0: 'Layer2', 1: 't+6', 2: 't+12', 3: 't+18', 4: 't+24'}, 3: {0: 'Layer3', 1: 't+6', 2: 't+12', 3: 't+18', 4: 't+24'}, } for key in layerDict: for i in range(0,layerDict[key]+1): if key == 1 and i == 0: pass else: poly = AdvancedGeometry.createShapelyWrapper(GeometryFactory.createPolygon(fcstVerticesDict["Layer"+str(key)+'fcst'+str(i)]), 0) featureName = "Layer"+str(key)+'fcst'+str(i) featureName = { "identifier": "Layer"+str(key)+'fcst'+str(i)+"_" + eventID, "dragCapability": "all", "visibilityConstraints": "selected", "borderColor": borderColorDict[key][i], "fillColor": {"red": 1, "green": 1, "blue": 1, "alpha": 0}, "label": labelDict[key][i], "geometry": { (TimeUtils.datetimeToEpochTimeMillis(startTime), TimeUtils.datetimeToEpochTimeMillis(endTime)): poly } } selectedFeatures.append(featureName) hazardEvent.setVisualFeatures(VisualFeatures(selectedFeatures)) return True
def addVisualFeatures(self, event, points): selectedFeatures = [] features = event.getVisualFeatures() for feature in features: if 'Outlook' in feature['identifier']: selectedFeatures.append(feature) startTime = event.getStartTime().replace(second=0, microsecond=0) startTime = startTime - datetime.timedelta(hours=1) endTime = TimeUtils.roundDatetime(event.getEndTime()) eventID = event.getEventID() polygonArea = AviationUtils.AviationUtils().polygonArea( event, self._originalGeomType, self._width) label = AviationUtils.AviationUtils().createLabel(event, polygonArea) poly = AdvancedGeometry.createShapelyWrapper( GeometryFactory.createPolygon(points), 0) basePoly = event.getGeometry() borderColor = { "red": 255 / 255.0, "green": 255 / 255.0, "blue": 0 / 255.0, "alpha": 1.0 } #yellow hazardEventPoly = { "identifier": "hazardEventPolygon_" + eventID, "visibilityConstraints": "selected", "borderColor": borderColor, "geometry": { (TimeUtils.datetimeToEpochTimeMillis(startTime), TimeUtils.datetimeToEpochTimeMillis(endTime) + 1000): poly } } basePoly = { "identifier": "basePreview_" + eventID, "visibilityConstraints": "always", "dragCapability": "all", "borderThickness": "eventType", "diameter": "eventType", "label": label, "borderColor": { "red": 255 / 255.0, "green": 255 / 255.0, "blue": 255 / 255.0, "alpha": 1 }, #white "geometry": { (TimeUtils.datetimeToEpochTimeMillis(startTime), TimeUtils.datetimeToEpochTimeMillis(endTime) + 1000): basePoly } } selectedFeatures.append(basePoly) selectedFeatures.append(hazardEventPoly) event.setVisualFeatures(VisualFeatures(selectedFeatures)) return True
def addPolygonVisualFeatures(self, hazardEvent): selectedFeatures = [] features = hazardEvent.getVisualFeatures() for feature in features: if 'Outlook' in feature['identifier']: selectedFeatures.append(feature) startTime = hazardEvent.getStartTime().replace(second=0, microsecond=0) startTime = startTime - datetime.timedelta(hours=2) endTime = TimeUtils.roundDatetime(hazardEvent.getEndTime()) VOR_points = hazardEvent.getHazardAttributes().get('VOR_points') eventID = hazardEvent.getEventID() polygonArea = AviationUtils.AviationUtils().polygonArea( hazardEvent, self._originalGeomType, None) domain = hazardEvent.getHazardAttributes().get( 'convectiveSigmetDomain') direction = hazardEvent.getHazardAttributes().get( 'convectiveSigmetDirection') speed = hazardEvent.getHazardAttributes().get('convectiveSigmetSpeed') cloudTop = hazardEvent.getHazardAttributes().get( 'convectiveSigmetCloudTop') cloudTopText = hazardEvent.getHazardAttributes().get( 'convectiveSigmetCloudTopText') status = hazardEvent.getStatus() if status == 'ISSUED': area = str(polygonArea) + " sq mi" numberStr = hazardEvent.getHazardAttributes().get( 'convectiveSigmetNumberStr') number = "\n" + numberStr + domain[0] + "\n" if cloudTop == 'topsAbove': tops = "\nAbove FL450" elif cloudTop == 'topsTo': tops = "\nTo FL " + str(cloudTopText) motion = "\n" + str(direction) + "@" + str(speed) + "kts" label = number + area + tops + motion else: area = str(polygonArea) + " sq mi" if cloudTop == 'topsAbove': tops = "\nAbove FL450" elif cloudTop == 'topsTo': tops = "\nTo FL " + str(cloudTopText) else: tops = "\nN/A" motion = "\n" + str(direction) + "@" + str(speed) + " kts" label = area + tops + motion poly = AdvancedGeometry.createShapelyWrapper( GeometryFactory.createPolygon(VOR_points), 0) basePoly = hazardEvent.getGeometry() fillColor = { "red": 130 / 255.0, "green": 0 / 255.0, "blue": 0 / 255.0, "alpha": 0.0 } borderColor = { "red": 255 / 255.0, "green": 255 / 255.0, "blue": 0 / 255.0, "alpha": 1.0 } VORPoly = { "identifier": "VORPreview_" + eventID, "visibilityConstraints": "always", "borderColor": "eventType", "fillColor": fillColor, "label": label, "geometry": { (TimeUtils.datetimeToEpochTimeMillis(startTime), TimeUtils.datetimeToEpochTimeMillis(endTime) + 1000): poly } } basePoly = { "identifier": "basePreview_" + eventID, "visibilityConstraints": "selected", "dragCapability": "all", "borderColor": borderColor, #"eventType", "fillColor": { "red": 1, "green": 1, "blue": 1, "alpha": 0 }, "geometry": { (TimeUtils.datetimeToEpochTimeMillis(startTime), TimeUtils.datetimeToEpochTimeMillis(endTime) + 1000): basePoly } } selectedFeatures.append(basePoly) selectedFeatures.append(VORPoly) hazardEvent.setVisualFeatures(VisualFeatures(selectedFeatures)) return True
def updateVisualFeatures(self, hazardEvent): numFcstLayers = hazardEvent.get("internationalSigmetVALayersSpinner") numObsLayers = hazardEvent.get( "internationalSigmetObservedLayerSpinner") startTime = hazardEvent.getStartTime().replace(second=0, microsecond=0) startTime = startTime - datetime.timedelta(hours=2) endTime = TimeUtils.roundDatetime(hazardEvent.getEndTime()) eventID = hazardEvent.getEventID() selectedFeatures = [] newBaseGeometry = hazardEvent.get('newGeometry') basePoly = AdvancedGeometry.createShapelyWrapper( GeometryFactory.createPolygon(newBaseGeometry), 0) hazardEvent.setGeometry(basePoly) basePoly = { "identifier": "basePreview_" + eventID, "visibilityConstraints": "always", "dragCapability": "all", "borderColor": "eventType", "fillColor": { "red": 1, "green": 1, "blue": 1, "alpha": 0 }, "label": "Observed Layer 1", "geometry": { (TimeUtils.datetimeToEpochTimeMillis(startTime), TimeUtils.datetimeToEpochTimeMillis(endTime)): basePoly } } selectedFeatures.append(basePoly) for i in range(0, numFcstLayers): featureName = 'vaFcstPoly_' + str(i + 1) fcstGeometry = hazardEvent.get(featureName) poly = AdvancedGeometry.createShapelyWrapper( GeometryFactory.createPolygon(fcstGeometry), 0) featureName = { "identifier": featureName + "_" + eventID, "dragCapability": "all", "borderColor": { "red": 255 / 255.0, "green": 255 / 255.0, "blue": 0 / 255.0, "alpha": 1.0 }, "fillColor": { "red": 1, "green": 1, "blue": 1, "alpha": 0 }, "label": "Forecast Layer" + str(i + 1), "geometry": { (TimeUtils.datetimeToEpochTimeMillis(startTime), TimeUtils.datetimeToEpochTimeMillis(endTime)): poly } } selectedFeatures.append(featureName) for i in range(0, numObsLayers): featureName = 'vaObsPoly' + str(i + 1) obsGeometry = hazardEvent.get(featureName) poly = AdvancedGeometry.createShapelyWrapper( GeometryFactory.createPolygon(obsGeometry), 0) featureName = { "identifier": featureName + "_" + eventID, "dragCapability": "all", "borderColor": { "red": 255 / 255.0, "green": 255 / 255.0, "blue": 255 / 255.0, "alpha": 1.0 }, "fillColor": { "red": 1, "green": 1, "blue": 1, "alpha": 0 }, "label": "Observed Layer" + str(i + 2), "geometry": { (TimeUtils.datetimeToEpochTimeMillis(startTime), TimeUtils.datetimeToEpochTimeMillis(endTime)): poly } } selectedFeatures.append(featureName) hazardEvent.setVisualFeatures(VisualFeatures(selectedFeatures)) return True
def createConvectiveSigmetOutlook(self, hazardEvent): numOutlooks = hazardEvent.get("convectiveSigmetOutlookSpinner") startTime = hazardEvent.getStartTime().replace(second=0, microsecond=0) startTime = startTime - datetime.timedelta(hours=2) endTime = TimeUtils.roundDatetime(hazardEvent.getEndTime()) vertices = hazardEvent.getFlattenedGeometry() vertices = shapely.geometry.base.dump_coords(vertices) vertices = vertices.pop() if hazardEvent.get('originalGeomType') == 'Polygon': pass elif hazardEvent.get('originalGeomType') == 'LineString': width = float(hazardEvent.get('convectiveSigmetWidth')) widthDegree = width / 60 buffer = [] buffer.append((vertices[0][0] - (widthDegree), vertices[0][1])) buffer.append((vertices[1][0] - (widthDegree), vertices[1][1])) buffer.append((vertices[1][0] + (widthDegree), vertices[1][1])) buffer.append((vertices[0][0] + (widthDegree), vertices[0][1])) vertices = buffer else: width = float(hazardEvent.get('convectiveSigmetWidth') / 2) buffer = [] buffer.append((vertices[0][0] - (widthDegree), vertices[0][1])) buffer.append((vertices[0][0], vertices[0][1] - (widthDegree))) buffer.append((vertices[0][0] + (widthDegree), vertices[0][1])) buffer.append((vertices[0][0], vertices[0][1] + (widthDegree))) vertices = buffer fcstVerticesDict = {} for i in range(0, 4): i = i + 1 newVerticesList = [] for vertex in vertices: newVert = [] for vert in vertex: vert = vert - 1.5 * i newVert.append(vert) newVerticesList.append(newVert) newVerticesTuple = tuple(newVerticesList) fcstVerticesDict['T+' + str(i * 3) + 'hrs'] = newVerticesTuple for key, value in fcstVerticesDict.iteritems(): hazardEvent.set(key, value) eventID = hazardEvent.getEventID() selectedFeatures = [] for i in range(0, numOutlooks): poly = AdvancedGeometry.createShapelyWrapper( GeometryFactory.createPolygon( fcstVerticesDict['T+' + str((i + 1) * 3) + 'hrs']), 0) featureName = { "identifier": 'Outlook' + str(i + 1) + eventID, "dragCapability": "all", "borderColor": { "red": 255 / 255.0, "green": 165 / 255.0, "blue": 0 / 255.0, "alpha": 1.0 }, "fillColor": { "red": 1, "green": 1, "blue": 1, "alpha": 0 }, "label": 'Outlook' + str(i + 1), "geometry": { (TimeUtils.datetimeToEpochTimeMillis(startTime), TimeUtils.datetimeToEpochTimeMillis(endTime)): poly } } selectedFeatures.append(featureName) visualFeatures = hazardEvent.getVisualFeatures() for feature in visualFeatures: if "Outlook" in feature['identifier']: pass else: selectedFeatures.append(feature) hazardEvent.setVisualFeatures(VisualFeatures(selectedFeatures)) return True
def lineToPolygon(self, polygon): poly = AdvancedGeometry.createShapelyWrapper(GeometryFactory.createPolygon(polygon), 0) return poly