github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/geo/geoproj/geoproj.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 geoproj contains functions that interface with the PROJ library. 12 package geoproj 13 14 // #cgo CXXFLAGS: -std=c++14 15 // #cgo CPPFLAGS: -I../../../c-deps/proj/src 16 // #cgo LDFLAGS: -lproj 17 // #cgo linux LDFLAGS: -lrt -lm -lpthread 18 // #cgo windows LDFLAGS: -lshlwapi -lrpcrt4 19 // 20 // #include "proj.h" 21 // #include <proj_api.h> 22 import "C" 23 import "unsafe" 24 25 // ProjPJ is the projPJ wrapper around the PROJ library's projPJ object. 26 type ProjPJ struct { 27 projPJ C.projPJ 28 } 29 30 // IsLatLng returns whether the underlying ProjPJ is a latlng system. 31 // TODO(otan): store this metadata in the projPJ struct. 32 func (p *ProjPJ) IsLatLng() bool { 33 return C.pj_is_latlong(p.projPJ) != 0 34 } 35 36 // NewProjPJFromText initializes a ProjPJ from text. 37 // TODO(otan): thread through thread contexts and retrieve error messages. 38 // TODO(otan): use slice management mechanisms. 39 // TODO(otan): free after creation. 40 func NewProjPJFromText(proj4text string) (*ProjPJ, error) { 41 str := C.CString(proj4text) 42 defer C.free(unsafe.Pointer(str)) 43 projPJ := C.pj_init_plus(str) 44 return &ProjPJ{projPJ: projPJ}, nil 45 }