[cig-commits] r15442 - in cs/spatialdata-0.1/trunk: libsrc/spatialdb modulesrc/spatialdb tests/pytests/spatialdb

brad at geodynamics.org brad at geodynamics.org
Wed Jul 8 13:13:28 PDT 2009


Author: brad
Date: 2009-07-08 13:13:28 -0700 (Wed, 08 Jul 2009)
New Revision: 15442

Modified:
   cs/spatialdata-0.1/trunk/libsrc/spatialdb/SpatialDB.cc
   cs/spatialdata-0.1/trunk/modulesrc/spatialdb/SpatialDBObj.i
   cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/TestSimpleDB.py
Log:
Updated SpatialDB interface and added Python unit test of multiquery().

Modified: cs/spatialdata-0.1/trunk/libsrc/spatialdb/SpatialDB.cc
===================================================================
--- cs/spatialdata-0.1/trunk/libsrc/spatialdb/SpatialDB.cc	2009-07-08 20:12:41 UTC (rev 15441)
+++ cs/spatialdata-0.1/trunk/libsrc/spatialdb/SpatialDB.cc	2009-07-08 20:13:28 UTC (rev 15442)
@@ -14,6 +14,8 @@
 
 #include "SpatialDB.hh" // Implementation of class methods
 
+#include <cassert> // USES assert()
+
 // ----------------------------------------------------------------------
 /// Default constructor
 spatialdata::spatialdb::SpatialDB::SpatialDB(void) :

Modified: cs/spatialdata-0.1/trunk/modulesrc/spatialdb/SpatialDBObj.i
===================================================================
--- cs/spatialdata-0.1/trunk/modulesrc/spatialdb/SpatialDBObj.i	2009-07-08 20:12:41 UTC (rev 15441)
+++ cs/spatialdata-0.1/trunk/modulesrc/spatialdb/SpatialDBObj.i	2009-07-08 20:13:28 UTC (rev 15442)
@@ -76,19 +76,19 @@
       void queryVals(const char* const* names,
 		     const int numVals) = 0;
       %clear(const char* const* names, const int numVals);
-      
+
       /** 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)
        */
@@ -105,10 +105,58 @@
 		const int numVals,
 		const double* coords,
 		const int numDims,
-		const spatialdata::geocoords::CoordSys* pCSQuery) = 0;
+		const spatialdata::geocoords::CoordSys* csQuery) = 0;
       %clear(double* vals, const int numVals);
       %clear(const double* coords, const int numDims);
       
+      /** 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.
+       */
+      %apply(double* INPLACE_ARRAY2, int DIM1, int DIM2) {
+	(double* vals,
+	 const int numLocsV,
+	 const int numValsV)
+	  };
+      %apply(int* INPLACE_ARRAY1, int DIM1) {
+	(int* err,
+	 const int numLocsE)
+	  };
+      %apply(double* IN_ARRAY2, int DIM1, int DIM2) {
+	(const double* coords,
+	 const int numLocsC,
+	 const int numDimsC)
+	  };
+      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);
+      %clear(double* vals, const int numLocsV, const int numValsV);
+      %clear(int* err, const int numLocsE);
+      %clear(const double* coords, const int numLocsC, const int numDimsC);
+      
     }; // class SpatialDB
     
   } // spatialdb

Modified: cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/TestSimpleDB.py
===================================================================
--- cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/TestSimpleDB.py	2009-07-08 20:12:41 UTC (rev 15441)
+++ cs/spatialdata-0.1/trunk/tests/pytests/spatialdb/TestSimpleDB.py	2009-07-08 20:13:28 UTC (rev 15442)
@@ -63,4 +63,35 @@
     return
 
 
+  def test_databasemulti(self):
+    locs = numpy.array( [[1.0, 2.0, 3.0],
+                         [5.6, 4.2, 8.6]],
+                        numpy.float64)
+    cs = CSCart()
+    cs._configure()
+    queryVals = ["two", "one"]
+    dataE = numpy.array( [[4.7, 6.3]]*2, numpy.float64)
+    errE = numpy.array([0, 0], numpy.int32)
+
+    db = self._db
+    db.open()
+    db.queryVals(queryVals)
+    data = numpy.zeros(dataE.shape, dtype=numpy.float64)
+    err = numpy.zeros(errE.shape, dtype=numpy.int32)
+    db.multiquery(data, err, locs, cs)
+    db.close()    
+
+    self.assertEqual(len(errE), len(err))
+    for vE, v in zip(errE, err):
+      self.assertEqual(vE, v)
+
+    self.assertEqual(len(dataE.shape), len(data.shape))
+    for dE, d in zip(dataE.shape, data.shape):
+      self.assertEqual(dE, d)
+    for vE, v in zip(numpy.reshape(dataE, -1), numpy.reshape(data, -1)):
+      self.assertAlmostEqual(vE, v, 6)
+
+    return
+
+
 # End of file 



More information about the CIG-COMMITS mailing list