Beispiel #1
0
 def _get_range(self):
     if self.mtype == "CELL":
         self.c_range = ctypes.pointer(libraster.Range())
         libraster.Rast_read_range(self.name, self.mapset, self.c_range)
     else:
         self.c_range = ctypes.pointer(libraster.FPRange())
         libraster.Rast_read_fp_range(self.name, self.mapset, self.c_range)
 def _get_range(self):
     if self.mtype == 'CELL':
         maprange = libraster.Range()
         libraster.Rast_read_range(self.name, self.mapset,
                                   ctypes.byref(maprange))
         self._min = libgis.CELL()
         self._max = libgis.CELL()
     else:
         maprange = libraster.FPRange()
         libraster.Rast_read_fp_range(self.name, self.mapset,
                                      ctypes.byref(maprange))
         self._min = libgis.DCELL()
         self._max = libgis.DCELL()
     libraster.Rast_get_fp_range_min_max(ctypes.byref(maprange),
                                         ctypes.byref(self._min),
                                         ctypes.byref(self._max))
     return self._min.value, self._max.value
Beispiel #3
0
def _read_raster_info(name, mapset):
    """Read the raster map info from the file system and store the content
       into a dictionary

       This method uses the ctypes interface to the gis and raster libraries
       to read the map metadata information

       :param name: The name of the map
       :param mapset: The mapset of the map
       :returns: The key value pairs of the map specific metadata, or None in
                 case of an error
    """

    kvp = {}

    if not libgis.G_find_raster(name, mapset):
        return None

    # Read the region information
    region = libgis.Cell_head()
    libraster.Rast_get_cellhd(name, mapset, byref(region))

    kvp["north"] = region.north
    kvp["south"] = region.south
    kvp["east"] = region.east
    kvp["west"] = region.west
    kvp["nsres"] = region.ns_res
    kvp["ewres"] = region.ew_res
    kvp["rows"] = region.cols
    kvp["cols"] = region.rows

    maptype = libraster.Rast_map_type(name, mapset)

    if maptype == libraster.DCELL_TYPE:
        kvp["datatype"] = "DCELL"
    elif maptype == libraster.FCELL_TYPE:
        kvp["datatype"] = "FCELL"
    elif maptype == libraster.CELL_TYPE:
        kvp["datatype"] = "CELL"

    # Read range
    if libraster.Rast_map_is_fp(name, mapset):
        range = libraster.FPRange()
        libraster.Rast_init_fp_range(byref(range))
        ret = libraster.Rast_read_fp_range(name, mapset, byref(range))
        if ret < 0:
            logging.error(_("Unable to read range file"))
            return None
        if ret == 2:
            kvp["min"] = None
            kvp["max"] = None
        else:
            min = libgis.DCELL()
            max = libgis.DCELL()
            libraster.Rast_get_fp_range_min_max(byref(range), byref(min),
                                                byref(max))
            kvp["min"] = min.value
            kvp["max"] = max.value
    else:
        range = libraster.Range()
        libraster.Rast_init_range(byref(range))
        ret = libraster.Rast_read_range(name, mapset, byref(range))
        if ret < 0:
            logging.error(_("Unable to read range file"))
            return None
        if ret == 2:
            kvp["min"] = None
            kvp["max"] = None
        else:
            min = libgis.CELL()
            max = libgis.CELL()
            libraster.Rast_get_range_min_max(byref(range), byref(min),
                                             byref(max))
            kvp["min"] = min.value
            kvp["max"] = max.value

    return kvp