1from libc cimport stdint 2from cpython cimport bool 3from libc.stdint cimport int64_t 4 5ctypedef stdint.uint64_t H3int 6ctypedef basestring H3str 7 8cdef extern from "h3api.h": 9 cdef int H3_VERSION_MAJOR 10 cdef int H3_VERSION_MINOR 11 cdef int H3_VERSION_PATCH 12 13 ctypedef stdint.uint64_t H3Index 14 15 ctypedef struct GeoCoord: 16 double lat # in radians 17 double lng "lon" # in radians 18 19 ctypedef struct GeoBoundary: 20 int num_verts "numVerts" 21 GeoCoord verts[10] # MAX_CELL_BNDRY_VERTS 22 23 ctypedef struct Geofence: 24 int numVerts 25 GeoCoord *verts 26 27 ctypedef struct GeoPolygon: 28 Geofence geofence 29 int numHoles 30 Geofence *holes 31 32 ctypedef struct GeoMultiPolygon: 33 int numPolygons 34 GeoPolygon *polygons 35 36 ctypedef struct LinkedGeoCoord: 37 GeoCoord data "vertex" 38 LinkedGeoCoord *next 39 40 # renaming these for clarity 41 ctypedef struct LinkedGeoLoop: 42 LinkedGeoCoord *data "first" 43 LinkedGeoCoord *_data_last "last" # not needed in Cython bindings 44 LinkedGeoLoop *next 45 46 ctypedef struct LinkedGeoPolygon: 47 LinkedGeoLoop *data "first" 48 LinkedGeoLoop *_data_last "last" # not needed in Cython bindings 49 LinkedGeoPolygon *next 50 51 ctypedef struct CoordIJ: 52 int i 53 int j 54 55 H3Index geoToH3(const GeoCoord *g, int res) nogil 56 57 void h3ToGeo(H3Index h3, GeoCoord *g) nogil 58 59 void h3ToGeoBoundary(H3Index h3, GeoBoundary *gp) 60 61 int maxKringSize(int k) 62 63 int hexRange(H3Index origin, int k, H3Index *out) 64 65 int hexRangeDistances(H3Index origin, int k, H3Index *out, int *distances) 66 67 int h3Distance(H3Index origin, H3Index h3) 68 69 int hexRanges(H3Index *h3Set, int length, int k, H3Index *out) 70 71 void kRing(H3Index origin, int k, H3Index *out) 72 73 void kRingDistances(H3Index origin, int k, H3Index *out, int *distances) 74 75 int hexRing(H3Index origin, int k, H3Index *out) 76 77 int maxPolyfillSize(const GeoPolygon *geoPolygon, int res) 78 79 void polyfill(const GeoPolygon *geoPolygon, int res, H3Index *out) 80 81 void h3SetToLinkedGeo(const H3Index *h3Set, const int numHexes, LinkedGeoPolygon *out) 82 83 void destroyLinkedPolygon(LinkedGeoPolygon *polygon) 84 85 double degsToRads(double degrees) nogil 86 87 double radsToDegs(double radians) nogil 88 89 stdint.int64_t numHexagons(int res) 90 91 int h3GetResolution(H3Index h) nogil 92 93 int h3GetBaseCell(H3Index h) 94 95 H3Index stringToH3(const char *str) 96 97 void h3ToString(H3Index h, char *str, size_t sz) 98 99 int h3IsValid(H3Index h) 100 101 H3Index h3ToParent(H3Index h, int parentRes) nogil 102 103 int maxH3ToChildrenSize(H3Index h, int childRes) 104 105 void h3ToChildren(H3Index h, int childRes, H3Index *children) 106 107 int compact(const H3Index *h3Set, H3Index *compactedSet, const int numHexes) 108 109 int maxUncompactSize(const H3Index *compactedSet, const int numHexes, const int res) 110 111 int uncompact(const H3Index *compactedSet, const int numHexes, H3Index *h3Set, const int maxHexes, const int res) 112 113 int h3IsResClassIII(H3Index h) 114 115 int h3IsPentagon(H3Index h) 116 117 int pentagonIndexCount() 118 119 void getPentagonIndexes(int res, H3Index *out) 120 121 int res0IndexCount() 122 123 void getRes0Indexes(H3Index *out) 124 125 H3Index h3ToCenterChild(H3Index h, int res) 126 127 int h3IndexesAreNeighbors(H3Index origin, H3Index destination) 128 129 H3Index getH3UnidirectionalEdge(H3Index origin, H3Index destination) 130 131 int h3UnidirectionalEdgeIsValid(H3Index edge) 132 133 H3Index getOriginH3IndexFromUnidirectionalEdge(H3Index edge) 134 135 H3Index getDestinationH3IndexFromUnidirectionalEdge(H3Index edge) 136 137 void getH3IndexesFromUnidirectionalEdge(H3Index edge, H3Index *originDestination) 138 139 void getH3UnidirectionalEdgesFromHexagon(H3Index origin, H3Index *edges) 140 141 void getH3UnidirectionalEdgeBoundary(H3Index edge, GeoBoundary *gb) 142 143 int h3LineSize(H3Index start, H3Index end) 144 int h3Line(H3Index start, H3Index end, H3Index *out) 145 146 int maxFaceCount(H3Index h3) 147 void h3GetFaces(H3Index h3, int *out) 148 149 int experimentalH3ToLocalIj(H3Index origin, H3Index h3, CoordIJ *out) 150 int experimentalLocalIjToH3(H3Index origin, const CoordIJ *ij, H3Index *out) 151 152 double hexAreaKm2(int res) nogil 153 double hexAreaM2(int res) nogil 154 155 double cellAreaRads2(H3Index h) nogil 156 double cellAreaKm2(H3Index h) nogil 157 double cellAreaM2(H3Index h) nogil 158 159 double edgeLengthKm(int res) nogil 160 double edgeLengthM(int res) nogil 161 162 double exactEdgeLengthRads(H3Index edge) nogil 163 double exactEdgeLengthKm(H3Index edge) nogil 164 double exactEdgeLengthM(H3Index edge) nogil 165 166 double pointDistRads(const GeoCoord *a, const GeoCoord *b) nogil 167 double pointDistKm(const GeoCoord *a, const GeoCoord *b) nogil 168 double pointDistM(const GeoCoord *a, const GeoCoord *b) nogil 169