Пример #1
0
def remFeaturesFromPuvspr2(setupObject, selectedFeatIDSet):
    puvspr2Path = setupObject.inputPath + os.sep + "puvspr2.dat"
    tempPuvspr2Path = cluz_setup.returnTempPathName(puvspr2Path, "dat")
    tempPuvspr2File = open(tempPuvspr2Path, "wb")
    writer = csv.writer(tempPuvspr2File)
    writer.writerow(["species", "pu", "amount"])

    with open(puvspr2Path, 'rb') as f:
        reader = csv.reader(f)
        reader.next()
        for row in reader:
            if int(row[0]) not in selectedFeatIDSet:
                writer.writerow(row)

    tempPuvspr2File.close()
    os.remove(puvspr2Path)
    os.rename(tempPuvspr2Path, puvspr2Path)
Пример #2
0
def remFeaturesFromTargetCsv_Dict(setupObject, selectedFeatIDSet):
    tempTargetPath = cluz_setup.returnTempPathName(setupObject.targetPath, "csv")
    tempTargetFile = open(tempTargetPath, "wb")
    writer = csv.writer(tempTargetFile)

    with open(setupObject.targetPath, 'rb') as f:
        reader = csv.reader(f)
        rowHeader = True
        for row in reader:
            if rowHeader == True:
                writer.writerow(row)
                rowHeader = False
            else:
                featID = int(row[0])
                if featID in selectedFeatIDSet:
                    pass
                else:
                    writer.writerow(row)

    tempTargetFile.close()
    os.remove(setupObject.targetPath)
    os.rename(tempTargetPath, setupObject.targetPath)
Пример #3
0
def addFeaturesToTargetCsvFile(setupObject, addAbundDict, featIDList):
    tempTargetPath = cluz_setup.returnTempPathName(setupObject.targetPath, "csv")
    tempTargetFile = open(tempTargetPath, "wb")
    writer = csv.writer(tempTargetFile)

    puLayer = QgsVectorLayer(setupObject.puPath, "Planning units", "ogr")
    addTargetDict = makeAddTargetDict(puLayer, addAbundDict, featIDList)

    with open(setupObject.targetPath, 'rb') as f:
        reader = csv.reader(f)
        for row in reader:
            writer.writerow(row)

        addTargetList = addTargetDict.keys()
        addTargetList.sort()
        for featID in addTargetList:
            (featCon, featTotal) = addTargetDict[featID]
            row = [str(featID), "blank", "0", "0", "0", str(featCon), str(featTotal), "-1"]
            writer.writerow(row)

    tempTargetFile.close()
    os.remove(setupObject.targetPath)
    os.rename(tempTargetPath, setupObject.targetPath)