github.com/cockroachdb/cockroachdb-parser@v0.23.3-0.20240213214944-911057d40c9a/pkg/geo/geopb/geopb.go (about) 1 // Copyright 2020 The Cockroach Authors. 2 // 3 // Use of this software is governed by the Business Source License 4 // included in the file licenses/BSL.txt. 5 // 6 // As of the Change Date specified in that file, in accordance with 7 // the Business Source License, use of this software will be governed 8 // by the Apache License, Version 2.0, included in the file 9 // licenses/APL.txt. 10 11 package geopb 12 13 import ( 14 "fmt" 15 "unsafe" 16 ) 17 18 // EWKBHex returns the EWKB-hex version of this data type 19 func (b *SpatialObject) EWKBHex() string { 20 return fmt.Sprintf("%X", b.EWKB) 21 } 22 23 // MemSize returns the size of the spatial object in memory. 24 func (b *SpatialObject) MemSize() uintptr { 25 var bboxSize uintptr 26 if bbox := b.BoundingBox; bbox != nil { 27 bboxSize = unsafe.Sizeof(*bbox) 28 } 29 return unsafe.Sizeof(*b) + bboxSize + uintptr(len(b.EWKB)) 30 } 31 32 // MultiType returns the corresponding multi-type for a shape type, or unset 33 // if there is no multi-type. 34 func (s ShapeType) MultiType() ShapeType { 35 switch s { 36 case ShapeType_Unset: 37 return ShapeType_Unset 38 case ShapeType_Point, ShapeType_MultiPoint: 39 return ShapeType_MultiPoint 40 case ShapeType_LineString, ShapeType_MultiLineString: 41 return ShapeType_MultiLineString 42 case ShapeType_Polygon, ShapeType_MultiPolygon: 43 return ShapeType_MultiPolygon 44 case ShapeType_GeometryCollection: 45 return ShapeType_GeometryCollection 46 default: 47 return ShapeType_Unset 48 } 49 }