char *msudf_simplify(UDF_INIT *initid,UDF_ARGS *args, char *buf, unsigned long *length, char *is_null, char *error) { char *result; GEOSGeom geom2; GEOSGeom geom1; double tolerance; DEBUG("msudf_simplify"); geom1 = msudf_getGeometry((unsigned char *)args->args[0],args->lengths[0]); if (geom1 == NULL) { strcpy(error,"Invalid geometry."); *is_null = 1; return NULL; } tolerance = *(double*) args->args[1] ; geom2 = GEOSSimplify(geom1,tolerance); if (geom2 != NULL) { GEOSSetSRID(geom2,GEOSGetSRID(geom1)); result = msudf_returnGeometry(initid,length,geom2); GEOSGeom_destroy(geom1); GEOSGeom_destroy(geom2); return result; } else { GEOSGeom_destroy(geom1); *is_null = 1; return NULL; } }
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<1>() { GEOSGeometry* geom1 = GEOSGeomFromWKT("POLYGON EMPTY"); ensure ( 0 != GEOSisEmpty(geom1) ); GEOSGeometry* geom2 = GEOSSimplify(geom1, 43.2); ensure ( 0 != GEOSisEmpty(geom2) ); }
void object::test<1>() { geom1_ = GEOSGeomFromWKT("POLYGON EMPTY"); ensure ( 0 != GEOSisEmpty(geom1_) ); geom2_ = GEOSSimplify(geom1_, 43.2); ensure ( 0 != GEOSisEmpty(geom2_) ); }
shapeObj *msGEOSSimplify(shapeObj *shape, double tolerance) { #ifdef USE_GEOS GEOSGeom g1, g2; if(!shape) return NULL; if(!shape->geometry) /* if no geometry for the shape then build one */ shape->geometry = (GEOSGeom) msGEOSShape2Geometry(shape); g1 = (GEOSGeom) shape->geometry; if(!g1) return NULL; g2 = GEOSSimplify(g1, tolerance); return msGEOSGeometry2Shape(g2); #else msSetError(MS_GEOSERR, "GEOS Simplify support is not available.", "msGEOSSimplify()"); return NULL; #endif }