def apply(self): pattern = self.cboParsePatern.getSelectedItem() if pattern != None: pattern = pattern.toString() timeSupport = SimpleTimeSupport( self.txtTimeSupportName.getText(), self.cboTimeAttribute.getSelectedItem(), DataTypes.DATE, (self.__starTime, self.__endTime), simpleDateFormat=SimpleDateFormat(pattern)) self.__layer.getDataStore().setTimeSupport(timeSupport) ApplicationLocator.getManager().refreshMenusAndToolBars()
def selfRegister(): application = ApplicationLocator.getManager() # # Registramos las traducciones i18n = ToolsLocator.getI18nManager() i18n.addResourceFamily("text", File(getResource(__file__, "i18n"))) # # Registramos los iconos en el tema de iconos icon = File(getResource(__file__, "images", "mobile-forms-designer.png")).toURI().toURL() print "ICON:", icon iconTheme = ToolsSwingLocator.getIconThemeManager().getCurrent() iconTheme.registerDefault("scripting.MobileFormsExtension", "action", "mobile-forms-designer", None, icon) # # Creamos la accion extension = MobileFormsExtension() actionManager = PluginsLocator.getActionInfoManager() action = actionManager.createAction( extension, "mobile-forms-designer", # Action name "Mobile forms designer", # Text "mobile-forms-designer", # Action command "mobile-forms-designer", # Icon name None, # Accelerator 650151000, # Position "_Show_mobile_forms_designer" # Tooltip ) action = actionManager.registerAction(action) application.addMenu(action, "HMachine/GvSIG Mobile-Geopaparazzi/Forms designer")
def selfRegister(): application = ApplicationLocator.getManager() # # Registramos los iconos en el tema de iconos iconTheme = ToolsSwingLocator.getIconThemeManager().getCurrent() icon = File(getResource(__file__, "images", "dbeaver16x16.png")).toURI().toURL() iconTheme.registerDefault("scripting.DBeaverExtension", "action", "dbeaver-launch", None, icon) # # Creamos la accion actionManager = PluginsLocator.getActionInfoManager() extension = DBeaverExtension() action = actionManager.createAction( extension, "dbeaver-launch", # Action name "DBeaver", # Text "dbeaver-launch", # Action command "dbeaver-launch", # Icon name None, # Accelerator 650700600, # Position "_Show_the_DBeaver_database_administrator_tool" # Tooltip ) action = actionManager.registerAction(action) application.addMenu(action, "tools/DBeaver")
def selfRegister(): application = ApplicationLocator.getManager() # # Registramos las traducciones i18n = ToolsLocator.getI18nManager() i18n.addResourceFamily("text",File(getResource(__file__,"i18n"))) # # Registramos los iconos en el tema de iconos icon = File(getResource(__file__,"images","view-time-add-basic-support-to-datasource.png")).toURI().toURL() iconTheme = ToolsSwingLocator.getIconThemeManager().getCurrent() iconTheme.registerDefault("scripting.addBasicTimeSupportToDatasource", "action", "view-time-add-basic-support-to-datasource", None, icon) # # Creamos la accion extension = AddBasicTimeSupportToDatasourceExtension() actionManager = PluginsLocator.getActionInfoManager() action = actionManager.createAction( extension, "view-time-add-basic-support-to-datasource", # Action name "Add basic support", # Text "view-time-add-basic-support-to-datasource", # Action command "view-time-add-basic-support-to-datasource", # Icon name None, # Accelerator 650151000, # Position "_Add_basic_time_support_to_vectorial_layer" # Tooltip ) action = actionManager.registerAction(action) application.addMenu(action, "View/Time/_Add_basic_time_support")
def selfRegister(): application = ApplicationLocator.getManager() # # Registramos las traducciones i18n = ToolsLocator.getI18nManager() i18n.addResourceFamily("text", File(getResource(__file__, "i18n"))) # # Registramos los iconos en el tema de iconos icon = File( getResource(__file__, "images", "view-query-coordinate-capture.png")).toURI().toURL() iconTheme = ToolsSwingLocator.getIconThemeManager().getCurrent() iconTheme.registerDefault("scripting.CoordinateCaptureExtension", "action", "view-query-coordinate-capture", None, icon) # # Creamos la accion extension = CoordinateCaptureExtension() actionManager = PluginsLocator.getActionInfoManager() action = actionManager.createAction( extension, "view-query-coordinate-capture", # Action name "Coordinate capture", # Text "view-query-coordinate-capture", # Action command "view-query-coordinate-capture", # Icon name None, # Accelerator 650700600, # Position "_Show_the_coordinate_capture" # Tooltip ) action = actionManager.registerAction(action) application.addMenu(action, "View/Query/Coordinate capture")
def getAllValidDocuments(self, documentException=None): application = ApplicationLocator.getManager() project = application.getCurrentProject() mlayer = gvsig.currentLayer() docs = project.getDocuments() all = [] try: for doc in docs: #print doc, type(doc) if isinstance(doc, ViewDocument): for layer in doc.getMapContext().getLayers(): #print "--", layer==mlayer, layer.getName() if isinstance(layer, FLyrVect): if documentException != layer: all.append(layer) elif isinstance(doc, TableDocument): #print "--", doc if doc.getAssociatedLayer() == None: if documentException != doc: all.append(doc) except: ex = sys.exc_info()[1] print "Error", ex.__class__.__name__, str(ex) return all
def selfRegister(): i18n = ToolsLocator.getI18nManager() application = ApplicationLocator.getManager() actionManager = PluginsLocator.getActionInfoManager() iconTheme = ToolsSwingLocator.getIconThemeManager().getCurrent() quickinfo_icon = File( gvsig.getResource(__file__, "images", "reportbypoint1.png")).toURI().toURL() iconTheme.registerDefault("scripting.reportbypoint", "action", "tools-reportbypoint", None, quickinfo_icon) reportbypoint_extension = ReportByPointExtension() reportbypoint_action = actionManager.createAction( reportbypoint_extension, "tools-reportbypoint", # Action name "Show report by point", # Text "settool-reportbypoint", # Action command "tools-reportbypoint", # Icon name None, # Accelerator 1009000000, # Position i18n.getTranslation("_Report_by_point_info") # Tooltip ) reportbypoint_action = actionManager.registerAction(reportbypoint_action) # Añadimos la entrada "Report by point" en el menu herramientas application.addMenu( reportbypoint_action, "tools/" + i18n.getTranslation("_Report_by_point_info")) # Añadimos el la accion como un boton en la barra de herramientas "Quickinfo". application.addSelectableTool(reportbypoint_action, "ReportByPoint")
def selfRegister(): application = ApplicationLocator.getManager() i18n = ToolsLocator.getI18nManager() icon_show = File(gvsig.getResource(__file__, "images", "snap16x16.png")).toURI().toURL() iconTheme = ToolsSwingLocator.getIconThemeManager().getCurrent() iconTheme.registerDefault("scripting.quick-snapping-tool", "action", "tools-quick-snapping-tool", None, icon_show) extension = QuickSnappingToolExtension() actionManager = PluginsLocator.getActionInfoManager() action_show = actionManager.createAction( extension, "tools-quick-snapping-tool", # Action name i18n.getTranslation("_Quick_Snapping_Tool"), # Text "show", # Action command "tools-quick-snapping-tool", # Icon name None, # Accelerator 1009000000, # Position "Quick Snapping Tool" # Tooltip ) action_show = actionManager.registerAction(action_show) application.addTool(action_show, i18n.getTranslation("_Quick_Snapping_Tool"))
def selfRegister(): selfRegisterI18n() i18n = ToolsLocator.getI18nManager() application = ApplicationLocator.getManager() actionManager = PluginsLocator.getActionInfoManager() iconTheme = ToolsSwingLocator.getIconThemeManager().getCurrent() toolfinder_icon = File(gvsig.getResource(__file__,"images","toolFinder.png")).toURI().toURL() iconTheme.registerDefault("scripting.toolfinder", "action", "tools-toolfinder", None, toolfinder_icon) #quickinfo_icon) mytool_extension = ToolFinderExtension() mytool_action = actionManager.createAction( mytool_extension, "tools-toolfinder", # Action name "Tool finder", # Text "settool-toolfinder", # Action command "tools-toolfinder", # Icon name None, # Accelerator 1009000000, # Position i18n.getTranslation("_Tool_finder") # Tooltip ) mytool_action = actionManager.registerAction(mytool_action) # Añadimos la entrada en el menu herramientas application.addMenu(mytool_action, "tools/"+i18n.getTranslation("_Tool_finder"))
def selfRegister(): i18n = ToolsLocator.getI18nManager() application = ApplicationLocator.getManager() actionManager = PluginsLocator.getActionInfoManager() iconTheme = ToolsSwingLocator.getIconThemeManager().getCurrent() exportmaptiles_icon = File( gvsig.getResource(__file__, "images", "exportmaptiles.png")).toURI().toURL() iconTheme.registerDefault("scripting.exportmaptiles", "action", "tools-exportmaptiles", None, exportmaptiles_icon) exportmaptiles_extension = ExportMapTilesPanelExtension() exportmaptiles_action = actionManager.createAction( exportmaptiles_extension, "tools-exportmaptiles", # Action name "Export map tiles", # Text "settool-exportmaptiles", # Action command "tools-exportmaptiles", # Icon name None, # Accelerator 1009000000, # Position i18n.getTranslation("_Export_map_tiles") # Tooltip ) exportmaptiles_action = actionManager.registerAction(exportmaptiles_action) # Añadimos la entrada "Quickinfo" en el menu herramientas application.addMenu(exportmaptiles_action, "tools/_ExportMapTiles") # Añadimos el la accion como un boton en la barra de herramientas "Quickinfo". application.addSelectableTool(exportmaptiles_action, "ExportMapTiles")
def selfRegister(): i18n = ToolsLocator.getI18nManager() application = ApplicationLocator.getManager() actionManager = PluginsLocator.getActionInfoManager() iconTheme = ToolsSwingLocator.getIconThemeManager().getCurrent() quickinfo_icon = File( gvsig.getResource(__file__, "images", "sentineldownloader.png")).toURI().toURL() iconTheme.registerDefault("scripting.sentineldownloader", "action", "tools-sentineldownloader", None, quickinfo_icon) reportbypoint_extension = SentinelDownloaderExtension() reportbypoint_action = actionManager.createAction( reportbypoint_extension, "tools-sentineldownloader", # Action name "Sentinel Downloader", # Text "settool-sentineldownloader", # Action command "tools-sentineldownloader", # Icon name None, # Accelerator 1009000000, # Position i18n.getTranslation("_Sentinel_Downloader") # Tooltip ) reportbypoint_action = actionManager.registerAction(reportbypoint_action) application.addMenu(reportbypoint_action, "tools/_Sentinel_Downloader") application.addSelectableTool(reportbypoint_action, "SentinelDownloader")
def loadDbf(dbfFilePath): manager = ApplicationLocator.getManager() datamanager = manager.getDataManager() storeparameters = datamanager.createStoreParameters("DBF") storeparameters.setDynValue("DbfFile", dbfFilePath) store = datamanager.openStore("DBF", storeparameters) return store
def selfRegister(): application = ApplicationLocator.getManager() i18n = ToolsLocator.getI18nManager() icon_show = File( gvsig.getResource(__file__, "images", "fieldcalculator16x16.png")).toURI().toURL() iconTheme = ToolsSwingLocator.getIconThemeManager().getCurrent() iconTheme.registerDefault("scripting.field-calculator-tool", "action", "tools-field-calculator-tool", None, icon_show) extension = FieldCalculatorToolExtension() actionManager = PluginsLocator.getActionInfoManager() action_show = actionManager.createAction( extension, "tools-field-calculator-tool", # Action name i18n.getTranslation("_Field_Calculator_Tool"), # Text "show", # Action command "tools-field-calculator-tool", # Icon name None, # Accelerator 501100000, # Position "_Field_Calculator_Tool" # Tooltip ) action_show = actionManager.registerAction(action_show) application.addMenu(action_show, "Table/_Field_Calculator_Tool") application.addTool( action_show, "table_tools") #/ )#i18n.getTranslation("_Field_Calculator_Tool"))
def selfRegister(): application = ApplicationLocator.getManager() # # Registramos las traducciones i18n = ToolsLocator.getI18nManager() i18n.addResourceFamily("text", File(getResource(__file__, "i18n"))) # # Registramos los iconos en el tema de iconos icon = File(getResource(__file__, "images", "table-import-fields.png")).toURI().toURL() iconTheme = ToolsSwingLocator.getIconThemeManager().getCurrent() iconTheme.registerDefault("scripting.ImportFieldsExtension", "action", "table-import-fields", None, icon) # # Creamos la accion extension = ImportFieldsExtension() actionManager = PluginsLocator.getActionInfoManager() action = actionManager.createAction( extension, "table-import-fields", # Action name "_Import_fields", # Text "table-import-fields", # Action command "table-import-fields", # Icon name None, # Accelerator 508200000, # Position "_Show_the_import_fields_dialog" # Tooltip ) action = actionManager.registerAction(action) application.addMenu(action, "Table/_Import_fields")
def selfRegister(): i18n = ToolsLocator.getI18nManager() application = ApplicationLocator.getManager() actionManager = PluginsLocator.getActionInfoManager() iconTheme = ToolsSwingLocator.getIconThemeManager().getCurrent() cadastralparcelsdownloader_icon = File( gvsig.getResource(__file__, "images", "cadastralparcelsdownloader.png")).toURI().toURL() iconTheme.registerDefault("scripting.cadastralparcelsdownloader", "action", "tools-cadastralparcelsdownloader", None, cadastralparcelsdownloader_icon) cadastralparcelsdownloader_extension = CadastralDownloaderExtension() cadastralparcelsdownloader_action = actionManager.createAction( cadastralparcelsdownloader_extension, "tools-cadastralparcelsdownloader", # Action name "Show cadastral parcels downloader", # Text "settool-cadastralparcelsdownloader", # Action command "tools-cadastralparcelsdownloader", # Icon name None, # Accelerator 1009000000, # Position i18n.getTranslation("_Show_cadastral_parcels_downloader") # Tooltip ) cadastralparcelsdownloader_action = actionManager.registerAction( cadastralparcelsdownloader_action) # Añadimos la entrada "Quickinfo" en el menu herramientas application.addMenu(cadastralparcelsdownloader_action, "tools/_cadastralparcelsdownloader") # Añadimos el la accion como un boton en la barra de herramientas "Quickinfo". application.addSelectableTool(cadastralparcelsdownloader_action, "CadastralParcelsDownloader")
def loadLayerNew(layerType, tocName=False, **parameters): # try: application = ApplicationLocator.getManager() datamanager = application.getDataManager() mapcontextmanager = application.getMapContextManager() store_parameters = datamanager.createStoreParameters(layerType) gvsig.copyToDynObject(parameters, store_parameters) store = datamanager.openStore(layerType, store_parameters) if tocName!=False: nameStore = tocName else: nameStore = store.getName() layer = mapcontextmanager.createLayer(nameStore, store) except Throwable, ex: raise RuntimeException("Can't load layer, "+ str(ex))
def selfRegister(): registerAction() application = ApplicationLocator.getManager() actionManager = PluginsLocator.getActionInfoManager() application.addMenu( actionManager.getAction("arena2-importer-showimporter"), "tools/ARENA2/Importador") application.addMenu( actionManager.getAction("arena2-importer-showtablecreator"), "tools/ARENA2/Crear tablas") application.addMenu( actionManager.getAction("arena2-importer-showvalidator"), "tools/ARENA2/Validador")
def getAllValidDocuments(self): application = ApplicationLocator.getManager() project = application.getCurrentProject() views = project.getDocuments() all = [] for view in views: #print view, type(view) if isinstance(view, ViewDocument): #print view, type(view) for layer in view.getMapContext().getLayers(): #print "--", layer==mlayer, layer.getName() all.append(layer) elif isinstance(view, TableDocument): #print "--", view all.append(view) return all
def checkSelectedRowCount(self): if self.selectedRowCount == 0: applicationLocator = ApplicationLocator() applicationManager = applicationLocator.getManager() mdiManager = applicationManager.getUIManager() window = mdiManager.getFocusWindow() # org.gvsig.andami.ui.ToolsWindowManager.Window rootPane = window.getRootPane() # JRootPane layeredPane = rootPane.getComponent(1) # JLayeredPane panel = layeredPane.getComponent(0) # JPanel window = panel.getComponent(0) # org.gvsig.andami.ui.ToolsWindowManager.Window defaultJTopologyReport = window.getComponent(0) # org.gvsig.topology.swing.impl.DefaultJTopologyReport pane = defaultJTopologyReport.getComponent(0) # JPanel tabbedPane = pane.getComponent(0) # JTabbedPane pane = tabbedPane.getComponent(0) # JPanel scrollPane = pane.getComponent(0) # JScrollPane viewport = scrollPane.getComponent(0) # JViewport table = viewport.getComponent(0) # JTable self.selectedRowCount = table.getSelectedRowCount()
def getMunicipalitiesParcelsFeatureSet(codmuni): manager = DALLocator.getDataManager() storeParameters = manager.createStoreParameters("H2Spatial") database_file = gvsig.getResource(__file__,"data","municipalities.mv.db") storeParameters.setDynValue("database_file",database_file) storeParameters.setDynValue("Table","Muni") storeParameters.setDynValue("SQL","""SELECT * FROM "Muni" WHERE CODMUN='{0}'""".format(codmuni)); store = manager.openStore("H2Spatial",storeParameters) #try: # query = u"""CODMUN='{0}'""".format(codmuni) # featureSet = store.getFeatureSet(query) #except: # return None application = ApplicationLocator.getManager() mapcontextmanager = application.getMapContextManager() layer = mapcontextmanager.createLayer(codmuni,store) gvsig.currentView().addLayer(layer) store.dispose()
def createTiles(newFolder="Tiles2", zoomLevels=[0, 2]): pathZoom = {} view = gvsig.currentView() vp = view.getMapContext().getViewPort() # Create main folder empdir = "/home/osc/temp/" #Utilities.TEMPDIRECTORYPATH pathFolder = os.path.join(empdir, newFolder) if os.path.exists(pathFolder): shutil.rmtree(pathFolder) os.mkdir(pathFolder) # Create Zooms levels for z in range(zoomLevels[0], zoomLevels[1] + 1): p = os.path.join(pathFolder, str(z)) pathZoom[z] = p os.mkdir(p) print "Zoom path: ", pathZoom # for 1 zoom for zoom in range(zoomLevels[0], zoomLevels[1] + 1): #Get scale # dividir en cuantos tiles hacen falta para cierto zoom # crear carpeta para cada columna / fila pathForThisTileCol = os.path.join(pathZoom[zoom], "{0}".format(zoom)) os.mkdir(pathForThisTileCol) rowTile = 0 pathForThisTileRow = os.path.join(pathForThisTileCol, "{0}.png".format(rowTile)) # en zoom 0 es /zoom/col/row.png print "Scale:", zoomScale[zoom] application = ApplicationLocator.getManager() docwin = application.getDocumentWindow(view()) gsv = zoomScale[zoom] #view.getMapContext().getScaleView() #Envelope global #envelope = view.getMap().getLayers().getMapContext().getFullEnvelope() #view.getMapContext().getViewPort().setEnvelope(envelope) view.getMapContext().setScaleView(gsv) time.sleep(2) img = docwin.getMapControl().getImage() print pathForThisTileRow Jimi.putImage(img, pathForThisTileRow)
def selfRegister(): i18n = ToolsLocator.getI18nManager() moduleId = "sigpac2csv" actionName = "tools-sigpac-sigpac2csv" tooltip_key = i18n.getTranslation("_Convert_SIGPAC_XML_to_gvSIG_format") menu_entry = "tools/SIGPAC/_Convert_XML_to_gvSIG" extension = SIGPAC2CSVExtension() application = ApplicationLocator.getManager() actionManager = PluginsLocator.getActionInfoManager() iconTheme = ToolsSwingLocator.getIconThemeManager().getCurrent() # # Registramos las traducciones i18n = ToolsLocator.getI18nManager() i18n.addResourceFamily("text", File(getResource(__file__, "i18n"))) # # Registramos los iconos en el tema de iconos icon = File(getResource(__file__, "images", actionName + ".png")).toURI().toURL() iconTheme = ToolsSwingLocator.getIconThemeManager().getCurrent() iconTheme.registerDefault("scripting." + moduleId, "action", actionName, None, icon) action = actionManager.createAction( extension, actionName, # Action name tooltip_key, # Text actionName, # Action command actionName, # Icon name None, # Accelerator 1009000000, # Position i18n.getTranslation(tooltip_key) # Tooltip ) action = actionManager.registerAction(action) # Añadimos la entrada en el menu herramientas application.addMenu(action, menu_entry)
def selfRegister(): i18n = ToolsLocator.getI18nManager() moduleId = "SelectTableDuplicates" actionName = "selection-table-select-duplicatesnofirst" tooltip_key = i18n.getTranslation("_Select_all_duplicates_except_the_first") menu_entry = "Selection/_Select_table_duplicates/_Select_all_duplicates_except_the_first" extension = SelectTableDuplicatesExtension() application = ApplicationLocator.getManager() actionManager = PluginsLocator.getActionInfoManager() iconTheme = ToolsSwingLocator.getIconThemeManager().getCurrent() # # Registramos los iconos en el tema de iconos icon = File(getResource(__file__,"images",actionName + ".png")).toURI().toURL() iconTheme = ToolsSwingLocator.getIconThemeManager().getCurrent() iconTheme.registerDefault("scripting." + moduleId, "action", actionName, None, icon) action = actionManager.createAction( extension, actionName, # Action name tooltip_key, # Text actionName, # Action command actionName, # Icon name None, # Accelerator 300450200, # Position i18n.getTranslation(tooltip_key) # Tooltip ) action = actionManager.registerAction(action) # Añadimos la entrada en el menu herramientas application.addMenu(action, menu_entry) # Añadimos la accion como un boton en la barra de herramientas. #application.addTool(action, "selection") application.getMainFrame().addTool(action,"selection","selection-table-duplicates"); application.refreshMenusAndToolBars()
def selfRegister(): config = AccidentRateConfig() config.readConfig() if not config.getboolean("ARENA2", "alreadyDisabled"): disableArena2() config.set("ARENA2", "alreadyDisabled", "false") config.writeConfig() application = ApplicationLocator.getManager() actionManager = PluginsLocator.getActionInfoManager() registerActions() action = actionManager.getAction("accidentrate-importer-showtablecreator") application.addMenu( action, u"tools/_AccidentRate/Administration/Crear tablas de accidentes") action = actionManager.getAction("accidentrate-importer-showimporter") application.addMenu( action, u"tools/_AccidentRate/Administration/Importador de accidentes") action = actionManager.getAction("accidentrate-closingdate-showdialog") application.addMenu(action, u"tools/_AccidentRate/Administration/Fecha de cierre") action = actionManager.getAction("accidentrate-search") application.addMenu(action, u"tools/_AccidentRate/Busqueda de accidentes") action = actionManager.getAction("accidentrate-addlayer") application.addMenu(action, u"tools/_AccidentRate/A\u00F1adir capa de accidentes") action = actionManager.getAction("accidentrate-importer-showvalidator") application.addMenu( action, u"tools/_AccidentRate/Administration/Validador de accidentes")
def createNewDataBaseBasicPronviciasMunicipios(): database_file = gvsig.getTempFile("/home/osc/temp/h2/catas",".mv.db") print "** DATABASE FILE_: ", database_file # Create store manager = DALLocator.getDataManager() serverParameters = manager.createServerExplorerParameters("H2Spatial") serverParameters.setDynValue("database_file",database_file) serverExplorer = manager.openServerExplorer("H2Spatial",serverParameters) p = serverExplorer.getAddParameters() p.setDynValue("Table","Provincias") ft = manager.createFeatureType() ft.add("CODIGO", DataTypes.STRING) ft.add("PROVINCIA", DataTypes.STRING) p.setDefaultFeatureType(ft) serverExplorer.add("H2Spatial", p, True) p = serverExplorer.getAddParameters() p.setDynValue("Table","Municipios") ft = manager.createFeatureType() ft.add("CODPROV", DataTypes.STRING) ft.add("PROV", DataTypes.STRING) ft.add("CODMUN", DataTypes.STRING) ft.add("MUN", DataTypes.STRING) ft.add("ID", DataTypes.STRING) p.setDefaultFeatureType(ft) serverExplorer.add("H2Spatial", p, True) # Open Store storeParameters = manager.createStoreParameters("H2Spatial") storeParameters.setDynValue("database_file",database_file) storeParameters.setDynValue("Table","Provincias") store = manager.openStore("H2Spatial",storeParameters) store.edit() for p in data.getProvincias(): value = p[1] #.encode('utf-8') store.append({ "CODIGO":p[0], "PROVINCIA":value}) store.commit() #for i in store.getFeatureSet(): # print i.get('PROVINCIA=')#.encode("utf-8") storeParameters = manager.createStoreParameters("H2Spatial") storeParameters.setDynValue("Table","Municipios") storeParameters.setDynValue("database_file",database_file) store = manager.openStore("H2Spatial",storeParameters) store.edit() csvFilePath = gvsig.getResource(__file__,"data","dataMunicipalities.csv") if not os.path.exists(csvFilePath): print "not found" return None with open(csvFilePath, 'rb') as csvfile: spamreader = csv.reader(csvfile, delimiter=',') #, quotechar='|') for row in spamreader: d = {} d["CODPROV"]=row[0].decode('utf-8') d["PROV"]=row[1].decode('utf-8') d["CODMUN"]=row[2].decode('utf-8') d["MUN"]=row[3].decode('utf-8') d["ID"]=row[4].decode('utf-8') store.append(d) store.commit() for n,f in enumerate(store): print f if n==100: break #Create layer return application = ApplicationLocator.getManager() mapcontextmanager = application.getMapContextManager() layer = mapcontextmanager.createLayer("Layer H2",store)
def main(*args): #Input print "Script generacion de informes" path_script = os.path.dirname(__file__) pathTemplate = os.path.join(path_script, "plantilla", "plantilla_informe_test2.odt") #Output # Utilizar este formato con una unica barra path_output = os.path.join("C:/", "gvsig_informes", "resultado") if os.path.exists(path_output) == False: raise Exception(OSError, "Path not found: " + path_output) pathOutputFile = os.path.join(path_output, "test_parcela%02d") pathEnvelope = os.path.join(path_output, "envelope.png") pathImageOut = os.path.join(path_output, "img%02d.png") print pathImageOut print pathEnvelope print pathOutputFile #Inicio print "Informe parcelario" application = ApplicationLocator.getManager() layer = currentLayer() docvista = currentView() if layer == None or docvista == None: raise Exception(ValueError, 'Not layer selected') return docwin = application.getDocumentWindow(docvista()) #Get scale gsv = currentView().getMapContext().getScaleView() #Envelope global envelope = currentView().getMap().getLayers().getMapContext( ).getFullEnvelope() currentView().getMapContext().getViewPort().setEnvelope(envelope) time.sleep(2) img = docwin.getMapControl().getImage() Jimi.putImage(img, pathEnvelope) #Create images and odt n = 0 for f in layer.getSelection(): print f.MASA, f.geometry() #Center view and set same scale geomf = f.geometry() currentView().centerView(geomf.getEnvelope()) currentView().getMapContext().setScaleView(gsv) time.sleep(4) #Imagen img = docwin.getMapControl().getImage() pathImage = pathImageOut % n Jimi.putImage(img, pathImage) # Create odt pathOutFile = pathOutputFile % n templateFile = pathTemplate #File(pathTemplate) outFile = File(pathOutFile) bcFile = pathImage template = JavaScriptFileTemplate(templateFile) values = f.getValues() template.setField("hoja", str(values['HOJA'])) template.setField("area", str(values['AREA'])) template.setField("coorx", f.COORX) template.setField("coory", f.COORY) ddoc = template.createDocument() pathGeometry = ("file:///" + bcFile).replace('\\', '/') pathEnvelopeForHref = ("file:///" + pathEnvelope).replace('\\', '/') ddoc.getDescendantByName("draw:frame", "Imagen2").setAttribute( "href", pathGeometry, Namespace.getNamespace("xlink", "http://www.w3.org/1999/xlink")) ddoc.getDescendantByName("draw:frame", "Imagen1").setAttribute( "href", pathEnvelopeForHref, Namespace.getNamespace("xlink", "http://www.w3.org/1999/xlink")) ddoc.saveAs(outFile) #template.saveAs(outFile) n += 1
def execute(self, actionCommand, *args): self.document = gvsig.currentDocument(TableManager.TYPENAME) if self.document == None: return i18nManager = ToolsLocator.getI18nManager() self.store = self.document.getFeatureStore() ## Previusly editing state if self.store.isEditing(): self.editingMode = True else: self.editingMode = False ## Analyce pending changes if self.store.getPendingChangesCount() > 0: message = i18nManager.getTranslation( "_info_confirm_dialog_field_calculator_commit_changes") title = "" optionType = commonsdialog.WARNING messageType = commonsdialog.WARNING msgid = "_field_calculator_save_pending_changes_at_finish" optionSave = ApplicationLocator.getManager().confirmDialog( message, title, optionType, messageType, msgid) if optionSave == commonsdialog.YES: pass else: logger( "User changes are not commited and FieldCalculator will commit all this changes", LOGGER_WARN) return ## name = i18nManager.getTranslation( "_Field_Calculator_Tool") + ": " + self.store.getName() self.taskStatus = ToolsLocator.getTaskStatusManager( ).createDefaultSimpleTaskStatus("") self.taskStatus.setAutoremove(True) windowManager = ToolsSwingLocator.getWindowManager() # Set first column option defaultField = None #table = gvsig.currentDocument(TableManager.TYPENAME) if self.document != None: selected = self.document.getMainWindow().getTablePanel().getTable( ).getSelectedColumnsAttributeDescriptor() if len(selected) >= 1: defaultField = selected[0].getName() # Open tool #prefs = readConfigFile() self.tool = FieldCalculatorTool(self.store, self.taskStatus, defaultField) self.expBuilder = self.tool.getExpBuilder() self.expFilter = self.tool.getExpFilter() self.dialog = windowManager.createDialog( self.tool.asJComponent(), name, None, WindowManager_v2.BUTTON_CANCEL | WindowManager_v2.BUTTON_APPLY) self.dialog.addActionListener(self) self.dialog.show(WindowManager.MODE.WINDOW) self.dialog.setButtonLabel(WindowManager_v2.BUTTON_CANCEL, i18nManager.getTranslation("_close")) columnSelectedDescriptor = self.tool.getFieldDescriptor() if columnSelectedDescriptor == None: self.dialog.setButtonEnabled(WindowManager_v2.BUTTON_APPLY, False) self.tool.setDialog(self.dialog)
def selfRegister(): config = AccidentRateConfig() config.readConfig() if not config.getboolean("ARENA2", "alreadyDisabled"): disableArena2() config.set("ARENA2", "alreadyDisabled", "false") config.writeConfig() application = ApplicationLocator.getManager() # # Registramos las traducciones i18n = ToolsLocator.getI18nManager() i18n.addResourceFamily("text", File(getResource(__file__, "i18n"))) # # Registramos los iconos en el tema de iconos iconTheme = ToolsSwingLocator.getIconThemeManager().getCurrent() icon = File( getResource(__file__, "images", "accidentrate-importer-showimporter.png")).toURI().toURL() iconTheme.registerDefault("scripting.AccidentRateExtension", "action", "accidentrate-importer-showimporter", None, icon) icon = File( getResource( __file__, "images", "accidentrate-importer-showtablecreator.png")).toURI().toURL() iconTheme.registerDefault("scripting.AccidentRateExtension", "action", "accidentrate-importer-showtablecreator", None, icon) icon = File( getResource( __file__, "images", "accidentrate-closingdate-showdialog.png")).toURI().toURL() iconTheme.registerDefault("scripting.AccidentRateExtension", "action", "accidentrate-closingdate-showdialog", None, icon) icon = File(getResource(__file__, "images", "accidentrate-search.png")).toURI().toURL() iconTheme.registerDefault("scripting.AccidentRateExtension", "action", "accidentrate-search", None, icon) icon = File(getResource(__file__, "images", "accidentrate-addlayer.png")).toURI().toURL() iconTheme.registerDefault("scripting.AccidentRateExtension", "action", "accidentrate-addlayer", None, icon) # # Creamos la accion actionManager = PluginsLocator.getActionInfoManager() extension = AccidentRateExtension() action = actionManager.createAction( extension, "accidentrate-importer-showtablecreator", # Action name "Creador de las tablas de accidentes", # Text "accidentrate-importer-showtablecreator", # Action command "accidentrate-importer-showtablecreator", # Icon name None, # Accelerator 1009000901, # Position "_Show_the_accidents_tables_creator_tool" # Tooltip ) action = actionManager.registerAction(action) application.addMenu( action, u"_AccidentRate/Administration/Gesti\u00F3n de accidentes/Crear tablas de accidentes" ) action = actionManager.createAction( extension, "accidentrate-importer-showimporter", # Action name "Importador de accidentes", # Text "accidentrate-importer-showimporter", # Action command "accidentrate-importer-showimporter", # Icon name None, # Accelerator 1009000902, # Position "_Show_the_accidents_import_tool" # Tooltip ) action = actionManager.registerAction(action) application.addMenu( action, u"_AccidentRate/Administration/Gesti\u00F3n de accidentes/Importador de accidentes" ) action = actionManager.createAction( extension, "accidentrate-closingdate-showdialog", # Action name "Administrar fecha de cierre", # Text "accidentrate-closingdate-showdialog", # Action command "accidentrate-closingdate-showdialog", # Icon name None, # Accelerator 1009000903, # Position "_Show_the_accidents_closing_date_tool" # Tooltip ) action = actionManager.registerAction(action) application.addMenu( action, u"_AccidentRate/Administration/Gesti\u00F3n de accidentes/Fecha de cierre" ) action = actionManager.createAction( extension, "accidentrate-search", # Action name "Busqueda de accidentes", # Text "accidentrate-search", # Action command "accidentrate-search", # Icon name None, # Accelerator 1009000100, # Position "Busqueda de accidentes" # Tooltip ) action = actionManager.registerAction(action) application.addMenu( action, u"_AccidentRate/Gesti\u00F3n de accidentes/Busqueda de accidentes") action = actionManager.createAction( extension, "accidentrate-addlayer", # Action name "Añadir capa de accidentes", # Text "accidentrate-addlayer", # Action command "accidentrate-addlayer", # Icon name None, # Accelerator 1009000200, # Position "Añadir capa de accidentes" # Tooltip ) action = actionManager.registerAction(action) application.addMenu( action, u"_AccidentRate/Gesti\u00F3n de accidentes/A\u00F1adir capa de accidentes" )
def registerActions(): application = ApplicationLocator.getManager() # # Registramos las traducciones i18n = ToolsLocator.getI18nManager() i18n.addResourceFamily("text", File(getResource(__file__, "i18n"))) # # Registramos los iconos en el tema de iconos iconTheme = ToolsSwingLocator.getIconThemeManager().getCurrent() icon = File( getResource(__file__, "images", "accidentrate-importer-showimporter.png")).toURI().toURL() iconTheme.registerDefault("scripting.AccidentRateExtension", "action", "accidentrate-importer-showimporter", None, icon) icon = File( getResource( __file__, "images", "accidentrate-importer-showtablecreator.png")).toURI().toURL() iconTheme.registerDefault("scripting.AccidentRateExtension", "action", "accidentrate-importer-showtablecreator", None, icon) icon = File( getResource( __file__, "images", "accidentrate-closingdate-showdialog.png")).toURI().toURL() iconTheme.registerDefault("scripting.AccidentRateExtension", "action", "accidentrate-closingdate-showdialog", None, icon) icon = File(getResource(__file__, "images", "accidentrate-search.png")).toURI().toURL() iconTheme.registerDefault("scripting.AccidentRateExtension", "action", "accidentrate-search", None, icon) icon = File(getResource(__file__, "images", "accidentrate-addlayer.png")).toURI().toURL() iconTheme.registerDefault("scripting.AccidentRateExtension", "action", "accidentrate-addlayer", None, icon) icon = File( getResource(__file__, "images", "arena2-importer-showvalidator.png")).toURI().toURL() iconTheme.registerDefault("scripting.AccidentRateExtension", "action", "accidentrate-importer-showvalidator", None, icon) # # Creamos la accion actionManager = PluginsLocator.getActionInfoManager() extension = AccidentRateExtension() action = actionManager.createAction( extension, "accidentrate-importer-showtablecreator", # Action name "Creador de las tablas de accidentes", # Text "accidentrate-importer-showtablecreator", # Action command "accidentrate-importer-showtablecreator", # Icon name None, # Accelerator 1009000901, # Position "_Show_the_accidents_tables_creator_tool" # Tooltip ) action = actionManager.registerAction(action, True) action = actionManager.createAction( extension, "accidentrate-importer-showimporter", # Action name "Importador de accidentes", # Text "accidentrate-importer-showimporter", # Action command "accidentrate-importer-showimporter", # Icon name None, # Accelerator 1009000902, # Position "_Show_the_accidents_import_tool" # Tooltip ) action = actionManager.registerAction(action, True) action = actionManager.createAction( extension, "accidentrate-closingdate-showdialog", # Action name "Administrar fecha de cierre", # Text "accidentrate-closingdate-showdialog", # Action command "accidentrate-closingdate-showdialog", # Icon name None, # Accelerator 1009000903, # Position "_Show_the_accidents_closing_date_tool" # Tooltip ) action = actionManager.registerAction(action, True) action = actionManager.createAction( extension, "accidentrate-search", # Action name "Busqueda de accidentes", # Text "accidentrate-search", # Action command "accidentrate-search", # Icon name None, # Accelerator 1009000100, # Position "Busqueda de accidentes" # Tooltip ) action = actionManager.registerAction(action, True) action = actionManager.createAction( extension, "accidentrate-addlayer", # Action name "Añadir capa de accidentes", # Text "accidentrate-addlayer", # Action command "accidentrate-addlayer", # Icon name None, # Accelerator 1009000200, # Position "Añadir capa de accidentes" # Tooltip ) action = actionManager.registerAction(action, True) action = actionManager.createAction( extension, "accidentrate-importer-showvalidator", # Action name "ARENA2 validator", # Text "accidentrate-importer-showvalidator", # Action command "accidentrate-importer-showvalidator", # Icon name None, # Accelerator 1009000904, # Position "_Show_the_ARENA2_validator_tool" # Tooltip ) action = actionManager.registerAction(action, True)
def getWindowOfTable(self): application = ApplicationLocator.getManager() projectManager = application.getProjectManager() tableManager = projectManager.getDocumentManager(TableManager.TYPENAME) return tableManager.getMainWindow(self,None)
def process(self,flayer, field1,field2,changeDefaultValue,defaultValue,changeForValue): i18nManager = ToolsLocator.getI18nManager() fstore = flayer.getFeatureStore() fset = fstore.getFeatureSet()#lection() featureType = gvsig.createFeatureType(fstore.getDefaultFeatureType()) nameField1 = featureType.get(field1).getName() nameField2 = featureType.get(field2).getName() fields = [field1, field2] allFields = [attr.getName() for attr in featureType.getAttributeDescriptors()] n=0 while True: n += 1 if len(nameField1)>=10: newFieldName1 = nameField1[:-1]+str(n) else: newFieldName1 = nameField1+str(n) if newFieldName1 not in allFields: break if self.isCanceled(): return False n=0 while True: n += 1 if len(nameField2)>=10: newFieldName2 = nameField2[:-1]+str(n) else: newFieldName2 = nameField2+str(n) if newFieldName2 not in allFields and newFieldName1 != newFieldName2: break if self.isCanceled(): return False featureType.add(newFieldName1,DataTypes.DATE) featureType.add(newFieldName2,DataTypes.DATE) if self.isCanceled(): return False if self.isPolygon(flayer.getFeatureStore()): output_store = self.buildOutPutStore( featureType, SHAPE_TYPE_POLYGON, "Result_polygon", "RESULT_POLYGON" ) self.buildOutPutStore( featureType, SHAPE_TYPE_LINE, "Result_line", "RESULT_LINE" ) self.buildOutPutStore( featureType, SHAPE_TYPE_POINT, "Result_point", "RESULT_POINT" ) elif self.isLine(flayer.getFeatureStore()): output_store = self.buildOutPutStore( featureType, SHAPE_TYPE_LINE, "Result_line", "RESULT_LINE" ) self.buildOutPutStore( featureType, SHAPE_TYPE_POLYGON, "Result_polygon", "RESULT_POLYGON" ) self.buildOutPutStore( featureType, SHAPE_TYPE_POINT, "Result_point", "RESULT_POINT" ) elif self.isPoint(flayer.getFeatureStore()): output_store = self.buildOutPutStore( featureType, SHAPE_TYPE_POINT, "Result_point", "RESULT_POINT" ) self.buildOutPutStore( featureType, SHAPE_TYPE_POLYGON, "Result_polygon", "RESULT_POLYGON" ) self.buildOutPutStore( featureType, SHAPE_TYPE_LINE, "Result_line", "RESULT_LINE" ) else: raise ("Not valid value") dataManager = ApplicationLocator.getManager().getDataTypesManager() self.setRangeOfValues(0, fset.getSize()) self.getStatus().setTitle("Processing..") self.setProgressText(i18nManager.getTranslation("_Converting_fields_to_dates")) for f in fset: nf =output_store.createNewFeature(f) ## Value 1 value1 = f.get(field1) if changeDefaultValue is True and str(value1)==str(defaultValue): value1 = changeForValue nf.set(newFieldName1, intToDate(value1)) ## Value 2 value2 = f.get(field2) if changeDefaultValue is True and str(value2)==str(defaultValue): value2 = changeForValue nf.set(newFieldName2, intToDate(value2)) output_store.insert(nf) if self.isCanceled() is True: return False else: self.next() output_store.finishEditing() #m = MapContextLocator.getMapContextManager().createLayer("Result", output_store) #gvsig.currentView().addLayer(m) #if not self.isPolygon(flayer.getFeatureStore()): # self.getNewVectorLayer("RESULT_POLYGON","result_polygon",OutputVectorLayer.SHAPE_TYPE_POLYGON,[Integer.getClass(0)],[""]) #elif not self.isLine(flayer.getFeatureStore()): # self.getNewVectorLayer("RESULT_LINE","result_line",OutputVectorLayer.SHAPE_TYPE_LINE,[Integer.getClass(0)],[""]) #elif not self.isPoint(flayer.getFeatureStore()): # self.getNewVectorLayer("RESULT_POINT","result_point",OutputVectorLayer.SHAPE_TYPE_POINT,[Integer.getClass(0)],[""]) return True