コード例 #1
0
def _map_exists(lock, conn, data):
    """Check if a map exists in the spatial database

       The value to be send via pipe is True in case the map exists and False
       if not.

       :param lock: A multiprocessing.Lock instance
       :param conn: A multiprocessing.Pipe instance used to send True or False
       :param data: The list of data entries [function_id, maptype, name, mapset]

    """
    maptype = data[1]
    name = data[2]
    mapset = data[3]
    check = False
    if maptype == RPCDefs.TYPE_RASTER:
        mapset = libgis.G_find_raster(name, mapset)
    elif maptype == RPCDefs.TYPE_VECTOR:
        mapset = libgis.G_find_vector(name, mapset)
    elif maptype == RPCDefs.TYPE_RASTER3D:
        mapset = libgis.G_find_raster3d(name, mapset)

    if mapset:
        check = True

    conn.send(check)
コード例 #2
0
ファイル: __init__.py プロジェクト: cz172638/pygrass
 def __new__(cls,
             name,
             mapset="",
             mtype='CELL',
             mode='r+',
             overwrite=False):
     reg = Region()
     shape = (reg.rows, reg.cols)
     mapset = libgis.G_find_raster(name, mapset)
     gtype = None
     if mapset:
         # map exist, set the map type
         gtype = libraster.Rast_map_type(name, mapset)
         mtype = RTYPE_STR[gtype]
     filename = grasscore.tempfile()
     obj = np.memmap.__new__(cls,
                             filename=filename,
                             dtype=RTYPE[mtype]['numpy'],
                             mode=mode,
                             shape=shape)
     obj.mtype = mtype.upper()
     obj.gtype = gtype if gtype else RTYPE[mtype]['grass type']
     obj._rows = reg.rows
     obj._cols = reg.cols
     obj.filename = filename
     obj._name = name
     obj.mapset = mapset
     obj.reg = reg
     obj.overwrite = overwrite
     return obj
コード例 #3
0
ファイル: abstract.py プロジェクト: pesekon2/grass
    def __init__(self, name, mapset="", *aopen, **kwopen):
        """The constructor need at least the name of the map
        *optional* field is the `mapset`.

        >>> ele = RasterAbstractBase(test_raster_name)
        >>> ele.name
        'abstract_test_map'
        >>> ele.exist()
        True

        ..
        """
        self.mapset = mapset
        if not mapset:
            # note that @must_be_in_current_mapset requires mapset to be set
            mapset = libgis.G_find_raster(name, mapset)
            if mapset is not None:
                self.mapset = utils.decode(mapset)

        self._name = name
        # Private attribute `_fd` that return the file descriptor of the map
        self._fd = None
        # Private attribute `_rows` that return the number of rows
        # in active window, When the class is instanced is empty and it is set
        # when you open the file, using Rast_window_rows()
        self._rows = None
        # Private attribute `_cols` that return the number of rows
        # in active window, When the class is instanced is empty and it is set
        # when you open the file, using Rast_window_cols()
        self._cols = None
        # self.region = Region()
        self.hist = History(self.name, self.mapset)
        self.cats = Category(self.name, self.mapset)
        self.info = Info(self.name, self.mapset)
        self._aopen = aopen
        self._kwopen = kwopen
        self._mtype = "CELL"
        self._mode = "r"
        self._overwrite = False
コード例 #4
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