Debian Codegraph @

internal/magic/geo.go

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