Changeset: b123e388dbdf for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=b123e388dbdf
Modified Files:
        geom/monetdb5/geom.h
        geom/monetdb5/geom.mal
        geom/monetdb5/geomPoints.c
        geom/sql/40_geom.sql
        monetdb5/optimizer/opt_geospatial.c
Branch: geo
Log Message:

Wrappers for the different spatial (contains + distance) functions and the 
filter
+ local functions of points declared static and removed from header


diffs (236 lines):

diff --git a/geom/monetdb5/geom.h b/geom/monetdb5/geom.h
--- a/geom/monetdb5/geom.h
+++ b/geom/monetdb5/geom.h
@@ -264,12 +264,9 @@ geom_export str wkbCoordinateFromMBR_bat
 
 /* POINTS */
 
-geom_export str wkbPointsContains1_geom_bat(bat* outBAT_id, wkb** geomWKB, 
bat* xBAT_id, bat* yBAT_id, int* srid);
-geom_export str wkbPointsContains2_geom_bat(bat* outBAT_id, wkb** geomWKB, 
bat* xBAT_id, bat* yBAT_id, int* srid);
-geom_export str wkbPointsDistance1_geom_bat(bat* outBAT_id, wkb** geomWKB, 
bat* xBAT_id, bat* yBAT_id, int* srid);
-geom_export str wkbPointsDistance2_geom_bat(bat* outBAT_id, wkb** geomWKB, 
bat* xBAT_id, bat* yBAT_id, int* srid);
+geom_export str wkbPointsContains_geom_bat(bat* outBAT_id, wkb** geomWKB, bat* 
xBAT_id, bat* yBAT_id, int* srid, int* filterVersion, int* spatialVersion);
 
-geom_export str wkbFilterWithImprints_geom_bat(bat*, wkb**, bat*, bat*);
-geom_export str wkbFilterWithPBSM_geom_bat(bat*, wkb**, bat*, bat*);
+geom_export str wkbPointsDistance_geom_bat(bat* outBAT_id, wkb** geomWKB, bat* 
xBAT_id, bat* yBAT_id, int* srid, int* filterVersion, int* spatialVersion);
 
-geom_export int isLeft( double P0x, double P0y, double P1x, double P1y, double 
P2x, double P2y);
+geom_export str wkbPointsFilter_geom_bat(bat*, wkb**, bat*, bat*, int* 
filterVersion);
+
diff --git a/geom/monetdb5/geom.mal b/geom/monetdb5/geom.mal
--- a/geom/monetdb5/geom.mal
+++ b/geom/monetdb5/geom.mal
@@ -435,7 +435,6 @@ end YMaxFromMBR;
 #address ordinatesMBR
 #comment "Creates the mbr for the given (xmin,ymin) and (xmax,ymax).";
 
-
 command prelude():void address geom_prelude;
 command epilogue():void address geom_epilogue;
 
@@ -451,14 +450,12 @@ command pbsmIndex{unsafe}(x:bat[:oid,:db
 command Distance(a:bat[:oid,:wkb], b:bat[:oid,:wkb]) :bat[:oid,:dbl] address 
wkbDistance_bat;
 command Distance(a:wkb, b:bat[:oid,:wkb]) :bat[:oid,:dbl] address 
wkbDistance_geom_bat;
 command Distance(a:bat[:oid,:wkb], b:wkb) :bat[:oid,:dbl] address 
wkbDistance_bat_geom;
-command Distance1(g:wkb, x:bat[:oid,:dbl], y:bat[:oid,:dbl], srid:int) 
:bat[:oid,:dbl] address wkbPointsDistance1_geom_bat;
-command Distance2(g:wkb, x:bat[:oid,:dbl], y:bat[:oid,:dbl], srid:int) 
:bat[:oid,:dbl] address wkbPointsDistance2_geom_bat;
+command Distance(g:wkb, x:bat[:oid,:dbl], y:bat[:oid,:dbl], srid:int, 
filterVrs:int, spatialVrs:int) :bat[:oid,:dbl] address 
wkbPointsDistance_geom_bat;
 
 command Contains(a:bat[:oid,:wkb], b:bat[:oid,:wkb]) :bat[:oid,:bit] address 
wkbContains_bat;
 command Contains(a:wkb, b:bat[:oid,:wkb]) :bat[:oid,:bit] address 
wkbContains_geom_bat;
 command Contains(a:bat[:oid,:wkb], b:wkb) :bat[:oid,:bit] address 
wkbContains_bat_geom;
-command Contains1(g:wkb, x:bat[:oid,:dbl], y:bat[:oid,:dbl], srid:int) 
:bat[:oid,:bit] address wkbPointsContains1_geom_bat;
-command Contains2(g:wkb, x:bat[:oid,:dbl], y:bat[:oid,:dbl], srid:int) 
:bat[:oid,:bit] address wkbPointsContains2_geom_bat;
+command Contains(g:wkb, x:bat[:oid,:dbl], y:bat[:oid,:dbl], srid:int, 
filterVrs:int, spatialVrs:int) :bat[:oid,:bit] address 
wkbPointsContains_geom_bat;
 
 #only one argument should be BAT
 #command Filter(a:bat[:oid,:wkb], b:bat[:oid,:wkb]) (aFiltered:bat[:oid,:wkb], 
bFiltered:bat[:oid,:wkb]) address wkbFilter_bat
@@ -466,10 +463,8 @@ command Contains2(g:wkb, x:bat[:oid,:dbl
 command Filter(a:wkb, b:bat[:oid,:wkb]) :bat[:oid,:wkb] address 
wkbFilter_geom_bat
 comment "Filters the points in the bats according to the MBR of the other 
bat.";
 command Filter(a:bat[:oid,:wkb], b:wkb) :bat[:oid,:wkb] address 
wkbFilter_bat_geom;
-command Filter(geom:wkb, x:bat[:oid,:dbl], y:bat[:oid,:dbl]) :bat[:oid,:oid] 
address wkbFilterWithImprints_geom_bat
-comment "Filters x,y coordinates in the BATs using imprints";
-command Filter1(geom:wkb, x:bat[:oid,:dbl], y:bat[:oid,:dbl]) :bat[:oid,:oid] 
address wkbFilterWithPBSM_geom_bat
-comment "Filters x,y coordinates in the BATs using PBSM";
+command Filter(geom:wkb, x:bat[:oid,:dbl], y:bat[:oid,:dbl], filterVrs:int) 
:bat[:oid,:oid] address wkbPointsFilter_geom_bat
+comment "Filters x,y coordinates in the BATs";
 
 #command point(x:bat[:oid,:dbl],y:bat[:oid,:dbl]) :bat[:oid,:wkb]
 #address wkbcreatepoint_bat
diff --git a/geom/monetdb5/geomPoints.c b/geom/monetdb5/geomPoints.c
--- a/geom/monetdb5/geomPoints.c
+++ b/geom/monetdb5/geomPoints.c
@@ -24,6 +24,7 @@
 #include "time.h"
 #include "unistd.h"
 
+/*
 typedef struct pbsm_ptr {
        BUN offset;
        unsigned long count;
@@ -35,7 +36,7 @@ static mbr *limits = NULL;
 
 //hard coded filename
 static char* filename = "../pbsmIndex_20m";
-
+*/
 
 //it gets two BATs with x,y coordinates and returns a new BAT with the points
 static BAT* BATMakePoint2D(BAT* xBAT, BAT* yBAT) {
@@ -206,7 +207,7 @@ outBAT->trevsorted = false;
 
 }
 
-str wkbPointsContains1_geom_bat(bat* outBAT_id, wkb** geomWKB, bat* xBAT_id, 
bat* yBAT_id, int* srid) {
+static str wkbPointsGeomContains_geom_bat(bat* outBAT_id, wkb** geomWKB, bat* 
xBAT_id, bat* yBAT_id, int* srid) {
        BAT *xBAT=NULL, *yBAT=NULL, *outBAT=NULL;
        BAT *pointsBAT = NULL, *pointsWithSRIDBAT=NULL;
        str ret=MAL_SUCCEED;
@@ -266,7 +267,7 @@ clean:
 }
 
 //Aternative implementation of contains using the winding number method
-inline int isLeft( double P0x, double P0y, double P1x, double P1y, double P2x, 
double P2y) {
+static inline int isLeft( double P0x, double P0y, double P1x, double P1y, 
double P2x, double P2y) {
        //borders are not included
     return ( ((P1x - P0x) * (P2y - P0y) - (P2x -  P0x) * (P1y - P0y)) > 0.0 ); 
 }
@@ -571,7 +572,7 @@ static str pnpolyWithHoles_(int *out, GE
 #define POLY_NUM_VERT 120
 #define POLY_NUM_HOLE 10
 
-str wkbPointsContains2_geom_bat(bat* out, wkb** geomWKB, bat* point_x, bat* 
point_y, int* srid) {
+static str wkbPointsWindingContains_geom_bat(bat* out, wkb** geomWKB, bat* 
point_x, bat* point_y, int* srid) {
        int interiorRingsNum = 0;
        GEOSGeom geosGeometry;
        str msg = NULL;
@@ -644,7 +645,7 @@ static BAT* BATDistance(wkb** geomWKB, B
        return outBAT;
 }
 
-str wkbPointsDistance1_geom_bat(bat* outBAT_id, wkb** geomWKB, bat* xBAT_id, 
bat* yBAT_id, int* srid) {
+static str wkbPointsGeomDistance_geom_bat(bat* outBAT_id, wkb** geomWKB, bat* 
xBAT_id, bat* yBAT_id, int* srid) {
        BAT *xBAT=NULL, *yBAT=NULL, *outBAT=NULL;
        BAT *pointsBAT = NULL, *pointsWithSRIDBAT=NULL;
        str ret=MAL_SUCCEED;
@@ -762,7 +763,7 @@ static BAT* point2point_distance(GEOSGeo
 
 }
 
-str wkbPointsDistance2_geom_bat(bat* outBAT_id, wkb** geomWKB, bat* xBAT_id, 
bat* yBAT_id, int* srid) {
+static str wkbPointsCartesianDistance_geom_bat(bat* outBAT_id, wkb** geomWKB, 
bat* xBAT_id, bat* yBAT_id, int* srid) {
        BAT *xBAT=NULL, *yBAT=NULL, *outBAT=NULL;
        GEOSGeom geosGeometry;
        str ret=MAL_SUCCEED;
@@ -817,7 +818,7 @@ clean:
        return ret;
 }
 
-str wkbFilterWithImprints_geom_bat(bat* candidateOIDsBAT_id, wkb** geomWKB, 
bat* xBAT_id, bat* yBAT_id) {
+static str wkbPointsFilterWithImprints_geom_bat(bat* candidateOIDsBAT_id, 
wkb** geomWKB, bat* xBAT_id, bat* yBAT_id) {
        BAT *xBAT=NULL, *yBAT=NULL, *xCandidateOIDsBAT=NULL, 
*candidateOIDsBAT=NULL;
        mbr* geomMBR;
        str err;
@@ -881,3 +882,41 @@ str wkbFilterWithImprints_geom_bat(bat* 
        BBPkeepref(*candidateOIDsBAT_id = candidateOIDsBAT->batCacheid);
        return MAL_SUCCEED;
 }
+
+
+/*Wrappers that choose the version of the spatial function and the filter that 
should be used*/
+
+str wkbPointsContains_geom_bat(bat* outBAT_id, wkb** geomWKB, bat* xBAT_id, 
bat* yBAT_id, int* srid, int* filterVersion, int* spatialVersion) {
+       (void) *filterVersion; //not used here but in the MAL optimiser
+       switch(*spatialVersion) {
+       case 1: 
+               return wkbPointsGeomContains_geom_bat(outBAT_id, geomWKB, 
xBAT_id, yBAT_id, srid);      
+       case 2:
+               return wkbPointsWindingContains_geom_bat(outBAT_id, geomWKB, 
xBAT_id, yBAT_id, srid);
+       default:
+               return createException(MAL, "batgeom.Contains", "Unknown 
Contains version");
+       }
+}
+
+str wkbPointsDistance_geom_bat(bat* outBAT_id, wkb** geomWKB, bat* xBAT_id, 
bat* yBAT_id, int* srid, int* filterVersion, int* spatialVersion) {
+       (void) *filterVersion; //not used here but in the MAL optimiser
+       switch(*spatialVersion) {
+       case 1: 
+               return wkbPointsGeomDistance_geom_bat(outBAT_id, geomWKB, 
xBAT_id, yBAT_id, srid);      
+       case 2:
+               return wkbPointsCartesianDistance_geom_bat(outBAT_id, geomWKB, 
xBAT_id, yBAT_id, srid);
+       default:
+               return createException(MAL, "batgeom.Distance", "Unknown 
Distance version");
+       }
+}
+
+str wkbPointsFilter_geom_bat(bat* candidatesBAT_id, wkb** geomWKB, bat* 
xBAT_id, bat* yBAT_id, int *filterVersion) {
+       switch(*filterVersion) {
+       case 1:
+               return wkbPointsFilterWithImprints_geom_bat(candidatesBAT_id, 
geomWKB, xBAT_id, yBAT_id);
+       //case 2:
+       //      return wkbPointsFilterWithPBSM_geom_bat(candidatesBAT_id, 
geomWKB, xBAT_id, yBAT_id);
+       default:
+               return createException(MAL, "batgeom.Filter", "Unknown Filter 
version");
+       }
+}
diff --git a/geom/sql/40_geom.sql b/geom/sql/40_geom.sql
--- a/geom/sql/40_geom.sql
+++ b/geom/sql/40_geom.sql
@@ -4052,14 +4052,12 @@ CREATE FUNCTION ST_Touches(geom1 Geometr
 CREATE FUNCTION ST_Crosses(geom1 Geometry, geom2 Geometry) RETURNS boolean 
EXTERNAL NAME geom."Crosses";
 CREATE FUNCTION ST_Within(geom1 Geometry, geom2 Geometry) RETURNS boolean 
EXTERNAL NAME geom."Within";
 CREATE FUNCTION ST_Contains(geom1 Geometry, geom2 Geometry) RETURNS boolean 
EXTERNAL NAME geom."Contains";
-CREATE FUNCTION ST_Contains1(geom1 Geometry, xCoordinate double, yCoordinate 
double, srid integer) RETURNS boolean EXTERNAL NAME geom."Contains1";
-CREATE FUNCTION ST_Contains2(geom1 Geometry, xCoordinate double, yCoordinate 
double, srid integer) RETURNS boolean EXTERNAL NAME geom."Contains2";
+CREATE FUNCTION ST_Contains(geom1 Geometry, xCoordinate double, yCoordinate 
double, srid integer, filterVersion integer, spatialVersion integer) RETURNS 
boolean EXTERNAL NAME geom."Contains";
 CREATE FUNCTION ST_Overlaps(geom1 Geometry, geom2 Geometry) RETURNS boolean 
EXTERNAL NAME geom."Overlaps";
 CREATE FUNCTION ST_Relate(geom1 Geometry, geom2 Geometry, 
intersection_matrix_pattern string) RETURNS boolean EXTERNAL NAME geom."Relate";
 --Distance between Geometries
 CREATE FUNCTION ST_Distance(geom1 Geometry, geom2 Geometry) RETURNS double 
EXTERNAL NAME geom."Distance";
-CREATE FUNCTION ST_Distance1(geom1 Geometry, xCoordinate double, yCoordinate 
double, srid integer) RETURNS double EXTERNAL NAME geom."Distance1";
-CREATE FUNCTION ST_Distance2(geom1 Geometry, xCoordinate double, yCoordinate 
double, srid integer) RETURNS double EXTERNAL NAME geom."Distance2";
+CREATE FUNCTION ST_Distance(geom1 Geometry, xCoordinate double, yCoordinate 
double, srid integer, filterVersion integer, spatialVersion integer) RETURNS 
double EXTERNAL NAME geom."Distance";
 --Functions that implement spatial operators
 CREATE FUNCTION ST_Intersection(geom1 Geometry, geom2 Geometry) RETURNS 
Geometry EXTERNAL NAME geom."Intersection";
 CREATE FUNCTION ST_Difference(geom1 Geometry, geom2 Geometry) RETURNS Geometry 
EXTERNAL NAME geom."Differnce";
diff --git a/monetdb5/optimizer/opt_geospatial.c 
b/monetdb5/optimizer/opt_geospatial.c
--- a/monetdb5/optimizer/opt_geospatial.c
+++ b/monetdb5/optimizer/opt_geospatial.c
@@ -43,6 +43,8 @@ static void createFilterInstruction(MalB
        filterInstrPtr = pushArgument(mb, filterInstrPtr, filterFirstArgument);
        filterInstrPtr = pushArgument(mb, filterInstrPtr, 
getArg(oldInstrPtr[instructionNum],2));
        filterInstrPtr = pushArgument(mb, filterInstrPtr, 
getArg(oldInstrPtr[instructionNum],3));
+       //thi argument is the filter version
+       filterInstrPtr = pushArgument(mb, filterInstrPtr, 
getArg(oldInstrPtr[instructionNum],5));
 
        //set the arguments for the x project
        setReturnArgument(projectXInstrPtr, projectXReturnId);
@@ -173,8 +175,8 @@ int OPTgeospatialImplementation(Client c
                        if((filterReturnId = 
getSubselectSecondInput(getArg(oldInstrPtr[i], 1))) > 0)
                                fixSubselect(mb, oldInstrPtr, i, 
filterReturnId);
                } else if(getModuleId(oldInstrPtr[i]) && 
!strcasecmp(getModuleId(oldInstrPtr[i]),"batgeom"))    {
-                       if((strcasecmp(getFunctionId(oldInstrPtr[i]), 
"contains1") == 0) || (strcasecmp(getFunctionId(oldInstrPtr[i]), "contains2") 
== 0))  {
-                               if(oldInstrPtr[i]->argc == 5) {
+                       if( strcasecmp(getFunctionId(oldInstrPtr[i]), 
"contains") == 0 )  {
+                               if(oldInstrPtr[i]->argc == (5+2)) { //+2 -> the 
verion arguments
                                        //call all necessary intructions for 
the filter and the evaluation of the spatial relation      
                                        createFilterInstruction(mb, 
oldInstrPtr, i, getArg(oldInstrPtr[i],1));
 
@@ -217,13 +219,13 @@ int OPTgeospatialImplementation(Client c
 
                                        actions +=2;
                                }
-                       } else if((strcasecmp(getFunctionId(oldInstrPtr[i]), 
"distance1") == 0 || strcasecmp(getFunctionId(oldInstrPtr[i]), "distance2") == 
0)  
+                       } else if( (strcasecmp(getFunctionId(oldInstrPtr[i]), 
"distance") == 0)  
                                        && 
strcasecmp(getFunctionId(oldInstrPtr[i+1]), "thetasubselect") == 0) {
                                //the filter does not make sense if comparison 
is > OR >= 
                        //      if(strcmp(getArg(oldInstrPtr[i+1],4), ">")==0 
||  strcmp(getArg(oldInstrPtr[i+1],4),">=")==0) {
                        //              pushInstruction(mb, oldInstrPtr[i]);
                        //      } else 
-                               if(oldInstrPtr[i]->argc == 5) {
+                               if(oldInstrPtr[i]->argc == (5+2)) { //+2 the 
version arguments
                                        InstrPtr bufferInstrPtr;
                                        int bufferReturnId;
                                        
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to