def SnapToNode(e, n, tresh, vectMap): """Find nearest node to click coordinates (within given threshold)""" if not haveCtypes: return None vectMap, mapSet = ParseMapStr(vectMap) openedMap = pointer(vectlib.Map_info()) ret = vectlib.Vect_open_old(openedMap, c_char_p(vectMap), c_char_p(mapSet)) if ret == 1: vectlib.Vect_close(openedMap) if ret != 2: return None nodeNum = vectlib.Vect_find_node(openedMap, c_double(e), c_double(n), c_double(0), c_double(tresh), vectlib.WITHOUT_Z) if nodeNum > 0: e = c_double(0) n = c_double(0) vectlib.Vect_get_node_coor(openedMap, nodeNum, byref(e), byref(n), None) # z e = e.value n = n.value else: vectlib.Vect_close(openedMap) return False return e, n
def curved(self): """Return""" mapset = GrassGis.G_find_vector2(self.nametin, "") if not mapset: sys.exit("Vector map <%s> not found" % self.nametin) # define map structure map_info = GrassGis.pointer(GrassVect.Map_info()) # define open level (level 2: topology) GrassVect.Vect_set_open_level(2) # open existing vector map GrassVect.Vect_open_old(map_info, self.nametin, mapset) print("Calculating curves") allrectas = [] rectas = self.get_rectas(map_info) for nivel in rectas: for recta in nivel: allrectas.append(recta) GrassVect.Vect_close(map_info) new = VectorTopo(self.namelines) new.open("w", with_z=True) for line in allrectas: new.write(Line(line)) new.close() grass.run_command( "v.build.polylines", input=self.namelines, output=self.namecurved, overwrite=True, quiet=True, )
def GetNearestNodeCat(e, n, layer, tresh, vectMap): if not haveCtypes: return -2 vectMapName, mapSet = ParseMapStr(vectMap) openedMap = pointer(vectlib.Map_info()) ret = vectlib.Vect_open_old(openedMap, c_char_p(encode(vectMapName)), c_char_p(encode(mapSet))) if ret == 1: vectlib.Vect_close(openedMap) if ret != 2: return -1 nodeNum = vectlib.Vect_find_node(openedMap, c_double(e), c_double(n), c_double(0), c_double(tresh), vectlib.WITHOUT_Z) if nodeNum > 0: e = c_double(0) n = c_double(0) vectlib.Vect_get_node_coor(openedMap, nodeNum, byref(e), byref(n), None) # z e = e.value n = n.value else: vectlib.Vect_close(openedMap) return -1 box = vectlib.bound_box() List = POINTER(vectlib.boxlist) List = vectlib.Vect_new_boxlist(c_int(0)) box.E = box.W = e box.N = box.S = n box.T = box.B = 0 vectlib.Vect_select_lines_by_box( openedMap, byref(box), vectlib.GV_POINT, List) found = 0 dcost = 0 Cats = POINTER(vectlib.line_cats) Cats = vectlib.Vect_new_cats_struct() cat = c_int(0) for j in range(List.contents.n_values): line = List.contents.id[j] type = vectlib.Vect_read_line(openedMap, None, Cats, line) if type != vectlib.GV_POINT: continue if vectlib.Vect_cat_get(Cats, c_int(layer), byref(cat)): found = 1 break if found: return cat.value return -1