spotfileupload.py 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. # -*- coding: utf-8 -*-
  2. """
  3. ***************************************************************************
  4. spotfileupload.py
  5. ---------------------
  6. Date : November 2012
  7. Copyright : (C) 2012 by Victor Olaya
  8. Email : volayaf at gmail dot com
  9. ***************************************************************************
  10. * *
  11. * This program is free software; you can redistribute it and/or modify *
  12. * it under the terms of the GNU General Public License as published by *
  13. * the Free Software Foundation; either version 2 of the License, or *
  14. * (at your option) any later version. *
  15. * *
  16. ***************************************************************************
  17. """
  18. __author__ = 'wanger'
  19. __date__ = 'November 2024'
  20. __copyright__ = '(C) 2024, wanger'
  21. import os
  22. from osgeo import ogr, gdal
  23. from PyQt5.QtGui import QIcon
  24. from PyQt5.QtWidgets import QApplication
  25. from future.moves import sys
  26. from qgis.PyQt import QtWidgets
  27. from qgis.core import (QgsProcessing,
  28. QgsProcessingParameterFeatureSource,
  29. QgsProcessingParameterString,
  30. QgsProcessingParameterFile,
  31. QgsProcessingParameterDateTime,
  32. QgsProcessingParameterEnum,
  33. QgsProcessingParameterCrs,
  34. QgsProcessingParameterField,
  35. QgsProcessingParameterExtent,
  36. QgsProcessingParameterBoolean,
  37. QgsProcessingParameterProviderConnection,
  38. QgsProcessingParameterDatabaseSchema,
  39. QgsProcessingParameterDatabaseTable,
  40. QgsProviderRegistry,
  41. QgsProcessingException,
  42. QgsProcessingParameterDefinition,
  43. QgsProviderConnectionException,
  44. QgsDataSourceUri)
  45. from processing.algs.gdal.GdalAlgorithm import GdalAlgorithm
  46. from processing.algs.gdal.GdalUtils import GdalUtils
  47. from processing.tools.PrintUtils import printStr
  48. from processing.tools.StringUtils import getConnectionStr
  49. from processing.tools.GeoServer.Geoserver import Geoserver
  50. from processing.tools.PostgreSQL.PostgreSQL import PostgreSQL
  51. from processing.tools.system import isWindows
  52. pluginPath = os.path.normpath(os.path.join(
  53. os.path.split(os.path.dirname(__file__))[0], os.pardir))
  54. gdal.SetConfigOption("GDAL_FILENAME_IS_UTF8", "YES")
  55. gdal.SetConfigOption("SHAPE_ENCODING", "GBK")
  56. class SpotfileUpload(GdalAlgorithm):
  57. LOGIN_USER = "灵武市"
  58. SPOTFILE = 'SPOTFILE'
  59. def __init__(self):
  60. super().__init__()
  61. def initAlgorithm(self, config=None):
  62. self.addParameter(QgsProcessingParameterFile(self.SPOTFILE,
  63. self.tr('图斑数据'),
  64. optional=False, fileFilter='Compress Files (*.zip *.rar)'))
  65. def name(self):
  66. return 'spotfileupload'
  67. def icon(self):
  68. return QIcon(os.path.join(pluginPath, 'images', 'dbms', 'upload.png'))
  69. def displayName(self):
  70. return self.tr('图斑数据上传')
  71. def shortDescription(self):
  72. return self.tr('图斑数据上传')
  73. def tags(self):
  74. t = self.tr('import,into,postgis,database,vector').split(',')
  75. t.extend(super().tags())
  76. return t
  77. def group(self):
  78. return self.tr('图斑核查与传输')
  79. def groupId(self):
  80. return 'spot'
  81. # 判断数据是否为字符串
  82. def is_string(self, var):
  83. return isinstance(var, str)
  84. def getConsoleCommands(self, parameters, context, feedback, executing=True):
  85. return []
  86. def contains_keys(self, obj, keys):
  87. if isinstance(obj, dict):
  88. return all(key in obj.keys() for key in keys)
  89. elif hasattr(type(obj), '__dict__'):
  90. return all(key in obj.__dict__ for key in keys)
  91. else:
  92. raise ValueError("Invalid object type")
  93. def commandName(self):
  94. return "ogr2ogr"