spotfiledelete.py 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. # -*- coding: utf-8 -*-
  2. """
  3. ***************************************************************************
  4. spotfiledelete.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 QgsProcessingParameterFileDestination
  28. from qgis.core import (QgsProcessing,
  29. QgsProcessingParameterFeatureSource,
  30. QgsProcessingParameterString,
  31. QgsProcessingParameterFile,
  32. QgsProcessingParameterDateTime,
  33. QgsProcessingParameterEnum,
  34. QgsProcessingParameterCrs,
  35. QgsProcessingParameterField,
  36. QgsProcessingParameterExtent,
  37. QgsProcessingParameterBoolean,
  38. QgsProcessingParameterProviderConnection,
  39. QgsProcessingParameterDatabaseSchema,
  40. QgsProcessingParameterDatabaseTable,
  41. QgsProviderRegistry,
  42. QgsProcessingException,
  43. QgsProcessingParameterDefinition,
  44. QgsProviderConnectionException,
  45. QgsDataSourceUri)
  46. from processing.tools.requestUtils import getSpotFileList
  47. from processing.algs.gdal.GdalAlgorithm import GdalAlgorithm
  48. from processing.algs.gdal.GdalUtils import GdalUtils
  49. from processing.tools.PrintUtils import printStr
  50. from processing.tools.StringUtils import getConnectionStr
  51. from processing.tools.GeoServer.Geoserver import Geoserver
  52. from processing.tools.PostgreSQL.PostgreSQL import PostgreSQL
  53. from processing.tools.system import isWindows
  54. pluginPath = os.path.normpath(os.path.join(
  55. os.path.split(os.path.dirname(__file__))[0], os.pardir))
  56. gdal.SetConfigOption("GDAL_FILENAME_IS_UTF8", "YES")
  57. gdal.SetConfigOption("SHAPE_ENCODING", "GBK")
  58. class SpotfileDelete(GdalAlgorithm):
  59. LOGIN_USER = "admin"
  60. SPOTFILEDELETE = 'SPOTFILEDELETE'
  61. SPOTFILEOUT = 'SPOTFILEOUT'
  62. spotfilelist = []
  63. def __init__(self):
  64. super().__init__()
  65. def initAlgorithm(self, config=None):
  66. res = getSpotFileList(uploaduser=self.LOGIN_USER)
  67. self.spotfilelist = res["data"]
  68. names = []
  69. for row in self.spotfilelist:
  70. names.append(row["name"])
  71. self.addParameter(QgsProcessingParameterEnum(name=self.SPOTFILEDELETE,
  72. description=self.tr('图斑数据记录'),
  73. options=names))
  74. def name(self):
  75. return 'spotfiledelete'
  76. def icon(self):
  77. return QIcon(os.path.join(pluginPath, 'images', 'dbms', 'delete.png'))
  78. def displayName(self):
  79. return self.tr('图斑数据删除')
  80. def shortDescription(self):
  81. return self.tr('图斑数据删除')
  82. def tags(self):
  83. t = self.tr('import,into,postgis,database,vector').split(',')
  84. t.extend(super().tags())
  85. return t
  86. def group(self):
  87. return self.tr('图斑核查与传输')
  88. def groupId(self):
  89. return 'spot'
  90. # 判断数据是否为字符串
  91. def is_string(self, var):
  92. return isinstance(var, str)
  93. def getConsoleCommands(self, parameters, context, feedback, executing=True):
  94. print(parameters)
  95. return []
  96. def contains_keys(self, obj, keys):
  97. if isinstance(obj, dict):
  98. return all(key in obj.keys() for key in keys)
  99. elif hasattr(type(obj), '__dict__'):
  100. return all(key in obj.__dict__ for key in keys)
  101. else:
  102. raise ValueError("Invalid object type")
  103. def commandName(self):
  104. return "ogr2ogr"