Disclosure of Invention
In order to overcome the defects of the prior art, one of the purposes of the invention is to provide a method for rendering elements and symbols of a cross-platform vector map based on a QGIS, wherein a symbol rendering framework based on the QGIS completely separates symbol design and rendering by using a strong rendering logic and layer management mechanism of the QGIS, and the symbols are designed in a symbol description mode, so that the symbols can be designed and edited independently, and the method has good independence and strong cross-platform capability.
The invention also aims to provide electronic equipment, which is based on a symbol rendering framework of the QGIS, completely separates symbol design and rendering by utilizing the powerful rendering logic and layer management mechanism of the QGIS, designs symbols by means of symbol description, can independently design and edit symbols, and has good independence and strong cross-platform capability.
The invention also aims to provide a computer readable storage medium, wherein a symbol rendering framework based on the QGIS can be realized when a computer program in the storage medium runs, the symbol design and rendering are completely separated by utilizing the strong rendering logic and layer management mechanism of the QGIS, the symbol is designed in a symbol description mode, the symbol can be designed and edited independently, and the computer readable storage medium has good independence and strong cross-platform capability.
One of the purposes of the invention is realized by adopting the following technical scheme:
a cross-platform vector map element symbol rendering method based on a QGIS (geographic information system) comprises the following steps:
establishing a basic element library, mapping each basic element into corresponding semantic description and storing the semantic description into the basic element library; the semantic description is used for establishing a corresponding basic element and a parameter value corresponding to the basic element; the basic elements comprise points, simple lines, dot-dash lines, width gradually-changing lines, double lines, simple surfaces, filling points and filling lines;
obtaining semantic description of corresponding basic elements according to a symbol design instruction input by a user to generate symbol description of corresponding symbols and storing the symbol description into a symbol library, wherein the symbol description is formed by semantic description of the basic elements; the symbol design instruction includes: a basic element selection instruction, a basic element parameter setting instruction and a basic element superposition instruction;
and acquiring the symbol description of the symbol to be drawn and rendering the symbol according to the symbol description and the map parameter information.
Further, the obtaining of the semantic description of the corresponding basic element according to the symbol design instruction input by the user to generate the symbol description of the corresponding symbol specifically includes:
obtaining semantic description of the corresponding basic element according to the basic element selection instruction and the basic element parameter setting instruction to generate sub-symbolic description of the current layer; and according to the basic element superposition instruction, superposing the sub-symbol descriptions of all the layers to generate the symbol description of the corresponding symbol.
Further, the sub-symbol descriptions of each layer include sub-color attributes of the basic elements of the current layer, the symbol description generated after the sub-symbol descriptions are superimposed includes main color attributes, the sub-color attributes are used for setting colors of the corresponding basic elements, and the main color attributes are used for setting colors of all basic elements which constitute the current symbol and are not set with colors.
Further, the sub-symbol description of each layer also includes a coordinate attribute of the basic element, and the coordinate attribute is used for positioning the position of the current basic element in the symbol to be drawn.
Further, the symbol description of each symbol is stored corresponding to a unique code.
Further, the obtaining of the symbol description of the symbol to be drawn and the rendering of the symbol according to the symbol description and the map parameter information specifically include:
searching corresponding symbol description according to the uniqueness code of the symbol to be drawn, identifying and analyzing each sub-symbol description in the symbol description through a basic semantic rule to obtain each basic element and the parameter of each basic element, and constructing corresponding Pen or Brush according to the parameter of each basic element by using GDI to perform symbol rendering.
The second purpose of the invention is realized by adopting the following technical scheme:
an electronic device comprising a processor and a memory, the memory storing an executable computer program, the processor being readable by the computer program in the memory and operative to implement a QGIS-based cross-platform vector map element symbol rendering method as described above.
The third purpose of the invention is realized by adopting the following technical scheme:
a computer readable storage medium having stored thereon an executable computer program which when run may implement a method of QGIS-based cross-platform vector map element symbol rendering as described above.
Compared with the prior art, the invention has the beneficial effects that:
the QGIS-based cross-platform vector map element symbol rendering method is based on a symbol rendering framework of the QGIS, utilizes the powerful rendering logic and layer management mechanism of the QGIS to completely separate symbol design and rendering, can independently design and edit symbols, and has good independence and strong cross-platform capability; the symbols are designed in a symbol description mode, the symbol description of the designed symbols is stored in a symbol library, and when the symbols need to be drawn, the corresponding symbol description can be directly obtained from the symbol library to perform symbol rendering.
Detailed Description
The present invention will be further described with reference to the accompanying drawings and the detailed description, and it should be noted that any combination of the embodiments or technical features described below can be used to form a new embodiment without conflict.
Referring to fig. 1 and 2, a method for rendering symbols of elements of a cross-platform vector map based on QGIS includes the following steps:
s1, establishing a basic element library, mapping each basic element into corresponding semantic description and storing the semantic description into the basic element library; the semantic description is used for establishing a corresponding basic element and a parameter value corresponding to the basic element; the basic elements comprise points, simple lines, dot-dash lines, width gradually-changing lines, double lines, simple surfaces, filling points and filling lines; mapping the basic elements through semantic description, wherein each element is mapped into corresponding description semantics, and parameters in the elements are also mapped into corresponding description semantics; basic elements and parameter values thereof can be established by analyzing the description semantics;
s2, obtaining semantic description of corresponding basic elements according to a symbol design instruction input by a user, generating symbol description of corresponding symbols and storing the symbol description into a symbol library, wherein the symbol description is formed by semantic description of the basic elements; the symbol design instruction includes: a basic element selection instruction, a basic element parameter setting instruction and a basic element superposition instruction; in the symbol design process, the color and the size of the basic element can be adjusted by modifying the parameter attribute in the semantic description of the basic element; complex symbols can be expressed by an overlaid description of the basic elements;
and S3, obtaining the symbol description of the symbol to be drawn and rendering the symbol according to the symbol description and the map parameter information.
The QGIS-based cross-platform vector map element symbol rendering method is based on a symbol rendering framework of the QGIS, utilizes the powerful rendering logic and layer management mechanism of the QGIS to completely separate symbol design and rendering, can independently design and edit symbols, and has good independence and strong cross-platform capability; the symbols are designed in a symbol description mode, the symbol description of the designed symbols is stored in a symbol library, and when the symbols need to be drawn, the corresponding symbol description can be directly obtained from the symbol library to perform symbol rendering.
One symbol rendering cycle consists of the following processes: firstly, obtaining all symbols to be drawn in a QGIS drawing area, obtaining map parameter information (including drawing proportion, background color of the drawing area and the like), then sending the parameter information to the realization classes of respective rendering of points, lines and surfaces, determining corresponding symbol description according to the unique code of the symbols, drawing the symbols through parameters after the symbol description analysis, the attribute information of basic elements, position information (position in the drawing area) and the like, and displaying the symbols in the drawing area.
The method inherits the rendering classes of points, lines and surfaces of a symbol layer and a renderer by virtue of rendering logic and a method of a QGIS (Quadrature information System) for visual definition of the symbol and symbolic rendering of the symbol, replaces the rendering realization of the bottom layer of the symbol layer, and perfectly combines definition and rendering of a symbol design rule.
As a preferred embodiment, the obtaining of the semantic description of the corresponding basic element according to the symbol design instruction input by the user to generate the symbolic description of the corresponding symbol specifically includes:
obtaining semantic description of the corresponding basic element according to the basic element selection instruction and the basic element parameter setting instruction to generate sub-symbolic description of the current layer; and according to the basic element superposition instruction, superposing the sub-symbol descriptions of all the layers to generate the symbol description of the corresponding symbol.
By the method, the hierarchical information of the symbols can be designed, eight basic elements provide parameter setting entries, and the sub-symbol description of the current layer is generated after the parameter setting is completed. That is, the basic element selection instruction selects the required basic element, and then the basic element parameter setting instruction sets the parameter of the basic element to obtain the semantic description of the corresponding basic element, that is, the sub-symbol description of the current layer is generated. For example, the line segment may have its length, width, color, rotation angle, left-right offset, up-down offset, etc. (as in fig. 3), and the selected line segment layer in the figure generates "line; 0.30; 0.000, 1.000; 0.000, -1.000 "represents, in order from left to right, that the primitive type is a line segment, the line width is 0.30, the first point coordinates are (0.000, 1.000), and the second point coordinates are (0.000, -1.000); the symbols of multiple layers generate complex symbol descriptions by superimposing different basic elements. Through the selection of the basic elements, the setting of parameters and the superposition and combination of a plurality of basic elements, a symbol which can express a certain meaning can be decomposed into one to a plurality of layers of basic elements, and each layer can be different basic elements.
As a preferred embodiment, the sub-symbol descriptions of each layer include sub-color attributes of the basic elements of the current layer, the symbol description generated by superimposing the sub-symbol descriptions includes a main color attribute, the sub-color attributes are used for setting the colors of the corresponding basic elements, and the main color attribute is used for setting the colors of all the basic elements which constitute the current symbol and are not provided with colors.
A complex symbol is composed of many basic elements, in the symbol design, there are the different and same color requirements of each basic element, in the method, each basic element can select color independently (or not), at the same time, the concept of dominant color of symbol is introduced, in the basic elements composing the symbol, the basic elements without selecting color all use the dominant color of symbol, when the color of each basic element of symbol needs to be consistent, it can not need to do color selection work many times.
As a preferred embodiment, the sub-symbol descriptions of the respective layers further include a coordinate attribute of the basic element, and the coordinate attribute is used for locating the position of the current basic element in the symbol to be drawn. The symbol is composed of a positioning point and a basic element existing relative to the positioning point, wherein the positioning point is the position of the center of the cross cursor in the drawing process (as shown in fig. 4). In the symbol design process, a two-dimensional coordinate system is established by taking a positioning center as an origin, simple elements forming symbols are added, and simple elements forming dot symbols can be added to the periphery accurately by using coordinates; the position of the simple element with respect to the origin can be adjusted by setting coordinate values by the coordinate attribute, and the simple element includes a single point, a multi-segment line, a polygon, a circular arc, a character, and an offset of an anchor point (the offset of a parameter set by the element to which the offset of the anchor point is added is referred to the anchor point after the offset, but the anchor point is not changed during the drawing, which corresponds to the fact that the elements after the offset of the anchor point are offset by the same amount in the same direction).
Furthermore, it is also possible to quickly set a multi-segment line or a polygon symbol by a coordinate attribute. In the multi-segment line and polygon symbols, the coordinate attributes can be directly adjusted except for the traditional offset method, so that complex line segments, irregular polygons and the like are realized. For example, by means of a multi-segment line set with coordinates as shown in fig. 5, the effect diagram is as shown in fig. 6. Therefore, the method is more convenient to realize by using a plurality of line segment combinations, and is more accurate in arrangement mode relative to offset and rotation.
In a preferred embodiment, the symbol description of each symbol is stored in correspondence with a unique code. By the method, the corresponding symbol description in the symbol library can be directly obtained through the unique code, and the method is simple and quick. Note that, symbols of the same code are the same, but symbols drawn using the same code can change their own information such as color and width by setting attribute values.
As a preferred embodiment, the obtaining of the symbol description of the symbol to be drawn and the rendering of the symbol according to the symbol description and the map parameter information specifically include:
searching corresponding symbol description according to the uniqueness code of the symbol to be drawn, identifying and analyzing each sub-symbol description in the symbol description through a basic semantic rule to obtain each basic element and the parameter of each basic element, and constructing corresponding Pen or Brush according to the parameter of each basic element by using GDI to perform symbol rendering.
The symbol construction rules applied in the method provided by the invention are as follows:
1) symbol color rule: a complex symbol is generally composed of a plurality of basic elements, in the symbol design, the color of each element is different from each other, and the color of each element is the same, in the system, each element can independently select the color (or not select) and simultaneously introduce the concept of dominant color of the symbol, in the basic elements composing the symbol, the elements which do not select the color all use the dominant color of the symbol, when the colors of the elements of the symbol are all required to be consistent, the color selection work can be carried out for a plurality of times.
2) The point element and the symbol are composed of a positioning point and a simple element existing relative to the positioning point, the positioning point is the position of the center of the cross cursor in the drawing process (as shown in fig. 4), in the symbol design process, a two-dimensional coordinate system is established by taking the positioning center as an origin, the simple element forming the symbol is added, and the position of the simple element relative to the origin is adjusted, the simple element comprises a single point, a multi-segment line, a polygon, an arc, a character and positioning point offset (the offset of parameters set by the element after the positioning point offset is added is referred to the positioning point after the offset, but the positioning point in the drawing process is unchanged, and is equivalent to that the elements after the positioning point offset are offset by the same amount in the same direction).
3) The simple line elements are simple lines with fixed line width which can be drawn only by the definition of pen lifting and pen dropping. Such as: solid lines, dashed lines, etc.
4) The dot-dash line element is a linear element formed by regularly inserting point symbols according to a definition rule, wherein the rule comprises a period, an endpoint, an offset and other insertion point symbol modes.
5) The width gradual change line element is added with 2-3 line types drawn in the process of gradual change of line width on the basis of a simple line.
6) The double-line element is a double-line element symbol formed by two simple lines or dot-dash lines according to a certain width and a connection form.
The symbol of the planar element is composed of a contour line and filling, the contour line is defined by the line symbol rule, and the filling mode is described separately here:
7) simple surface elements are simple surface elements filled with no fill or some transparency of one color.
8) The filling point elements are of two types, namely grid filling and center filling: and certain transverse and longitudinal distances and offset angles form a parallelogram, point symbols are filled at grid points, and point symbols are inserted into the centroid positions of the planar elements.
9) The fill line symbol is comprised of a line angle, a starting offset, and a spacing between two interposed lines to fill the line symbol.
10) The lines are called to fill in a vertical or bisectional pattern based on the orientation edges.
11) Meanwhile, the planar symbol supports multiple types of symbols, actually two symbols, and the same name is used to show which type of symbol depends on the attribute of the element, for example, when the backlight attribute is different, the symbol is different.
In the method provided by the invention, the symbol rendering class is divided into three types of points, lines and surfaces in general, and is responsible for acquiring corresponding symbol styles through coding element information sent by a QGIS rendering system and variables related to symbols in an attribute table, controlling the display conditions of the symbols through colors, line widths and the like, and controlling the corresponding changes of scaling and non-scaling according to the proportion.
1) When the point symbols are rendered, the non-character numbers are directly drawn after coordinate conversion through a series of track points, the character symbols are drawn after contour points of characters are calculated through the PaintPath, and paths are obtained through positioning points and coordinate conversion.
2) When the broken-line gradient is drawn, each real part is regarded as one surface, namely, a surface (as shown in fig. 7) consisting of 4 offset points (half of the line width is offset) on the upper side and the lower side of the head point and the tail point of the real part and 2 additional points when the real part passes through the top point is calculated, and finally, a plurality of surfaces drawn by all the real parts are combined into a gradient symbol. The solid line and the gradual change line are the same, and only the surface combined by the offset points at each vertex needs to be calculated. The method can also solve the problem of synchronization of the real parts of the lines after turning when double dotted lines are drawn.
3) When the grid filling surface is drawn, by means of a QT drawing mechanism, a primitive, namely a small picture with point symbols drawn at four grid points in two lines and two columns, is drawn first, the primitive is set to a drawing brush, and the whole surface entity is drawn directly by the drawing brush. Fill line symbols can also be drawn in the same way.
The invention also provides an electronic device, which comprises a processor and a memory, wherein the memory stores an executable computer program, and the processor can read the computer program in the memory and run to realize the QGIS-based cross-platform vector map element symbol rendering method.
Furthermore, the present invention also provides a computer readable storage medium, which stores an executable computer program, and when the computer program runs, the method for rendering symbols of elements of a cross-platform vector map based on QGIS as described above can be implemented.
The computer-readable storage medium stores a computer program in which the method of the present invention, if implemented in the form of software functional units and sold or used as a stand-alone product, can be stored. Based on such understanding, all or part of the flow of the method according to the embodiments of the present invention may also be implemented by a computer program, which may be stored in a computer storage medium and used by a processor to implement the steps of the embodiments of the method. Wherein the computer program comprises computer program code, which may be in the form of source code, object code, an executable file or some intermediate form, etc. The computer storage medium may include: any entity or device capable of carrying the computer program code, recording medium, usb disk, removable hard disk, magnetic disk, optical disk, computer Memory, Read-Only Memory (ROM), Random Access Memory (RAM), electrical carrier wave signals, telecommunications signals, software distribution medium, and the like. It should be noted that the computer storage media may include content that is subject to appropriate increase or decrease as required by legislation and patent practice in jurisdictions, for example, in some jurisdictions, computer storage media that does not include electrical carrier signals and telecommunications signals as subject to legislation and patent practice.
The above embodiments are only preferred embodiments of the present invention, and the protection scope of the present invention is not limited thereby, and any insubstantial changes and substitutions made by those skilled in the art based on the present invention are within the protection scope of the present invention.