github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/geo/geos/geos.h (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 #include <stdlib.h> 12 13 #ifdef __cplusplus 14 extern "C" { 15 #endif 16 17 // Data Types adapted from `capi/geos_c.h.in` in GEOS. 18 typedef void* CR_GEOS_Geometry; 19 20 // NB: Both CR_GEOS_Slice and CR_GEOS_String can contain non-printable 21 // data, so neither is necessarily compatible with a NUL character 22 // terminated C string. Functions that need data that does not contain 23 // the NUL character, so that they can convert to a NUL terminated C 24 // string, must document that additional constraint in their interface. 25 26 // CR_GEOS_Slice contains data that does not need to be freed. It 27 // can be either a Go or C pointer (which indicates who allocated the 28 // memory). 29 typedef struct { 30 char* data; 31 size_t len; 32 } CR_GEOS_Slice; 33 34 // CR_GEOS_String contains a C pointer that needs to be freed. 35 typedef struct { 36 char* data; 37 size_t len; 38 } CR_GEOS_String; 39 40 // CR_GEOS_BufferParams are parameters that will be passed to buffer. 41 typedef struct { 42 int endCapStyle; 43 int joinStyle; 44 int singleSided; 45 int quadrantSegments; 46 double mitreLimit; 47 } CR_GEOS_BufferParamsInput; 48 49 typedef CR_GEOS_String CR_GEOS_Status; 50 51 // CR_GEOS contains all the functions loaded by GEOS. 52 typedef struct CR_GEOS CR_GEOS; 53 54 // CR_GEOS_Init initializes the provided GEOSLib with GEOS using dlopen/dlsym. 55 // Returns a string containing an error if an error was found. The loc slice 56 // must be convertible to a NUL character terminated C string. 57 // The CR_GEOS object will be stored in lib. 58 // The error returned does not need to be freed (see comment for CR_GEOS_Slice). 59 CR_GEOS_Slice CR_GEOS_Init(CR_GEOS_Slice loc, CR_GEOS** lib); 60 61 // CR_GEOS_WKTToWKB converts a given WKT into it's EWKB form. The wkt slice must be 62 // convertible to a NUL character terminated C string. 63 CR_GEOS_Status CR_GEOS_WKTToEWKB(CR_GEOS* lib, CR_GEOS_Slice wkt, int srid, CR_GEOS_String* ewkb); 64 65 // CR_GEOS_ClipEWKBByRect clips a given EWKB by the given rectangle. 66 CR_GEOS_Status CR_GEOS_ClipEWKBByRect(CR_GEOS* lib, CR_GEOS_Slice ewkb, double xmin, double ymin, 67 double xmax, double ymax, CR_GEOS_String* clippedEWKB); 68 // CR_GEOS_Buffer buffers a given EWKB by the given distance and params. 69 CR_GEOS_Status CR_GEOS_Buffer(CR_GEOS* lib, CR_GEOS_Slice ewkb, CR_GEOS_BufferParamsInput params, 70 double distance, CR_GEOS_String* ret); 71 72 // 73 // Unary operators. 74 // 75 76 CR_GEOS_Status CR_GEOS_Area(CR_GEOS* lib, CR_GEOS_Slice a, double* ret); 77 CR_GEOS_Status CR_GEOS_Length(CR_GEOS* lib, CR_GEOS_Slice a, double* ret); 78 CR_GEOS_Status CR_GEOS_Centroid(CR_GEOS* lib, CR_GEOS_Slice a, CR_GEOS_String* centroidEWKB); 79 80 // 81 // Linear reference. 82 // 83 CR_GEOS_Status CR_GEOS_Interpolate(CR_GEOS *lib, CR_GEOS_Slice a, double distance, 84 CR_GEOS_String *interpolatedPoint); 85 86 // 87 // Binary operators. 88 // 89 90 CR_GEOS_Status CR_GEOS_Distance(CR_GEOS* lib, CR_GEOS_Slice a, CR_GEOS_Slice b, double* ret); 91 92 // 93 // Binary predicates. 94 // 95 96 CR_GEOS_Status CR_GEOS_Covers(CR_GEOS* lib, CR_GEOS_Slice a, CR_GEOS_Slice b, char* ret); 97 CR_GEOS_Status CR_GEOS_CoveredBy(CR_GEOS* lib, CR_GEOS_Slice a, CR_GEOS_Slice b, char* ret); 98 CR_GEOS_Status CR_GEOS_Contains(CR_GEOS* lib, CR_GEOS_Slice a, CR_GEOS_Slice b, char* ret); 99 CR_GEOS_Status CR_GEOS_Crosses(CR_GEOS* lib, CR_GEOS_Slice a, CR_GEOS_Slice b, char* ret); 100 CR_GEOS_Status CR_GEOS_Equals(CR_GEOS* lib, CR_GEOS_Slice a, CR_GEOS_Slice b, char* ret); 101 CR_GEOS_Status CR_GEOS_Intersects(CR_GEOS* lib, CR_GEOS_Slice a, CR_GEOS_Slice b, char* ret); 102 CR_GEOS_Status CR_GEOS_Overlaps(CR_GEOS* lib, CR_GEOS_Slice a, CR_GEOS_Slice b, char* ret); 103 CR_GEOS_Status CR_GEOS_Touches(CR_GEOS* lib, CR_GEOS_Slice a, CR_GEOS_Slice b, char* ret); 104 CR_GEOS_Status CR_GEOS_Within(CR_GEOS* lib, CR_GEOS_Slice a, CR_GEOS_Slice b, char* ret); 105 106 // 107 // DE-9IM related 108 // 109 110 CR_GEOS_Status CR_GEOS_Relate(CR_GEOS* lib, CR_GEOS_Slice a, CR_GEOS_Slice b, CR_GEOS_String* ret); 111 CR_GEOS_Status CR_GEOS_RelatePattern(CR_GEOS* lib, CR_GEOS_Slice a, CR_GEOS_Slice b, 112 CR_GEOS_Slice pattern, char* ret); 113 114 #ifdef __cplusplus 115 } // extern "C" 116 #endif