def writeSoilFile(self, shapefile):
        ds = ogr.Open(shapefile)
        lyr = ds.GetLayer()
        db = dbio.connect(self.dbname)
        cur = db.cursor()
        cur.execute(
            "select * from information_schema.tables where table_name='basin' and table_schema=%s", (self.name,))
        if not bool(cur.rowcount):
            temptable = ''.join(random.SystemRandom().choice(
                string.ascii_letters) for _ in range(8))
            cur.execute(
                "create table {0}(gid serial primary key, geom geometry)".format(temptable))
            for i in range(lyr.GetFeatureCount()):
                f = lyr.GetNextFeature()
                g = f.GetGeometryRef()
                cur.execute("insert into {0}(geom) values(st_geomfromtext('{1}',4326))".format(
                    temptable, g.ExportToWkt()))
            sql = "select updategeometrysrid('{0}','geom',4326)".format(
                temptable)
            db.commit()
            cur.execute(
                "create index {0}_s on {0} using gist(geom)".format(temptable))
            ds = None
            cur.execute(
                "select schema_name from information_schema.schemata where schema_name='{0}'".format(self.name))
            if not bool(cur.rowcount):
                cur.execute("create schema {0}".format(self.name))
            sql = "create table {0}.basin (gid integer, elev real, depths real[], geom geometry(Point, 4326), line text, constraint {0}_gidkey primary key(gid),  CONSTRAINT enforce_dims_geom CHECK (st_ndims(geom) = 2), CONSTRAINT enforce_geotype_geom CHECK (geometrytype(geom) = 'POINT'::text OR geom IS NULL))".format(self.name)
            cur.execute(sql)
            sql = "insert into {0}.basin (gid, elev, depths, geom, line) select v.id,v.elev,v.depths,v.geom,v.line from vic.soils as v,{1} as t where st_intersects(v.geom,t.geom) and resolution={2}".format(
                self.name, temptable, self.res)
            cur.execute(sql)
            cur.execute("drop table {0}".format(temptable))
            db.commit()
            cur.execute(
                "create index basin_s on {0}.basin using gist(geom)".format(self.name))
            db.commit()
        sql = "select line,gid,st_y(geom),st_x(geom),elev,depths from {0}.basin order by gid".format(
            self.name)
        cur.execute(sql)
        lines = cur.fetchall()
        with open(self.model_path + '/soil.txt', 'w') as fout:
            for line in lines:
                gid, lat, lon, elev, depths = line[1:]
                fout.write("{0}\n".format(line[0]))
                self.lat.append(lat)
                self.lon.append(lon)
                self.gid[gid] = (lat, lon)
                self.lgid[(lat, lon)] = gid
                self.depths[gid] = depths
                self.elev[gid] = elev
        cur.execute("alter table {0}.basin drop column line".format(self.name))
        cur.close()
        db.close()
Write soil parameter file for current simulation based on basin shapefile.
dataset/ETHPy150Open nasa/RHEAS/src/vic/vic.py/VIC.writeSoilFile