Debian Codegraph @

internal/magic/geo.go

raw symbols SCIP
1 package magic
2
3 import (
4 "bytes"
5 "encoding/binary"
6 "slices"
7 )
8
9 // Shp matches a shape format file.
10 // https://www.esri.com/library/whitepapers/pdfs/shapefile.pdf
11 func Shp(raw []byte, limit uint32) bool {
12 if len(raw) < 112 {
13 return false
14 }
15
16 if binary.BigEndian.Uint32(raw[0:4]) != 9994 ||
17 binary.BigEndian.Uint32(raw[4:8]) != 0 ||
18 binary.BigEndian.Uint32(raw[8:12]) != 0 ||
19 binary.BigEndian.Uint32(raw[12:16]) != 0 ||
20 binary.BigEndian.Uint32(raw[16:20]) != 0 ||
21 binary.BigEndian.Uint32(raw[20:24]) != 0 ||
22 binary.LittleEndian.Uint32(raw[28:32]) != 1000 {
23 return false
24 }
25
26 shapeTypes := []int{
27 0, // Null shape
28 1, // Point
29 3, // Polyline
30 5, // Polygon
31 8, // MultiPoint
32 11, // PointZ
33 13, // PolylineZ
34 15, // PolygonZ
35 18, // MultiPointZ
36 21, // PointM
37 23, // PolylineM
38 25, // PolygonM
39 28, // MultiPointM
40 31, // MultiPatch
41 }
42
43 return slices.Contains(shapeTypes, int(binary.LittleEndian.Uint32(raw[108:112])))
44 }
45
46 // Shx matches a shape index format file.
47 // https://www.esri.com/library/whitepapers/pdfs/shapefile.pdf
48 func Shx(raw []byte, limit uint32) bool {
49 return bytes.HasPrefix(raw, []byte{0x00, 0x00, 0x27, 0x0A})
50 }