def __init__(self): self.ppath = os.path.dirname(os.path.abspath(__file__)) self.confDirPath = os.path.join(os.getenv('GRASS_ADDON_BASE'), 'etc', 'wx.metadata', 'config') path = os.path.join('wx.metadata', 'config') self.connResources = get_lib_path(modname=path, libname='connections_resources.xml') if self.connResources is None: grass.fatal("Fatal error: library < %s > not found" % path) else: self.connResources = os.path.join(self.connResources, 'connections_resources.xml') self.configureLibPath = get_lib_path(modname=path, libname='init_md.txt') if self.configureLibPath is None: grass.fatal("Fatal error: library < %s > not found" % path) path = os.path.join('wx.metadata', 'profiles') self.profilesLibPath = get_lib_path(modname=path, libname='basicProfile.xml') if self.profilesLibPath is None: grass.fatal("Fatal error: library < %s > not found" % path) self.lib_path = os.path.normpath(self.configureLibPath + os.sep + os.pardir)
def __init__(self): self.ppath = os.path.dirname(os.path.abspath(__file__)) self.confDirPath = os.path.join( os.getenv("GRASS_ADDON_BASE"), "etc", "wx.metadata", "config", ) path = os.path.join("wx.metadata", "config") self.connResources = get_lib_path( modname=path, libname="connections_resources.xml", ) if self.connResources is None: grass.fatal("Fatal error: library < {} > not found".format(path), ) else: self.connResources = os.path.join( self.connResources, "connections_resources.xml", ) self.configureLibPath = get_lib_path( modname=path, libname="init_md.txt", ) if self.configureLibPath is None: grass.fatal("Fatal error: library < {} > not found".format(path), ) path = os.path.join("wx.metadata", "profiles") self.profilesLibPath = get_lib_path( modname=path, libname="basicProfile.xml", ) if self.profilesLibPath is None: grass.fatal("Fatal error: library < %s > not found" % path) self.lib_path = os.path.normpath( os.path.join(self.configureLibPath, os.pardir), )
import os import sys import atexit # check if within a GRASS session? if "GISBASE" not in os.environ: print("You must be in GRASS GIS to run this program.") sys.exit(1) # TODO: avoid PyGRASS altogether import grass.script as grass #from grass.pygrass.raster.abstract import Info from grass.pygrass.utils import get_lib_path # add "etc" directory to $PATH path = get_lib_path("i.fusion.hpf", "") if path is None: raise ImportError("Not able to find the path %s directory." % path) sys.path.append(path) # import modules from "etc" from high_pass_filter import get_high_pass_filter, get_modulator_factor, get_modulator_factor2 def run(cmd, **kwargs): """Pass arbitrary number of key-word arguments to grass commands and the "quiet" flag by default.""" grass.run_command(cmd, quiet=True, **kwargs) def cleanup():
#%option G_OPT_F_OUTPUT #% key: backup #% description: Create backup file #% required: no #%end # ###################### import os import sys #sys.path.insert(1, os.path.join(os.path.dirname(sys.path[0]), 'etc', 'v.road')) import grass.script as grass from grass.pygrass.utils import get_lib_path path = get_lib_path(modname='v.civil') if path is None: grass.fatal("Not able to find the civil library directory.") sys.path.append(path) import road_road as Road import road_crosstools as Tools2 import road_topotools as Topotools # ============================================= # Main # ============================================= def main(): """Manage v.road
def createPDF(self, save=True): self.story = self._parseMDOWS() self.doc = Pdf('Metadata file', 'GRASS GIS') self.doc.set_theme(MyTheme) logo_path = get_lib_path("wx.metadata", 'config') logo_path = os.path.join(logo_path, 'logo_variant_bg.png') self.doc.add_image(logo_path, 57, 73, LEFT) if self.map is None: self.doc.add_header(self.filename, T1) else: self.doc.add_header(self.map, T1) self.doc.add_header(self.filename, T2) if self.type == 'vector': name = 'vector map' self.doc.add_header(name, T2) else: name = 'raster map' self.doc.add_header(name, T2) self.doc.add_header("%s metadata profile" % self.profile, T3) self.doc.add_spacer(2) if map is not None: mapPic = self.getMapPic() self.doc.add_image(mapPic, 200, 200, CENTER) self.textFactory(title="Keywords", name='Keywords', tag='identification', multiple=-1) self.textFactory(title="Abstract", name='Abstract', tag='identification') # #################### metadata ################################# self.doc.add_spacer(25) self.doc.add_header("Metadata on metadata", H1) head = ['Organization name', 'E-mail', 'Role'] # this is the header row self.tableFactory("Metadata point of contact", head, 'contact') self.textFactory(title="Metadata date", name='Datestamp', tag='datestamp') self.textFactory(title="Metadata language", name='Language', tag='languagecode') # #################### identification ################################# self.doc.add(PageBreak()) self.doc.add_header("Identification", H1) self.textFactory(title="Restource title", name='Title', tag='identification') self.textFactory(title="Identifier", name='Identifier', tag='identifier') # self.textFactory(title="Resource locator", name='Identifier',tag='identifier')#TODO linkage is missing self.tableFactory("Resource language", ['Language'], 'identification') # head = ['Organization name', 'E-mail','Role'] #.tableFactory("identifier",head,'contact') ##################### Keywords ################################## TODO ##################### Geographic ################################## self.doc.add_spacer(25) self.doc.add_header('Geographic Location', H1) maxy = float(self.findItem(self.story['identification'], 'maxy', 0)) maxx = float(self.findItem(self.story['identification'], 'maxx', 0)) miny = float(self.findItem(self.story['identification'], 'miny', 0)) minx = float(self.findItem(self.story['identification'], 'minx', 0)) head = [[ 'North Bound Latitude', 'East Bound Longitude', 'South Bound Latitude', 'West Bound Longitude' ]] head.append([maxx, maxy, minx, miny]) self.doc.add_table(head, self.TABLE_WIDTH) self.doc.add_spacer(25) mapPath = MapBBFactory([[maxx, minx], [maxy, miny]], ) ##################### Add google picture(extend) ################################## try: gmap = Image(mapPath.link1, 200, 200) gmap1 = Image(mapPath.link2, 200, 200) self.doc.add(Table([[gmap1, gmap]])) self.doc.add(PageBreak()) except: GWarning( "Cannot download metadata picture of extend provided by Google API. Please check internet connection." ) ##################### Temporal ################################## self.doc.add_spacer(25) self.doc.add_header('Temporal reference', H1) self.textFactory(title="Temporal extend start", name='Temporal extend start', tag='identification') self.textFactory(title="Temporal extend end", name='Temporal extend end', tag='identification') ##################### Quality ################################## self.doc.add_spacer(25) self.doc.add_header('Quality a validity', H1) self.textFactory(title="Lineage", name='Lineage', tag='dataquality') #self.textFactory(title="Temporal extend start", name='Temporal extend start',tag='identification') # TODO md.identification.denominators ######################Conformity ######################## self.doc.add_spacer(25) self.doc.add_header('Conformity', H1) head = ['Conformance date', "Conformance date type", 'Specification'] self.tableFactory("Conformity", head, 'dataquality') ###################### Constraints ######################## self.doc.add_spacer(25) self.doc.add_header('Constraints', H1) self.tableFactory("Condition applying to use", ["Use limitation"], 'identification') self.tableFactory("Condition applying to access", ["Access constraints"], 'identification') self.tableFactory("Limitation on public access", ["Other constraintrs"], 'identification') ###################### Responsible party ######################## self.doc.add_spacer(25) self.doc.add_header('Responsible party', H1) header = ["Organization name", "E-mail", "Role"] self.tableFactory( "Organisations responsible for the establishment, management, maintenance and distribution of spatial data sets and services", header, 'identification') text = self.doc.render() # http://www.reportlab.com/docs/reportlab-userguide.pdf if save and self.pdf_file is not None: path = self.savePDF(text) return path return text
try: from owslib.sos import SensorObservationService from grass.script import parser, run_command, overwrite from grass.script import core as grass from grass.script import vector from grass.pygrass.vector import VectorTopo from grass.pygrass.vector.geometry import Point from grass.pygrass.vector.table import Link from grass.pygrass.utils import get_lib_path import grass.temporal as tgis except ImportError as e: sys.stderr.write('Error importing internal libs. ' 'Did you run the script from GRASS GIS?\n') raise (e) path = get_lib_path(modname='sos', libname='libsos') if path is None: grass.script.fatal('Not able to find the sos library directory.') sys.path.append(path) from soslib import xml2geojson, json2geojson from soslib import handle_not_given_options def cleanup(): pass def main(): fl = str() for f, val in flags.iteritems():
# % required: no # % guisection: Temporal # %end import os import sys import glob import shutil import tempfile from datetime import datetime, timedelta import grass.script as grass from grass.pygrass.utils import get_lib_path from grass.exceptions import CalledModuleError path = get_lib_path(modname="i.modis", libname="libmodis") if path is None: grass.fatal("Not able to find the modis library directory.") sys.path.append(path) class grassParseModis: """Class to reproduce parseModis class when VRT is used for mosaic :param str filename: the name of MODIS hdf file """ def __init__(self, filename, date): self.hdfname = filename self.date = date def retRangeTime(self):
#% description: Full path to output file to use with t.register #% required: no #% guisection: Temporal #%end import os import sys import glob import shutil import tempfile from datetime import datetime, timedelta import grass.script as grass from grass.pygrass.utils import get_lib_path from grass.exceptions import CalledModuleError path = get_lib_path(modname='i.modis', libname='libmodis') if path is None: grass.fatal("Not able to find the modis library directory.") sys.path.append(path) class grassParseModis: """Class to reproduce parseModis class when VRT is used for mosaic :param str filename: the name of MODIS hdf file """ def __init__(self, filename, date): self.hdfname = filename self.date = date def retRangeTime(self):
import sys # i18N import gettext if "GISBASE" not in os.environ: print("You must be in GRASS GIS to run this program.") sys.exit(1) gettext.install("grasswxpy", os.path.join(os.getenv("GISBASE"), "locale")) sys.path.append(os.path.join(os.getenv("GISBASE"), "gui", "wxpython")) from grass.pygrass.utils import get_lib_path path = get_lib_path("v.krige", "") if path is None: raise ImportError(_("Not able to find the path %s directory.") % path) sys.path.append(path) # dependencies to be checked once, as they are quite time-consuming. cfr. grass.parser. # GRASS binding try: import grass.script as grass except ImportError: sys.exit(_("No GRASS-python library found")) # move other checks in functions, as R? # globals
#%end #%flag #% key: r #% description: Read from existing CSV files #%end #----------------------------------------------------- import sys import os from grass.script.core import parser from grass.pygrass.utils import get_lib_path, get_mapset_raster from grass.pygrass.vector import VectorTopo, Vector from grass.pygrass.vector.table import Link path = get_lib_path("v.stats", "") if path is None: raise ImportError("Not able to find the path %s directory." % path) sys.path.append(path) from vstats import get_shp_csv, get_zones, get_rst_csv from imp_csv import update_cols def main(opt, flg): # # Set check variables # overwrite = True rasters = opt['rasters'].split(',') if opt['rasters'] else []
# %option G_OPT_F_OUTPUT # % key: backup # % description: Create backup file # % required: no # %end # ###################### import os import sys # sys.path.insert(1, os.path.join(os.path.dirname(sys.path[0]), 'etc', 'v.road')) import grass.script as grass from grass.pygrass.utils import get_lib_path path = get_lib_path(modname="v.civil") if path is None: grass.fatal("Not able to find the civil library directory.") sys.path.append(path) import road_road as Road import road_crosstools as Tools2 import road_topotools as Topotools # ============================================= # Main # ============================================= def main(): """Manage v.road
#% type: string #% label: Type of output #% options: areas, points #% answer: areas #% required: no #%end import grass.script as gscript from grass.pygrass.utils import get_lib_path import sys import os from subprocess import call, Popen, check_output from shutil import copyfile from random import uniform, randint path = get_lib_path(modname='maskrcnn', libname='py3detect') if path is None: grass.script.fatal('Not able to find the maskrcnn library directory.') ########################################################### # unfortunately, it needs python3, see file py3train.py ########################################################### # sys.path.append(path) # from configs import ModelConfig def main(options, flags): imagesDir = options['images_directory'] modelPath = options['model'] classes = options['classes']
import sys import atexit # check if within a GRASS session? if "GISBASE" not in os.environ: print "You must be in GRASS GIS to run this program." sys.exit(1) # PyGRASS import grass.script as grass from grass.pygrass.modules.shortcuts import general as g from grass.pygrass.raster.abstract import Info from grass.pygrass.utils import get_lib_path # add "etc" directory to $PATH path = get_lib_path("i.fusion.hpf", "") if path is None: raise ImportError("Not able to find the path %s directory." % path) sys.path.append(path) # import modules from "etc" from high_pass_filter import get_high_pass_filter, get_modulator_factor, get_modulator_factor2 def run(cmd, **kwargs): """Pass arbitrary number of key-word arguments to grass commands and the "quiet" flag by default.""" grass.run_command(cmd, quiet=True, **kwargs) def cleanup():
#% key: rois_per_image #% type: integer #% label: How many ROIs train per image #% required: no #% multiple: no #% answer: 64 #% guisection: Training parameters #%end import grass.script as gscript from grass.pygrass.utils import get_lib_path import sys import os from subprocess import call path = get_lib_path(modname='maskrcnn', libname='py3train') if path is None: grass.script.fatal('Not able to find the maskrcnn library directory.') ########################################################### # unfortunately, it needs python3, see file py3train.py ########################################################### # sys.path.append(path) # from configs import ModelConfig def main(options, flags): dataset = options['training_dataset'] initialWeights = options['model'] classes = options['classes']