GeoHex v3 implementation in C99.
VERSION: 1.50
https://sites.google.com/site/geohexdocs/ http://geohex.net/
#include <geohex3.h>
#include <stdio.h>
#include <stdint.h>
int main (int argc, char *argv[]) {
for (int i = 1; i < argc; i++) {
printf("/********* geohex:%s **********/\n", argv[i]);
const geohex_verify_result_t result = geohex_verify_code(argv[i]);
switch (result) {
case GEOHEX_VERIFY_RESULT_SUCCESS:
{
const geohex_t geohex = geohex_get_zone_by_code(argv[i]);
printf("code = %s\n", geohex.code);
printf("level = %zu\n", geohex.level);
printf("size = %Lf\n", geohex.size);
printf("[location]\n");
printf("lat = %Lf\n", geohex.location.lat);
printf("lng = %Lf\n", geohex.location.lng);
printf("[coordinate]\n");
printf("x = %ld\n", geohex.coordinate.x);
printf("y = %ld\n", geohex.coordinate.y);
}
break;
case GEOHEX_VERIFY_RESULT_INVALID_CODE:
printf("code:%s is invalid.\n", argv[i]);
break;
case GEOHEX_VERIFY_RESULT_INVALID_LEVEL:
printf("code:%s is invalid level. MAX_LEVEL:%d\n", argv[i], GEOHEX_MAX_LEVEL);
break;
}
}
}
- picotest
- cmake
- prove
git clone https://github.com/karupanerura/c-geohex3.git
cd c-geohex3
git submodule update --init
cmake .
make
make test
sudo -H make install
SEE DETAIL: geohex3.h
Details of struct:
- lat:
long double
- latitude - lng:
long double
- longitude
Details of struct:
- x:
int64_t
- y:
int64_t
Details of struct:
- top:
- left:
geohex_location_t
- right:
geohex_location_t
- left:
- middle:
- left:
geohex_location_t
- right:
geohex_location_t
- left:
- bottom:
- left:
geohex_location_t
- right:
geohex_location_t
- left:
Details of struct:
- location:
geohex_location_t
- coordinate:
geohex_coordinate_t
- code:
char *
- level:
geohex_level_t
- size:
long double
Enum value. Result of verifing geohex's code.
- GEOHEX_VERIFY_RESULT_SUCCESS: Success to verify code.
- GEOHEX_VERIFY_RESULT_INVALID_CODE: Invalid code format.
- GEOHEX_VERIFY_RESULT_INVALID_LEVEL: Invalid geohex's level. (0-15 is valid.)
Alias of size_t
.
Because geohex's level is defined as strlen(code) - 2
.
SEE DETAIL: geohex3.h
Creates geohex_coordinate_t
.
geohex_coordinate_t coordinate = geohex_coordinate(123L, 123L);
Creates geohex_location_t
.
geohex_location_t location = geohex_location(40.5814792855475L, 134.296601127877L);
Creates geohex_t
by location.
geohex_t geohex = geohex_get_zone_by_location(geohex_location(40.5814792855475L, 134.296601127877L), 7);
Creates geohex_t
by coordinate.
geohex_t geohex = geohex_get_zone_by_coordinate(geohex_coordinate(123L, 123L), 7);
Creates geohex_t
by geohex's code.
geohex_t geohex = geohex_get_zone_by_code("XE1234");
Calculate geohex size.
Calculate geohex level.
geohex_level_t level = geohex_calc_level_by_code("XE2345"); // => 4
Verify geohex code.
const geohex_verify_result_t result = geohex_verify_code(geohex_code);
switch (result) {
case GEOHEX_VERIFY_RESULT_SUCCESS:
...;
break;
case GEOHEX_VERIFY_RESULT_INVALID_CODE:
...;
break;
case GEOHEX_VERIFY_RESULT_INVALID_LEVEL:
...;
break;
}
Convert geohex_location_t
to geohex_coordinate_t
.
geohex_coordinate_t coordinate = geohex_location2coordinate(geohex_location(40.5814792855475L, 134.296601127877L));
Convert geohex_coordinate_t
to geohex_location_t
.
geohex_coordinate_t coordinate = geohex_coordinate2location(geohex_coordinate(123L, 123L));
Convert geohex_t
to geohex_polygon_t
.
(calc vertex location of geohex's polygon.)
geohex_t geohex = geohex_get_zone_by_code("XE1234");
geohex_polygon_t polygon = geohex_get_hex_polygon(&geohex);
MIT Licence. (GeoHex is MIT Licence too.)
karupanerura