Example #1
0
 def __openShpfile(self):
     """
     Open a shapefile and read in the contents, pop up the attribute menu 
     with the attributes of the shapefile
     """   
     print "open shape file!"
     directory="C:/Users/sjha1/Documents/GitHub/Simulator_GUI/Python-Sample/data/states/48States.shp"
     #tkFileDialog.askopenfilename(filetypes=[("SHAPE_FILE","*.shp")])
     print directory
     
     if directory == "":
         return
     
     self.shapes, self.shp_type, self.bbox = shp_reader.read_shp(directory)
     #read corresponding dbf data
     dbfFile = dbf.DbfLoader(directory[:-3] + "dbf")
     
     t = dbfFile.table2list()
     varNames = dbfFile.get_field_names()
     variables = {}
     for variable in varNames:
         variables[variable] = [record[varNames.index(variable)] for record in t]
         
     if self.dbfdata!=None:
         self.attibmenu.delete(0, len(self.dbfdata)-1)
         
     #add attributes into menu
     for key in variables.keys():
         self.__addAttribute(key)
     
     self.dbfdata = variables
     self.menubar.entryconfig(2, state=Tkconstants.NORMAL)
     self.__updateCanvas("STATE_NAME")
Example #2
0
 def __init__(self, shpName):
     projectDir = os.path.dirname(shpName)
     prefix = os.path.basename(shpName).split(".")[0]
     self.dbfFileName = projectDir + "/" + prefix + ".dbf"
     dbfFile = dbf.DbfLoader(self.dbfFileName)
     shpFile = shp.shapefile(shpName)
     self.dbfFile = dbfFile
     self.shapeFile = shpFile
     self.__table = 0
Example #3
0
    def __openShpfile(self):
        """Open a shapefile and read in the contents, pop up the attribute menu with the attributes of the shapefile"""
        print "open shape file!"
        directory = tkFileDialog.askopenfilename(filetypes=[("SHAPE_FILE",
                                                             "*.shp")])

        self.lb_FileName.config(text=directory.split("/")[-1])
        writeCalculations(
            self.text, "Completed reading file: " + directory.split("/")[-1],
            False, NB)

        if directory == "":
            return

        self.shapes, self.shp_type, self.bbox = shp_reader.read_shp(directory)

        #read corresponding dbf data
        dbfFile = dbf.DbfLoader(directory[:-3] + "dbf")

        t = dbfFile.table2list()
        varNames = dbfFile.get_field_names()
        variables = {}
        for variable in varNames:
            #print variable, len(variable)
            variables[variable] = [
                record[varNames.index(variable)] for record in t
            ]

        self.variable = StringVar(self.root)
        self.variable.set(varNames[0])
        self.lst_Attributes = apply(
            OptionMenu, (self.fr_Analysis, self.variable) + tuple(varNames))
        self.lst_Attributes.grid(row=1,
                                 column=1,
                                 sticky=(E, W),
                                 pady=20,
                                 padx=20,
                                 ipadx=40)
        self.lst_Attributes.configure(width=7)
        self.dbfdata = variables