|
4 | 4 |
|
5 | 5 | function wkb2geom(buff, crs) |
6 | 6 | byteswap = isone(read(buff, UInt8)) ? ltoh : ntoh |
7 | | - typebits = read(buff, UInt32) |
| 7 | + wkbtype = read(buff, UInt32) |
8 | 8 | # Input variants of WKB supported are standard, extended, and ISO WKB geometry with Z dimensions (M/ZM not supported) |
9 | 9 | if CoordRefSystems.ncoords(crs) == 3 |
10 | 10 | # SQL/MM Part 3 and SFSQL 1.2 use offsets of 1000 (Z), 2000 (M) and 3000 (ZM) |
11 | 11 | # to indicate the present of higher dimensional coordinates in a WKB geometry |
12 | | - if typebits > 3007 |
| 12 | + if wkbtype >= 1001 && wkbtype <= 1007 |
| 13 | + # the SFSQL 1.2 offset of 1000 (Z) is present and subtracting a round number of 1000 gives the standard WKB type |
| 14 | + wkbtype -= 1000 |
13 | 15 | # 99-402 was a short-lived extension to SFSQL 1.1 that used a high-bit flag to indicate the presence of Z coordinates in a WKB geometry |
14 | 16 | # the high-bit flag 0x80000000 for Z (or 0x40000000 for M) is set and masking it off gives the standard WKB type |
15 | | - wkbtype = typebits & 0x7FFFFFFF |
16 | | - # check that the WKB typebits is not outside the SFSQL 1.2 Z encoding range (1001-1007) |
17 | | - elseif typebits <= 1007 |
18 | | - # the SFSQL 1.2 offset of 1000 (Z) is present and subtracting a round number of 1000 gives the standard WKB type |
19 | | - wkbtype = typebits - 1000 |
| 17 | + elseif wkbtype > 0x80000000 |
| 18 | + # the SFSQL 1.1 high-bit flag 0x80000000 (Z) is present and removing the flag reveals the standard WKB type |
| 19 | + wkbtype -= 0x80000000 |
20 | 20 | else |
21 | | - @error "Unsupported WKB Geometry Type with M or ZM dimension encoding: $typebits" |
| 21 | + @error "Unsupported WKB Geometry Type with M or ZM dimension encoding: $wkbtype" |
22 | 22 | end |
23 | | - else |
24 | | - # standard WKB typebits without Z dimension encoding |
25 | | - wkbtype = typebits |
26 | 23 | end |
27 | 24 |
|
28 | 25 | if wkbtype <= 3 |
@@ -86,7 +83,7 @@ function wkb2chain(buff, crs, byteswap) |
86 | 83 | npoints = byteswap(read(buff, UInt32)) |
87 | 84 | chain = wkb2points(buff, npoints, crs, byteswap) |
88 | 85 | if length(chain) >= 2 && first(chain) == last(chain) |
89 | | - Ring(chain[1:end-1]) |
| 86 | + Ring(chain[1:(end - 1)]) |
90 | 87 | elseif length(chain) >= 2 |
91 | 88 | Rope(chain) |
92 | 89 | else |
|
98 | 95 | function wkb2poly(buff, crs, byteswap) |
99 | 96 | nrings = byteswap(read(buff, UInt32)) |
100 | 97 | rings = map(1:nrings) do _ |
101 | | - wkb2chain(buff, crs, byteswap) |
| 98 | + wkb2chain(buff, crs, byteswap) |
102 | 99 | end |
103 | 100 | PolyArea(rings) |
104 | 101 | end |
|
0 commit comments