def initGlobalsFromFile(filename): """ At this stage we are defaulting the filename to sys.argv[1], but this should really be done with getopt """ shpfile = shapelibc.open(str(sys.argv[1]),"rb") minbounds = shapelibc.ShapeFile_info(shpfile)[2] maxbounds = shapelibc.ShapeFile_info(shpfile)[2] dbffile = dbflibc.open(str(sys.argv[1]),"rb") numrecords = dbflibc.DBFFile_record_count(dbffile) numfields = dbflibc.DBFFile_field_count(dbffile) return
def initGlobalsFromFile(filename): """ At this stage we are defaulting the filename to sys.argv[1], but this should really be done with getopt """ shpfile = shapelibc.open(str(sys.argv[1]), "rb") minbounds = shapelibc.ShapeFile_info(shpfile)[2] maxbounds = shapelibc.ShapeFile_info(shpfile)[2] dbffile = dbflibc.open(str(sys.argv[1]), "rb") numrecords = dbflibc.DBFFile_record_count(dbffile) numfields = dbflibc.DBFFile_field_count(dbffile) return
#try and figure out what was passed to us #if we were passed something with a .shp extension, try and find a dbf #if not, try and find a .shp and a dbf inputfile = args[0] #if the dude added the .shp we strip it if inputfile[-4:0].upper() == ".SHP": inputfile = inputfile[:len(inputfile)-4] #if no outputfile was specced, give it a name outputfile = inputfile + ".kml" #see if we can open it try: shpfile = shapelibc.open(inputfile,"rb") except IOError,err: #if we cannot open the shpfile we should die print str(err) sys.exit(2) #we got this far, now try the dbf try: dbffile = dbflibc.open(inputfile,"rb") except IOError,err: print """You did not supply a dbf file, all objects of the same type will be considered equal.""" nodbf = True
#try and figure out what was passed to us #if we were passed something with a .shp extension, try and find a dbf #if not, try and find a .shp and a dbf inputfile = args[0] #if the dude added the .shp we strip it if inputfile[-4:0].upper() == ".SHP": inputfile = inputfile[:len(inputfile) - 4] #if no outputfile was specced, give it a name outputfile = inputfile + ".kml" #see if we can open it try: shpfile = shapelibc.open(inputfile, "rb") except IOError, err: #if we cannot open the shpfile we should die print str(err) sys.exit(2) #we got this far, now try the dbf try: dbffile = dbflibc.open(inputfile, "rb") except IOError, err: print """You did not supply a dbf file, all objects of the same type will be considered equal.""" nodbf = True