def check_multilines(vector): vector, mset = vector.split('@') if '@' in vector else (vector, '') msgr = get_msgr() vec = VectorTopo(vector, mapset=mset, mode='r') vec.open("r") info = gcore.parse_command('v.category', input=vector, option='print') for i in info.keys(): vec.cat(int(i), 'lines', 1) # if i == '28': # import ipdb; ipdb.set_trace() if len(vec.cat(int(i), 'lines', 1)) > 1: # import ipdb; ipdb.set_trace() warn = ("Multilines for the same category %s" % i) msgr.warning(warn) vec.close()
def check_multilines(vector): vector, mset = vector.split("@") if "@" in vector else (vector, "") msgr = get_msgr() vec = VectorTopo(vector, mapset=mset, mode="r") vec.open("r") info = gcore.parse_command("v.category", input=vector, option="print") for i in info.keys(): vec.cat(int(i), "lines", 1) # if i == '28': # import ipdb; ipdb.set_trace() if len(vec.cat(int(i), "lines", 1)) > 1: # import ipdb; ipdb.set_trace() warn = "Multilines for the same category %s" % i msgr.warning(warn) vec.close()
def uppoints(self): """Return""" name_map = self.name_map + "__Topo" topo = VectorTopo(name_map) topo.open("r", layer=1) pts_org = [] pts_chg = [] attrs = [] for i in range(1, len(topo) + 1): act = topo.read(i).attrs["action"] if act != "": cat = topo.read(i).attrs["cat"] pto_org = topo.cat(cat, "points", 1)[0] pto_chg = Point(pto_org.x, pto_org.y, pto_org.z) if topo.read(i).attrs["x"] is not None: pto_chg.x = float(topo.read(i).attrs["x"]) if topo.read(i).attrs["y"] is not None: pto_chg.y = float(topo.read(i).attrs["y"]) if topo.read(i).attrs["z"] is not None: pto_chg.z = float(topo.read(i).attrs["z"]) pts_org.append(pto_org) pts_chg.append(pto_chg) attrs.append( [ cat, topo.read(i).attrs["pk"], topo.read(i).attrs["name"], topo.read(i).attrs["azi"], topo.read(i).attrs["p_type"], topo.read(i).attrs["align"], topo.read(i).attrs["vparam"], topo.read(i).attrs["v_type"], topo.read(i).attrs["terr"], topo.read(i).attrs["t_type"], topo.read(i).attrs["dist_d"], pto_chg.x, pto_chg.y, pto_chg.z, "", ] ) topo.close() if pts_org != []: topo.open("rw", 1, with_z=True) for i, pto in enumerate(pts_org): topo.rewrite(pto, pts_chg[i], attrs[i][1:]) topo.table.conn.commit() topo.close()
def uppoints(self): """ Return """ name_map = self.name_map + '__Topo' topo = VectorTopo(name_map) topo.open('r', layer=1) pts_org = [] pts_chg = [] attrs = [] for i in range(1, len(topo) + 1): act = topo.read(i).attrs['action'] if act != '': cat = topo.read(i).attrs['cat'] pto_org = topo.cat(cat, 'points', 1)[0] pto_chg = Point(pto_org.x, pto_org.y, pto_org.z) if topo.read(i).attrs['x'] is not None: pto_chg.x = float(topo.read(i).attrs['x']) if topo.read(i).attrs['y'] is not None: pto_chg.y = float(topo.read(i).attrs['y']) if topo.read(i).attrs['z'] is not None: pto_chg.z = float(topo.read(i).attrs['z']) pts_org.append(pto_org) pts_chg.append(pto_chg) attrs.append([ cat, topo.read(i).attrs['pk'], topo.read(i).attrs['name'], topo.read(i).attrs['azi'], topo.read(i).attrs['p_type'], topo.read(i).attrs['align'], topo.read(i).attrs['vparam'], topo.read(i).attrs['v_type'], topo.read(i).attrs['terr'], topo.read(i).attrs['t_type'], topo.read(i).attrs['dist_d'], pto_chg.x, pto_chg.y, pto_chg.z, '' ]) topo.close() if pts_org != []: topo.open('rw', 1, with_z=True) for i, pto in enumerate(pts_org): topo.rewrite(pto, pts_chg[i], attrs[i][1:]) topo.table.conn.commit() topo.close()
def write_results2newvec(stream, E, basins_tot, inputs): """ Create the stream vector and write the basins object in a vector with the same cat value of the ID basin """ pid = os.getpid() tmp_thin = "tmprgreen_%i_thin" % pid tmp_clean = "tmprgreen_%i_clean" % pid gcore.run_command("r.thin", input=stream, output=tmp_thin) gcore.run_command("r.to.vect", input=tmp_thin, flags="v", output=tmp_clean, type="line") gcore.run_command("v.edit", map=tmp_clean, tool="delete", cats="0") # pdb.set_trace() gcore.run_command("v.build", map=tmp_clean) dissolve_lines(tmp_clean, E) # TODO: dissolve the areas with the same cat # adding columns gcore.run_command( "v.db.addcolumn", map=E, columns="Qown double precision," "Qtot double precision, Hmean double precision," "H0 double precision, Eown_kW double precision," "IDup1 int, Eup1_kW double precision," "IDup2 int, Eup2_kW double precision," "IDup3 int, Eup3_kW double precision," "Etot_kW double precision", ) gcore.run_command("db.dropcolumn", flags="f", table=E, column="label") # Open database connection vec = VectorTopo(E) vec.open("rw") link = vec.dblinks[0] conn = link.connection() # prepare a cursor object using cursor() method cursor = conn.cursor() # I modify with specific power (kW/km) see # 4._Julio_Alterach_-_Evaluation_of_the_residual_potential_ # hydropower_production_in_Italy # compute the lenght of the river in a basin # import ipdb; ipdb.set_trace() for ID in inputs: length = 0 for l in vec.cat(ID, "lines"): length += l.length() basins_tot[ID].length = length db = [ basins_tot[ID].discharge_own, basins_tot[ID].discharge_tot, basins_tot[ID].h_mean, basins_tot[ID].h_closure, basins_tot[ID].E_own, ] if len(basins_tot[ID].E_up) == 0: db = db + [0, 0.0, 0, 0.0, 0, 0.0, basins_tot[ID].E_own] elif len(basins_tot[ID].E_up) == 1: db = db + [ list(basins_tot[ID].E_up.keys())[0], list(basins_tot[ID].E_up.values())[0], 0, 0.0, 0, 0.0, basins_tot[ID].E_own + sum(basins_tot[ID].E_up.values()), ] elif len(basins_tot[ID].E_up) == 2: db = db + [ list(basins_tot[ID].E_up.keys())[0], list(basins_tot[ID].E_up.values())[0], list(basins_tot[ID].E_up.keys())[1], list(basins_tot[ID].E_up.values())[1], 0, 0.0, basins_tot[ID].E_own + sum(basins_tot[ID].E_up.values()), ] elif len(basins_tot[ID].E_up) == 3: # pdb.set_trace() db = db + [ list(basins_tot[ID].E_up.keys())[0], list(basins_tot[ID].E_up.values())[0], list(basins_tot[ID].E_up.keys())[1], list(basins_tot[ID].E_up.values())[1], list(basins_tot[ID].E_up.keys())[2], list(basins_tot[ID].E_up.values())[2], basins_tot[ID].E_own + sum(basins_tot[ID].E_up.values()), ] else: db = db + [0, 0.0, 0, 0.0, 0, 0.0, basins_tot[ID].E_own] db = [float(d) for d in db] # FIXME: numpy.float is not accepted # TODO: change values, give only key and vals without key vec.table.update(basins_tot[ID].ID, db, cursor) # disconnect from server conn.commit() conn.close() vec.close()