Browse Source

Change the C struct attribute name to be consistent with the other classes

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@54914 15284696-431f-4ddb-bdfa-cd5b030d7da7
Pietro Zambelli 12 years ago
parent
commit
584e86bd8e

+ 41 - 40
lib/python/pygrass/raster/history.py

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

+ 4 - 4
lib/python/pygrass/raster/rowio.py

@@ -45,7 +45,7 @@ get_row = {
 class RowIO(object):
 class RowIO(object):
 
 
     def __init__(self):
     def __init__(self):
-        self.crowio = librowio.ROWIO()
+        self.c_rowio = librowio.ROWIO()
         self.fd = None
         self.fd = None
         self.rows = None
         self.rows = None
         self.cols = None
         self.cols = None
@@ -58,7 +58,7 @@ class RowIO(object):
         self.cols = cols
         self.cols = cols
         self.mtype = mtype
         self.mtype = mtype
         self.row_size = ctypes.sizeof(RTYPE[mtype]['grass def'] * cols)
         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.rows,
                                  self.row_size,
                                  self.row_size,
                                  get_row[self.mtype],
                                  get_row[self.mtype],
@@ -66,13 +66,13 @@ class RowIO(object):
             raise GrassError('Fatal error, Rowio not setup correctly.')
             raise GrassError('Fatal error, Rowio not setup correctly.')
 
 
     def release(self):
     def release(self):
-        librowio.Rowio_release(ctypes.byref(self.crowio))
+        librowio.Rowio_release(ctypes.byref(self.c_rowio))
         self.fd = None
         self.fd = None
         self.rows = None
         self.rows = None
         self.cols = None
         self.cols = None
         self.mtype = None
         self.mtype = None
 
 
     def get(self, row_index, buf):
     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)
         ctypes.memmove(buf.p, rowio_buf, self.row_size)
         return buf
         return buf

+ 10 - 10
lib/python/pygrass/raster/segment.py

@@ -16,7 +16,7 @@ class Segment(object):
         self.srows = srows
         self.srows = srows
         self.scols = scols
         self.scols = scols
         self.maxmem = maxmem
         self.maxmem = maxmem
-        self.cseg = libseg.SEGMENT()
+        self.c_seg = ctypes.pointer(libseg.SEGMENT())
 
 
     def rows(self):
     def rows(self):
         return libraster.Rast_window_rows()
         return libraster.Rast_window_rows()
@@ -48,7 +48,7 @@ class Segment(object):
         size = ctypes.sizeof(RTYPE[mapobj.mtype]['ctypes'])
         size = ctypes.sizeof(RTYPE[mapobj.mtype]['ctypes'])
         file_name = libgis.G_tempfile()
         file_name = libgis.G_tempfile()
         #import pdb; pdb.set_trace()
         #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.rows(), self.cols(),
                             self.srows, self.scols,
                             self.srows, self.scols,
                             size,
                             size,
@@ -78,29 +78,29 @@ class Segment(object):
         if file_name == '':
         if file_name == '':
             file_name = mapobj.temp_file.name
             file_name = mapobj.temp_file.name
         mapobj.temp_file = open(file_name, 'w')
         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)
                             self.segments_in_mem)
 
 
     def get_row(self, row_index, buf):
     def get_row(self, row_index, buf):
         """Return the row using, the `segment` method"""
         """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
         return buf
 
 
     def put_row(self, row_index, buf):
     def put_row(self, row_index, buf):
         """Write the row using the `segment` method"""
         """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):
     def get(self, row_index, col_index):
         """Return the value of the map
         """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)
                            ctypes.byref(self.val), row_index, col_index)
         return self.val.value
         return self.val.value
 
 
     def put(self, row_index, col_index):
     def put(self, row_index, col_index):
         """Write the value to the map
         """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)
                            ctypes.byref(self.val), row_index, col_index)
 
 
     def get_seg_number(self, row_index, col_index):
     def get_seg_number(self, row_index, col_index):
@@ -115,15 +115,15 @@ class Segment(object):
         the segment file seg. Must be called after the final segment_put()
         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
         to force all pending updates to disk. Must also be called before the
         first call to segment_get_row."""
         first call to segment_get_row."""
-        libseg.segment_flush(ctypes.byref(self.cseg))
+        libseg.segment_flush(self.c_seg)
 
 
     def close(self):
     def close(self):
         """Free memory allocated to segment and delete temp file.  """
         """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):
     def release(self):
         """Free memory allocated to segment.
         """Free memory allocated to segment.
         Releases the allocated memory associated with the segment file seg.
         Releases the allocated memory associated with the segment file seg.
         Note: Does not close the file. Does not flush the data which may be
         Note: Does not close the file. Does not flush the data which may be
         pending from previous segment_put() calls."""
         pending from previous segment_put() calls."""
-        libseg.segment_release(ctypes.byref(self.cseg))
+        libseg.segment_release(self.c_seg)