def __init__(self, north=0, south=0, east=0, west=0, top=0, bottom=0): self.c_bbox = ctypes.pointer(libvect.bound_box()) self.north = north self.south = south self.east = east self.west = west self.top = top self.bottom = bottom
def setUp(self): """Create bbox object""" self.c_bbox = ctypes.pointer(libvect.bound_box()) # x range self.c_bbox.contents.E = 220 self.c_bbox.contents.W = 215 # y range self.c_bbox.contents.N = 135 self.c_bbox.contents.S = 125 # z range self.c_bbox.contents.T = 340 self.c_bbox.contents.B = 330
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
def _read_vector_info(name, mapset): """Read the vector map info from the file system and store the content into a dictionary This method uses the ctypes interface to the vector libraries to read the map metadata information :param name: The name of the map :param mapset: The mapset of the map :returns: The key value pairs of the map specific metadata, or None in case of an error """ kvp = {} if not libgis.G_find_vector(name, mapset): return None # The vector map structure Map = libvector.Map_info() # We open the maps always in topology mode first libvector.Vect_set_open_level(2) with_topo = True # Code lend from v.info main.c if libvector.Vect_open_old_head2(byref(Map), name, mapset, "1") < 2: # force level 1, open fully # NOTE: number of points, lines, boundaries, centroids, # faces, kernels is still available libvector.Vect_set_open_level(1) # no topology with_topo = False if libvector.Vect_open_old2(byref(Map), name, mapset, "1") < 1: logging.error( _("Unable to open vector map <%s>" % (libvector.Vect_get_full_name(byref(Map))))) return None # Release the vector spatial index memory when closed libvector.Vect_set_release_support(byref(Map)) # Read the extent information bbox = libvector.bound_box() libvector.Vect_get_map_box(byref(Map), byref(bbox)) kvp["north"] = bbox.N kvp["south"] = bbox.S kvp["east"] = bbox.E kvp["west"] = bbox.W kvp["top"] = bbox.T kvp["bottom"] = bbox.B kvp["map3d"] = bool(libvector.Vect_is_3d(byref(Map))) # Read number of features if with_topo: kvp["points"] = libvector.Vect_get_num_primitives( byref(Map), libvector.GV_POINT) kvp["lines"] = libvector.Vect_get_num_primitives( byref(Map), libvector.GV_LINE) kvp["boundaries"] = libvector.Vect_get_num_primitives( byref(Map), libvector.GV_BOUNDARY) kvp["centroids"] = libvector.Vect_get_num_primitives( byref(Map), libvector.GV_CENTROID) kvp["faces"] = libvector.Vect_get_num_primitives( byref(Map), libvector.GV_FACE) kvp["kernels"] = libvector.Vect_get_num_primitives( byref(Map), libvector.GV_KERNEL) # Summarize the primitives kvp["primitives"] = kvp["points"] + kvp["lines"] + \ kvp["boundaries"] + kvp["centroids"] if kvp["map3d"]: kvp["primitives"] += kvp["faces"] + kvp["kernels"] # Read topology information kvp["nodes"] = libvector.Vect_get_num_nodes(byref(Map)) kvp["areas"] = libvector.Vect_get_num_areas(byref(Map)) kvp["islands"] = libvector.Vect_get_num_islands(byref(Map)) kvp["holes"] = libvector.Vect_get_num_holes(byref(Map)) kvp["volumes"] = libvector.Vect_get_num_primitives( byref(Map), libvector.GV_VOLUME) else: kvp["points"] = None kvp["lines"] = None kvp["boundaries"] = None kvp["centroids"] = None kvp["faces"] = None kvp["kernels"] = None kvp["primitives"] = None kvp["nodes"] = None kvp["areas"] = None kvp["islands"] = None kvp["holes"] = None kvp["volumes"] = None libvector.Vect_close(byref(Map)) return kvp
def _read_vector_info(name, mapset): """Read the vector map info from the file system and store the content into a dictionary This method uses the ctypes interface to the vector libraries to read the map metadata information :param name: The name of the map :param mapset: The mapset of the map :returns: The key value pairs of the map specific metadata, or None in case of an error """ kvp = {} if not libgis.G_find_vector(name, mapset): return None # The vector map structure Map = libvector.Map_info() # We open the maps always in topology mode first libvector.Vect_set_open_level(2) with_topo = True # Code lend from v.info main.c if libvector.Vect_open_old_head2(byref(Map), name, mapset, "1") < 2: # force level 1, open fully # NOTE: number of points, lines, boundaries, centroids, # faces, kernels is still available libvector.Vect_set_open_level(1) # no topology with_topo = False if libvector.Vect_open_old2(byref(Map), name, mapset, "1") < 1: logging.error(_("Unable to open vector map <%s>" % (libvector.Vect_get_full_name(byref(Map))))) return None # Release the vector spatial index memory when closed libvector.Vect_set_release_support(byref(Map)) # Read the extent information bbox = libvector.bound_box() libvector.Vect_get_map_box(byref(Map), byref(bbox)) kvp["north"] = bbox.N kvp["south"] = bbox.S kvp["east"] = bbox.E kvp["west"] = bbox.W kvp["top"] = bbox.T kvp["bottom"] = bbox.B kvp["map3d"] = bool(libvector.Vect_is_3d(byref(Map))) # Read number of features if with_topo: kvp["points"] = libvector.Vect_get_num_primitives( byref(Map), libvector.GV_POINT) kvp["lines"] = libvector.Vect_get_num_primitives( byref(Map), libvector.GV_LINE) kvp["boundaries"] = libvector.Vect_get_num_primitives( byref(Map), libvector.GV_BOUNDARY) kvp["centroids"] = libvector.Vect_get_num_primitives( byref(Map), libvector.GV_CENTROID) kvp["faces"] = libvector.Vect_get_num_primitives( byref(Map), libvector.GV_FACE) kvp["kernels"] = libvector.Vect_get_num_primitives( byref(Map), libvector.GV_KERNEL) # Summarize the primitives kvp["primitives"] = kvp["points"] + kvp["lines"] + \ kvp["boundaries"] + kvp["centroids"] if kvp["map3d"]: kvp["primitives"] += kvp["faces"] + kvp["kernels"] # Read topology information kvp["nodes"] = libvector.Vect_get_num_nodes(byref(Map)) kvp["areas"] = libvector.Vect_get_num_areas(byref(Map)) kvp["islands"] = libvector.Vect_get_num_islands(byref(Map)) kvp["holes"] = libvector.Vect_get_num_holes(byref(Map)) kvp["volumes"] = libvector.Vect_get_num_primitives( byref(Map), libvector.GV_VOLUME) else: kvp["points"] = None kvp["lines"] = None kvp["boundaries"] = None kvp["centroids"] = None kvp["faces"] = None kvp["kernels"] = None kvp["primitives"] = None kvp["nodes"] = None kvp["areas"] = None kvp["islands"] = None kvp["holes"] = None kvp["volumes"] = None libvector.Vect_close(byref(Map)) return kvp
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(vectMapName), c_char_p(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