A method and device for generating river gradient graphics
By calculating and drawing the line width of river graphics on a pixel-by-pixel level, the problem in the prior art that river graphics are prone to staircase effects is solved, a true gradient effect of river graphics is achieved, and the drawing quality of river gradient graphics is significantly improved.
Patent Information
- Application Number
- CN202010753707.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-07-30
- Publication Date
- 2025-01-21
- Estimated Expiration
- 2040-07-30
AI Technical Summary
When drawing a gradient pattern of rivers, the prior art is prone to produce a step effect, resulting in the stepped shape of the rivers, and the gradient effect is not ideal.
By obtaining the position coordinate array of the river and projecting it to the screen coordinate system, all line segments of the river are determined, and calculated and drawn based on factors such as the slope of each line segment, the coordinates of the pixels, the starting width, ending width, and total length of the river. The line width of each pixel realizes the pixel-by-pixel gradient of the river graphics.
It solves the problem that the traditional segmentation method easily produces a staircase effect when drawing river gradient graphics, and realizes the true size gradient of river graphics. The gradient effect is better and consistent with the actual situation.
Smart Images

Figure CN111915700B_ABST
Abstract
Description
Technical Field
[0001] The invention relates to a method and a device for generating river gradient graphics, belonging to the technical field of river gradient graphics drawing. Background Art
[0002] Rivers are one of the common basic geographical elements and an important part of topographic maps. They reflect the basic skeleton of the terrain. On maps, in order to vividly show the flow direction and convergence relationship of rivers, rivers are generally drawn in a graphic gradient manner. In the period of manual mapping, single-line rivers are generally divided into several small segments, and then line segments of different widths are drawn for different segments in order; in the period of computer-aided mapping, rivers are drawn by simulating the method of manually drawing gradient rivers, that is, the river is divided into multiple segments, and the river is drawn in a step-by-step thickening method. Compared with the manual method of drawing gradient rivers, the computer-aided mapping method can greatly improve the mapping efficiency and can show the river morphology to a greater extent. However, there are the following problems: when drawing river graphics, each river segment is first drawn in segments, and then the river segments are connected to obtain the overall river graphics. The drawn rivers are of equal width in the same segment, and the changes between segments appear at the nodes. The nodes are prone to produce a step effect, which leads to the problem that the overall graphics are stepped, and the river gradient effect is not ideal.
[0003] There are also some methods to solve the above problems. For example, Li Li, Wang Jiechen, etc. proposed a river gradient method based on segmented buffer technology in a document entitled "A method for drawing gradient symbols of single-line rivers" published in the 11th issue of Surveying and Mapping Bulletin in 2008. This method first divides the river into several differential segments with a very small spacing to avoid step-like mutations, and then establishes a buffer zone for each segment to avoid the shortcomings of too straight lines and obvious turns; Yang Li published a document entitled "Realization of river system gradient effects based on CorelDraw secondary development" in the 2nd issue of Modern Surveying and Mapping in 2019. In the paper entitled "Design and Development of Gradient River Cartography Symbols", Zeng Liting and Chen Yongkang published a paper entitled "Design and Development of Gradient River Cartography Symbols" at the 2011 National Conference on Geometric Design and Computing. In this paper, a method for achieving the gradient effect of a river system was proposed. The method draws a perpendicular line to each node on the axis of the river, obtains side points far from the axis on the perpendicular line, and connects adjacent points with straight lines or arcs according to the position of the points, thus achieving a natural transition at the nodes.
[0004] The above methods either improve the step problem of river graphics drawing by reducing the spacing when the river is segmented, or improve the step problem by precisely determining the width of different river sections, or improve the step problem by realizing natural transition at the nodes. Although certain effects can be achieved, fundamentally speaking, river graphics are still drawn in sections, and there is still the problem that the river is of equal width in the same section. In fact, the river width will gradually narrow or widen as the river goes, that is, the river width will gradually change, rather than being of equal width. Therefore, the above methods do not achieve true river graphics size gradient, the drawn river graphics do not match the actual situation, and the river gradient effect is poor. Summary of the invention
[0005] The object of the present invention is to provide a method and device for generating river gradient graphics, so as to solve the problem that the gradient effect of river gradient graphics generated by the existing method is poor.
[0006] To achieve the above object, the present invention provides a method for generating a river gradient graph, the method comprising the following steps:
[0007] Get the location coordinate array of the river;
[0008] Project the river's position coordinate array to the screen coordinate system. After the projection, each two adjacent points in the position coordinate array form a line segment, and then obtain all the line segments corresponding to the river.
[0009] Draw each line segment of the river, and after all the line segments corresponding to the river are drawn, a river gradient graphic is obtained;
[0010] Among them, the drawing process of a line segment is:
[0011] Calculate the coordinates of all the pixels that the line segment passes through;
[0012] The line width corresponding to each pixel point is determined according to the starting width of the river, the ending width of the river, the total length of the river, and the length along the line from the starting point of the river to the corresponding pixel point;
[0013] Each pixel is drawn according to the slope of the line segment, the coordinates of the corresponding pixel and the line width, until all the pixel points through which the line segment passes are drawn.
[0014] The present invention also provides a river gradient graphic generation device, which includes a processor and a memory, and the processor executes a computer program stored in the memory to implement the above-mentioned river gradient graphic generation method.
[0015] The beneficial effects of the present invention are as follows: the present invention uses pixel points as units to draw river graphics, firstly determines all the line segments of the river, then calculates all the pixel points that each line segment of the river passes through, and then completes the line segment drawing by drawing each pixel point that the line segment passes through, thereby completing the river graphics drawing. Among them, when drawing the pixel points, the factors such as the slope of the line segment where the pixel point is located, the coordinates of the pixel point, the starting width of the river, the ending width of the river, the total length of the river, and the length along the line from the starting point of the river to the pixel point are comprehensively considered, thereby ensuring the accuracy of the pixel point drawing; the present invention can realize the drawing of river gradient graphics at the pixel level, which solves the problem that the traditional segmentation method is prone to produce a step effect when drawing river gradient graphics, and the gradient effect is better.
[0016] Furthermore, in order to calculate the line width corresponding to the pixel point, in the above method and device, the line width calculation formula is used to calculate the line width corresponding to each pixel point, and the line width calculation formula is: w = w s +(w e -w s )·L k / L, where w is the line width corresponding to the pixel point, w s 、w e are the starting width and ending width of the river respectively, L is the total length of the river, L k It is the length along the line from the starting point of the river to the corresponding pixel point.
[0017] Furthermore, in order to realize the drawing of pixel points, in the above method and device, a pixel point (x k ,y k ) is drawn as follows: at the pixel point (x k ,y k ) is drawn at the vertical line of the line segment, and a pixel point (x k ,y k ), the equidistant side points refer to the two equidistant side points on the vertical line that are adjacent to the pixel point (x k ,y k ) is equal to the pixel point w / 2, w is the pixel point (x k ,y k ) corresponding to the line width; these two equidistant side points form a new line segment, and the pixel point (x) is completed by drawing all the pixel points through which the new line segment passes. k ,y k )’s drawing.
[0018] Furthermore, in the above method and device, a pixel point (x k ,y k ) are (x k ′,yk ′)、(x k ″,y k ″), the calculation formulas for the coordinates of two equidistant points in the screen coordinate system are as follows:
[0019]
[0020]
[0021] In the formula, Δx is the difference between the horizontal coordinates of the two end points of the line segment, and Δy is the difference between the vertical coordinates of the two end points of the line segment.
[0022] Furthermore, in the above method and device, the Bresenham algorithm is used to calculate the coordinates of all pixel points that the line segment passes through.
[0023] Furthermore, in order to make the river drawing effect smoother, in the above method and device, the method also includes the step of smoothing the position coordinate array of the river, and projecting the smoothed position coordinate array of the river to the screen coordinate system.
[0024] Furthermore, in the above method and device, a linear iteration method is used to smooth the position coordinate array of the river. BRIEF DESCRIPTION OF THE DRAWINGS
[0025] Figure 1 is a flow chart of a method for generating a river gradient graphic in an embodiment of the method of the present invention;
[0026] Figure 2 is a schematic diagram of pixel drawing in an embodiment of the method of the present invention;
[0027] Figure 3 is a schematic diagram of a river gradient graph in an embodiment of the method of the present invention;
[0028] Figure 4 It is a structural diagram of a river gradient graphics generating device in an embodiment of the device of the present invention. DETAILED DESCRIPTION
[0029] In order to make the purpose, technical solutions and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the accompanying drawings and embodiments.
[0030] Method Example:
[0031] Take the ordered position coordinate array of a single river as the processing object and use Figure 1 The process of generating the river gradient graphic of the river by the river gradient graphic generation method of the present embodiment is as follows:
[0032] Step 1: Get the original position coordinate array of the river, use the linear iteration method to smooth the original position coordinate array of the river (for example, smooth it by interpolation method), and generate a new position coordinate array of the river to ensure that the river drawing effect is smoother.
[0033] Step 2: Generate all line segments corresponding to the river;
[0034] Project the new position coordinate array of the river to the screen coordinate system. Each two adjacent points in the projected position coordinate array form a line segment, and then obtain all the line segments corresponding to the river. For example, in the projected position coordinate array, each adjacent point S(x s ,y s )、E(x e ,y e ) form a line segment SE.
[0035] Step 3: Draw each line segment of the river. The drawing process of line segment SE is as follows:
[0036] 1) Calculate the coordinates of all pixels that the line segment SE passes through;
[0037] In this embodiment, the Bresenham algorithm is used to calculate the coordinates of all the pixels that each line segment passes through. This method is a prior art and specifically includes the following steps:
[0038] First, calculate the slope m of line segment SE:
[0039] Δx=x e -x s , Δy=y e -y s Formula (1)
[0040] m=Δy / Δx Formula (2)
[0041] Then, the corresponding calculation method is selected according to the slope m of the line segment SE, which is mainly divided into the following two cases:
[0042] If |m|≤1, the x-axis direction is selected as the increasing direction, where if x s ≤x e , then each step increases by 1; if x s >x e , then each step increases by -1. For example, when 0≤m≤1 and x s ≤x e The following steps are taken to calculate the pixel points through which the line segment SE to be drawn passes:
[0043] ① Take the endpoint S of the line segment SE to be drawn as the first pixel point, and calculate the discriminant parameter p0 of the first pixel point:
[0044] p0=2·Δy-Δx Formula (3)
[0045] ② Starting from k = 0, the horizontal coordinate value x of each pixel along the line k The following tests are carried out:
[0046] If p k <0, the coordinates of the next pixel are (x k +1,y k ),and:
[0047] p k+1 =p k +2·Δy Formula (4)
[0048] If p k ≥0, then the coordinates of the next pixel are (x k +1,y k +1), and:
[0049] p k+1 =p k +2·Δy-2·Δx Formula (5)
[0050] ③Repeat step ② for a total of Δx-1 times.
[0051] If |m|>1, the y direction is selected as the increasing direction, where if y s ≤y e , then each step increases by 1; if y s >y e , then each step increases by -1. For example, when m>1 and y s ≤y e The following steps are taken to calculate the pixel points through which the line segment SE to be drawn passes:
[0052] ① Take the endpoint S of the line segment SE to be drawn as the first pixel point, and calculate the discriminant parameter p0 of the first pixel point:
[0053] p0=2·Δx-Δy Formula (6)
[0054] ② Starting from k = 0, the ordinate value y of each pixel along the line k The following tests are carried out:
[0055] If p k <0, the coordinates of the next pixel are (x k ,y k +1), and:
[0056] p k+1 =p k +2·Δx Formula (7)
[0057] If p k ≥0, then the coordinates of the next pixel are (x k +1,y k +1), and:
[0058] p k+1 =p k +2·Δx-2·Δy Formula (8)
[0059] ③Repeat step ② for a total of Δy-1 times.
[0060] 2) Calculate the line width corresponding to each pixel point that the line segment SE passes through;
[0061] After the coordinates of all the pixels that the line segment SE passes through are calculated using the Bresenham algorithm, the line width corresponding to each pixel can be determined based on the starting width of the river, the ending width of the river, the total length of the river, and the length along the line from the starting point of the river to the corresponding pixel.
[0062] This embodiment uses a linear interpolation method to calculate the line width of each pixel point that the line segment SE passes through. Let w s 、w e are the starting width and ending width of the river respectively, L is the total length of the river, L k is any pixel point (x k ,y k ) along the line length, then the pixel point (x k ,y k ) is calculated as follows:
[0063] w=w s +(w e -w s )·L k / L Formula (9)
[0064] Among them, w s 、w e It needs to be determined based on the actual situation of the river.
[0065] 3) Draw each pixel point that the line segment SE passes through according to the slope of the line segment SE, the coordinates of the corresponding pixel points and the line width, until all the pixel points that the line segment SE passes through are drawn, and the drawing of the line segment SE is completed.
[0066] Draw any pixel point (x k ,y k ) is used as an example to explain in detail, the slope of line segment SE is m, the pixel point (x k ,y k ) has a line width of w, such as Figure 2As shown, first calculate the pixel point (x k ,y k ) corresponds to two equidistant points (x k ′,y k ′) and (x k ″,y k ″), specifically, by k ,y k ) is a perpendicular line to the line segment SE, and a point on the perpendicular line that is adjacent to the pixel point (x k ,y k ) is equal to two pixels w / 2 as the pixel point (x k ,y k ) are two equidistant points.
[0067] In the screen coordinate system, the positive direction of the y axis is downward, the positive direction of the x axis is to the right, and the equidistant points (x k ′,y k ′) and (x k ″,y k The calculation formula of the coordinates is as follows:
[0068]
[0069]
[0070] In the formula, Δx is the difference between the horizontal coordinates of the two endpoints of line segment SE, and Δy is the difference between the vertical coordinates of the two endpoints of line segment SE. Of course, we can also use the coordinates of the two endpoints of line segment SE to calculate the slope m of line segment SE, and then calculate α = tan -1 m, and then we get sinα and cosα.
[0071] Then, place the equidistant points (x k ′,y k ′) and (x k ″,y k ″) as the two endpoints of the new line segment to form a new line segment, use the Bresenham algorithm to find all the pixels that the new line segment passes through and draw these pixels, so as to complete the pixel point (x k ,y k )’s drawing.
[0072] Step 4: After all the line segments corresponding to the river are drawn, a river gradient graphic is obtained.
[0073] Repeat step 3 above for all the line segments of the river to generate a river gradient graph. The result is as follows: Figure 3 It can be seen that the river gradient graphics drawn by the method of this embodiment are rich in details and have good rendering effect.
[0074] The river gradient graphics generation method of the present embodiment includes the step of smoothing the original position coordinate array of the river, with the purpose of obtaining more river position coordinate data by smoothing the original position coordinate array of the river, thereby ensuring a smoother river drawing effect; as other implementation methods, if the acquired original position coordinate array of the river already contains a sufficient number of river position coordinate data to obtain an ideal river drawing effect, the smoothing step can be omitted, and in this case, the ideal river gradient graphics can be obtained by directly performing subsequent processing on the acquired original position coordinate array of the river.
[0075] Device Example:
[0076] The river gradient graphics generating device of this embodiment is as follows: Figure 4 As shown, the device includes a processor and a memory, wherein a computer program that can be run on the processor is stored in the memory, and the processor implements the method in the above method embodiment when executing the computer program.
[0077] That is, the method in the above method embodiment should be understood as a process of a river gradient graphic generation method that can be implemented by computer program instructions. These computer program instructions can be provided to a processor so that the processor executes these instructions to generate functions specified in the above method flow.
[0078] The processor referred to in this embodiment refers to a processing device such as a microprocessor MCU or a programmable logic device FPGA.
[0079] The memory referred to in this embodiment includes a physical device for storing information, which is usually to digitize the information and then store it in a medium using electrical, magnetic or optical methods. For example: various memories that use electrical energy to store information, such as RAM, ROM, etc.; various memories that use magnetic energy to store information, such as hard disks, floppy disks, tapes, magnetic core memories, bubble memories, and USB flash drives; various memories that use optical methods to store information, such as CDs or DVDs. Of course, there are other types of memories, such as quantum memories, graphene memories, and so on.
[0080] The device is composed of the above-mentioned memory, processor and computer program, and is implemented by the processor executing corresponding program instructions in the computer. The processor can be equipped with various operating systems, such as Windows operating system, Linux system, Android, iOS system, etc.
Claims
1. A method for generating river gradient graphics, characterized in that: The method comprises the following steps: Get the location coordinate array of the river; Project the river's position coordinate array to the screen coordinate system. After the projection, each two adjacent points in the position coordinate array form a line segment, and then obtain all the line segments corresponding to the river. Draw each line segment of the river, and after all the line segments corresponding to the river are drawn, a river gradient graphic is obtained; Among them, the drawing process of a line segment is: Calculate the coordinates of all the pixels that the line segment passes through; The line width corresponding to each pixel point is determined according to the starting width of the river, the ending width of the river, the total length of the river, and the length along the line from the starting point of the river to the corresponding pixel point; the line width calculation formula is: = , where is the line width corresponding to the pixel point, 、 are the starting width and ending width of the river respectively. is the total length of the river, is the length of the line from the starting point of the river to the corresponding pixel point; Each pixel is drawn according to the slope of the line segment, the coordinates of the corresponding pixel and the line width, until all the pixel points through which the line segment passes are drawn.
2. The method for generating river gradient graphics according to claim 1, characterized in that: Pixel points on a line segment ( , ) is drawn as follows: at the pixel point ( , ) is drawn at the vertical line of the line segment, and a pixel point ( , ), wherein the equidistant side points refer to the two equidistant side points on the vertical line that are adjacent to the pixel point ( , ) is equal to Pixels, is a pixel ( , ) corresponding to the line width; these two equidistant side points form a new line segment, and the pixel point ( , )’s drawing.
3. The method for generating river gradient graphics according to claim 2, characterized in that: Pixel points on a line segment ( , ) are ( , )、( , ), the calculation formulas for the coordinates of two equidistant points in the screen coordinate system are as follows: , , In the formula, , , is the difference between the horizontal coordinates of the two end points of the line segment. is the difference between the ordinates of the two end points of the line segment.
4. The method for generating river gradient graphics according to claim 1, characterized in that: The Bresenham algorithm is used to calculate the coordinates of all pixels that the line segment passes through.
5. The method for generating river gradient graphics according to claim 1, characterized in that: The method also includes the step of smoothing the position coordinate array of the river, and projecting the smoothed position coordinate array of the river to a screen coordinate system.
6. The method for generating river gradient graphics according to claim 5, characterized in that: The linear iteration method is used to smooth the position coordinate array of the river.
7. A river gradient graphics generating device, characterized in that: The device comprises a processor and a memory, wherein the processor executes a computer program stored in the memory to implement the river gradient graphics generation method according to any one of claims 1 to 6.
Citation Information
Patent Citations
River water environment physical model measuring device and method
CN103234870A
Water conservation map data model-based flood risk map drawing method and system thereof
CN103366633A