Skip to content

Instantly share code, notes, and snippets.

@TimSC
Last active January 2, 2017 23:15
Show Gist options
  • Select an option

  • Save TimSC/eded1a36335cdb97f64729bb5c5f9db0 to your computer and use it in GitHub Desktop.

Select an option

Save TimSC/eded1a36335cdb97f64729bb5c5f9db0 to your computer and use it in GitHub Desktop.
Test geos_c library
//Compile with: g++ test.cpp -lgeos_c -o test
#include <geos_c.h>
#include <stdio.h>
void noticeFunc(const char *message, ...)
{
printf("notice: %s\n", message);
}
void errorFunc(const char *message, ...)
{
printf("error: %s\n", message);
}
int main(){
GEOSContextHandle_t cx = GEOS_init_r();
GEOSContext_setNoticeHandler_r(cx, &noticeFunc);
GEOSContext_setErrorHandler_r(cx, &errorFunc);
GEOSWKTReader *r = GEOSWKTReader_create_r(cx);
GEOSGeometry *geom = GEOSWKTReader_read_r(cx, r, "POINT(0.000001 51.0)");
GEOSWKTWriter *w = GEOSWKTWriter_create_r(cx);
GEOSWKTWriter_setTrim_r(cx, w, true);
char *wkt = GEOSWKTWriter_write_r(cx, w, geom);
printf("%s\n", wkt);
GEOSWKTReader_destroy_r(cx, r);
GEOSWKTWriter_destroy_r(cx, w);
GEOS_finish_r(cx);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment