Exemple #1
0
def totalTweets(bin, rdd):
    lPointObj = []
    for cPoint in bin.poly:
        lPointObj.append(pointClass.Point(cPoint[1], cPoint[0]))
    clusterPoly = pointClass.Polygon(lPointObj)
    bin.postsInHull = rdd.filter(lambda x: clusterPoly.bPointInPoly(
        pointClass.Point(x["longitude"], x["latitude"]))).count()
Exemple #2
0
def makeTotalsArray(record, bc_lClustPoly, bUseTime):
    lRet = []
    for poly in bc_lClustPoly.value:
        if not bUseTime and poly.bPointInPoly(
                pointClass.Point(record.lon, record.lat)):
            lRet.append(1)
        elif bUseTime and poly.bEventInTime(
                pointClass.Point(record.lon, record.lat), record.dt.date()):
            lRet.append(1)
        else:
            lRet.append(0)
    return lRet
Exemple #3
0
def testListFromData(data):
    #return value is list of lists;
    # 0 - polygons labeldd 'train'
    # 1 - polygons labeled 'pos'
    # 2 - polygons labeled 'neg'
    lTrain, lPos, lNeg = [], [], []
    for site in data['sites']:
        pList = []
        dList = []
        for i2 in range(len(site['lats'])):
            pList.append(pointClass.Point(site['lons'][i2], site['lats'][i2]))
        for datePairs in site['dates']:
            mindate = datetime.strptime(datePairs['min'].split('T')[0],
                                        '%Y-%m-%d').date()
            maxdate = datetime.strptime(datePairs['max'].split('T')[0],
                                        '%Y-%m-%d').date()
            dList.append((mindate, maxdate))
        name = site["name"]
        if name == "train":
            lTrain.append(pointClass.spaceTimePlane(pList, dList, name))
        elif name == "pos":
            lPos.append(pointClass.spaceTimePlane(pList, dList, name))
        elif name == "neg":
            lNeg.append(pointClass.spaceTimePlane(pList, dList, name))
        else:
            print "Polygon name does not follow correct scheme, (train, pos, neg)"
    return (lTrain, lPos, lNeg)
Exemple #4
0
def outEOI(lat, lon, dt, bc_lTargetPolygons):
    recordPoint = pointClass.Point(lon, lat)
    rDate = dt.date()
    for site in bc_lTargetPolygons.value:
        if site.bEventOutOfTime(recordPoint, rDate):
            return True
    return False
Exemple #5
0
def createHull(cluster, bUseTime):
    loLa = set([])
    for point in cluster.records:
        loLa.add(str(point.lon) + "," + str(point.lat))
    loLa = map(lambda x: [float(x.split(",")[0]),
                          float(x.split(",")[1])], loLa)
    if len(loLa) > 2:
        loLa = np.array(loLa)
        hull = ConvexHull(loLa)
        lClustPoints = []
        lPointObj = []
        for verts in hull.vertices:
            lClustPoints.append([loLa[verts, 1], loLa[verts, 0]])
            lPointObj.append(pointClass.Point(loLa[verts, 0], loLa[verts, 1]))
        if bUseTime:
            cluster.objPoly = pointClass.spaceTimePlane(
                lPointObj, [(cluster.dt.date(), cluster.dt.date())], "Hull")
        else:
            cluster.objPoly = pointClass.Polygon(lPointObj)
        cluster.poly = lClustPoints
    else:
        lPointObj = []
        lClustPoints = []
        for lolaOff in [
            (-0.001, -0.001),
            (-0.001, 0.001),
            (0.001, 0.001),
            (0.001, -0.001),
        ]:
            offset = [loLa[0][0] + lolaOff[0], loLa[0][1] + lolaOff[1]]
            lPointObj.append(pointClass.Point(offset[0], offset[1]))
            lClustPoints.append([offset[1], offset[0]])
        if bUseTime:
            cluster.objPoly = pointClass.spaceTimePlane(
                lPointObj, [(cluster.dt.date(), cluster.dt.date())], "Hull")
        else:
            cluster.objPoly = pointClass.Polygon(lPointObj)
        cluster.poly = lClustPoints
Exemple #6
0
def readInShapeDocument(data):
    lST = []
    siteList = data['sites']
    for site in siteList:
        pList = []
        dList = []
        for i2 in range(len(site['lats'])):
            pList.append(pointClass.Point(site['lons'][i2], site['lats'][i2]))
        for datePairs in site['dates']:
            mindate = datetime.strptime(datePairs['min'].split('T')[0],
                                        '%Y-%m-%d').date()
            maxdate = datetime.strptime(datePairs['max'].split('T')[0],
                                        '%Y-%m-%d').date()
            dList.append((mindate, maxdate))
        lST.append(pointClass.spaceTimePlane(pList, dList, site['name']))
    return lST
Exemple #7
0
def readInShapeFile(fileName):
    pointReader = open(fileName, 'rb')
    polyList = []
    pointList = []
    polyIndex = -1
    for row in pointReader:
        fInd, lat, lon = row.split(",")
        if int(fInd) != polyIndex:
            if polyIndex != -1:
                newPoly = pointClass.Polygon(pointList)
                polyList.append(newPoly)
                pointList = []
            polyIndex = int(fInd)
        newPoint = pointClass.Point(lon, lat)
        pointList.append(newPoint)
    newPoly = pointClass.Polygon(pointList)
    polyList.append(newPoly)
    return polyList
Exemple #8
0
    polyFiles = os.listdir(strDir)
    retDict = {}
    if strDir[-1] != '/':
        strDir = strDir + '/'
    for file in polyFiles:
        retDict[file[0:8]] = readInShapeFile(strDir + file)
    return retDict


if __name__ == "__main__":
    polyList = readInShapeFile("../polygon/shapeFile2.txt")
    print "The capture boxes are defined by: "
    for poly in polyList:
        print str(poly) + '\n'

    p1 = pointClass.Point(-122.3235, 47.603)
    p2 = pointClass.Point(-122.321, 47.61)
    p3 = pointClass.Point(-122.342878, 47.607403)
    p4 = pointClass.Point(-122.326, 47.61131)
    p5 = pointClass.Point(-122.322718, 47.605963)
    p6 = pointClass.Point(-122.324000, 47.603995)
    p7 = pointClass.Point(-122.328002, 47.609703)
    p8 = pointClass.Point(-122.320331, 47.607742)
    pList = [p1, p2, p3, p4, p5, p6, p7, p8]
    for p in pList:
        print "Point: " + str(p)
        for ind in range(len(polyList)):
            if polyList[ind].bPointInPoly(p):
                print '\t' + "is in region number " + str(ind)
            else:
                print '\t' + "is out of region number " + str(ind)
Exemple #9
0
def inROI(lat, lon, bc_lTargetPolygons):
    recordPoint = pointClass.Point(lon, lat)
    for site in bc_lTargetPolygons.value:
        if site.bPointInPoly(recordPoint):
            return True
    return False