[cig-commits] r6112 - in cs/spatialdata-0.1/trunk: modulesrc/spatialdb spatialdata/spatialdb spatialdata/spatialdb/generator

brad at geodynamics.org brad at geodynamics.org
Fri Feb 23 15:35:05 PST 2007


Author: brad
Date: 2007-02-23 15:35:05 -0800 (Fri, 23 Feb 2007)
New Revision: 6112

Added:
   cs/spatialdata-0.1/trunk/spatialdata/spatialdb/generator/SimpleDBCreator.py
Modified:
   cs/spatialdata-0.1/trunk/modulesrc/spatialdb/spatialdb.pyxe.src
   cs/spatialdata-0.1/trunk/spatialdata/spatialdb/SimpleDB.py
   cs/spatialdata-0.1/trunk/spatialdata/spatialdb/SimpleIOAscii.py
   cs/spatialdata-0.1/trunk/spatialdata/spatialdb/SpatialDB.py
Log:
Added SimpleDBCreator object for creating simple databases. Adjusted doc strings. Need to work on generator module to finish implementation.

Modified: cs/spatialdata-0.1/trunk/modulesrc/spatialdb/spatialdb.pyxe.src
===================================================================
--- cs/spatialdata-0.1/trunk/modulesrc/spatialdb/spatialdb.pyxe.src	2007-02-23 20:21:03 UTC (rev 6111)
+++ cs/spatialdata-0.1/trunk/modulesrc/spatialdb/spatialdb.pyxe.src	2007-02-23 23:35:05 UTC (rev 6112)
@@ -25,17 +25,20 @@
   void* PyCObject_AsVoidPtr(object)
 
 
+cdef extern from "stdlib.h":
+  ctypedef unsigned long size_t
+  void* malloc(size_t size)
+  void free(void* mem)
+  void strcpy(char*, char*)
+
+
 cdef void* ptrFromHandle(obj):
-  """Extract pointer from PyCObject."""
+  """
+  Extract pointer from PyCObject.
+  """
   return PyCObject_AsVoidPtr(obj.handle)
 
 
-cdef extern from "stdlib.h":
-    ctypedef unsigned long size_t
-    void* malloc(size_t size)
-    void free(void* mem)
-    void strcpy(char*, char*)
-
 # ----------------------------------------------------------------------
 cdef class SpatialDB:
 
@@ -44,7 +47,9 @@
   cdef readonly object name # Identifier for type of object
 
   def __init__(self):
-    """Constructor."""
+    """
+    Constructor.
+    """
     self.handle = None
     self.thisptr = NULL
     self.name = "spatialdata_spatialdb_SpatialDB"
@@ -53,7 +58,9 @@
 
   property label:
     def __set__(self, name):
-      """Set label of spatial database."""
+      """
+      Set label of spatial database.
+      """
       # create shim for method 'label'
       #embed{ void SpatialDB_label_set(void* pObj, char* name)
       ((spatialdata::spatialdb::SpatialDB*) pObj)->label(name);
@@ -62,7 +69,9 @@
       SpatialDB_label_set(self.thisptr, name)
 
     def __get__(self):
-      """Get label of spatial database."""
+      """
+      Get label of spatial database.
+      """
       # create shim for method 'label'
       #embed{ char* SpatialDB_label_get(void* pObj)
       return (char*) ((spatialdata::spatialdb::SpatialDB*) pObj)->label();
@@ -72,7 +81,9 @@
 
       
   def open(self):
-    """Open database and prepare for querying."""
+    """
+    Open database and prepare for querying.
+    """
     # create shim for method 'open'
     #embed{ void SpatialDB_open(void* pObj)
     ((spatialdata::spatialdb::SpatialDB*) pObj)->open();
@@ -83,7 +94,9 @@
 
 
   def close(self):
-    """Close the database."""
+    """
+    Close the database.
+    """
     # create shim for method 'close'
     #embed{ void SpatialDB_close(void* pObj)
     ((spatialdata::spatialdb::SpatialDB*) pObj)->close();
@@ -94,7 +107,9 @@
 
 
   def queryVals(self, names):
-    """Set values to be returned by queries."""
+    """
+    Set values to be returned by queries.
+    """
     # create shim for method 'queryVals'
     #embed{ void SpatialDB_queryVals(void* pObj, char** names, int numVals)
     ((spatialdata::spatialdb::SpatialDB*) pObj)->queryVals((const char**) names, numVals);
@@ -120,7 +135,9 @@
 
 
   def query(self, locs, cs, nvals):
-    """Query db to get values at locations."""
+    """
+    Query db to get values at locations.
+    """
     # create shim for method 'query'
     #embed{ void SpatialDB_query(void* pObj, double* vals, int nvals, double* coords, int spaceDim, void* csObj)
     spatialdata::geocoords::CoordSys* pCS =
@@ -173,7 +190,9 @@
 
 
   def _createHandle(self):
-    """Wrap pointer to C++ object in PyCObject."""
+    """
+    Wrap pointer to C++ object in PyCObject.
+    """
     # create shim for destructor
     #embed{ void SpatialDB_destructor(void* pObj)
     spatialdata::spatialdb::SpatialDB* pDB =
@@ -187,7 +206,9 @@
 cdef class SimpleDB(SpatialDB):
 
   def __init__(self):
-    """Constructor."""
+    """
+    Constructor.
+    """
     # create shim for constructor
     #embed{ void* SimpleDB_constructor()
       return (void*)(new spatialdata::spatialdb::SimpleDB);
@@ -200,7 +221,9 @@
 
 
   def queryType(self, name):
-    """Set query type"""
+    """
+    Set query type.
+    """
     # create shim for method 'queryType'
     #embed{ void SimpleDB_queryType(void* pObj, char* name)
     spatialdata::spatialdb::SimpleDB::QueryEnum queryType =
@@ -222,7 +245,9 @@
 
 
   def ioHandler(self, handle):
-    """Set the I/O handler."""
+    """
+    Set the I/O handler.
+    """
     # create shim for method 'ioHandler'
     #embed{ void SimpleDB_ioHandler(void* pObj, void* pHandlerObj)
     spatialdata::spatialdb::SimpleIO* pHandler =
@@ -246,7 +271,9 @@
   cdef readonly object name # Identifier for type of object
 
   def __init__(self):
-    """Constructor."""
+    """
+    Constructor.
+    """
     self.handle = None
     self.thisptr = NULL
     self.name = "spatialdata_spatialdb_SimpleIO"
@@ -254,7 +281,9 @@
 
 
   def filename(self, name):
-    """Set filename for database"""
+    """
+    Set filename for database.
+    """
     # create shim for method 'filename'
     #embed{ void SimpleIO_filename(void* pObj, char* name)
     ((spatialdata::spatialdb::SimpleIO*) pObj)->filename(name);
@@ -265,7 +294,9 @@
 
 
   def _createHandle(self):
-    """Wrap pointer to C++ object in PyCObject."""
+    """
+    Wrap pointer to C++ object in PyCObject.
+    """
     # create shim for destructor
     #embed{ void SimpleIO_destructor(void* pObj)
     spatialdata::spatialdb::SimpleIO* pIO =
@@ -279,7 +310,9 @@
 cdef class SimpleIOAscii(SimpleIO):
 
   def __init__(self):
-    """Constructor."""
+    """
+    Constructor.
+    """
     # create shim for constructor
     #embed{ void* SimpleIOAscii_constructor()
       return (void*)(new spatialdata::spatialdb::SimpleIOAscii);
@@ -292,7 +325,9 @@
 
 
   def write(self, data, cs):
-    """Write the database."""
+    """
+    Write database to file.
+    """
     # create shim for method 'write'
     #embed{ void SimpleIOAscii_write(void* pObj, void* pDataObj, void* pCSObj)
     spatialdata::spatialdb::SimpleDB::DataStruct* pData =
@@ -309,7 +344,4 @@
     return
 
 
-# version
-__id__ = "$Id$"
-
 # End of file 

Modified: cs/spatialdata-0.1/trunk/spatialdata/spatialdb/SimpleDB.py
===================================================================
--- cs/spatialdata-0.1/trunk/spatialdata/spatialdb/SimpleDB.py	2007-02-23 20:21:03 UTC (rev 6111)
+++ cs/spatialdata-0.1/trunk/spatialdata/spatialdb/SimpleDB.py	2007-02-23 23:35:05 UTC (rev 6112)
@@ -76,7 +76,5 @@
     self.queryType = self.inventory.queryType
     return
 
-# version
-__id__ = "$Id$"
 
 # End of file 

Modified: cs/spatialdata-0.1/trunk/spatialdata/spatialdb/SimpleIOAscii.py
===================================================================
--- cs/spatialdata-0.1/trunk/spatialdata/spatialdb/SimpleIOAscii.py	2007-02-23 20:21:03 UTC (rev 6111)
+++ cs/spatialdata-0.1/trunk/spatialdata/spatialdb/SimpleIOAscii.py	2007-02-23 23:35:05 UTC (rev 6112)
@@ -17,11 +17,16 @@
 
 # SimpleIOAscii class
 class SimpleIOAscii(SimpleIO):
-  """Python ascii I/O manager for simple spatial database (SimpleDB)."""
+  """
+  Python ascii I/O manager for simple spatial database (SimpleDB).
+  """
 
   # PUBLIC METHODS /////////////////////////////////////////////////////
 
   def write(self, cppDB, cs):
+    """
+    Write database data to file.
+    """
     self.cppHandle.write(cppDB, cs.cppHandle)
     return
 
@@ -34,7 +39,4 @@
     return
 
 
-# version
-__id__ = "$Id$"
-
 # End of file 

Modified: cs/spatialdata-0.1/trunk/spatialdata/spatialdb/SpatialDB.py
===================================================================
--- cs/spatialdata-0.1/trunk/spatialdata/spatialdb/SpatialDB.py	2007-02-23 20:21:03 UTC (rev 6111)
+++ cs/spatialdata-0.1/trunk/spatialdata/spatialdb/SpatialDB.py	2007-02-23 23:35:05 UTC (rev 6112)
@@ -87,7 +87,4 @@
     return
   
 
-# version
-__id__ = "$Id$"
-
 # End of file 

Added: cs/spatialdata-0.1/trunk/spatialdata/spatialdb/generator/SimpleDBCreator.py
===================================================================
--- cs/spatialdata-0.1/trunk/spatialdata/spatialdb/generator/SimpleDBCreator.py	2007-02-23 20:21:03 UTC (rev 6111)
+++ cs/spatialdata-0.1/trunk/spatialdata/spatialdb/generator/SimpleDBCreator.py	2007-02-23 23:35:05 UTC (rev 6112)
@@ -0,0 +1,70 @@
+#!/usr/bin/env python
+#
+# ----------------------------------------------------------------------
+#
+#                           Brad T. Aagaard
+#                        U.S. Geological Survey
+#
+# <LicenseText>
+#
+# ----------------------------------------------------------------------
+#
+
+## @file spatialdata/spatialdb/generator/SimpleDBCreator.py
+
+## @brief Python object for creating a SimpleDB file.
+
+# SimpleDBCreator class
+class SimpleDBCreator(object):
+  """
+  Python object for creating a SimpleDB file.
+  """
+
+  # PUBLIC METHODS /////////////////////////////////////////////////////
+
+  def create(self, filename, values, units, coords, data, dataDim, cs):
+    """
+    Create database file.
+    """
+    self._validate(values, units, coords, data)
+    (numLocs, spaceDim) = coords.shape
+    numValues = len(values)
+    
+    import spatialdb.spatialdb.generator.generator as bindings
+    cppData = bindings.createData(values, units, coords, data, dataDim)
+
+    # Create SimpleIOAscii object
+    # Write database file
+    return
+  
+
+  def __init__(self):
+    """
+    Constructor.
+    """
+    return
+
+
+  # PRIVATE METHODS ////////////////////////////////////////////////////
+
+  def _validate(values, units, coords, data):
+    """
+    Check consistency of dimensions.
+    """
+    msg = ""
+    numValues = len(values)
+    if numValues != len(units):
+      msg += "Number of values given in 'values' and 'units' do not match."
+    (numLocs, spaceDim) = coords.shape
+    (dataLocs, dataValues) = data.shape
+    if numLocs != dataLocs:
+      msg += "Number of locations in 'coords' and 'data' do not match."
+    if numValues != dataValues:
+      msg += "Number of values in 'values' and 'data' do not match."
+    if msg != "":
+      raise ValueError(msg)
+    return
+
+
+
+# End of file 



More information about the cig-commits mailing list