Exemplo n.º 1
0
def transform(g, dx=0, dy=0, sx=1, sy=1, shx=0, shy=0, r=0):
    """
  Tranforms a geometry with an affine transformation.

  *g* is the :class:`Geometry <geoscript.geom.Geometry>` to transform. 

  *dx*, *dy* specify the x,y translation.

  *sx*, *sy* specify the x,y scale factors.

  *shx, shy* specify the x,y shear factors.

  *r* specifies the rotation angle in radians.
  """
    tx = AffineTransform(sx, shy, shx, sy, dx, dy)
    tx.rotate(r)
    return JTS.transform(g, AffineTransform2D(tx))
Exemplo n.º 2
0
 def reproject_shape(clz, shape, crs1, crs2):
     transform = clz.get_transform(crs1, crs2)
     return Shape(JTS.transform(shape._jgeom, transform))
Exemplo n.º 3
0
def preparePathCastData(hazardEvent):
    '''
     This method returns the pathcast data.

     @return the Pathcast
    '''
    bridge = Bridge()
    pathcastConfig = bridge.getPathCastConfig()

    # Area configuration
    areaSource = pathcastConfig.get("areaSource")
    areaField = pathcastConfig.get("areaField")
    parentAreaField = pathcastConfig.get("parentAreaField")

    # Point configuration
    pointSource = pathcastConfig.get("pointSource")
    pointField = pathcastConfig.get("pointField")

    # Basic configuration
    maxCount = pathcastConfig.get("maxCount")
    maxGroup = pathcastConfig.get("maxGroup")
    withInPolygon = pathcastConfig.get("withInPolygon")

    # convert the threshold to Meters
    thresholdInMeters = pathcastConfig.get("thresholdInMiles") * 1609.344

    stormMotion = hazardEvent.get("stormMotion")
    if stormMotion:
        speed = stormMotion.get("speed")
        bearing = stormMotion.get("bearing")
    startID = time.mktime(hazardEvent.getStartTime().timetuple()) * 1000

    trackPoints = list(hazardEvent.get("trackPoints", []))
    if stormMotion:  # Storm Track Recommender was ran
        # Create a list of all the coordinates
        coordinates = []
        for point in trackPoints:
            coord = GeometryFactory.createPoint(point.get("point"))
            coordinates.append(coord)

        if len(coordinates) < 2:
            coordinates.append(coordinates.get(0))

        # Create a LineString from the TrackPoints and then buffer it
        # to get a polygon to query locations for.
        geom = GeometryFactory.createLineString(coordinates)
        javaGeom = JUtil.pyValToJavaObj(geom)
        pdm = PointsDataManager.getInstance()
        wfoCenter = pdm.getWfoCenter()
        crs = MapUtil.constructStereographic(MapUtil.AWIPS_EARTH_RADIUS,
                                             MapUtil.AWIPS_EARTH_RADIUS,
                                             wfoCenter.y, wfoCenter.x)
        latLonToLocal = MapUtil.getTransformFromLatLon(crs)
        javaGeom = JTS.transform(javaGeom, latLonToLocal)
        javaGeom = JTS.transform(
            javaGeom.convexHull().buffer(thresholdInMeters),
            latLonToLocal.inverse())
        geom = JUtil.javaObjToPyVal(javaGeom)

        if withInPolygon:
            # Means that all points returned must be within the polygon
            bufferedPathCastArea = hazardEvent.getProductGeometry(
            ).intersection(geom)
        else:
            bufferedPathCastArea = geom
    else:  # Stationary, Storm Track Recommender was not ran
        bufferedPathCastArea = hazardEvent.getProductGeometry()
        trackPoint = {
            "pointType": "tracking",
            "shapeType": "point",
            "pointID": startID,
            "point": hazardEvent.getProductGeometry().centroid,
        }
        trackPoints.append(trackPoint)

    # Query for all the locations and areas for the pathcast based on the buffered area
    warngenLocDicts = SpatialQuery.executeConfiguredQuery(
        bufferedPathCastArea, hazardEvent.getSiteID(), "PathcastPoints")
    areaFeaturesDicts = SpatialQuery.executeConfiguredQuery(
        bufferedPathCastArea, hazardEvent.getSiteID(), "PathcastAreas")

    for trackPoint in trackPoints:
        tpId = trackPoint.get("pointID", None)
        if tpId != None:
            if long(tpId) < long(startID):
                continue

        tpPoint = trackPoint.get("point", None)
        if tpPoint:
            tpPoint = GeometryFactory.createPoint(tpPoint)
        else:
            tpPoint = hazardEvent.getProductGeometry().centroid

        myArea = None
        if areaFeaturesDicts != None:
            # Find area and parent area
            for areaDict in areaFeaturesDicts:
                if areaDict.get("geom").contains(tpPoint):
                    myArea = areaDict
                    break

        # Set area info
        if myArea != None:
            trackPoint["area"] = str(myArea.get(areaField)).strip()
            trackPoint["parentArea"] = str(myArea.get(parentAreaField))

        # Get the closest points for this track point.
        closestPoints = getClosestPoints(pointField, areaField, parentAreaField, thresholdInMeters, \
                                              tpPoint, areaFeaturesDicts, trackPoint, warngenLocDicts)
        trackPoint["closestPoints"] = closestPoints

    # Figure out which locations should go with which trackpoint. Starts
    # with first trackpoint and go through each location within maxCount,
    # check for same location in other trackpoints. If same location
    # exists, remove from which ever trackpoint is farthest away
    closestPtCoords = []
    for i in range(0, len(trackPoints)):
        tp = trackPoints[i]
        points = tp.get("closestPoints")
        if points == None:
            continue
        for cp in list(points):
            for j in range(i + 1, len(trackPoints)):
                tp2 = trackPoints[j]
                if tp2 != tp:
                    points2 = tp2.get("closestPoints")
                    found = find(cp, points2)
                    if found != None:
                        # We found a point within maxCount in this list.
                        if found.get("distance") < cp.get("distance"):
                            # This point is closer to the other pathcast
                            points.remove(cp)
                            break
                        else:
                            # Remove from other pathcast, we are closer
                            points2.remove(found)
                        tp2["closestPoints"] = points2
        tmpPoints = []
        # Truncate the list to maxCount
        del points[maxCount:]
        for cp in points:
            coord = cp.get("point")
            if not coord in closestPtCoords:
                # To prevent duplicate cities in pathcast,
                # only unused point is added to tmpPoints
                tmpPoints.append(cp)
                closestPtCoords.append(coord)
        tp["closestPoints"] = points

    # Remove any trackpoints from the list that
    # do not contain any closest points.
    for tp in list(trackPoints):
        if len(tp.get("closestPoints", [])) == 0:
            trackPoints.remove(tp)

    # Ensure we are within the maxGroup
    while len(trackPoints) > maxGroup:
        del trackPoints[-1]

    return trackPoints