예제 #1
0
    def _getInvalidParams(self, params):
        """Check of analysis input data for invalid values (Parameters tab)"""
        # dict of invalid values {key from self.itemData (comboboxes from
        # Parameters tab) : invalid value}
        invParams = []

        # check vector map
        if params["input"]:
            mapName, mapSet = params["input"].split("@")
            if mapSet in grass.list_grouped("vector"):
                vectMaps = grass.list_grouped("vector")[mapSet]

        if not params["input"] or mapName not in vectMaps:
            invParams = list(params.keys())[:]
            return invParams

        # check arc/node layer
        layers = utils.GetVectorNumberOfLayers(params["input"])

        for layer in [
                "arc_layer", "node_layer", "turn_layer", "turn_cat_layer"
        ]:
            if not layers or params[layer] not in layers:
                invParams.append(layer)

        dbInfo = VectorDBInfo(params["input"])

        try:
            table = dbInfo.GetTable(int(params["arc_layer"]))
            columnchoices = dbInfo.GetTableDesc(table)
        except (KeyError, ValueError):
            table = None

        # check costs columns
        for col in ["arc_column", "arc_backward_column", "node_column"]:

            if col == "node_column":
                try:
                    table = dbInfo.GetTable(int(params["node_layer"]))
                    columnchoices = dbInfo.GetTableDesc(table)
                except (KeyError, ValueError):
                    table = None

            if not table or not params[col] in list(columnchoices.keys()):
                invParams.append(col)
                continue

            if columnchoices[params[col]]["type"] not in [
                    "integer",
                    "double precision",
            ]:
                invParams.append(col)
                continue

        return invParams
예제 #2
0
파일: vnet_data.py 프로젝트: rkrug/grass-ci
    def _getInvalidParams(self, params):
        """Check of analysis input data for invalid values (Parameters tab)"""
        # dict of invalid values {key from self.itemData (comboboxes from
        # Parameters tab) : invalid value}
        invParams = []

        # check vector map
        if params["input"]:
            mapName, mapSet = params["input"].split("@")
            if mapSet in grass.list_grouped('vector'):
                vectMaps = grass.list_grouped('vector')[mapSet]

        if not params["input"] or mapName not in vectMaps:
            invParams = params.keys()[:]
            return invParams

        # check arc/node layer
        layers = utils.GetVectorNumberOfLayers(params["input"])

        for l in ['arc_layer', 'node_layer', 'turn_layer', 'turn_cat_layer']:
            if not layers or params[l] not in layers:
                invParams.append(l)

        dbInfo = VectorDBInfo(params["input"])

        try:
            table = dbInfo.GetTable(int(params["arc_layer"]))
            columnchoices = dbInfo.GetTableDesc(table)
        except (KeyError, ValueError):
            table = None

        # check costs columns
        for col in ["arc_column", "arc_backward_column", "node_column"]:

            if col == "node_column":
                try:
                    table = dbInfo.GetTable(int(params["node_layer"]))
                    columnchoices = dbInfo.GetTableDesc(table)
                except (KeyError, ValueError):
                    table = None

            if not table or not params[col] in columnchoices.keys():
                invParams.append(col)
                continue

            if columnchoices[
                    params[col]]['type'] not in [
                    'integer', 'double precision']:
                invParams.append(col)
                continue

        return invParams
예제 #3
0
파일: v.build.all.py 프로젝트: caomw/grass
def main():
    env = grass.gisenv()
    mapset = env['MAPSET']
    ret = 0

    vectors = grass.list_grouped('vect')[mapset]
    num_vectors = len(vectors)
    
    if grass.verbosity() < 2:
        quiet = True
    else:
        quiet = False
        
    i = 1
    for vect in vectors:
	map = "%s@%s" % (vect, mapset)
	grass.message(_("%s\nBuilding topology for vector map <%s> (%d of %d)...\n%s") % \
                          ('-' * 80, map, i, num_vectors, '-' * 80))
	grass.verbose(_("v.build map=%s") % map)
	if grass.run_command("v.build", map = map, quiet = quiet) != 0:
            grass.error(_("Building topology for vector map <%s> failed") % map)
	    ret = 1
        i += 1
    
    return ret
예제 #4
0
def main():
    env = grass.gisenv()
    mapset = env['MAPSET']
    ret = 0

    vectors = grass.list_grouped('vect')[mapset]
    num_vectors = len(vectors)

    if grass.verbosity() < 2:
        quiet = True
    else:
        quiet = False

    i = 1
    for vect in vectors:
        map = "%s@%s" % (vect, mapset)
        grass.message(
            _("%s\nBuilding topology for vector map <%s> (%d of %d)...\n%s") %
            ('-' * 80, map, i, num_vectors, '-' * 80))
        grass.verbose(_("v.build map=%s") % map)
        try:
            grass.run_command("v.build", map=map, quiet=quiet)
        except CalledModuleError:
            grass.error(
                _("Building topology for vector map <%s> failed") % map)
            ret = 1
        i += 1

    return ret
예제 #5
0
def main():
    env = grass.gisenv()
    mapset = env["MAPSET"]
    converted = 0
    ret = 0
    for vect in grass.list_grouped("oldvect")[mapset]:
        inmap = "%s@%s" % (vect, mapset)
        outmap = vect.replace(".", "_")
        try:
            grass.run_command("v.convert", input=inmap, output=outmap)
        except CalledModuleError:
            grass.warning(_("Error converting map <%s> to <%s>") % (inmap, outmap))
            ret = 1
        else:
            converted += 1

        if converted < 1:
            grass.warning(
                _(
                    "No vector maps converted as no old vector maps present in current mapset."
                )
            )
        else:
            grass.message(
                _("Total %u vector maps in current mapset converted.") % converted
            )
            grass.message(
                _("Please verify new vector map(s) before deleting old vector map(s).")
            )

        sys.exit(ret)
예제 #6
0
def main():
    env = grass.gisenv()
    mapset = env["MAPSET"]
    converted = 0
    ret = 0
    for vect in grass.list_grouped("oldvect")[mapset]:
        inmap = "%s@%s" % (vect, mapset)
        outmap = vect.replace(".", "_")
        if grass.run_command("v.convert", input=inmap, output=outmap) == 0:
            converted += 1
        else:
            grass.warning(_("Error converting map <%s> to <%s>") % (inmap, outmap))
            ret = 1

        if converted < 1:
            grass.warning(_("No vector maps converted as no old vector maps present in current mapset."))
        else:
            grass.message(_("Total %u vector maps in current mapset converted.") % converted)
            grass.message(_("Please verify new vector map(s) before deleting old vector map(s)."))

        sys.exit(ret)
예제 #7
0
def main():
    env = grass.gisenv()
    mapset = env['MAPSET']
    converted = 0
    ret = 0
    for site in grass.list_grouped('sites')[mapset]:
	inmap = "%s@%s" % (site, mapset)
	outmap = site.replace(".", "_") + "_points"
	grass.message(_("Processing %s -> %s") % (inmap, outmap))
	if grass.run_command("v.in.sites", input = inmap, output = outmap) == 0:
	    converted += 1
	else:
	    grass.warning(_("Error converting map %s to %s") % (inmap, outmap))
	    ret = 1

	if converted < 1:
	    grass.warning(_("No sites maps converted as no old sites maps present in current mapset."))
	else:
	    grass.message(_("Total %u sites maps in current mapset converted to vector maps (original names extended by '_points')") % converted)
	    grass.message(_("Please verify new vector map(s) before deleting old sites map(s)."))

	sys.exit(ret)
예제 #8
0
def temp_maps_exist():
    maps = gcore.list_grouped('raster')[gcore.gisenv()['MAPSET']]
    return [x for x in TMP if x in maps]
예제 #9
0
def _get_horizon_maps():
    return gcore.list_grouped('rast',
                              pattern=TMP_NAME + "*")[gcore.gisenv()['MAPSET']]
예제 #10
0
def CreateNewRaster(
    parent, title=_("Create new vector map"), exceptMap=None, disableAdd=False
):
    """!Create new vector map layer

    @param cmd (prog, **kwargs)
    @param title window title
    @param exceptMap list of maps to be excepted
    @param disableAdd disable 'add layer' checkbox

    @return dialog instance
    @return None on error
    """
    vExternalOut = grass.parse_command("r.external.out", flags="p", delimiter=":")

    UsingGDAL = "Not using GDAL" not in vExternalOut

    if not UsingGDAL:
        showType = False
    else:
        showType = True

    dlg = NewRasterDialog(parent, title=title, disableAdd=disableAdd, showType=showType)

    if dlg.ShowModal() != wx.ID_OK:
        dlg.Destroy()
        return None

    outmap = dlg.GetName()
    # key    = dlg.GetKey()
    if outmap == exceptMap:
        GError(parent=parent, message=_("Unable to create raster map <%s>.") % outmap)
        dlg.Destroy()
        return None

    if outmap == "":  # should not happen
        dlg.Destroy()
        return None

    if not UsingGDAL:
        listOfRasters = grass.list_grouped("rast")[grass.gisenv()["MAPSET"]]
    else:
        listOfRasters = RunCommand(
            "r.external",
            quiet=True,
            parent=parent,
            read=True,
            flags="l",
            out=outmap,
            source=vExternalOut["directory"],
        ).splitlines()

    if (
        not UserSettings.Get(group="cmd", key="overwrite", subkey="enabled")
        and outmap in listOfRasters
    ):
        dlgOw = wx.MessageDialog(
            parent,
            message=_(
                "Raster map <%s> already exists "
                "in the current mapset. "
                "Do you want to overwrite it?"
            )
            % outmap,
            caption=_("Overwrite?"),
            style=wx.YES_NO | wx.YES_DEFAULT | wx.ICON_QUESTION,
        )
        if dlgOw.ShowModal() == wx.ID_YES:
            overwrite = True
        else:
            dlgOw.Destroy()
            dlg.Destroy()
            return None

    if UserSettings.Get(group="cmd", key="overwrite", subkey="enabled"):
        overwrite = True

    if UsingGDAL:
        # create link for OGR layers
        RunCommand(
            "r.external",
            overwrite=overwrite,
            parent=parent,
            directory=vExternalOut["directory"],
            layer=outmap,
        )

    # return fully qualified map name
    if "@" not in outmap:
        outmap += "@" + grass.gisenv()["MAPSET"]

    # if log:
    #    log.WriteLog(_("New raster map <%s> created") % outmap)
    return dlg
예제 #11
0
def CreateNewRaster(parent,
                    title=_('Create new vector map'),
                    exceptMap=None,
                    disableAdd=False):
    """!Create new vector map layer
    
    @param cmd (prog, **kwargs)
    @param title window title
    @param exceptMap list of maps to be excepted
    @param disableAdd disable 'add layer' checkbox
    
    @return dialog instance
    @return None on error
    """
    vExternalOut = grass.parse_command('r.external.out',
                                       flags='p',
                                       delimiter=':')

    UsingGDAL = vExternalOut.has_key('Not using GDAL') == False

    if not UsingGDAL:
        showType = False
    else:
        showType = True

    dlg = NewRasterDialog(parent,
                          title=title,
                          disableAdd=disableAdd,
                          showType=showType)

    if dlg.ShowModal() != wx.ID_OK:
        dlg.Destroy()
        return None

    outmap = dlg.GetName()
    #key    = dlg.GetKey()
    if outmap == exceptMap:
        GError(parent=parent,
               message=_("Unable to create raster map <%s>.") % outmap)
        dlg.Destroy()
        return None

    if outmap == '':  # should not happen
        dlg.Destroy()
        return None

    if not UsingGDAL:
        listOfRasters = grass.list_grouped('rast')[grass.gisenv()['MAPSET']]
    else:
        listOfRasters = RunCommand(
            'r.external',
            quiet=True,
            parent=parent,
            read=True,
            flags='l',
            out=outmap,
            source=vExternalOut['directory']).splitlines()

    if not UserSettings.Get(group = 'cmd', key = 'overwrite', subkey = 'enabled') and \
            outmap in listOfRasters:
        dlgOw = wx.MessageDialog(
            parent,
            message=_("Raster map <%s> already exists "
                      "in the current mapset. "
                      "Do you want to overwrite it?") % outmap,
            caption=_("Overwrite?"),
            style=wx.YES_NO | wx.YES_DEFAULT | wx.ICON_QUESTION)
        if dlgOw.ShowModal() == wx.ID_YES:
            overwrite = True
        else:
            dlgOw.Destroy()
            dlg.Destroy()
            return None

    if UserSettings.Get(group='cmd', key='overwrite', subkey='enabled'):
        overwrite = True

    if UsingGDAL:
        # create link for OGR layers
        RunCommand('r.external',
                   overwrite=overwrite,
                   parent=parent,
                   directory=vExternalOut['directory'],
                   layer=outmap)

    # return fully qualified map name
    if '@' not in outmap:
        outmap += '@' + grass.gisenv()['MAPSET']

    #if log:
    #    log.WriteLog(_("New raster map <%s> created") % outmap)
    return dlg
예제 #12
0
def _get_horizon_maps():
    return gcore.list_grouped("rast",
                              pattern=TMP_NAME + "*")[gcore.gisenv()["MAPSET"]]
예제 #13
0
def temp_maps_exist():
    maps = gcore.list_grouped("raster")[gcore.gisenv()["MAPSET"]]
    return [x for x in TMP if x in maps]