void object::test<1> () { numcalls = 0; initGEOS(notice, notice); GEOS_interruptRegisterCallback(countCalls); ensure_equals(numcalls, 0); GEOSGeometry* geom1 = GEOSGeomFromWKT("LINESTRING(0 0, 1 0)"); ensure("GEOSGeomFromWKT failed", nullptr != geom1); GEOSGeometry* geom2 = GEOSBuffer(geom1, 1, 8); ensure("GEOSBufferWithStyle failed", nullptr != geom2); ensure("interrupt callback never called", numcalls > 0); GEOSGeom_destroy(geom1); GEOSGeom_destroy(geom2); GEOS_interruptRegisterCallback(nullptr); /* unregister */ finishGEOS(); }
void geo_simplify(sqlite3_context *context,int argc,sqlite3_value **argv) { if(argc == 2 && sqlite3_value_type(argv[0]) == SQLITE_BLOB) { GEOSGeometry* geometry; GEOSGeometry* simplify_geo; unsigned char* wkb; size_t size; const void* data = sqlite3_value_blob(argv[0]); size_t data_size = sqlite3_value_bytes(argv[0]); double tolerance = sqlite3_value_double(argv[1]); _init_geos(); geometry = _geo_from_wkb((const unsigned char*)data,data_size); if(geometry != 0) { simplify_geo = GEOSSimplify(geometry,tolerance); if(simplify_geo != 0) { wkb = GEOSGeomToWKB_buf(simplify_geo,&size); sqlite3_result_blob(context,wkb,size,SQLITE_TRANSIENT); GEOSGeom_destroy(simplify_geo); GEOSFree(wkb); } } GEOSGeom_destroy(geometry); finishGEOS(); } }
void object::test<2> () { numcalls = 0; initGEOS(notice, notice); GEOS_interruptRegisterCallback(countCalls); ensure_equals(numcalls, 0); GEOSGeometry* geom1 = GEOSGeomFromWKT("LINESTRING(0 0, 1 1, 2 2, 4 4)"); GEOSGeometry* geom2 = GEOSGeomFromWKT("LINESTRING(0 0, 1 1.01, 4 4.001)"); ensure("GEOSGeomFromWKT failed", nullptr != geom1); GEOSGeometry* geom3 = GEOSSnap(geom1, geom2, 0.1); ensure("GEOSSnap failed", nullptr != geom3); ensure("interrupt callback never called", numcalls > 0); GEOSGeom_destroy(geom1); GEOSGeom_destroy(geom2); GEOSGeom_destroy(geom3); GEOS_interruptRegisterCallback(nullptr); /* unregister */ finishGEOS(); }
~test_capigeosrelateboundarynoderule_data() { GEOSGeom_destroy(geom1_); GEOSGeom_destroy(geom2_); GEOSFree(pat_); finishGEOS(); }
void geo_polyline_encode(sqlite3_context *context,int argc,sqlite3_value **argv) { if(argc >= 1 && sqlite3_value_type(argv[0]) == SQLITE_BLOB) { GEOSGeometry* geometry; char* encodestr; const void* data = sqlite3_value_blob(argv[0]); size_t data_size = sqlite3_value_bytes(argv[0]); int point = 1; if(argc > 1) { point = sqlite3_value_int(argv[1]); } _init_geos(); geometry = _geo_from_wkb((const unsigned char*)data,data_size); if(geometry != 0) { encodestr = polyline_encode(geometry,point); if(encodestr != 0) { sqlite3_result_text(context,encodestr,-1,SQLITE_TRANSIENT); free(encodestr); } } GEOSGeom_destroy(geometry); finishGEOS(); } }
static void _relation_compute(sqlite3_context *context,int argc,sqlite3_value **argv,RelationCompute Func) { if(argc == 2 && sqlite3_value_type(argv[0]) == SQLITE_BLOB && sqlite3_value_type(argv[1]) == SQLITE_BLOB) { GEOSGeometry* geometry1; GEOSGeometry* geometry2; GEOSGeometry* geo_result; unsigned char* wkb; size_t size; const void* data1 = sqlite3_value_blob(argv[0]); size_t data_size1 = sqlite3_value_bytes(argv[0]); const void* data2 = sqlite3_value_blob(argv[1]); size_t data_size2 = sqlite3_value_bytes(argv[1]); _init_geos(); geometry1 = _geo_from_wkb((const unsigned char*)data1,data_size1); geometry2 = _geo_from_wkb((const unsigned char*)data2,data_size2); if(geometry1 != 0 && geometry2 != 0) { geo_result = Func(geometry1,geometry2); if(geo_result != 0) { wkb = GEOSGeomToWKB_buf(geo_result,&size); sqlite3_result_blob(context,wkb,size,SQLITE_TRANSIENT); GEOSGeom_destroy(geo_result); GEOSFree(wkb); } } if(geometry1!=0)GEOSGeom_destroy(geometry1); if(geometry2!=0)GEOSGeom_destroy(geometry2); finishGEOS(); } }
void geo_polyline_decode(sqlite3_context *context,int argc,sqlite3_value **argv) { if(argc >= 1 && sqlite3_value_type(argv[0]) == SQLITE_TEXT) { GEOSGeometry* geometry; const unsigned char* data = sqlite3_value_text(argv[0]); int point = 1; size_t size = 0; if(argc > 1) { point = sqlite3_value_int(argv[1]); } _init_geos(); geometry = polyline_decode(data,point); if(geometry != 0) { unsigned char* wkb = GEOSGeomToWKB_buf(geometry,&size); if(wkb != NULL) { sqlite3_result_blob(context,wkb,size,SQLITE_TRANSIENT); GEOSFree(wkb); } } GEOSGeom_destroy(geometry); finishGEOS(); } }
static void _relation_judge(sqlite3_context *context,int argc,sqlite3_value **argv,RelationJudge Func) { if(argc == 2 && sqlite3_value_type(argv[0]) == SQLITE_BLOB && sqlite3_value_type(argv[1]) == SQLITE_BLOB) { GEOSGeometry* geometry1; GEOSGeometry* geometry2; char result; const void* data1 = sqlite3_value_blob(argv[0]); size_t data_size1 = sqlite3_value_bytes(argv[0]); const void* data2 = sqlite3_value_blob(argv[1]); size_t data_size2 = sqlite3_value_bytes(argv[1]); _init_geos(); geometry1 = _geo_from_wkb((const unsigned char*)data1,data_size1); geometry2 = _geo_from_wkb((const unsigned char*)data2,data_size2); if(geometry1 != 0 && geometry2 != 0) { result = Func(geometry1,geometry2); sqlite3_result_int(context,result); } if(geometry1!=0)GEOSGeom_destroy(geometry1); if(geometry2!=0)GEOSGeom_destroy(geometry2); finishGEOS(); } }
~test_capigeosconvexhull_data() { GEOSGeom_destroy(input_); GEOSGeom_destroy(expected_); input_ = 0; expected_ = 0; finishGEOS(); }
~test_capigeoswithin_data() { GEOSGeom_destroy(geom1_); GEOSGeom_destroy(geom2_); geom1_ = nullptr; geom2_ = nullptr; finishGEOS(); }
~test_capigeossimplify_data() { GEOSGeom_destroy(geom1_); GEOSGeom_destroy(geom2_); geom1_ = 0; geom2_ = 0; finishGEOS(); }
~test_capigeosnearestpoints_data() { GEOSGeom_destroy(geom1_); GEOSGeom_destroy(geom2_); geom1_ = 0; geom2_ = 0; finishGEOS(); }
~test_capigeosintersects_data() { GEOSGeom_destroy(geom1_); GEOSGeom_destroy(geom2_); geom1_ = 0; geom2_ = 0; finishGEOS(); }
~test_capigeosnode_data() { GEOSGeom_destroy(geom1_); GEOSGeom_destroy(geom2_); GEOSWKTWriter_destroy(w_); geom1_ = 0; geom2_ = 0; finishGEOS(); }
~test_capiunaryunion_data() { GEOSGeom_destroy(geom1_); GEOSGeom_destroy(geom2_); GEOSWKTWriter_destroy(wktw_); geom1_ = 0; geom2_ = 0; finishGEOS(); }
~test_capigeosminimumrectangle_data() { GEOSGeom_destroy(input_); input_ = nullptr; GEOSWKTWriter_destroy(wktw_); GEOSFree(wkt_); wkt_ = nullptr; finishGEOS(); }
void geo_bound(sqlite3_context *context,int argc,sqlite3_value **argv) { if(argc >= 1) { const unsigned char* ogc; unsigned char* ret_geo_buf; size_t size; double x1,x2,y1,y2; GEOSCoordSequence* seq = 0; GEOSGeometry* geometry = 0; GEOSGeometry* middle_geo = 0; _init_geos(); if(argc == 1 && sqlite3_value_type(argv[0]) == SQLITE_BLOB) { size = sqlite3_value_bytes(argv[0]); ogc = (const unsigned char*)sqlite3_value_blob(argv[0]); middle_geo = _geo_from_wkb(ogc,size); } else if(argc == 1 && sqlite3_value_type(argv[0]) == SQLITE_TEXT) { ogc = sqlite3_value_text(argv[0]); middle_geo = _geo_from_wkt(ogc); } else if(argc == 4) { x1 = sqlite3_value_double(argv[0]); y1 = sqlite3_value_double(argv[1]); x2 = sqlite3_value_double(argv[2]); y2 = sqlite3_value_double(argv[3]); seq = GEOSCoordSeq_create(2,2); GEOSCoordSeq_setX(seq,0,x1); GEOSCoordSeq_setY(seq,0,y1); GEOSCoordSeq_setX(seq,1,x2); GEOSCoordSeq_setY(seq,1,y2); middle_geo = GEOSGeom_createLineString(seq); } if(middle_geo != 0) { geometry = GEOSEnvelope(middle_geo); if(geometry != 0) { ret_geo_buf = GEOSGeomToWKB_buf(geometry,&size); sqlite3_result_blob(context,ret_geo_buf,size,SQLITE_TRANSIENT); GEOSGeom_destroy(geometry); GEOSFree(ret_geo_buf); } GEOSGeom_destroy(middle_geo); } finishGEOS(); } }
~test_capigeosgeomfromwkb_data() { GEOSGeom_destroy(geom2_); geom2_ = nullptr; GEOSGeom_destroy(geom1_); geom1_ = nullptr; GEOSWKTReader_destroy(reader_); reader_ = nullptr; finishGEOS(); }
~test_capioffsetcurve_data() { GEOSGeom_destroy(geom1_); GEOSGeom_destroy(geom2_); GEOSWKTWriter_destroy(wktw_); GEOSFree(wkt_); geom1_ = 0; geom2_ = 0; wkt_ = 0; finishGEOS(); }
~test_capigeosdistance_data() { GEOSGeom_destroy(geom1_); GEOSGeom_destroy(geom2_); GEOSGeom_destroy(geom3_); GEOSWKTWriter_destroy(w_); geom1_ = nullptr; geom2_ = nullptr; geom3_ = nullptr; finishGEOS(); }
~test_capigeosclipbyrect_data() { GEOSGeom_destroy(geom1_); GEOSGeom_destroy(geom2_); GEOSGeom_destroy(geom3_); GEOSWKTWriter_destroy(w_); geom1_ = 0; geom2_ = 0; geom3_ = 0; finishGEOS(); }
~test_capigeospreparedgeometry_data() { GEOSGeom_destroy(geom1_); GEOSGeom_destroy(geom2_); GEOSPreparedGeom_destroy(prepGeom1_); GEOSPreparedGeom_destroy(prepGeom2_); geom1_ = nullptr; geom2_ = nullptr; prepGeom1_ = nullptr; prepGeom2_ = nullptr; finishGEOS(); }
SPATIALITE_DECLARE void spatialite_cleanup () { /* OBSOLETE - strongly discouraged !!!!! always using spatialite_cleanup_ex() as a replacement is warmly reccomended */ #ifndef OMIT_GEOS finishGEOS (); #endif #ifdef ENABLE_LWGEOM gaiaResetLwGeomMsg (); #endif sqlite3_reset_auto_extension (); }
void geo_valid(sqlite3_context *context,int argc,sqlite3_value **argv) { if(argc == 1 && sqlite3_value_type(argv[0]) == SQLITE_BLOB) { GEOSGeometry* geometry; const void* data = sqlite3_value_blob(argv[0]); size_t data_size = sqlite3_value_bytes(argv[0]); _init_geos(); geometry = _geo_from_wkb((const unsigned char*)data,data_size); if(geometry != 0) { char empty = (GEOSisValid(geometry) == 1) ? 1 : 0; sqlite3_result_int(context,empty); } GEOSGeom_destroy(geometry); finishGEOS(); } }
void geo_subgeos(sqlite3_context *context,int argc,sqlite3_value **argv) { if(argc == 1 && sqlite3_value_type(argv[0]) == SQLITE_BLOB) { GEOSGeometry* geometry; const void* data = sqlite3_value_blob(argv[0]); size_t data_size = sqlite3_value_bytes(argv[0]); _init_geos(); geometry = _geo_from_wkb((const unsigned char*)data,data_size); if(geometry != 0) { int sub_geos = GEOSGetNumGeometries(geometry); sqlite3_result_int(context,sub_geos); } GEOSGeom_destroy(geometry); finishGEOS(); } }
void object::test<4> () { initGEOS(notice, notice); GEOSGeometry* geom1 = GEOSGeomFromWKT("LINESTRING(0 0, 1 0)"); ensure("GEOSGeomFromWKT failed", nullptr != geom1); GEOS_interruptRegisterCallback(interruptNow); GEOSGeometry* geom2 = GEOSBuffer(geom1, 1, 8); ensure("GEOSBuffer wasn't interrupted", nullptr == geom2); GEOS_interruptRegisterCallback(nullptr); /* unregister */ // TODO: check the actual exception ? (sent to notice() callback) GEOSGeom_destroy(geom1); finishGEOS(); }
void geo_maxy(sqlite3_context *context,int argc,sqlite3_value **argv) { if(argc == 1 && sqlite3_value_type(argv[0]) == SQLITE_BLOB) { GEOSGeometry* geometry; Rect rect; const void* data = sqlite3_value_blob(argv[0]); size_t data_size = sqlite3_value_bytes(argv[0]); _init_geos(); geometry = _geo_from_wkb((const unsigned char*)data,data_size); if(geometry != 0) { _get_envelope(geometry,&rect); sqlite3_result_double(context,rect.maxY); } GEOSGeom_destroy(geometry); finishGEOS(); } }
void geo_length(sqlite3_context *context,int argc,sqlite3_value **argv) { if(argc == 1 && sqlite3_value_type(argv[0]) == SQLITE_BLOB) { GEOSGeometry* geometry; const void* data = sqlite3_value_blob(argv[0]); size_t data_size = sqlite3_value_bytes(argv[0]); _init_geos(); geometry = _geo_from_wkb((const unsigned char*)data,data_size); if(geometry != 0) { double length = 0; GEOSLength(geometry,&length); sqlite3_result_double(context,length); } GEOSGeom_destroy(geometry); finishGEOS(); } }
void geo_type(sqlite3_context *context,int argc,sqlite3_value **argv) { if(argc == 1 && sqlite3_value_type(argv[0]) == SQLITE_BLOB) { GEOSGeometry* geometry; char* type; const void* data = sqlite3_value_blob(argv[0]); size_t data_size = sqlite3_value_bytes(argv[0]); _init_geos(); geometry = _geo_from_wkb((const unsigned char*)data,data_size); if(geometry != 0) { type = GEOSGeomType(geometry); sqlite3_result_text(context,type,-1,SQLITE_TRANSIENT); GEOSFree(type); } GEOSGeom_destroy(geometry); finishGEOS(); } }
void geo_wkb(sqlite3_context *context,int argc,sqlite3_value **argv) { if(argc == 1 && sqlite3_value_type(argv[0]) == SQLITE_TEXT) { GEOSGeometry* geometry; const char* wkt = (const char*)sqlite3_value_text(argv[0]); unsigned char* wkb; size_t size; _init_geos(); geometry = _geo_from_wkt(wkt); if(geometry != 0) { wkb = GEOSGeomToWKB_buf(geometry,&size); sqlite3_result_blob(context,(const void*)wkb,size,SQLITE_TRANSIENT); GEOSFree(wkb); } GEOSGeom_destroy(geometry); finishGEOS(); } }