Ejemplo n.º 1
0
    def doEdit(self):
        try:
            from metatoolseditor import MetatoolsEditor
        except:
            QMessageBox.critical(
                self.iface.mainWindow(),
                QCoreApplication.translate("Metatools", "Metatools"),
                QCoreApplication.translate("Metatools",
                                           "Editor can't be loaded: %s %s!") %
                (unicode(sys.exc_info()[0]), unicode(sys.exc_info()[1])))
            return

        # check if metadata file exists
        if not self.checkMetadata():
            return

        # check matadata standard
        standard = MetaInfoStandard.tryDetermineStandard(self.metaProvider)
        if standard != MetaInfoStandard.ISO19115 and standard != MetaInfoStandard.FGDC:
            QMessageBox.critical(
                self.iface.mainWindow(),
                QCoreApplication.translate("Metatools", "Metatools"),
                QCoreApplication.translate(
                    "Metatools",
                    "Unsupported metadata standard! Only ISO19115 and FGDC supported now!"
                ))
            return

        dlg = MetatoolsEditor()
        dlg.setContent(self.metaProvider)
        dlg.exec_()
Ejemplo n.º 2
0
  def doView(self):
    try:
      from metatoolsviewer import MetatoolsViewer
    except:
      QMessageBox.critical(self.iface.mainWindow(),
                           QCoreApplication.translate("Metatools", "Metatools"),
                           QCoreApplication.translate("Metatools", "Viewer can't be loaded: %s %s!") % (unicode(sys.exc_info()[0]), unicode(sys.exc_info()[1]))
                          )
      return

    # check metadata exists
    if not self.checkMetadata():
      return

    # check matadata standard
    standard = MetaInfoStandard.tryDetermineStandard(self.metaProvider)
    if standard != MetaInfoStandard.ISO19115 and standard != MetaInfoStandard.FGDC:
      QMessageBox.critical(self.iface.mainWindow(),
                           QCoreApplication.translate("Metatools", "Metatools"),
                           QCoreApplication.translate("Metatools", "Unsupported metadata standard! Only ISO19115 and FGDC supported now!")
                          )
      return

    # TODO: validate metadata file

    # get xsl file path
    settings = QSettings("NextGIS", "metatools")
    if standard == MetaInfoStandard.ISO19115:
        xsltFilePath = os.path.join(self.pluginPath, "xsl/") + settings.value("iso19115/stylesheet", "iso19115.xsl")
    if standard == MetaInfoStandard.FGDC:
        xsltFilePath = os.path.join(self.pluginPath, "xsl/") + settings.value("fgdc/stylesheet", "fgdc.xsl")

    dlg = MetatoolsViewer()
    if dlg.setContent(self.metaProvider, xsltFilePath):
      dlg.exec_()
Ejemplo n.º 3
0
  def execUsgs(self):
    settings = QSettings("NextGIS", "metatools")
    if not settings.value("tools/hasFGDC", False):
      return

    # check if metadata file exists
    if not self.checkMetadata():
      return

    # check matadata standard
    standard = MetaInfoStandard.tryDetermineStandard(self.metaProvider)

    if standard != MetaInfoStandard.FGDC:
      QMessageBox.critical(self.iface.mainWindow(),
                           QCoreApplication.translate("Metatools", "Metatools"),
                           QCoreApplication.translate("Metatools", "USGS tool support only FGDC standard!")
                          )
      return

    # start tool
    execFilePath = settings.value("tools/tkme", "")

    try:
      import subprocess
      prov = self.metaProvider
      temporaryMetafile = prov.SaveToTempFile()
      subprocess.Popen([unicode(execFilePath), unicode(temporaryMetafile)], cwd=toolPath).wait()
      prov.LoadFromTempFile(temporaryMetafile)
    except:
      QMessageBox.critical(self.iface.mainWindow(),
                           QCoreApplication.translate("Metatools", "Metatools"),
                           QCoreApplication.translate("Metatools", "USGS tool can't be runing: ") + unicode(sys.exc_info()[1])
                          )
Ejemplo n.º 4
0
  def execUsgs(self):
    settings = QSettings("NextGIS", "metatools")
    if not settings.value("tools/hasFGDC", False):
      return

    # check if metadata file exists
    if not self.checkMetadata():
      return

    # check matadata standard
    standard = MetaInfoStandard.tryDetermineStandard(self.metaProvider)

    if standard != MetaInfoStandard.FGDC:
      QMessageBox.critical(self.iface.mainWindow(),
                           QCoreApplication.translate("Metatools", "Metatools"),
                           QCoreApplication.translate("Metatools", "USGS tool support only FGDC standard!")
                          )
      return

    # start tool
    execFilePath = settings.value("tools/tkme", "")

    try:
      import subprocess
      prov = self.metaProvider
      temporaryMetafile = prov.SaveToTempFile()
      subprocess.Popen([unicode(execFilePath), unicode(temporaryMetafile)], cwd=toolPath).wait()
      prov.LoadFromTempFile(temporaryMetafile)
    except:
      QMessageBox.critical(self.iface.mainWindow(),
                           QCoreApplication.translate("Metatools", "Metatools"),
                           QCoreApplication.translate("Metatools", "USGS tool can't be runing: ") + unicode(sys.exc_info()[1])
                          )
Ejemplo n.º 5
0
  def doEdit(self):
    try:
      from metatoolseditor import MetatoolsEditor
    except:
      QMessageBox.critical(self.iface.mainWindow(),
                           QCoreApplication.translate("Metatools", "Metatools"),
                           QCoreApplication.translate("Metatools", "Editor can't be loaded: %s %s!") % (unicode(sys.exc_info()[0]), unicode(sys.exc_info()[1]))
                          )
      return

    # check if metadata file exists
    if not self.checkMetadata():
      return

    # check matadata standard
    standard = MetaInfoStandard.tryDetermineStandard(self.metaProvider)
    if standard != MetaInfoStandard.ISO19115 and standard != MetaInfoStandard.FGDC:
      QMessageBox.critical(self.iface.mainWindow(),
                           QCoreApplication.translate("Metatools", "Metatools"),
                           QCoreApplication.translate("Metatools", "Unsupported metadata standard! Only ISO19115 and FGDC supported now!")
                          )
      return

    dlg = MetatoolsEditor()
    dlg.setContent(self.metaProvider)
    dlg.exec_()
Ejemplo n.º 6
0
  def doView(self):
    try:
      from metatoolsviewer import MetatoolsViewer
    except:
      QMessageBox.critical(self.iface.mainWindow(),
                           QCoreApplication.translate("Metatools", "Metatools"),
                           QCoreApplication.translate("Metatools", "Viewer can't be loaded: %s %s!") % (unicode(sys.exc_info()[0]), unicode(sys.exc_info()[1]))
                          )
      return

    # check metadata exists
    if not self.checkMetadata():
      return

    # check matadata standard
    standard = MetaInfoStandard.tryDetermineStandard(self.metaProvider)
    if standard != MetaInfoStandard.ISO19115 and standard != MetaInfoStandard.FGDC:
      QMessageBox.critical(self.iface.mainWindow(),
                           QCoreApplication.translate("Metatools", "Metatools"),
                           QCoreApplication.translate("Metatools", "Unsupported metadata standard! Only ISO19115 and FGDC supported now!")
                          )
      return

    # TODO: validate metadata file

    # get xsl file path
    settings = QSettings("NextGIS", "metatools")
    if standard == MetaInfoStandard.ISO19115:
        xsltFilePath = os.path.join(self.pluginPath, "xsl/") + settings.value("iso19115/stylesheet", "iso19115.xsl")
    if standard == MetaInfoStandard.FGDC:
        xsltFilePath = os.path.join(self.pluginPath, "xsl/") + settings.value("fgdc/stylesheet", "fgdc.xsl")

    dlg = MetatoolsViewer()
    if dlg.setContent(self.metaProvider, xsltFilePath):
      dlg.exec_()
Ejemplo n.º 7
0
  def execMp(self):
    settings = QSettings("NextGIS", "metatools")
    if not settings.value("tools/hasFGDC", False):
      return

    # check if metadata exists
    if not self.checkMetadata():
      return

    # check matadata standard
    standard = MetaInfoStandard.tryDetermineStandard(self.metaProvider)

    if standard != MetaInfoStandard.FGDC:
      QMessageBox.critical(self.iface.mainWindow(),
                           QCoreApplication.translate("Metatools", "Metatools"),
                           QCoreApplication.translate("Metatools", "MP tool support only FGDC standard!")
                          )
      return

    # start tool
    mpFilePath = settings.value("tools/mp", "")
    errFilePath = settings.value("tools/err2html", "")

    tempPath = os.tempnam()
    temporaryMetafile = self.metaProvider.SaveToTempFile()
    result = ''

    try:
      import subprocess
      subprocess.check_call([mpFilePath, "-e", tempPath, temporaryMetafile], shell=throwShell, cwd=toolPath)

      if sys.hexversion >= 34013184:
        result = subprocess.check_output([errFilePath, tempPath], shell=throwShell, cwd=toolPath)
      else:
        # workaround for python < 2.7
        # ... stderr=subprocess.STDOUT, stdin=subprocess.PIPE ... ! F****D Python 2.5 bug on windows!
        err2htmlProc = subprocess.Popen([errFilePath, tempPath], shell=throwShell, cwd=toolPath, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, stdin=subprocess.PIPE)
        err2htmlProc.stdin.close()
        result = err2htmlProc.communicate()[0]

    except:
      QMessageBox.critical(self.iface.mainWindow(),
                           QCoreApplication.translate("Metatools", "Metatools"),
                           QCoreApplication.translate("Metatools", "MP tool can't be runing: ") + unicode(sys.exc_info()[1])
                          )
      return
    finally:
      if os.path.exists(tempPath):
          os.remove(tempPath)
      # explicit kill temporary metafile
      if os.path.exists(temporaryMetafile):
          os.remove(temporaryMetafile)

    # show result
    from metatoolsviewer import MetatoolsViewer
    dlg = MetatoolsViewer()
    dlg.setHtml(result)
    dlg.setWindowTitle(QCoreApplication.translate("Metatools", "MP result"))
    dlg.exec_()
Ejemplo n.º 8
0
  def execMp(self):
    settings = QSettings("NextGIS", "metatools")
    if not settings.value("tools/hasFGDC", False):
      return

    # check if metadata exists
    if not self.checkMetadata():
      return

    # check matadata standard
    standard = MetaInfoStandard.tryDetermineStandard(self.metaProvider)

    if standard != MetaInfoStandard.FGDC:
      QMessageBox.critical(self.iface.mainWindow(),
                           QCoreApplication.translate("Metatools", "Metatools"),
                           QCoreApplication.translate("Metatools", "MP tool support only FGDC standard!")
                          )
      return

    # start tool
    mpFilePath = settings.value("tools/mp", "")
    errFilePath = settings.value("tools/err2html", "")

    tempPath = os.tempnam()
    temporaryMetafile = self.metaProvider.SaveToTempFile()
    result = ''

    try:
      import subprocess
      subprocess.check_call([mpFilePath, "-e", tempPath, temporaryMetafile], shell=throwShell, cwd=toolPath)

      if sys.hexversion >= 34013184:
        result = subprocess.check_output([errFilePath, tempPath], shell=throwShell, cwd=toolPath)
      else:
        # workaround for python < 2.7
        # ... stderr=subprocess.STDOUT, stdin=subprocess.PIPE ... ! F****D Python 2.5 bug on windows!
        err2htmlProc = subprocess.Popen([errFilePath, tempPath], shell=throwShell, cwd=toolPath, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, stdin=subprocess.PIPE)
        err2htmlProc.stdin.close()
        result = err2htmlProc.communicate()[0]

    except:
      QMessageBox.critical(self.iface.mainWindow(),
                           QCoreApplication.translate("Metatools", "Metatools"),
                           QCoreApplication.translate("Metatools", "MP tool can't be runing: ") + unicode(sys.exc_info()[1])
                          )
      return
    finally:
      if os.path.exists(tempPath):
          os.remove(tempPath)
      # explicit kill temporary metafile
      if os.path.exists(temporaryMetafile):
          os.remove(temporaryMetafile)

    # show result
    from metatoolsviewer import MetatoolsViewer
    dlg = MetatoolsViewer()
    dlg.setHtml(result)
    dlg.setWindowTitle(QCoreApplication.translate("Metatools", "MP result"))
    dlg.exec_()
Ejemplo n.º 9
0
    def validateMetadataFile(self):
        # check if metadata exists
        if not self.checkMetadata():
            return

        # check matadata standard
        standard = MetaInfoStandard.tryDetermineStandard(self.metaProvider)
        if standard != MetaInfoStandard.FGDC:
            QMessageBox.critical(
                self.iface.mainWindow(),
                QCoreApplication.translate("Metatools", "Metatools"),
                QCoreApplication.translate(
                    "Metatools",
                    "Unsupported metadata standard! Only FGDC supported now!"))
            return

        from PyQt4.QtXmlPatterns import QXmlSchema, QXmlSchemaValidator
        # TODO: validate metadata file

        # setup xml schema
        schema = QXmlSchema()

        # setup handler
        self.handler = ErrorHandler(
            QCoreApplication.translate("Metatools", "Metadata is invalid"))
        schema.setMessageHandler(self.handler)

        # load schema from file
        xsdFilePath = self.pluginPath + '/xsd/fgdc/fgdc-std-001-1998.xsd'
        #if standard != MetaInfoStandard.FGDC:
        #    xsdFilePath = 'c:/xsd/gml/basicTypes.xsd' #   gmd/gmd.xsd'
        schemaUrl = QUrl(xsdFilePath)
        loadResult = schema.load(schemaUrl)
        if not loadResult or self.handler.errorOccured:
            QMessageBox.critical(
                self.iface.mainWindow(),
                QCoreApplication.translate("Metatools", "Metatools"),
                QCoreApplication.translate("Metatools",
                                           "Schema for validate not loaded!"))
            return

        #setup validator
        validator = QXmlSchemaValidator(schema)
        validator.setMessageHandler(self.handler)

        #validate
        metadata = self.metaProvider.getMetadata().encode('utf-8')
        if validator.validate(metadata):
            QMessageBox.information(
                self.iface.mainWindow(),
                QCoreApplication.translate("Metatools", "Metatools"),
                QCoreApplication.translate("Metatools", "Metadata is valid!"))
Ejemplo n.º 10
0
  def validateMetadataFile(self):
    # check if metadata exists
    if not self.checkMetadata():
      return

    # check matadata standard
    standard = MetaInfoStandard.tryDetermineStandard(self.metaProvider)
    if standard != MetaInfoStandard.FGDC:
      QMessageBox.critical(self.iface.mainWindow(),
                           QCoreApplication.translate("Metatools", "Metatools"),
                           QCoreApplication.translate("Metatools", "Unsupported metadata standard! Only FGDC supported now!")
                          )
      return


    from PyQt4.QtXmlPatterns import QXmlSchema, QXmlSchemaValidator
    # TODO: validate metadata file

    # setup xml schema
    schema = QXmlSchema()

    # setup handler
    self.handler = ErrorHandler(QCoreApplication.translate("Metatools", "Metadata is invalid"))
    schema.setMessageHandler(self.handler)

    # load schema from file
    xsdFilePath = self.pluginPath + '/xsd/fgdc/fgdc-std-001-1998.xsd'
    #if standard != MetaInfoStandard.FGDC:
    #    xsdFilePath = 'c:/xsd/gml/basicTypes.xsd' #   gmd/gmd.xsd'
    schemaUrl = QUrl(xsdFilePath)
    loadResult = schema.load(schemaUrl)
    if not loadResult or self.handler.errorOccured:
        QMessageBox.critical(self.iface.mainWindow(),
                             QCoreApplication.translate("Metatools", "Metatools"),
                             QCoreApplication.translate("Metatools", "Schema for validate not loaded!")
                            )
        return

    #setup validator
    validator = QXmlSchemaValidator(schema)
    validator.setMessageHandler(self.handler)

    #validate
    metadata = self.metaProvider.getMetadata().encode('utf-8')
    if validator.validate(metadata):
        QMessageBox.information(self.iface.mainWindow(),
                                QCoreApplication.translate("Metatools", "Metatools"),
                                QCoreApplication.translate("Metatools", "Metadata is valid!")
                               )
Ejemplo n.º 11
0
  def run_Editor(self):
      # check if metadata file exists
      if not self.checkMetadata():
        return
      standard = MetaInfoStandard.tryDetermineStandard(self.metaProvider)
      if standard != MetaInfoStandard.ISO19115:
        QMessageBox.critical(self.iface.mainWindow(),u"Μεταδεδομένα",u"Τα μεταδεδομένα δεν είναι συμβατά με Inspire!")
        return
 
      self.IsRunning=True
      dlg = Editor(self.iface,self.metaFilePath)
      dlg.setContent(self.metaProvider)
      dlg.exec_()
      self.IsRunning=False
      dlg.removetemplayer()
Ejemplo n.º 12
0
    def applyTemplates(self):
        # TODO: !!! Remake to metaprovider !!!
        # TODO: !!! Adding standard check !!!

        # TODO: check if there are some templates selected

        # get profile from settings
        settings = QSettings("NextGIS", "metatools")
        profile = "xml_iso19115.xml"
        if profile == "":
            QMessageBox.warning(
                self, self.tr("No profile"),
                self.
                tr("No profile selected. Please set default profile in plugin settings"
                   ))
            return

        profilePath = unicode(
            QDir.toNativeSeparators(
                os.path.join(currentPath, "xml_profiles", unicode(profile))))

        try:
            for layer in self.layers:
                # get metadata file path
                metaFilePath = utils.mdPathFromLayerPath(layer)

                # check if metadata file exists and create it if necessary
                if not os.path.exists(metaFilePath):
                    try:
                        shutil.copyfile(profilePath, metaFilePath)
                    except:
                        QMessageBox.warning(
                            self, self.tr("Metatools"),
                            self.tr("Metadata file can't be created: ") +
                            unicode(sys.exc_info()[1]))
                        continue

                # check metadata standard
                metaprovider = FileMetadataProvider(
                    unicode(layer))  #temporary code
                standard = MetaInfoStandard.tryDetermineStandard(metaprovider)
                if standard != MetaInfoStandard.ISO19115:
                    QMessageBox.warning(
                        self, self.tr("Metatools"),
                        self.
                        tr("File %s has unsupported metadata standard! Only ISO19115 supported now!"
                           ) % (layer))
                    continue

                if os.path.splitext(unicode(layer))[1].lower() not in (".shp",
                                                                       ".mif",
                                                                       ".tab"):
                    # extract image specific information
                    if self.chkUpdateImageInfo.isChecked():
                        utils.writeRasterInfo(layer, metaFilePath)

                    # generate preview
                    if self.chkGeneratePreview.isChecked():
                        utils.generatePreview(layer)
                else:
                    if self.chkUpdateImageInfo.isChecked():
                        utils.writeVectorInfo(layer, metaFilePath)

                # load metadata file
                metadata_file = QFile(metaFilePath)
                metaXML = QDomDocument()
                metaXML.setContent(metadata_file)

                # apply templates (BAD version - change to applier with standard)
                self.applyInstitutionTemplate(metaXML)
                self.applyLicenseTemplate(metaXML)
                self.applyWorkflowTemplate(metaXML)
                self.applyDatatypeTemplate(metaXML)
                self.applyLogFile(metaXML)

                # save metadata file (hmm.. why not QFile?)
                metafile = codecs.open(metaFilePath, "w", encoding="utf-8")
                metafile.write(metaXML.toString())
                metafile.close()

            QMessageBox.information(self, self.tr("Metatools"),
                                    self.tr("Done!"))

            # clear selection and disable Apply button
            self.lstLayers.clearSelection()
            self.layers = []
            self.btnApply.setEnabled(False)

            # save settings
            self.__saveSettings()
        except:
            QMessageBox.warning(
                self, self.tr("Metatools"),
                self.tr("Operation can't be completed: ") +
                unicode(sys.exc_info()[1]))
  def applyTemplates(self):
    # TODO: !!! Remake to metaprovider !!!
    # TODO: !!! Adding standard check !!!

    # TODO: check if there are some templates selected

    # get profile from settings
    settings = QSettings("NextGIS", "metatools")
    profile = settings.value("general/defaultProfile", "")
    if profile == "":
      QMessageBox.warning(self,
                          self.tr("No profile"),
                          self.tr("No profile selected. Please set default profile in plugin settings")
                         )
      return

    profilePath = unicode(QDir.toNativeSeparators(os.path.join(currentPath, "xml_profiles", unicode(profile))))

    try:
      for layer in self.layers:
        # get metadata file path
        metaFilePath = utils.mdPathFromLayerPath(layer)

        # check if metadata file exists and create it if necessary
        if not os.path.exists(metaFilePath):
          try:
            shutil.copyfile(profilePath, metaFilePath)
          except:
            QMessageBox.warning(self,
                                self.tr("Metatools"),
                                self.tr("Metadata file can't be created: ") + unicode(sys.exc_info()[1])
                               )
            continue

        # check metadata standard
        metaprovider = FileMetadataProvider(unicode(layer)) #temporary code
        standard = MetaInfoStandard.tryDetermineStandard(metaprovider)
        if standard != MetaInfoStandard.ISO19115:
          QMessageBox.warning(self,
                              self.tr("Metatools"),
                              self.tr("File %s has unsupported metadata standard! Only ISO19115 supported now!") % (layer))
          continue

        if os.path.splitext(unicode(layer))[1].lower() not in (".shp", ".mif", ".tab"):
            # extract image specific information
            if self.chkUpdateImageInfo.isChecked():
              utils.writeRasterInfo(layer, metaFilePath)

            # generate preview
            if self.chkGeneratePreview.isChecked():
              utils.generatePreview(layer)
        else:
            if self.chkUpdateImageInfo.isChecked():
              utils.writeVectorInfo(layer, metaFilePath)

        # load metadata file
        metadata_file = QFile(metaFilePath)
        metaXML = QDomDocument()
        metaXML.setContent(metadata_file)

        # apply templates (BAD version - change to applier with standard)
        self.applyInstitutionTemplate(metaXML)
        self.applyLicenseTemplate(metaXML)
        self.applyWorkflowTemplate(metaXML)
        self.applyDatatypeTemplate(metaXML)
        self.applyLogFile(metaXML)

        # save metadata file (hmm.. why not QFile?)
        metafile = codecs.open(metaFilePath, "w", encoding="utf-8")
        metafile.write(unicode(metaXML, "utf-8"))
        metafile.close()

      QMessageBox.information(self,
                              self.tr("Metatools"),
                              self.tr("Done!")
                             )

      # clear selection and disable Apply button
      self.lstLayers.clearSelection()
      self.layers = []
      self.btnApply.setEnabled(False)

      # save settings
      self.__saveSettings()
    except:
      QMessageBox.warning(self,
                          self.tr("Metatools"),
                          self.tr("Operation can't be completed: ") + unicode(sys.exc_info()[1])
                         )