def test_angles(self): """Test Node angles""" node = Node(v_id=4, c_mapinfo=self.c_mapinfo) angles = (-1.5707963705062866, 0.7853981852531433, 1.2793395519256592, 1.8622530698776245, 2.356194496154785) self.assertTupleEqual(angles, tuple(node.angles()))
def test_ilines(self): """Test Node neighbors""" node = Node(v_id=4, c_mapinfo=self.c_mapinfo) self.assertTupleEqual((6, -4, 7, -3, -5), tuple(node.ilines())) self.assertTupleEqual((-4, -3, -5), tuple(node.ilines(only_in=True))) node = Node(v_id=4, c_mapinfo=self.c_mapinfo) self.assertTupleEqual((6, 7), tuple(node.ilines(only_out=True)))
def nodes(self, bbox): """Find the nearest area. Vect_find_area""" found = Ilist() if libvect.Vect_select_nodes_by_box(self.c_mapinfo, bbox.c_bbox, found.c_ilist): for n_id in found: yield Node(v_id=n_id, c_mapinfo=self.c_mapinfo, table=self.table, writable=self.writable)
def node(self, point, maxdist): """Find the nearest node around a specific point. :param point: The point to search :type point: grass.pygrass.vector.geometry.Point :param maxdist: The maximum search distance around the point :type maxdist: float :return: A grass.pygrass.vector.geometry.Node if found or None This methods uses libvect.Vect_find_node()() Examples: >>> from grass.pygrass.vector import VectorTopo >>> from grass.pygrass.vector.geometry import Point >>> test_vect = VectorTopo(test_vector_name) >>> test_vect.open('r') # Find nearest node >>> points = (Point(10,0), Point(10,4), Point(14,0)) >>> result = [] >>> for point in points: ... f = test_vect.find_by_point.node(point=point, maxdist=1) ... if f: ... result.append(f) >>> result [Node(2), Node(1), Node(6)] >>> test_vect.find_by_point.node(point=Point(20,20), maxdist=0) >>> test_vect.close() """ node_id = libvect.Vect_find_node( self.c_mapinfo, point.x, point.y, point.z if point.z else 0, float(maxdist), int(not point.is2D), ) if node_id: return Node( v_id=node_id, c_mapinfo=self.c_mapinfo, table=self.table, writeable=self.writeable, )
def nodes(self, bbox): """Find nodes inside a boundingbox. :param bbox: The boundingbox to search in :type bbox: grass.pygrass.vector.basic.Bbox :return: A list of nodes or None if nothing was found This methods uses libvect.Vect_select_nodes_by_box() Examples: >>> from grass.pygrass.vector import VectorTopo >>> from grass.pygrass.vector.basic import Bbox >>> test_vect = VectorTopo(test_vector_name) >>> test_vect.open('r') # Find nodes in box >>> bbox = Bbox(north=5, south=-1, east=15, west=9) >>> result = test_vect.find_by_bbox.nodes(bbox=bbox) >>> [node for node in result] [Node(2), Node(1), Node(4), Node(3), Node(5), Node(6)] >>> bbox = Bbox(north=20, south=18, east=20, west=18) >>> test_vect.find_by_bbox.nodes(bbox=bbox) >>> test_vect.close() """ found = Ilist() if libvect.Vect_select_nodes_by_box(self.c_mapinfo, bbox.c_bbox, found.c_ilist): if len(found) > 0: return ( Node( v_id=n_id, c_mapinfo=self.c_mapinfo, table=self.table, writeable=self.writeable, ) for n_id in found )
def test_coords(self): """Test Node coordinates""" node = Node(v_id=4, c_mapinfo=self.c_mapinfo) self.assertTupleEqual((1.0, 0.0), node.coords())
def test_init(self): """Test Node __init__""" node = Node(v_id=4, c_mapinfo=self.c_mapinfo) self.assertEqual(4, node.id) self.assertTrue(node.is2D) self.assertEqual(5, node.nlines)
def test_angles(self): """Test Node angles""" node = Node(v_id=206, c_mapinfo=self.c_mapinfo) angles = (-3.044905185699463, -1.026218056678772, 0.10362745821475983, 2.2236430644989014) self.assertTupleEqual(angles, tuple(node.angles()))
def test_ilines(self): """Test Node coordinates""" node = Node(v_id=206, c_mapinfo=self.c_mapinfo) self.assertTupleEqual((288, -301, -287, 284), tuple(node.ilines())) self.assertTupleEqual((-301, -287), tuple(node.ilines(only_in=True))) self.assertTupleEqual((288, 284), tuple(node.ilines(only_out=True)))
def test_coords(self): """Test Node coordinates""" node = Node(v_id=206, c_mapinfo=self.c_mapinfo) self.assertTupleEqual((620906.5786131569, 221685.65913128198), node.coords())