Spatial data format conversion method and device, electronic equipment and storage medium
By directly obtaining and utilizing the geometric type information and dimension information of spatial data for format conversion, the complexity and low efficiency of converting the Gserialized format to wkb format in PostGIS is solved, and efficient spatial data conversion is achieved.
Patent Information
- Application Number
- CN202411363282.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-27
- Publication Date
- 2024-12-27
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
When PostGIS converts the Gserialized format spatial data in the PostgreSQL database to wkb format, the process is complicated and inefficient, and multiple parsing and conversion are required through the intermediate structure lwgeom.
By obtaining the geometric type information and dimension information of the spatial data to be converted, the format conversion is performed directly to form the target spatial data. There is no need to use the target type information and dimension information to perform direct format conversion through the intermediate structure.
It improves the efficiency of spatial data conversion, reduces complexity, realizes direct data conversion, reduces the number of analysis and memory application process, and improves system performance.
Smart Images

Figure CN119202054A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of data processing technology, and in particular to a method, device, electronic device and storage medium for format conversion of spatial data. Background Art
[0002] In PostgreSQL databases, the spatial data used by the PostGIS spatial data extension is stored in the Gserialized format. When using spatial data, PostGIS converts the stored Gserialized data into an intermediate lwgeom structure, then processes the lwgeom to obtain the corresponding results. The lwgeom structure, as an intermediate structure, contains a GBOX structure (containing bounding box information), an srid value, the spatial data geometry type, lwflags (including dimensionality and type information), and a structure with a simple type of pointarray coordinate information and a complex type of the contained simple type LWGEOM collection.
[0003] Considering the issue of universality, PostGIS generally does not perform special processing for specific functions, but instead converts Gserialized uniformly. Therefore, each time, additional memory allocation is required for the intermediate structure lwgeom to store the results of parsing the Gserialized data. For type conversion functions, the intermediate structure lwgeom needs to be parsed again to construct the output of the corresponding data format. Therefore, when converting spatial data in Gserialized format to wkb format, it is necessary to first convert the Gserialized data to the intermediate structure lwgeom and then to wkb format data. This conversion process is cumbersome and inefficient. Summary of the Invention
[0004] The present invention provides a method, device, electronic device and storage medium for format conversion of spatial data, so as to solve the problems of complex spatial data conversion process and low conversion efficiency.
[0005] According to one aspect of the present invention, a method for converting spatial data format is provided, comprising:
[0006] Obtaining the spatial data to be converted and parsing it to determine the geometric type information and dimension information of the spatial data to be converted;
[0007] determining target type information according to the geometric type information;
[0008] The format of the spatial data to be converted is converted according to the target type information and dimension information to form target spatial data.
[0009] According to another aspect of the present invention, there is provided a device for converting the format of spatial data, comprising:
[0010] The module for acquiring data to be converted is used to acquire and parse the spatial data to be converted, and determine the geometric type information and dimension information of the spatial data to be converted;
[0011] a target type determination module, configured to determine target type information according to the geometric type information;
[0012] The format conversion module is used to perform format conversion on the spatial data to be converted according to the target type information and dimension information to form target spatial data.
[0013] According to another aspect of the present invention, an electronic device is provided, comprising:
[0014] at least one processor, and a memory communicatively coupled to the at least one processor;
[0015] The memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute the spatial data format conversion method described in any embodiment of the present invention.
[0016] According to another aspect of the present invention, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the spatial data format conversion method described in any embodiment of the present invention when executed.
[0017] The technical solution of the embodiment of the present invention obtains the spatial data to be converted and parses it to determine the geometric type information and dimensional information of the spatial data to be converted; determines the target type information based on the geometric type information; performs format conversion on the spatial data to be converted based on the target type information and dimensional information to form target spatial data, which solves the problem of low efficiency of spatial data format conversion. The geometric type information and dimensional information of the spatial data to be converted are determined by parsing the spatial data to be converted, and the target type information is determined based on the geometric type information. Different types of spatial data to be converted are converted in different ways. Based on the target type information and dimensional information, the format of the spatial data to be converted is directly converted to obtain the target spatial data without converting it into an intermediate structure. This improves conversion efficiency, reduces the complexity of spatial data conversion, and can directly realize data conversion.
[0018] It should be understood that the content described in this section is not intended to identify the key or important features of the embodiments of the present invention, nor is it intended to limit the scope of the present invention. Other features of the present invention will become readily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0020] Figure 1 This is a flowchart of a method for converting spatial data format provided in accordance with the first embodiment of the present invention;
[0021] Figure 2 This is a flowchart of a method for converting spatial data format provided in accordance with a second embodiment of the present invention;
[0022] Figure 3 This is a schematic structural diagram of a spatial data format conversion device provided in accordance with a third embodiment of the present invention;
[0023] Figure 4 The present invention is a schematic structural diagram of an electronic device for implementing the spatial data format conversion method according to an embodiment of the present invention. DETAILED DESCRIPTION
[0024] In order to enable those skilled in the art to better understand the solutions of the present invention, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the embodiments described are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts should fall within the scope of protection of the present invention.
[0025] It should be noted that the terms "first", "second", etc. in the description and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that the numbers used in this way can be interchanged where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0026] Example 1
[0027] Figure 1 This is a flowchart of a method for converting the format of spatial data provided in Example 1 of the present invention. This embodiment is applicable to situations where the format of spatial data is converted. The method can be executed by a spatial data format conversion device. The spatial data format conversion device can be implemented in the form of hardware and / or software, and the spatial data format conversion device can be configured in an electronic device.
[0028] like Figure 1 As shown, the method includes:
[0029] S101: Acquire and parse spatial data to be converted to determine geometric type information and dimension information of the spatial data to be converted.
[0030] In this embodiment, the spatial data to be converted can be understood as spatial data that requires format conversion. The spatial data to be converted can be Gserialized data. The geometric type information can be point, line, surface, etc. The dimensional information can be two-dimensional, three-dimensional, four-dimensional, etc.
[0031] The spatial data to be converted can be pre-stored in a database and read from the database when in use or when certain conditions are met to obtain the spatial data to be converted. The spatial data to be converted includes various types of information, such as the length of the data, the dimension information of the spatial data, the type information of the spatial data (geometric data or geographic data), the SRID (Spatial Reference System Identifier) of the spatial data, the bounding box information of the spatial data, the geometric type information of the spatial data, the component coordinate information of the spatial data, etc. The spatial data to be converted can be parsed according to its format to directly obtain the geometric type information of the spatial data to be converted, and the spatial data to be converted can be parsed to obtain information related to the dimension, and the dimension information can be determined based on this information.
[0032] For example, the Gserialized structure is as follows:
[0033]
[0034] Flags meaning:
[0035] *HasZ (0x01)
[0036] *HasM (0x02)
[0037] *HasBBox (0x04)
[0038] *IsGeodetic (Is it geographic data?) (0x08)
[0039] *Reserved (0x10)
[0040] *HasExtendedFlags (0x20)
[0041] *VersionBit1 (0x40)
[0042] *VersionBit2 (0x80)
[0043] Take the line type as an example:
[0044] TEXT:LINESTRING(1 1,2 3,4 5)
[0045] Gserialized: 40010000 000000 44 0000803F 00008040 0000803F0000A04002000000 03000000 000000000000F03F 000000000000F03F00000000000000400000000000000840 00000000000010400000000000001440
[0046] Among them, 40010000 is the length of Gserialized, 000000 is srid, and 44 is FLAGS, indicating that the data is two-dimensional and there is BBOX. Because there is bbox, 0000803F 00008040 0000803F0000A040 after Flags represent the xmin xmax ymin ymax of bbox respectively. The part after bbox is data, 02000000 indicates the type of spatial data, 03000000 indicates the number of points in the line, and finally the X, Y coordinates of each point that makes up this line.
[0047] By analyzing the above-mentioned spatial data to be converted, it is determined that the geometric type information is a line type and the dimension information is two-dimensional.
[0048] S102. Determine target type information according to the geometric type information.
[0049] In this embodiment, the target type information can be understood as the geometric type of the data finally obtained after format conversion.
[0050] The correspondence between the geometric types of different types of data is determined in advance. The type of spatial data to be converted and the type of spatial data to be ultimately converted are determined. The correspondence between the geometric types can then be determined accordingly. After the geometric type information is determined, the target type information can be determined based on the correspondence.
[0051] For example, the corresponding relationship between the geometric types of spatial data of type Gseriailzied and spatial data of type WKB is as follows:
[0052] Table 1. Correspondence between geometric types of spatial data
[0053]
[0054]
[0055] Taking the type of spatial data to be converted as Gseriailzied, the type of the converted data as wkb, and the geometric type information of the spatial data to be converted as POINT as an example, by looking up the table, it can be determined that the target type information is WKB_POINT; or by looking up the table, it can be determined that the geometric type information of the converted spatial data is WKB_POINT, and it is divided into point type spatial data, that is, the target type information is point type. This method can unify a type of data into one type of data for processing. For example, for some complex types of data, their geometric types are different, but the general type of the data they include is the same, and they can be processed in the same way.
[0056] S103 : Perform format conversion on the spatial data to be converted according to the target type information and dimension information to form target spatial data.
[0057] In this embodiment, the target spatial data may be understood as data obtained through format conversion; the type of the target spatial data may be wkb.
[0058] For each type of spatial data, its data structure is determined. The data structures of different types of spatial data can be the same or different. The data format definition of the target spatial data that needs to be converted is determined based on the target type information. The data format definition can include the parameter types required for this type of data, such as system byte order, geometric type information, coordinate information, etc. Based on the target type information and dimension information, the type number, data length and other information of the target spatial data can be determined. According to the data format definition of the target spatial data, the corresponding type of information is obtained and sorted according to the format to form the target spatial data. After determining the target spatial data, the corresponding memory space can be applied for to store the target spatial data.
[0059] An embodiment of the present invention provides a method for format conversion of spatial data, which obtains and parses the spatial data to be converted to determine the geometric type information and dimensional information of the spatial data to be converted; determines the target type information based on the geometric type information; and performs format conversion on the spatial data to be converted based on the target type information and dimensional information to form target spatial data, thereby solving the problem of low efficiency in format conversion of spatial data. The geometric type information and dimensional information of the spatial data to be converted are determined by parsing the spatial data to be converted, and the target type information is determined based on the geometric type information. Different types of spatial data to be converted are converted in different ways. The format of the spatial data to be converted is directly converted based on the target type information and dimensional information to obtain the target spatial data without converting it into an intermediate structure. This improves conversion efficiency, reduces the complexity of spatial data conversion, and can directly implement data conversion.
[0060] Example 2
[0061] Figure 2 This is a flowchart of a method for converting spatial data format provided by the second embodiment of the present invention. This embodiment is refined based on the above embodiment. Figure 2 As shown, the method includes:
[0062] S201: Acquire and parse spatial data to be converted to determine geometric type information and dimension information of the spatial data to be converted.
[0063] S202: Determine target type information according to the geometric type information.
[0064] S203: Determine the type number corresponding to the target type information, and determine the target number according to the dimension information and the type number.
[0065] In this embodiment, the target number can be understood as a number stored in the target spatial data, and the target number is used to indicate the geometric type of the target spatial data, for example, Type_number in Table 1 in the above embodiment.
[0066] Different geometry types and their corresponding type numbers are predetermined and can be stored in a data table or other manner. After determining the target type information, the type number corresponding to the target type information is determined by querying the predetermined correspondence between the geometry type and the type number. The type number is then processed based on the dimension information, for example, by increasing or decreasing a preset value, or by performing a calculation on the type number using a calculation formula, etc.
[0067] As an optional embodiment, this optional embodiment further optimizes the determination of the target number according to the dimension information and the type number, including steps A1-A3:
[0068] A1. When the dimension information is two-dimensional, the type number is used as the target number.
[0069] A2. When the dimension information is three-dimensional, the first parameter is determined based on the type of the third dimension, and the sum of the first parameter and the type number is used as the target number.
[0070] In this embodiment, the first parameter can be understood as a pre-set parameter, which can be a fixed value, for example, 1000, 2000, etc. The first parameter is predetermined, and the first parameter can be determined by analyzing the data structure characteristics of the three-dimensional spatial data to be converted and the target spatial data; since when the spatial data is three-dimensional, its third dimension can be the Z-axis coordinate or the M-axis coordinate, the first parameters corresponding to different dimensions can be different, and the first parameters corresponding to different types of dimensions are predetermined. When the dimensional information is three-dimensional, the type of the third dimension is determined, that is, whether the third dimension is the Z-axis or the M-axis, and the first parameter is determined based on the correspondence between the type of the third dimension and the first parameter. The first parameter is added to the type number, and the sum obtained is used as the target number.
[0071] A3. When the dimension information is four-dimensional, the second parameter is determined based on the types of the third and fourth dimensions, and the sum of the second parameter and the type number is used as the target number.
[0072] In this embodiment, the second parameter can be understood as a pre-set parameter, which can be a fixed value or a numerical value obtained through calculation. When the dimensional information is four-dimensional, the types of the third and fourth dimensions are determined, a parameter is determined based on the type of the third dimension, and a parameter is determined based on the type of the fourth dimension. The two parameters are summed, the maximum value is taken, and other operations are performed to obtain the second parameter. The second parameter is then added to the type number, and the resulting sum is used as the target number.
[0073] For example, taking the type number (Type_number) equal to 1 as an example, when the dimension information is three-dimensional, if the type of the third parameter is Z-axis, the first parameter is 1000, and the target number is 1001; if the type of the third parameter is M-axis, the first parameter is 2000, and the target number is 2001; when the dimension information is four-dimensional, the type of the third parameter is Z-axis, the type of the fourth parameter is M-axis, the second parameter is 1000+2000=3000, and the target number is 3001.
[0074] S204 : Read data fields in the spatial data to be converted according to the target type information, and form target spatial data based on the read data and the target number.
[0075] Different types of spatial data to be converted contain different types of target spatial data, and their structures may also be different. The data structure of the target spatial data can be determined based on the target type information, and the type of data to be read can be determined based on the data structure. The corresponding data fields in the spatial data to be converted are read based on the type of data to be read, and the corresponding data is obtained. The target spatial data is formed based on the read data and the target number. The target spatial data is formed by the target number, and the geometric type of the target spatial data is identified. The read data can be spatial data such as the coordinates and quantity of the point, which is used to represent information such as the specific points of the spatial data.
[0076] As an optional embodiment, this optional embodiment further optimizes reading data fields in the spatial data to be converted according to target type information, including steps B1-B2:
[0077] B1. When the target type information is set or composite type spatial data, read the spatial data to be converted to obtain the elements and the number of elements.
[0078] In this embodiment, set-type spatial data refers to spatial data stored in the form of a set, which may include different types of spatial data, such as point, line, and surface types of spatial data; composite-type spatial data refers to spatial data that includes multiple types of spatial data, such as both point and line types of spatial data.
[0079] When the target type information is set or composite spatial data, the spatial data to be converted includes one or more types of data. Each type of data is treated as an element, and the spatial data to be converted is read to obtain the elements and the number of elements. For example, when the target type information corresponding to the spatial data to be converted is composite spatial data including points and lines, each point and each line is treated as an element, and the number of elements is counted to obtain the number of elements.
[0080] B2. For each element, determine the target type information corresponding to the element, read the data fields in the spatial data to be converted according to the target type information, and splice the read data in order.
[0081] For each element, the target type information corresponding to the element is analyzed; for example, when the element is a point, its corresponding target type information is point-type spatial data; when the element is a line, its corresponding target type information is point-type spatial data; when the element is a surface, its corresponding target type information is surface-type spatial data; when the element is a set, its corresponding target type information is set-type spatial data, and so on. The corresponding data structure is determined based on the target type information, and the type of data to be read is determined based on the data structure. Based on the type of data to be read, the corresponding data fields in the spatial data to be converted are read to obtain the data corresponding to each element. The read data is then spliced in the order of the elements themselves or a predefined order to complete the data reading.
[0082] As an optional embodiment, this optional embodiment further optimizes reading data fields in the spatial data to be converted according to the target type information, including: when the target type information is point type spatial data, reading the data fields in the spatial data to be converted to obtain point coordinate information.
[0083] When the target type information is point-type spatial data, directly read the data field storing the point coordinates in the spatial data to be converted to obtain the point coordinate information. The point coordinate information includes all coordinate information such as the horizontal coordinate and vertical coordinate of the point. The point coordinate information obtained in this step is the read data.
[0084] As an optional embodiment, this optional embodiment further optimizes reading the data fields in the spatial data to be converted according to the target type information, including: when the target type information is line type spatial data, reading the data fields in the spatial data to be converted, obtaining the point quantity information and point coordinate information.
[0085] When the target type information is line-type spatial data, since a line is composed of multiple points, the point quantity information (i.e., the total number of points forming the line) can be obtained by reading the data field storing the number of points in the spatial data to be converted. The point coordinate information (including all coordinate information, such as the horizontal and vertical coordinates, can also be obtained by reading the data field storing the coordinates of the points in the spatial data to be converted). The point quantity information and point coordinate information obtained in this step are the read data.
[0086] As an optional embodiment, this optional embodiment further optimizes reading data fields in the spatial data to be converted according to target type information, including steps C1-C2:
[0087] C1. When the target type information is surface type spatial data, read the data field in the spatial data to be converted to obtain the total number of rings and the number of points corresponding to each ring.
[0088] When the target spatial data type is area-type data, the plane may contain one or more rings. If there are multiple rings, the rings are divided into inner and outer rings. The spatial data to be converted and the target spatial data handle the number of points in inner and outer rings differently. Read the corresponding data fields in the spatial data to be converted to obtain the total number of rings and the number of points corresponding to each ring.
[0089] C2. Based on the number of points corresponding to the first ring, read the point coordinate information of the data field in the spatial data to be converted, obtain the coordinates of all points corresponding to the first ring from the point coordinate information, and form the data corresponding to the first ring based on the coordinates of all points and their corresponding number of points, until the data corresponding to all rings are obtained.
[0090] Based on the number of points corresponding to the first ring, the coordinates of the points are read from the data field storing the point coordinate information in the spatial data to be converted. The coordinates of all points corresponding to the first ring are read. For example, if the number of points corresponding to the first ring is m, the data field storing the point coordinate information stores all the point coordinates in sequence. Reading m coordinates in sequence yields the coordinates of all the points corresponding to the first ring. The data corresponding to the first ring is formed based on the coordinates and number of points corresponding to the first ring. The data corresponding to the remaining rings is read in the same manner until the data corresponding to all rings is read. The total number of rings and the data corresponding to each ring are considered the read data.
[0091] For example, an embodiment of the present application provides a method for reading spatial data to be converted in a Gseriailzied spatial data format:
[0092] Gseriailzied spatial data format:
[0093] Data part:
[0094] Type: <polygontype>
[0095] NRings:0if empty,N otherwise
[0096] npointsring1: Points Number of ring 1
[0097] npointsring2:Points Number of ring 2 ...
[0099] <? Pad? >:pad if nrings%2>0
[0100] X1
[0101] Y1
[0102] X2
[0103] Y2 ...
[0105] Among them, NRings represents the total number of rings. If it is 0, it means there is no data; if it is N (N is not equal to 0), it means that the total number of rings is N. npointsring1 represents the number of points corresponding to the first ring, npointsring2 represents the number of points corresponding to the second ring, and so on. X1 and Y1 are the coordinates of the first point, X2 and Y2 are the coordinates of the second point, and so on. As shown above, in the spatial data in the Gseriailzied format, the relevant information of each ring and the coordinates of its points are separated, that is, the information of all rings is stored first, and the coordinates of all points of all rings are stored last; the method of the embodiment of the present application reads the information of each ring in turn, reads the number of points corresponding to each ring and the coordinates of all points, and stores the data corresponding to each ring in a unified manner.
[0106] Illustratively, an embodiment of the present application provides a Wkb data format, which includes at least the following data:
[0107]
[0108]
[0109] Among them, NumRings is the total number of rings, numPoints is the number of points corresponding to the rings; Point stores the coordinates of all points corresponding to the rings.
[0110] Read NRings from the Gseriailzied spatial data as NumRings of the wkb data. Read npointsring1 and copy the coordinate information of all points at the coordinate information location as the data of the first ring LinearRing. The number of coordinate information of all points = npointsring1 * dimension. Read the data of all rings in the same way.
[0111] When reading data, when the target type information is a set or composite type spatial data, the data needs to be decomposed into elements and read according to the target type information corresponding to each element. The specific reading method of each element can refer to the above reading method; taking the target type information as set type spatial data, and the elements in the spatial data to be converted include point, line, and surface type data as an example, read the point, line, and surface data according to the above-mentioned reading methods of point type spatial data, line type spatial data, and surface type spatial data, and finally splice them.
[0112] As an optional embodiment, this optional embodiment is further optimized to include: determining the length of the coordinate data based on the dimension information and point number information of the spatial data to be converted; applying for memory space based on the length of the coordinate data, and writing the target spatial data into the memory space.
[0113] In this embodiment, the point number information can be understood as the number of all points included in the spatial data to be converted. The coordinate data length can be understood as the data length of the coordinate point.
[0114] Parse the spatial data to be converted to determine the dimensionality and point count. Based on this information, determine the total amount of coordinate data to be stored. The length of the coordinate data is then determined. Based on the length of the coordinate data, appropriate memory space is requested. For example, memory space of the same size as the coordinate data length or larger than the coordinate data length can be requested. This decision can be made based on the type of data to be stored. The resulting target spatial data is then written into the memory space to complete the data storage.
[0115] As an optional embodiment, this optional embodiment further optimizes the determination of the coordinate data length based on the dimensional information and point number information of the spatial data to be converted, including: determining the total amount of data to be stored based on the dimensional information and point number information; and taking the product of the total amount and the preset byte length as the coordinate data length.
[0116] In this embodiment, the data to be stored can be understood as data that needs to be stored, such as coordinate data, geometric type information, and the like. Since the coordinate information corresponding to points of different dimensions is different, the amount of coordinate data is also different. For example, the number of coordinate data for two-dimensional data is 2 (for example, x and y), the number of coordinate data for three-dimensional data is 3, and the number of coordinate data for four-dimensional data is 4. Multiply the dimension information and the number of points information to obtain the total number of coordinates. Predetermine the byte length required to store a single coordinate data, for example, 8 bytes. Multiply the total number and the preset byte length, and the product obtained is used as the coordinate data length.
[0117] Taking the preset byte length of eight bytes as an example, when determining the coordinate data length, for point type spatial data, since there is only one point, the coordinate data length = dimension * 8 bytes; for line type spatial data, the coordinate data length = the number of points * dimension * 8 bytes; for surface type spatial data, the coordinate data length = the number of points * dimension * 8 bytes; for set or composite type spatial data, the coordinate data length = the number of all points * dimension * 8 bytes, where all points include points of all types of elements such as points, lines, and surfaces.
[0118] Optionally, the target spatial data also includes system byte order and geometry type information;
[0119] The system byte order can be determined based on parameters such as the model and performance of the device executing the method. The storage space size for the system byte order can be pre-determined and divided. For example, a fixed one-byte memory space is requested to store the system byte order. The geometric type information can be determined based on the geometric type information of the spatial data to be converted, for example, by querying Table 1. The geometric type information can be target type information, that is, when determining the target type information, the geometric type information determined by querying the table is directly used as the target type information. Alternatively, a correspondence between the geometric type information of the target spatial data and the target type information can be pre-determined. After determining the geometric type information of the target spatial data, the corresponding target type information is determined based on the correspondence. Taking WKB spatial data as an example, referring to Table 1, there are 17 types of geometric type information for WKB spatial data. In this embodiment of the present application, the target type information is divided into four types for data reading. Therefore, a correspondence between the 17 types of set type information and the four types of target type information can be pre-established. The storage space size for the geometric type information can be pre-determined and divided. For example, a fixed four-byte memory space is requested to store the geometric type information.
[0120] For example, this embodiment provides a Gseriailzied spatial data format, including the following four types of data:
[0121] 1. size
[0122] 2. Srid
[0123] 3. Flags
[0124] 4. Data
[0125] example:
[0126] 80000000 000000 40 01000000 01000000 000000000000F03F
[0127] 000000000000F03F
[0128] Size: 80000000
[0129] Srid: 000000
[0130] Flags: 40
[0131] Data:
[0132] Type: 01000000
[0133] NPoints: 01000000
[0134] X:000000000000f03f
[0135] Y:000000000000f03f
[0136] For example, this embodiment provides a data format definition of wkb spatial data:
[0137] 1. byteOrder
[0138] 2. wkbType
[0139] 3. structPoint
[0140] example:
[0141] 01 01000000 000000000000f03f 000000000000f03f
[0142] BtyeOrder:01
[0143] wkbType:01000000
[0144] structPoint:
[0145] X:000000000000f03f
[0146] Y:000000000000f03f
[0147] Taking the spatial data in the above example as an example, the spatial data to be converted is Gseriailzied spatial data, and the target spatial data is WKB spatial data, the format conversion process of spatial data is explained. When converting Gseriailzied spatial data to WKB spatial data, the conversion method includes the following steps:
[0148] 1. Memory application:
[0149] 1. The first part is a fixed one-byte system byte order;
[0150] 2. The second part is a fixed four-byte geometry type information;
[0151] 3. The third part is the non-fixed coordinate data length, which is used to store the coordinate information of spatial data. It is necessary to obtain the Gserialized spatial data type information, dimension information, and point number information. It needs to be processed separately for different spatial types. For the point type data in the example, you only need to use dimension * eight bytes (single coordinate length) to get the length of this part.
[0152] 2. Data writing:
[0153] 1. Get the system byte order, Big Endian is 00, Little Endian is 01;
[0154] 2. Use the dimension information in flags in the Gseriailzied spatial data and the first Type in Data to determine the wkbType in wkb;
[0155] After determining wkbType, determine the target number based on its corresponding Type_number and dimension information.
[0156] 3. For point type spatial data, the coordinate part in the Data part of the Gseriailzied spatial data can be directly copied to the structPoint part of wkb;
[0157] 4. For line type spatial data, you can directly copy the NPoints and coordinates in the Data part of the Gseriailzied spatial data to the structPoint part of wkb;
[0158] 5. For surface type spatial data, since Gseriailzied spatial data and wkb spatial data process the number of inner and outer ring points differently, it is necessary to determine the number of inner and outer rings and the number of points in each ring, process them, and then write them into the structPoint part of wkb.
[0159] 6. For collections or composite spatial data, wkb first writes the collection as the first element into byteOrder, wkbType, and NumWKBGeometries (the number of elements in the collection), and then processes each element in the collection as a separate element and concatenates them. Therefore, the subsequent processing methods for each element can refer to the processing methods in steps 3-5, where the byteOrder of each element still needs to be written.
[0160] According to the above conversion process, it can be seen that the spatial data conversion method provided in the embodiment of the present application only needs to determine the type of spatial data, calculate the size of the memory required for wkb, and then truncate the simple Gserialized spatial data, partially modify the complex Gserialized spatial data, and copy the point coordinate data in the Gserialized spatial data to obtain its corresponding wkb data.
[0161] The embodiment of the present invention provides a method for format conversion of spatial data, which solves the problem of low efficiency of spatial data format conversion. The geometric type information and dimensional information of the spatial data to be converted are determined by parsing the spatial data to be converted, and the target type information is determined according to the geometric type information. For spatial data of point, surface, line, set, and composite types, different methods are used to directly perform format conversion according to different data structures to obtain target spatial data without converting to an intermediate structure, thereby improving conversion efficiency, reducing the complexity of spatial data conversion, and directly realizing data conversion. The target number and coordinate data length are determined based on the dimensional information, the type of spatial data is identified by the target number, and the memory space is applied for to store the converted target spatial data by the coordinate data length. The spatial data conversion method provided by the embodiment of the present application can reduce the number of parsing times, optimize the memory application process, and improve system performance.
[0162] Example 3
[0163] Figure 3 This is a schematic diagram of a spatial data format conversion device provided by the third embodiment of the present invention. Figure 3 As shown, the device includes: a to-be-converted data acquisition module 31 , a target type determination module 32 and a format conversion module 33 .
[0164] The data acquisition module 31 is used to acquire the spatial data to be converted and analyze it to determine the geometric type information and dimension information of the spatial data to be converted.
[0165] a target type determination module 32, configured to determine target type information according to the geometric type information;
[0166] The format conversion module 33 is configured to perform format conversion on the spatial data to be converted according to the target type information and dimension information to form target spatial data.
[0167] An embodiment of the present invention provides a format conversion device for spatial data, which obtains and parses the spatial data to be converted to determine the geometric type information and dimensional information of the spatial data to be converted; determines the target type information based on the geometric type information; and performs format conversion on the spatial data to be converted based on the target type information and dimensional information to form target spatial data, thereby solving the problem of low efficiency in spatial data format conversion. The geometric type information and dimensional information of the spatial data to be converted are determined by parsing the spatial data to be converted, and the target type information is determined based on the geometric type information. Different types of spatial data to be converted are converted in different ways. The format of the spatial data to be converted is directly converted based on the target type information and dimensional information to obtain the target spatial data without converting it into an intermediate structure. This improves conversion efficiency, reduces the complexity of spatial data conversion, and can directly implement data conversion.
[0168] Optionally, the format conversion module 33 includes:
[0169] a target number determining unit, configured to determine a type number corresponding to the target type information, and determine the target number according to the dimension information and the type number;
[0170] The target spatial data determining unit is configured to read data fields in the spatial data to be converted according to the target type information, and form target spatial data based on the read data and the target number.
[0171] Optionally, the target number determination unit is specifically used to: when the dimensional information is two-dimensional, use the type number as the target number; when the dimensional information is three-dimensional, determine the first parameter based on the type of the third dimension, and use the sum of the first parameter and the type number as the target number; when the dimensional information is four-dimensional, determine the second parameter based on the types of the third dimension and the fourth dimension, and use the sum of the second parameter and the type number as the target number.
[0172] Optionally, the target spatial data determination unit is specifically used to: when the target type information is set or composite type spatial data, read the spatial data to be converted to obtain the elements and the number of elements; for each element, determine the target type information corresponding to the element, read the data field in the spatial data to be converted according to the target type information, and splice the read data in sequence.
[0173] Optionally, the target spatial data determination unit is specifically configured to: when the target type information is point type spatial data, read a data field in the spatial data to be converted to obtain point coordinate information.
[0174] Optionally, the target spatial data determination unit is specifically configured to: when the target type information is line type spatial data, read the data field in the spatial data to be converted to obtain point quantity information and point coordinate information.
[0175] Optionally, the target spatial data determination unit is specifically used to: when the target type information is surface type spatial data, read the data field in the spatial data to be converted to obtain the total number of rings and the number of points corresponding to each ring; based on the number of points corresponding to the first ring, read the point coordinate information of the data field in the spatial data to be converted, obtain the coordinates of all points corresponding to the first ring from the point coordinate information, and form the data corresponding to the first ring based on the coordinates of all points and their corresponding number of points, until the data corresponding to all rings are obtained.
[0176] Optionally, the device further includes:
[0177] A data length determination module, configured to determine the length of coordinate data according to the dimension information and point number information of the spatial data to be converted;
[0178] The space application module is used to apply for memory space based on the length of the coordinate data and write the target space data into the memory space.
[0179] Optionally, a data length determination module includes:
[0180] a total quantity determining unit, configured to determine the total quantity of data to be stored according to the dimension information and the point number information;
[0181] The length determining unit is configured to take the product of the total number and a preset byte length as the coordinate data length.
[0182] The spatial data format conversion device provided in the embodiment of the present invention can execute the spatial data format conversion method provided in any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the execution method.
[0183] Example 4
[0184] Figure 4 A schematic diagram of the structure of an electronic device 40 that can be used to implement an embodiment of the present invention is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital assistants, cellular phones, smart phones, wearable devices (such as helmets, glasses, watches, etc.) and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present invention described and / or claimed herein.
[0185] like Figure 4 As shown, the electronic device 40 includes at least one processor 41 and a memory, such as a read-only memory (ROM) 42, a random access memory (RAM) 43, etc., which is communicatively connected to the at least one processor 41. The memory stores a computer program that can be executed by the at least one processor, and the processor 41 can perform various appropriate actions and processes according to the computer program stored in the read-only memory (ROM) 42 or the computer program loaded from the storage unit 48 into the random access memory (RAM) 43. Various programs and data required for the operation of the electronic device 40 can also be stored in the RAM 43. The processor 41, ROM 42, and RAM 43 are connected to each other via a bus 44. An input / output (I / O) interface 45 is also connected to the bus 44.
[0186] Multiple components in the electronic device 40 are connected to the I / O interface 45, including an input unit 46, such as a keyboard, a mouse, etc.; an output unit 47, such as various types of displays, speakers, etc.; a storage unit 48, such as a magnetic disk, an optical disk, etc.; and a communication unit 49, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 49 allows the electronic device 40 to exchange information / data with other devices via a computer network such as the Internet and / or various telecommunication networks.
[0187] Processor 41 can be any general-purpose and / or specialized processing component with processing and computing capabilities. Some examples of processor 41 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various specialized artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, digital signal processors (DSPs), and any appropriate processor, controller, microcontroller, etc. Processor 41 executes the various methods and processes described above, such as the spatial data format conversion method.
[0188] In some embodiments, the spatial data format conversion method can be implemented as a computer program, which is tangibly contained in a computer-readable storage medium, such as the storage unit 48. In some embodiments, part or all of the computer program can be loaded and / or installed on the electronic device 40 via the ROM 42 and / or the communication unit 49. When the computer program is loaded into the RAM 43 and executed by the processor 41, one or more steps of the spatial data format conversion method described above can be performed. Alternatively, in other embodiments, the processor 41 can be configured to perform the spatial data format conversion method in any other appropriate manner (e.g., by means of firmware).
[0189] Various embodiments of the systems and techniques described herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), system-on-chip systems (SOCs), programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments can include being implemented in one or more computer programs that are executable and / or interpreted on a programmable system that includes at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
[0190] Computer programs for implementing the methods of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, such that when the computer program is executed by the processor, the functions / operations specified in the flowcharts and / or block diagrams are implemented. The computer program may be executed entirely on the machine, partially on the machine, as a stand-alone software package, partially on the machine and partially on a remote machine, or entirely on a remote machine or server.
[0191] In the context of the present invention, computer-readable storage media can be tangible media that can contain or store a computer program for use with an instruction execution system, device or equipment or used in combination with an instruction execution system, device or equipment. Computer-readable storage media can include but are not limited to electronic, magnetic, optical, electromagnetic, infrared or semiconductor systems, devices or equipment, or any suitable combination of the foregoing. Alternatively, computer-readable storage media can be machine-readable signal media. More specific examples of machine-readable storage media can include electrical connections based on one or more lines, portable computer disks, hard disks, random access memories (RAM), read-only memories (ROM), erasable programmable read-only memories (EPROM or flash memory), optical fibers, portable compact disk read-only memories (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.
[0192] To provide interaction with a user, the systems and techniques described herein can be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user can provide input to the electronic device. Other types of devices can also be used to provide interaction with the user; for example, the feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including acoustic input, voice input, or tactile input).
[0193] The systems and techniques described herein can be implemented in a computing system that includes back-end components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes front-end components (e.g., a user computer with a graphical user interface or web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such back-end components, middleware components, or front-end components. The components of the system can be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), a blockchain network, and the Internet.
[0194] A computing system may include clients and servers. The clients and servers are typically remote from each other and typically interact via a communication network. This client-server relationship arises through computer programs running on the respective computers, creating a client-server relationship. The server may be a cloud server, also known as a cloud computing server or cloud host. This server is a hosting product within the cloud computing service ecosystem that addresses the management difficulties and limited scalability of traditional physical hosting and VPS services.
[0195] It should be understood that the various forms of the processes shown above can be used to reorder, add, or delete steps. For example, the steps described in the present invention can be performed in parallel, sequentially, or in a different order, as long as the desired results of the technical solution of the present invention can be achieved. This is not limited herein.
[0196] The above specific embodiments do not limit the scope of protection of the present invention. Those skilled in the art will appreciate that various modifications, combinations, sub-combinations, and substitutions may be made based on design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of the present invention are intended to be included within the scope of protection of the present invention.< / polygontype>
Claims
1. A method for converting spatial data format, characterized in that: include: Obtaining and parsing the spatial data to be converted, and determining the geometric type information and dimension information of the spatial data to be converted; Determine target type information according to the geometric type information; The format of the spatial data to be converted is converted according to the target type information and the dimension information to form target spatial data.
2. The method according to claim 1, characterized in that The step of converting the format of the spatial data to be converted according to the target type information and the dimension information to form the target spatial data includes: Determine the type number corresponding to the target type information, and determine the target number according to the dimension information and the type number; The data fields in the to-be-converted spatial data are read according to the target type information, and the target spatial data are formed based on the read data and the target number.
3. The method according to claim 2, characterized in that The determining the target number according to the dimension information and the type number includes: When the dimension information is two-dimensional, the type number is used as the target number; When the dimension information is three-dimensional, a first parameter is determined based on the type of the third dimension, and a sum of the first parameter and the type number is used as a target number; When the dimensional information is four-dimensional, the second parameter is determined based on the types of the third dimension and the fourth dimension, and the sum of the second parameter and the type number is used as the target number.
4. The method according to claim 2, characterized in that: The step of reading the data field in the to-be-converted spatial data according to the target type information includes: When the target type information is set or composite type spatial data, reading the to-be-converted spatial data to obtain elements and the number of elements; For each element, target type information corresponding to the element is determined, data fields in the to-be-converted spatial data are read according to the target type information, and the read data are spliced in sequence.
5. The method according to any one of claims 2 to 4, characterized in that: The step of reading the data field in the to-be-converted spatial data according to the target type information includes: When the target type information is point type spatial data, the data field in the spatial data to be converted is read to obtain point coordinate information.
6. The method according to any one of claims 2 to 4, characterized in that: The step of reading the data field in the to-be-converted spatial data according to the target type information includes: When the target type information is line type spatial data, the data field in the spatial data to be converted is read to obtain point quantity information and point coordinate information.
7. The method according to any one of claims 2 to 4, characterized in that: The step of reading the data field in the to-be-converted spatial data according to the target type information includes: When the target type information is surface type spatial data, reading the data field in the spatial data to be converted, and obtaining the total number of rings and the number of points corresponding to each ring; Based on the number of points corresponding to the first ring, read the point coordinate information of the data field in the spatial data to be converted, obtain the coordinates of all points corresponding to the first ring from the point coordinate information, and form the data corresponding to the first ring based on the coordinates of all points and their corresponding number of points, until the data corresponding to all the rings are obtained.
8. The method according to claim 1, characterized in that: Also includes: Determine the length of the coordinate data according to the dimension information and the number of points of the spatial data to be converted; Memory space is requested based on the length of the coordinate data, and the target space data is written into the memory space.
9. The method according to claim 8, characterized in that The determining the length of the coordinate data according to the dimension information and the number of points of the spatial data to be converted comprises: Determine the total amount of data to be stored according to the dimension information and the point number information; The product of the total number and the preset byte length is used as the coordinate data length.
10. A spatial data format conversion device, characterized in that: include: The module for acquiring data to be converted is used to acquire and parse the spatial data to be converted, and determine the geometric type information and dimension information of the spatial data to be converted; A target type determination module, used to determine target type information according to the geometric type information; The format conversion module is used to perform format conversion on the spatial data to be converted according to the target type information and dimension information to form target spatial data.
11. An electronic device, characterized in that: The electronic device comprises: at least one processor, and a memory communicatively coupled to the at least one processor; The memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute the spatial data format conversion method according to any one of claims 1 to 9.
12. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the spatial data format conversion method according to any one of claims 1 to 9 when executed.
Citation Information
Patent Citations
GIS (Geographic Information System) spatial object storage method and system thereof
CN108090150A
Conversion method, device and equipment of PostGIS geometric data and storage medium
CN117668087A
Oracle geometric data conversion method and device, equipment and storage medium
CN117668088A
Method and system for converting Oracle spatial data into post gresql spatial data in database
CN117931918A
Computer-implemented conversion of technical drawing data representing a map and object detection based thereupon
EP4083913A1
Cited By
Vector data management method and device, program product and storage medium
CN121188048A
Method and device for analyzing and converting SDE.STGEOMETRY type data
CN121597749A
A method and device for parsing and converting SDE.ST_GEOMETRY type data
CN121597749B
