wolfhece.PyVertex ================= .. py:module:: wolfhece.PyVertex .. autoapi-nested-parse:: Author: HECE - University of Liege, Pierre Archambeau Date: 2024 Copyright (c) 2024 University of Liege. All rights reserved. This script and its content are protected by copyright law. Unauthorized copying or distribution of this file, via any medium, is strictly prohibited. Module Contents --------------- .. py:data:: msg .. py:function:: getRGBfromI(rgbint: int) Convert integer to RGB .. py:function:: getIfromRGB(rgb: Union[list, tuple]) Convert RGB to integer .. py:function:: circle(x: float, y: float, r: float, numseg: int = 20) .. py:function:: cross(x: float, y: float, r: float) .. py:function:: quad(x: float, y: float, r: float) .. py:class:: Cloud_Styles(*args, **kwds) Bases: :py:obj:`enum.Enum` .. autoapi-inheritance-diagram:: wolfhece.PyVertex.Cloud_Styles :parts: 1 :private-bases: Create a collection of name/value pairs. Example enumeration: >>> class Color(Enum): ... RED = 1 ... BLUE = 2 ... GREEN = 3 Access them by: - attribute access:: >>> Color.RED - value lookup: >>> Color(1) - name lookup: >>> Color['RED'] Enumerations can be iterated over, and know how many members they have: >>> len(Color) 3 >>> list(Color) [, , ] Methods can be added to enumerations, and members can have their own attributes -- see the documentation for details. .. py:attribute:: POINT :value: 0 .. py:attribute:: CIRCLE :value: 1 .. py:attribute:: CROSS :value: 2 .. py:attribute:: QUAD :value: 3 .. py:class:: wolfvertex(x: float, y: float, z: float = -99999.0) Vertex WOLF - 3 coordonnées + valeurs associées dans un dictionnaire .. py:attribute:: x :type: float .. py:attribute:: y :type: float .. py:attribute:: z :type: float .. py:attribute:: values :type: dict :value: None .. py:attribute:: in_use :value: True .. py:method:: rotate(angle: float, center: tuple) Rotate the vertex :param angle: angle in radians (positive for counterclockwise) :param center: center of the rotation (x, y) .. py:method:: as_shapelypoint() Return a shapely Point .. py:method:: copy() Return a copy of the vertex .. py:method:: getcoords() Return the coordinates as a numpy array .. py:method:: dist3D(v: wolfvertex) -> float Return the 3D distance to another vertex :param v: vertex to compare .. py:method:: dist2D(v: wolfvertex) -> float Return the 2D distance to another vertex :param v: vertex to compare .. py:method:: addvalue(id, value) Add a value to the vertex :param id: key of the value :param value: value to add .. py:method:: add_value(id, value) Add a set of values to the vertex :param id: key of the value :param value: value to add .. py:method:: add_values(values: dict) Add a set of values to the vertex :param values: dictionary of values to add .. py:method:: getvalue(id) Return a value from the vertex :param id: key of the value .. py:method:: get_value(id) Return a set of values from the vertex :param id: key of the value .. py:method:: get_values(ids: list) -> dict Return a set of values from the vertex .. py:method:: limit2bounds(bounds=None) Limit the vertex to a set of bounds :param bounds: [[xmin, xmax], [ymin, ymax]] -- floats .. py:method:: is_like(v: wolfvertex, tol: float = 1e-06) Return True if the vertex is close to another one :param v: vertex to compare :param tol: tolerance .. py:class:: cloudproperties(lines=[], parent: cloud_vertices = None) Properties of a cloud of vertices .. py:attribute:: used :type: bool .. py:attribute:: color :type: int .. py:attribute:: width :type: int .. py:attribute:: style :type: int .. py:attribute:: alpha :type: int .. py:attribute:: filled :type: bool .. py:attribute:: legendvisible :type: bool .. py:attribute:: transparent :type: bool .. py:attribute:: flash :type: bool .. py:attribute:: legendtext :type: str .. py:attribute:: legendrelpos :type: int .. py:attribute:: legendx :type: float .. py:attribute:: legendy :type: float .. py:attribute:: legendbold :type: bool .. py:attribute:: legenditalic :type: bool .. py:attribute:: legendunderlined :type: bool .. py:attribute:: legendfontname .. py:attribute:: legendfontsize :type: int .. py:attribute:: legendcolor :type: int .. py:attribute:: legendpriority :type: int .. py:attribute:: legendorientation :type: int .. py:attribute:: legendwidth :type: int .. py:attribute:: legendheight :type: int .. py:attribute:: extrude :type: bool :value: False .. py:attribute:: myprops :type: wolfhece.PyParams.Wolf_Param :value: None .. py:attribute:: parent :value: None .. py:method:: fill_property() .. py:method:: defaultprop() Default properties .. py:method:: destroyprop() .. py:method:: show() .. py:class:: cloud_vertices(fname: Union[str, pathlib.Path] = '', fromxls: str = '', header: bool = False, toload=True, idx: str = '', plotted: bool = True, mapviewer=None, need_for_wx: bool = False, bbox: shapely.geometry.Polygon = None, dxf_imported_elts=['MTEXT', 'INSERT']) Bases: :py:obj:`wolfhece.drawing_obj.Element_To_Draw` .. autoapi-inheritance-diagram:: wolfhece.PyVertex.cloud_vertices :parts: 1 :private-bases: Scatter points with associated values Accepted formats : dxf, ascii Ascii separator : tabulation ' ', semicolon ';' 'dxf' type is automatically finded based on file extension otherwise, ascii file is supposed. If header exists in the first line of the file, you have to mention it by header=True in initialization. Total number of columns (nb) is important : - if nb >3 : the file must contain a header - if header[2].lower() == 'z', the file contains XYZ coordinates, otherwise all columns >1 are interpreted as values associated to XY Number os values = nb - (2 or 3) depending if Z coordinate exists Data are stored in Python dictionnary : - 'vertex' : XY or XYZ Each value is accessible through its headname as key : - 'headname1' : value with headname1 - 'headname2' : value with headname2 - 'headnamen' : value with headnamen For more information, see 'readfile' or 'import_from_dxf' .. py:attribute:: filename :type: str .. py:attribute:: myvertices :type: dict[int, dict['vertex':wolfvertex, str:float]] .. py:attribute:: xbounds :type: tuple .. py:attribute:: ybounds :type: tuple .. py:attribute:: zbounds :type: tuple .. py:attribute:: myprop :type: cloudproperties .. py:attribute:: mytree :type: scipy.spatial.KDTree .. py:attribute:: loaded :value: False .. py:attribute:: _header :value: False .. py:attribute:: gllist :value: 0 .. py:attribute:: forceupdategl :value: False .. py:attribute:: ongoing :value: False .. py:method:: create_kdtree() Set a Scipy KDTree structure based on a copy of the vertices .. py:method:: find_nearest(xyz: numpy.ndarray | list, nb: int = 1) Find nearest neighbors from Scipy KDTree structure based on a copy of the vertices. See : https://docs.scipy.org/doc/scipy/reference/generated/scipy.spatial.KDTree.query.html :param xyz: coordinates to find nearest neighbors -- shape (n, m) - where m is the number of coordinates (2 or 3) :param nb: number of nearest neighbors to find :return: list of distances, list of "Wolfvertex", list of elements stored in self.myvertices - or list of lists if xyz is a list of coordinates .. py:method:: init_from_nparray(array: numpy.ndarray) Fill-in from nparray -- shape (n,3) .. py:method:: check_plot() The cloud is plotted -- useful for mapviewer .. py:method:: uncheck_plot(unload=True) The cloud is not plotted -- useful for mapviewer .. py:method:: readfile(fname: str = '', header: bool = False) Reading an ascii file with or without header :param fname: (str) file name :param header: (bool) header in file (first line with column names) The separator is automatically detected among : tabulation, semicolon, space, comma. The file must contain at least 2 columns (X, Y) and may contain a third one (Z) and more (values). If values are present, they are stored in the dictionnary with their header name as key. .. py:method:: import_from_dxf(fn: str = '', imported_elts=['MTEXT', 'INSERT']) Importing DXF file using ezdxf library :param fn: file name (*.dxf) .. py:method:: import_from_shapefile(fn: str = '', targetcolumn: str = 'X1_Y1_Z1', bbox: shapely.geometry.Polygon = None) Importing Shapefile using geopandas library :param fn: file name :param targetcolumn: column name to be used for XYZ coordinates -- 'X1_Y1_Z1' is used by SPW-ARNE-DCENN .. py:method:: add_vertex(vertextoadd: wolfvertex = None, id=None, cloud: dict = None) Add a vertex to the cloud :param vertextoadd: vertex to add :param id: id of the vertex -- if None, the id is the length of the cloud :param cloud: cloud of vertices to add -- wolfvertex instances are pointed not copied .. py:method:: add_vertices(vertices: list[wolfvertex]) Add a list of vertices to the cloud .. py:method:: get_vertices() Return the vertices as a list .. py:method:: plot_legend(sx=None, sy=None, xmin=None, ymin=None, xmax=None, ymax=None, size=None) Plot OpenGL Legend is an image texture FIXME : to be improved .. py:method:: plot(update: bool = False, *args, **kwargs) OpenGL plot of the cloud of vertices FIXME : to be improved .. py:method:: show_properties() Show properties of the cloud .. py:method:: _updatebounds(newvert: wolfvertex = None, newcloud: dict = None) Update the bounds of the cloud :param newvert : (optional) vertex added to the cloud :param newcloud: (optional) cloud added to the cloud 'newvert' or 'newcloud' can be passed as argument during add_vertex operation. In this way, the bounds are updated without going through all the vertices -> expected more rapid. .. py:method:: find_minmax(force=False) Find the bounds of the cloud :param force: force the computation of the bounds .. py:method:: get_xyz(key='vertex') -> numpy.ndarray Return the vertices as numpy array :param key: key to be used for the third column (Z) -- 'vertex' or any key in the dictionnary -- if 'vertex'', [[X,Y,Z]] are returned .. py:property:: has_values :type: bool Check if the cloud has values (other than X,Y,Z) .. py:property:: header :type: list[str] Return the headers of the cloud .. py:method:: add_values_by_id_list(id: str, values: list[float]) Add values to the cloud :param id: use as key for the values :param values: list of values to be added - must be the same length as number of vertices .. py:property:: xyz :type: numpy.ndarray Alias for get_xyz method .. py:property:: nbvertices :type: int Number of vertices in the cloud .. py:method:: interp_on_array(myarray, key: str = 'vertex', method: Literal['linear', 'nearest', 'cubic'] = 'linear') Interpolation of the cloud on a 2D array :param myarray: WolfArray instance :param key: key to be used for the third column (Z) -- 'vertex' or any key in the dictionnary :param method: interpolation method -- 'linear', 'nearest', 'cubic' see interpolate_on_cloud method of WolfArray for more information .. py:method:: iter_on_vertices() Iteration on vertices .. py:method:: get_multipoint() Return the cloud as a Shapely MultiPoint .. py:method:: projectontrace(trace, return_cloud: bool = True, proximity: float = 99999.0) Project the cloud onto a trace (type 'vector') :param trace: vector class :param return_cloud: return a cloud or the lists [s],[z] :param proximity: search distance for projection :returns: New cloud containing the position information on the trace and altitude (s,z) else: s,z: 2 lists of floats :rtype: if return_cloud .. py:method:: plot_matplotlib(ax=None, **kwargs) Plot the cloud using matplotlib :param ax: axis to plot on -- if None, a new figure is created :param kwargs: additional arguments for matplotlib