Changeset: 9e00b2dc4663 for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=9e00b2dc4663 Modified Files: geom/monetdb5/geom.c geom/monetdb5/geom.mal monetdb5/mal/mal_instruction.h Branch: geo Log Message:
geospatial optimiser: Add MBRfilter before contains diffs (119 lines): diff --git a/geom/monetdb5/geom.c b/geom/monetdb5/geom.c --- a/geom/monetdb5/geom.c +++ b/geom/monetdb5/geom.c @@ -129,6 +129,8 @@ geom_export str wkbRelate(bit*, wkb**, w geom_export str wkbCovers(bit *out, wkb **geomWKB_a, wkb **geomWKB_b); geom_export str wkbCoveredBy(bit *out, wkb **geomWKB_a, wkb **geomWKB_b); +geom_export str wkbFilter_bat(int* outBAT_id, int* aBAT_id, int* bBAT_id); + //LocateAlong //LocateBetween @@ -2902,6 +2904,81 @@ str wkbContains_bat_bat(int* outBAT_id, } +str wkbFilter_bat(int* outBAT_id, int* aBAT_id, int* bBAT_id) { + BAT *outBAT = NULL, *aBAT = NULL, *bBAT = NULL; + wkb *aWKB = NULL, *bWKB = NULL; + bit outBIT; + BATiter aBAT_iter, bBAT_iter; + BUN i=0; + + mbr *aMBR=NULL, *bMBR=NULL; + + //get the descriptor of the BAT + if ((aBAT = BATdescriptor(*aBAT_id)) == NULL) { + throw(MAL, "batgeom.MBRfilter", RUNTIME_OBJECT_MISSING); + } + if ((bBAT = BATdescriptor(*bBAT_id)) == NULL) { + BBPreleaseref(aBAT->batCacheid); + throw(MAL, "batgeom.MBRfilter", RUNTIME_OBJECT_MISSING); + } + + if ( aBAT->htype != TYPE_void || //header type of aBAT not void + bBAT->htype != TYPE_void || //header type of bBAT not void + aBAT->hseqbase != bBAT->hseqbase || //the idxs of the headers of the BATs are not the same + BATcount(aBAT) != BATcount(bBAT)) { //the number of valid elements in the BATs are not the same + BBPreleaseref(aBAT->batCacheid); + BBPreleaseref(bBAT->batCacheid); + throw(MAL, "batgeom.MBRfilter", "the arguments must have dense and aligned heads"); + } + + //create a new BAT for the output + if ((outBAT = BATnew(TYPE_void, ATOMindex("wkb"), BATcount(aBAT), TRANSIENT)) == NULL) { + BBPreleaseref(aBAT->batCacheid); + BBPreleaseref(bBAT->batCacheid); + throw(MAL, "batgeom.MBRfilter", MAL_MALLOC_FAIL); + } + //set the first idx of the output BAT equal to that of the aBAT + BATseqbase(outBAT, aBAT->hseqbase); + + //iterator over the BATs + aBAT_iter = bat_iterator(aBAT); + bBAT_iter = bat_iterator(bBAT); + + for (i = BUNfirst(aBAT); i < BATcount(aBAT); i++) { + str err = NULL; + aWKB = (wkb*) BUNtail(aBAT_iter, i + BUNfirst(aBAT)); + bWKB = (wkb*) BUNtail(bBAT_iter, i + BUNfirst(bBAT)); + + if ((err = wkbContains(&outBIT, &aWKB, &bWKB)) != MAL_SUCCEED) { //check + str msg; + BBPreleaseref(aBAT->batCacheid); + BBPreleaseref(bBAT->batCacheid); + BBPreleaseref(outBAT->batCacheid); + msg = createException(MAL, "batgeom.MBRfilter", "%s", err); + GDKfree(err); + return msg; + } + if(outBIT) + BUNappend(outBAT,&bWKB, TRUE); //add the result to the outBAT + } + + //set some properties of the new BAT + BATsetcount(outBAT, BATcount(aBAT)); + BATsettrivprop(outBAT); + BATderiveProps(outBAT,FALSE); + BBPreleaseref(aBAT->batCacheid); + BBPreleaseref(bBAT->batCacheid); + BBPkeepref(*outBAT_id = outBAT->batCacheid); + + //free the MBRs + GDKfree(aMBR); + GDKfree(bMBR); + + return MAL_SUCCEED; + + +} + str wkbCrosses(bit *out, wkb **geomWKB_a, wkb **geomWKB_b) { int res = wkbspatial(geomWKB_a, geomWKB_b, GEOSCrosses); *out = bit_nil; diff --git a/geom/monetdb5/geom.mal b/geom/monetdb5/geom.mal --- a/geom/monetdb5/geom.mal +++ b/geom/monetdb5/geom.mal @@ -413,6 +413,9 @@ command epilogue():void address geom_epi geom.prelude(); module batgeom; + +command MBRfilter{unsafe}(a:bat[:oid,:wkb], b:bat[:oid,:wkb]) :bat[:oid,:wkb] address wkbFilter_bat +comment "Filters the points in the second bat according to the MBR of the first bat. First bat shoud contain only one geometry in order for the filtering to be possible."; #command point(x:bat[:oid,:dbl],y:bat[:oid,:dbl]) :bat[:oid,:wkb] #address wkbcreatepoint_bat #comment "Construct a point-BAT from two geometry-BATs"; diff --git a/monetdb5/mal/mal_instruction.h b/monetdb5/mal/mal_instruction.h --- a/monetdb5/mal/mal_instruction.h +++ b/monetdb5/mal/mal_instruction.h @@ -182,7 +182,7 @@ mal_export InstrPtr pushArgument(MalBlkP mal_export InstrPtr setArgument(MalBlkPtr mb, InstrPtr p, int idx, int varid); mal_export InstrPtr pushReturn(MalBlkPtr mb, InstrPtr p, int varid); mal_export InstrPtr pushArgumentId(MalBlkPtr mb, InstrPtr p, str name); -mal_export void delArgument(InstrPtr p, int varid); +mal_export void delArgument(InstrPtr p, int idx); mal_export void setVarType(MalBlkPtr mb, int i, int tpe); mal_export void clrAllTypes(MalBlkPtr mb); mal_export void setArgType(MalBlkPtr mb, InstrPtr p, int i, int tpe); _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list