示例#1
0
def tempParseGSA(GSA_file_CSV, GSA_file_SHP, idVar, nameVar):
    if GSA_file_CSV == None or GSA_file_SHP == None:
        return (None, None)

    gsaCSV = []
    with open(GSA_file_CSV) as csvfile:
        try:
            reader = csv.reader(csvfile)
            for row in reader:
                tempRow = [x.replace("'", "APOSTROPHE") for x in row]
                gsaCSV.append(tempRow)
        except:
            return (None, True)

    #TODO: remove this
    gsaSVG = "out/gsa/mymap.svg"
    generateMap(GSA_file_SHP, gsaSVG)

    with open(gsaSVG, 'r') as myfile:
        data = None
        try:
            data = myfile.read()
        except:
            return (None, True)
    data = data.replace('"', "'")
    nameMapping = util.getNameMapping(gsaSVG, idVar, nameVar)
    nameMapping = {key: value.replace("'", "APOSTROPHE") for key, value in nameMapping.items()}
    return json.dumps(str(gsaCSV).replace('"', "'")), json.dumps(data), json.dumps(str(nameMapping).replace('"', "'"))
示例#2
0
文件: gsa.py 项目: zemlni/GAT
def reg():
    case_num = request.args.get('case_num', None)
    fileDict = dao.getFileDict(case_num)
    GSA_file_CSV = fileDict.get('GSA_Input_CSV')
    GSA_file_SHP = fileDict.get('GSA_Input_SHP')
    gsa_meta = fileDict.get('GSA_meta')
    svgNaming = fileDict.get('GSA_data')[0]
    with open('out/gsa/mymap.svg', 'r') as myfile:
        mymap = myfile.read()

    mymap = mymap.replace('"', "'")

    observations = weights.extractObservations(GSA_file_CSV, "ALL",
                                               gsa_meta[3])
    w = weights.generateWeightsUsingShapefile(GSA_file_SHP,
                                              idVariable=gsa_meta[2])

    regions = regionalization.generateRegions(w=w,
                                              observations=observations)[0]
    regions = regionalization.getNamesFromRegions(regions)
    nameMapping = util.getNameMapping('out/gsa/mymap.svg', gsa_meta[0],
                                      gsa_meta[1])
    nameMapping = {
        key: value.replace("'", "APOSTROPHE")
        for key, value in nameMapping.items()
    }
    numRegs = len(set(regions.values()))
    return render_template("regionalization.html",
                           case_num=case_num,
                           mymap=json.dumps(mymap),
                           regions=json.dumps(regions),
                           numRegs=numRegs,
                           svgNaming=svgNaming,
                           nameMapping=json.dumps(str(nameMapping)))