[GRASS-SVN] r54914 - grass/trunk/lib/python/pygrass/raster

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Feb 5 00:19:46 PST 2013


Author: zarch
Date: 2013-02-05 00:19:46 -0800 (Tue, 05 Feb 2013)
New Revision: 54914

Modified:
   grass/trunk/lib/python/pygrass/raster/history.py
   grass/trunk/lib/python/pygrass/raster/rowio.py
   grass/trunk/lib/python/pygrass/raster/segment.py
Log:
Change the C struct attribute name to be consistent with the other classes

Modified: grass/trunk/lib/python/pygrass/raster/history.py
===================================================================
--- grass/trunk/lib/python/pygrass/raster/history.py	2013-02-05 08:19:35 UTC (rev 54913)
+++ grass/trunk/lib/python/pygrass/raster/history.py	2013-02-05 08:19:46 UTC (rev 54914)
@@ -14,33 +14,34 @@
     *Examples*
 
     ::
-
-        >>> import grass.pygrass as pygrass
-        >>> hist = pygrass.raster.History()
-        >>> hist.read('aspect')
+        >>> import grass.lib.gis as libgis
+        >>> libgis.G_gisinit('')
+        >>> hist = History('elevation')
         >>> hist.creator
         'helena'
         >>> hist.src1
-        'raster elevation file elev_ned10m'
+        ''
         >>> hist.src2
         ''
         >>> hist.keyword
-        'generated by r.slope.aspect'
+        'generated by r.proj'
         >>> hist.date
-        datetime.datetime(2006, 11, 7, 1, 11, 23)
+        datetime.datetime(2006, 11, 7, 1, 9, 51)
         >>> hist.mapset
         'PERMANENT'
         >>> hist.maptype
         'raster'
         >>> hist.title
-        'asp_ned10m'
+        'elev_ned10m'
 
     ..
     """
-    def __init__(self):
-        self.hist = libraster.History()
+    def __init__(self, name=''):
+        self.c_hist = ctypes.pointer(libraster.History())
         #                'Tue Nov  7 01:11:23 2006'
         self.date_fmt = '%a %b  %d %H:%M:%S %Y'
+        if name:
+            self.read(name)
 
     def __del__(self):
         """Rast_free_history"""
@@ -49,11 +50,11 @@
     #----------------------------------------------------------------------
     #libraster.HIST_CREATOR
     def _get_creator(self):
-        return libraster.Rast_get_history(ctypes.byref(self.hist),
+        return libraster.Rast_get_history(self.c_hist,
                                           libraster.HIST_CREATOR)
 
     def _set_creator(self, creator):
-        return libraster.Rast_set_history(ctypes.byref(self.hist),
+        return libraster.Rast_set_history(self.c_hist,
                                           libraster.HIST_CREATOR,
                                           ctypes.c_char_p(creator))
 
@@ -62,11 +63,11 @@
     #----------------------------------------------------------------------
     #libraster.HIST_DATSRC_1
     def _get_src1(self):
-        return libraster.Rast_get_history(ctypes.byref(self.hist),
+        return libraster.Rast_get_history(self.c_hist,
                                           libraster.HIST_DATSRC_1)
 
     def _set_src1(self, src1):
-        return libraster.Rast_set_history(ctypes.byref(self.hist),
+        return libraster.Rast_set_history(self.c_hist,
                                           libraster.HIST_DATSRC_1,
                                           ctypes.c_char_p(src1))
 
@@ -75,11 +76,11 @@
     #----------------------------------------------------------------------
     #libraster.HIST_DATSRC_2
     def _get_src2(self):
-        return libraster.Rast_get_history(ctypes.byref(self.hist),
+        return libraster.Rast_get_history(self.c_hist,
                                           libraster.HIST_DATSRC_2)
 
     def _set_src2(self, src2):
-        return libraster.Rast_set_history(ctypes.byref(self.hist),
+        return libraster.Rast_set_history(self.c_hist,
                                           libraster.HIST_DATSRC_2,
                                           ctypes.c_char_p(src2))
 
@@ -88,11 +89,11 @@
     #----------------------------------------------------------------------
     #libraster.HIST_KEYWORD
     def _get_keyword(self):
-        return libraster.Rast_get_history(ctypes.byref(self.hist),
+        return libraster.Rast_get_history(self.c_hist,
                                           libraster.HIST_KEYWRD)
 
     def _set_keyword(self, keyword):
-        return libraster.Rast_set_history(ctypes.byref(self.hist),
+        return libraster.Rast_set_history(self.c_hist,
                                           libraster.HIST_KEYWRD,
                                           ctypes.c_char_p(keyword))
 
@@ -101,13 +102,13 @@
     #----------------------------------------------------------------------
     #libraster.HIST_MAPID
     def _get_date(self):
-        date_str = libraster.Rast_get_history(ctypes.byref(self.hist),
+        date_str = libraster.Rast_get_history(self.c_hist,
                                               libraster.HIST_MAPID)
         return datetime.datetime.strptime(date_str, self.date_fmt)
 
     def _set_date(self, datetimeobj):
         date_str = datetimeobj.strftime(self.date_fmt)
-        return libraster.Rast_set_history(ctypes.byref(self.hist),
+        return libraster.Rast_set_history(self.c_hist,
                                           libraster.HIST_MAPID,
                                           ctypes.c_char_p(date_str))
 
@@ -116,11 +117,11 @@
     #----------------------------------------------------------------------
     #libraster.HIST_MAPSET
     def _get_mapset(self):
-        return libraster.Rast_get_history(ctypes.byref(self.hist),
+        return libraster.Rast_get_history(self.c_hist,
                                           libraster.HIST_MAPSET)
 
     def _set_mapset(self, mapset):
-        return libraster.Rast_set_history(ctypes.byref(self.hist),
+        return libraster.Rast_set_history(self.c_hist,
                                           libraster.HIST_MAPSET,
                                           ctypes.c_char_p(mapset))
 
@@ -129,11 +130,11 @@
     #----------------------------------------------------------------------
     #libraster.HIST_MAPTYPE
     def _get_maptype(self):
-        return libraster.Rast_get_history(ctypes.byref(self.hist),
+        return libraster.Rast_get_history(self.c_hist,
                                           libraster.HIST_MAPTYPE)
 
     def _set_maptype(self, maptype):
-        return libraster.Rast_set_history(ctypes.byref(self.hist),
+        return libraster.Rast_set_history(self.c_hist,
                                           libraster.HIST_MAPTYPE,
                                           ctypes.c_char_p(maptype))
 
@@ -145,11 +146,11 @@
     # Never used in any raster modules
     #
     #    def _get_num_fields(self):
-    #        return libraster.Rast_get_history(ctypes.byref(self.hist),
+    #        return libraster.Rast_get_history(self.c_hist,
     #                                          libraster.HIST_NUM_FIELDS)
     #
     #    def _set_num_fields(self, num_fields):
-    #        return libraster.Rast_set_history(ctypes.byref(self.hist),
+    #        return libraster.Rast_set_history(self.c_hist,
     #                                          libraster.HIST_NUM_FIELDS,
     #                                          ctypes.c_char_p(num_fields))
     #
@@ -157,11 +158,11 @@
     #----------------------------------------------------------------------
     #libraster.HIST_TITLE
     def _get_title(self):
-        return libraster.Rast_get_history(ctypes.byref(self.hist),
+        return libraster.Rast_get_history(self.c_hist,
                                           libraster.HIST_TITLE)
 
     def _set_title(self, title):
-        return libraster.Rast_set_history(ctypes.byref(self.hist),
+        return libraster.Rast_set_history(self.c_hist,
                                           libraster.HIST_TITLE,
                                           ctypes.c_char_p(title))
 
@@ -169,37 +170,37 @@
 
     def append(self, obj):
         """Rast_append_history"""
-        libraster.Rast_append_history(ctypes.byref(self.hist),
+        libraster.Rast_append_history(self.c_hist,
                                       ctypes.c_char_p(str(obj)))
 
     def appent_fmt(self, fmt, *args):
         """Rast_append_format_history"""
-        libraster.Rast_append_format_history(ctypes.byref(self.hist),
+        libraster.Rast_append_format_history(self.c_hist,
                                              ctypes.c_char_p(fmt),
                                              *args)
 
     def clear(self):
         """Rast_clear_history"""
-        libraster.Rast_clear_history(ctypes.byref(self.hist))
+        libraster.Rast_clear_history(self.c_hist)
 
     def command(self):
         """Rast_command_history"""
-        libraster.Rast_command_history(ctypes.byref(self.hist))
+        libraster.Rast_command_history(self.c_hist)
 
     def format(self, field, fmt, *args):
         """Rast_format_history"""
-        libraster.Rast_format_history(ctypes.byref(self.hist),
+        libraster.Rast_format_history(self.c_hist,
                                       ctypes.c_int(field),
                                       ctypes.c_char_p(fmt),
                                       *args)
 
     def length(self):
         """Rast_history_length"""
-        libraster.Rast_history_length(ctypes.byref(self.hist))
+        libraster.Rast_history_length(self.c_hist)
 
     def line(self, line):
         """Rast_history_line"""
-        libraster.Rast_history_line(ctypes.byref(self.hist),
+        libraster.Rast_history_line(self.c_hist,
                                     ctypes.c_int(line))
 
     def read(self, name):
@@ -210,27 +211,27 @@
             >>> import ctypes
             >>> import grass.lib.raster as libraster
             >>> hist = libraster.History()
-            >>> libraster.Rast_read_history(ctypes.c_char_p('aspect'),
+            >>> libraster.Rast_read_history(ctypes.c_char_p('elevation'),
             ...                             ctypes.c_char_p(''),
             ...                             ctypes.byref(hist))
             0
             >>> libraster.Rast_get_history(ctypes.byref(hist),
             ...                            libraster.HIST_MAPID)
-            'Tue Nov  7 01:11:23 2006'
+            'Tue Nov  7 01:09:51 2006'
 
         ..
         """
         libraster.Rast_read_history(ctypes.c_char_p(name),
                                     ctypes.c_char_p(''),
-                                    ctypes.byref(self.hist))
+                                    self.c_hist)
 
     def write(self, name):
         """Rast_write_history"""
         libraster.Rast_write_history(ctypes.c_char_p(name),
-                                     ctypes.byref(self.hist))
+                                     self.c_hist)
 
     def short(self, name, maptype,):
         """Rast_short_history"""
         libraster.Rast_short_history(ctypes.c_char_p(name),
                                      ctypes.c_char_p(maptype),
-                                     ctypes.byref(self.hist))
+                                     self.c_hist)

Modified: grass/trunk/lib/python/pygrass/raster/rowio.py
===================================================================
--- grass/trunk/lib/python/pygrass/raster/rowio.py	2013-02-05 08:19:35 UTC (rev 54913)
+++ grass/trunk/lib/python/pygrass/raster/rowio.py	2013-02-05 08:19:46 UTC (rev 54914)
@@ -45,7 +45,7 @@
 class RowIO(object):
 
     def __init__(self):
-        self.crowio = librowio.ROWIO()
+        self.c_rowio = librowio.ROWIO()
         self.fd = None
         self.rows = None
         self.cols = None
@@ -58,7 +58,7 @@
         self.cols = cols
         self.mtype = mtype
         self.row_size = ctypes.sizeof(RTYPE[mtype]['grass def'] * cols)
-        if (librowio.Rowio_setup(ctypes.byref(self.crowio), self.fd,
+        if (librowio.Rowio_setup(ctypes.byref(self.c_rowio), self.fd,
                                  self.rows,
                                  self.row_size,
                                  get_row[self.mtype],
@@ -66,13 +66,13 @@
             raise GrassError('Fatal error, Rowio not setup correctly.')
 
     def release(self):
-        librowio.Rowio_release(ctypes.byref(self.crowio))
+        librowio.Rowio_release(ctypes.byref(self.c_rowio))
         self.fd = None
         self.rows = None
         self.cols = None
         self.mtype = None
 
     def get(self, row_index, buf):
-        rowio_buf = librowio.Rowio_get(ctypes.byref(self.crowio), row_index)
+        rowio_buf = librowio.Rowio_get(ctypes.byref(self.c_rowio), row_index)
         ctypes.memmove(buf.p, rowio_buf, self.row_size)
         return buf

Modified: grass/trunk/lib/python/pygrass/raster/segment.py
===================================================================
--- grass/trunk/lib/python/pygrass/raster/segment.py	2013-02-05 08:19:35 UTC (rev 54913)
+++ grass/trunk/lib/python/pygrass/raster/segment.py	2013-02-05 08:19:46 UTC (rev 54914)
@@ -16,7 +16,7 @@
         self.srows = srows
         self.scols = scols
         self.maxmem = maxmem
-        self.cseg = libseg.SEGMENT()
+        self.c_seg = ctypes.pointer(libseg.SEGMENT())
 
     def rows(self):
         return libraster.Rast_window_rows()
@@ -48,7 +48,7 @@
         size = ctypes.sizeof(RTYPE[mapobj.mtype]['ctypes'])
         file_name = libgis.G_tempfile()
         #import pdb; pdb.set_trace()
-        libseg.segment_open(ctypes.byref(self.cseg), file_name,
+        libseg.segment_open(self.c_seg, file_name,
                             self.rows(), self.cols(),
                             self.srows, self.scols,
                             size,
@@ -78,29 +78,29 @@
         if file_name == '':
             file_name = mapobj.temp_file.name
         mapobj.temp_file = open(file_name, 'w')
-        libseg.segment_init(ctypes.byref(self.cseg), mapobj.temp_file.fileno(),
+        libseg.segment_init(self.c_seg, mapobj.temp_file.fileno(),
                             self.segments_in_mem)
 
     def get_row(self, row_index, buf):
         """Return the row using, the `segment` method"""
-        libseg.segment_get_row(ctypes.byref(self.cseg), buf.p, row_index)
+        libseg.segment_get_row(self.c_seg, buf.p, row_index)
         return buf
 
     def put_row(self, row_index, buf):
         """Write the row using the `segment` method"""
-        libseg.segment_put_row(ctypes.byref(self.cseg), buf.p, row_index)
+        libseg.segment_put_row(self.c_seg, buf.p, row_index)
 
     def get(self, row_index, col_index):
         """Return the value of the map
         """
-        libseg.segment_get(ctypes.byref(self.cseg),
+        libseg.segment_get(self.c_seg,
                            ctypes.byref(self.val), row_index, col_index)
         return self.val.value
 
     def put(self, row_index, col_index):
         """Write the value to the map
         """
-        libseg.segment_put(ctypes.byref(self.cseg),
+        libseg.segment_put(self.c_seg,
                            ctypes.byref(self.val), row_index, col_index)
 
     def get_seg_number(self, row_index, col_index):
@@ -115,15 +115,15 @@
         the segment file seg. Must be called after the final segment_put()
         to force all pending updates to disk. Must also be called before the
         first call to segment_get_row."""
-        libseg.segment_flush(ctypes.byref(self.cseg))
+        libseg.segment_flush(self.c_seg)
 
     def close(self):
         """Free memory allocated to segment and delete temp file.  """
-        libseg.segment_close(ctypes.byref(self.cseg))
+        libseg.segment_close(self.c_seg)
 
     def release(self):
         """Free memory allocated to segment.
         Releases the allocated memory associated with the segment file seg.
         Note: Does not close the file. Does not flush the data which may be
         pending from previous segment_put() calls."""
-        libseg.segment_release(ctypes.byref(self.cseg))
+        libseg.segment_release(self.c_seg)



More information about the grass-commit mailing list