mirror of
https://github.com/BertoldVdb/ZoneDetect.git
synced 2026-04-19 12:55:51 +00:00
Add simple string lookup function
This commit is contained in:
parent
1eb2a136e9
commit
be3fb27712
3 changed files with 5 additions and 14 deletions
15
demo.c
15
demo.c
|
|
@ -1,3 +1,4 @@
|
|||
|
||||
/*
|
||||
* Copyright (c) 2018, Bertold Van den Bergh (vandenbergh@bertold.org)
|
||||
* All rights reserved.
|
||||
|
|
@ -27,7 +28,6 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "zonedetect.h"
|
||||
|
||||
void printResults(ZoneDetect *cd, ZoneDetectResult *results, float safezone)
|
||||
|
|
@ -74,7 +74,6 @@ void onError(int errZD, int errNative)
|
|||
fprintf(stderr, "ZD error: %s (0x%08X)\n", ZDGetErrorString(errZD), (unsigned)errNative);
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
if(argc != 4) {
|
||||
|
|
@ -84,15 +83,7 @@ int main(int argc, char *argv[])
|
|||
|
||||
ZDSetErrorHandler(onError);
|
||||
|
||||
uint8_t* data = malloc(128*1024*1024);
|
||||
FILE* f= fopen(argv[1], "rb");
|
||||
if(!f){ return 3; }
|
||||
size_t bytes = fread(data, 1, 128*1024*1024, f);
|
||||
fclose(f);
|
||||
|
||||
printf("Read %lu bytes\n", bytes);
|
||||
//ZoneDetect *const cd = ZDOpenDatabase(argv[1]);
|
||||
ZoneDetect *const cd = ZDOpenDatabaseFromMemory(data, bytes);
|
||||
ZoneDetect *const cd = ZDOpenDatabase(argv[1]);
|
||||
if(!cd) return 2;
|
||||
|
||||
const float lat = (float)atof(argv[2]);
|
||||
|
|
@ -102,7 +93,7 @@ int main(int argc, char *argv[])
|
|||
ZoneDetectResult *results = ZDLookup(cd, lat, lon, &safezone);
|
||||
printResults(cd, results, safezone);
|
||||
|
||||
printf("The magic string is [%s]\n", ZDHelperLookupString(cd, lat, lon));
|
||||
printf("The simple string is [%s]\n", ZDHelperSimpleLookupString(cd, lat, lon));
|
||||
|
||||
ZDCloseDatabase(cd);
|
||||
|
||||
|
|
|
|||
|
|
@ -1124,7 +1124,7 @@ int ZDSetErrorHandler(void (*handler)(int, int))
|
|||
return 0;
|
||||
}
|
||||
|
||||
char* ZDHelperLookupString(const ZoneDetect* library, float lat, float lon)
|
||||
char* ZDHelperSimpleLookupString(const ZoneDetect* library, float lat, float lon)
|
||||
{
|
||||
ZoneDetectResult *result = ZDLookup(library, lat, lon, NULL);
|
||||
if(!result) {
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ ZD_EXPORT const char *ZDGetErrorString(int errZD);
|
|||
|
||||
ZD_EXPORT float* ZDPolygonToList(const ZoneDetect *library, uint32_t polygonId, size_t* length);
|
||||
|
||||
ZD_EXPORT char* ZDHelperLookupString(const ZoneDetect* library, float lat, float lon);
|
||||
ZD_EXPORT char* ZDHelperSimpleLookupString(const ZoneDetect* library, float lat, float lon);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue