[cig-commits] r15440 - in cs/spatialdata-0.1/trunk: libsrc/spatialdb tests/libtests/spatialdb tests/libtests/spatialdb/data

brad at geodynamics.org brad at geodynamics.org
Tue Jul 7 18:00:33 PDT 2009


Author: brad
Date: 2009-07-07 18:00:32 -0700 (Tue, 07 Jul 2009)
New Revision: 15440

Modified:
   cs/spatialdata-0.1/trunk/libsrc/spatialdb/SpatialDB.cc
   cs/spatialdata-0.1/trunk/libsrc/spatialdb/SpatialDB.hh
   cs/spatialdata-0.1/trunk/tests/libtests/spatialdb/TestSpatialDB.cc
   cs/spatialdata-0.1/trunk/tests/libtests/spatialdb/TestSpatialDB.hh
   cs/spatialdata-0.1/trunk/tests/libtests/spatialdb/data/spatialdb.dat
Log:
Added query function for multiple locations (allow efficient queries from Python).

Modified: cs/spatialdata-0.1/trunk/libsrc/spatialdb/SpatialDB.cc
===================================================================
--- cs/spatialdata-0.1/trunk/libsrc/spatialdb/SpatialDB.cc	2009-07-07 21:35:30 UTC (rev 15439)
+++ cs/spatialdata-0.1/trunk/libsrc/spatialdb/SpatialDB.cc	2009-07-08 01:00:32 UTC (rev 15440)
@@ -34,7 +34,34 @@
 { // destructor
 } // destructor
 
-// version
-// $Id$
+// ----------------------------------------------------------------------
+// Perform multiple queries of the database.
+void
+spatialdata::spatialdb::SpatialDB::multiquery(double* vals,
+					      const int numLocsV,
+					      const int numValsV,
+					      int* err,
+					      const int numLocsE,
+					      const double* coords,
+					      const int numLocsC,
+					      const int numDimsC,
+					      const spatialdata::geocoords::CoordSys* csQuery)
+{ // multiquery
+  assert(numLocsV == numLocsE);
+  assert(numLocsC == numLocsE);
+  assert( (0 == vals && 0 == numLocsV && 0 == numValsV) ||
+	  (0 != vals && numLocsV > 0 && numValsV > 0) );
+  assert( (0 == err && 0 == numLocsE) ||
+	  (0 != err && numLocsE > 0) );
+  assert( (0 == coords && 0 == numLocsC && 0 == numDimsC) ||
+	  (0 != coords && numLocsC > 0 && numDimsC > 0) );
 
+  for (int i=0, indexV=0, indexC=0;
+       i < numLocsV;
+       ++i, indexV+=numValsV, indexC+=numDimsC)
+    err[i] = query(&vals[indexV], numValsV, &coords[indexC], numDimsC,
+		   csQuery);
+} // multiquery
+
+
 // End of file 

Modified: cs/spatialdata-0.1/trunk/libsrc/spatialdb/SpatialDB.hh
===================================================================
--- cs/spatialdata-0.1/trunk/libsrc/spatialdb/SpatialDB.hh	2009-07-07 21:35:30 UTC (rev 15439)
+++ cs/spatialdata-0.1/trunk/libsrc/spatialdb/SpatialDB.hh	2009-07-08 01:00:32 UTC (rev 15440)
@@ -76,16 +76,16 @@
 
   /** Query the database.
    *
-   * @note pVals should be preallocated to accommodate numVals values.
+   * @note vals should be preallocated to accommodate numVals values.
    *
-   * @pre Must call open() before query()
+   * @pre Must call open() before query().
    *
    * @param vals Array for computed values (output from query), must be
    *   allocated BEFORE calling query().
    * @param numVals Number of values expected (size of pVals array)
-   * @param coords Coordinates of point for query
-   * @param numDims Number of dimensions for coordinates
-   * @param pCSQuery Coordinate system of coordinates
+   * @param coords Coordinates of point for query [numDims].
+   * @param numDims Number of dimensions for coordinates.
+   * @param csQuery Coordinate system of coordinates.
    *
    * @returns 0 on success, 1 on failure (i.e., could not interpolate)
    */
@@ -94,8 +94,39 @@
 	    const int numVals,
 	    const double* coords,
 	    const int numDims,
-	    const spatialdata::geocoords::CoordSys* pCSQuery) = 0;
+	    const spatialdata::geocoords::CoordSys* csQuery) = 0;
 
+  /** Perform multiple queries of the database.
+   *
+   * @note vals should be preallocated to accommodate numVals values
+   * at numLocs locations.
+   *
+   * @note err should be preallocated to accommodate numLocs values.
+   *
+   * @pre Must call open() before query().
+   *
+   * @param vals Array for computed values (output from query), must be
+   *   allocated BEFORE calling query() [numLocs*numVals].
+   * @param numLocsV Number of locations.
+   * @param numValsV Number of values expected.
+   * @param err Array for error flag values (output from query), must be
+   *   allocated BEFORE calling query() [numLocs].
+   * @param numLocsE Number of locations.
+   * @param coords Coordinates of point for query [numLocs*numDims].
+   * @param numLocsC Number of locations.
+   * @param numDimsC Number of dimensions for coordinates.
+   * @param csQuery Coordinate system of coordinates.
+   */
+  void multiquery(double* vals,
+		  const int numLocsV,
+		  const int numValsV,
+		  int* err,
+		  const int numLocsE,
+		  const double* coords,
+		  const int numLocsC,
+		  const int numDimsC,
+		  const spatialdata::geocoords::CoordSys* csQuery);
+
  private :
   // PRIVATE METHODS ////////////////////////////////////////////////////
   

Modified: cs/spatialdata-0.1/trunk/tests/libtests/spatialdb/TestSpatialDB.cc
===================================================================
--- cs/spatialdata-0.1/trunk/tests/libtests/spatialdb/TestSpatialDB.cc	2009-07-07 21:35:30 UTC (rev 15439)
+++ cs/spatialdata-0.1/trunk/tests/libtests/spatialdb/TestSpatialDB.cc	2009-07-08 01:00:32 UTC (rev 15440)
@@ -66,7 +66,7 @@
   const char* names[] = {"two", "one", "four", "three"};
   const char* units[] = {"km", "m", "None", "MPa"};
   const int numVals = 4;
-  const double queryLoc[] = { 1.0, 2.0, 3.0 };
+  const double queryLoc[] = { 0.6, 0.1, 0.2 };
   const double vals[] = { 6.3e+3, 4.7, 0.8, 1.2e+6 };
   const int errFlags[] = { 0 };
   const int spaceDim = 3;
@@ -90,6 +90,56 @@
 } // testDB
 
 // ----------------------------------------------------------------------
+// Test SpatialDB queries w/multiple points.
+void
+spatialdata::spatialdb::TestSpatialDB::testDBmulti(void)
+{ // testDBmulti
+  CPPUNIT_ASSERT(0 != _pDB);
+
+  const int numVals = 4;
+  const int numLocs = 2;
+  const int spaceDim = 3;
+  const char* names[numVals] = {"two", "one", "four", "three"};
+  const char* units[numVals] = {"km", "m", "None", "MPa"};
+  const double queryLocs[numLocs*spaceDim] = { 
+    0.6, 0.1, 0.2,
+    0.1, 0.6, 0.3,
+  };
+  const double vals[numLocs*numVals] = { 
+    6.3e+3, 4.7, 0.8, 1.2e+6,
+    3.6e+3, 7.4, 8.0, 2.1e+6,
+  };
+  const int errFlags[numLocs] = { 0, 0 };
+
+  _pDB->queryVals(names, numVals);
+
+  int size = numLocs * numVals;
+  double* valsQ = (0 < size) ? new double[size] : 0;
+  size = numLocs;
+  int* errQ = (0 < size) ? new int[size] : 0;
+  		  
+  spatialdata::geocoords::CSCart csCart;
+  csCart.initialize();
+
+  _pDB->multiquery(valsQ, numLocs, numVals, 
+		   errQ, numLocs,
+		   queryLocs, numLocs, spaceDim, &csCart);
+
+  const double tolerance = 1.0e-06;
+  for (int iLoc=0; iLoc < numLocs; ++iLoc) {
+    CPPUNIT_ASSERT_EQUAL(errFlags[iLoc], errQ[iLoc]);
+    for (int iVal=0, index=0; iVal < numVals; ++iVal, index++)
+      CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, valsQ[index]/vals[index],
+				   tolerance);
+  } // for
+
+  delete[] valsQ; valsQ = 0;
+  delete[] errQ; errQ = 0;
+
+  _pDB->close();
+} // testDBmulti
+
+// ----------------------------------------------------------------------
 // Test SpatialDB w/C query
 void
 spatialdata::spatialdb::TestSpatialDB::testDB_c(void)
@@ -99,7 +149,7 @@
   const char* names[] = {"two", "one"};
   const char* units[] = {"km", "m"};
   const int numVals = 2;
-  const double queryLoc[] = { 1.0, 2.0, 3.0 };
+  const double queryLoc[] = { 0.6, 0.1, 0.2 };
   const int spaceDim = 3;
   const double vals[] = { 6.3e+3, 4.7 };
   const int errFlags[] = { 0 };

Modified: cs/spatialdata-0.1/trunk/tests/libtests/spatialdb/TestSpatialDB.hh
===================================================================
--- cs/spatialdata-0.1/trunk/tests/libtests/spatialdb/TestSpatialDB.hh	2009-07-07 21:35:30 UTC (rev 15439)
+++ cs/spatialdata-0.1/trunk/tests/libtests/spatialdb/TestSpatialDB.hh	2009-07-08 01:00:32 UTC (rev 15440)
@@ -37,6 +37,7 @@
   // CPPUNIT TEST SUITE /////////////////////////////////////////////////
   CPPUNIT_TEST_SUITE( TestSpatialDB );
   CPPUNIT_TEST( testDB );
+  CPPUNIT_TEST( testDBmulti );
   CPPUNIT_TEST( testDB_c );
   CPPUNIT_TEST_SUITE_END();
 
@@ -52,6 +53,9 @@
   /// Test SpatialDB
   void testDB(void);
 
+  /// Test SpatialDB queries w/multiple points.
+  void testDBmulti(void);
+
   /// Test SpatialDB w/C query
   void testDB_c(void);
 

Modified: cs/spatialdata-0.1/trunk/tests/libtests/spatialdb/data/spatialdb.dat
===================================================================
--- cs/spatialdata-0.1/trunk/tests/libtests/spatialdb/data/spatialdb.dat	2009-07-07 21:35:30 UTC (rev 15439)
+++ cs/spatialdata-0.1/trunk/tests/libtests/spatialdb/data/spatialdb.dat	2009-07-08 01:00:32 UTC (rev 15440)
@@ -3,10 +3,11 @@
   num-values = 4
   value-names =  One  Two  Three Four
   value-units =  m  km  MPa  None
-  num-locs = 1
-  data-dim = 0
+  num-locs = 2
+  data-dim = 1
   cs-data = cartesian {
     to-meters = 1.0
   }
 }
   6.000000e-01  1.000000e-01  2.000000e-01    4.7  6.3  1.2  0.8
+  1.000000e-01  6.000000e-01  3.000000e-01    7.4  3.6  2.1  8.0



More information about the CIG-COMMITS mailing list