main.py 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3. import os
  4. import sys
  5. import log
  6. import utils
  7. import json
  8. import arcpy
  9. from zbmx.zbmx import ModelBuider
  10. # from fzjbnt.fzjbnt import FzJbnt
  11. from fzxz.fzxz import Fzxz
  12. from fzxz.fzxzmap import FzxzMap
  13. from hgxfx.hgxfx import Hgxfx
  14. from ztt.ztt import Ztt
  15. from ctfx.ctfx import Ctfx
  16. from clipFeature.clipFeature import ClipFeature
  17. from xmydsyx.xmydsyx import Xmydsyx
  18. import importlib, sys
  19. importlib.reload(sys)
  20. def run(fun, data):
  21. try:
  22. switch = {
  23. 'ModelBuider': modelBuider,
  24. 'Fzxz': fzXzfx,
  25. 'FzxzMap': fzxzMap,
  26. # 'FzJbnt': fzJbnt,
  27. 'Hgxfx': hgxfx,
  28. 'Ztt': ztt,
  29. 'Ctfx': ctfx,
  30. 'Xmydsyx': xmydsyx,
  31. 'ClipFeature': clipFeature,
  32. }
  33. switch.get(fun, default())(data)
  34. except arcpy.ExecuteError:
  35. print("####ERROR####" + arcpy.GetMessages())
  36. log.error(arcpy.GetMessages())
  37. except:
  38. msg = str(sys.exc_info()).decode('string-escape')
  39. print("####ERROR####" + msg)
  40. log.error(msg)
  41. # 默认情况下执行的函数
  42. def default():
  43. print('No such case')
  44. # 模型构建
  45. def modelBuider(data):
  46. # root = os.path.dirname(os.path.abspath(__file__))
  47. # jsonData = os.path.join(root,"zbmx/data.json")
  48. # with open(jsonData, 'r')as fp:
  49. # data = json.load(fp)
  50. mp = ModelBuider(data)
  51. mp.run()
  52. # 辅助选址
  53. def fzXzfx(data):
  54. mp = Fzxz(data["bsm"])
  55. mp.run()
  56. # 辅助选址出图
  57. def fzxzMap(data):
  58. mp = FzxzMap()
  59. mp.run()
  60. # 合规性分析
  61. def hgxfx(data):
  62. mp = Hgxfx(data["bsm"])
  63. mp.run()
  64. # 冲突分析
  65. def ctfx(data):
  66. mp = Ctfx(data["bsm"])
  67. mp.run()
  68. # 数据裁剪
  69. def clipFeature(data):
  70. mp = ClipFeature()
  71. mp.run()
  72. # 项目用地适宜性分析
  73. def xmydsyx(data):
  74. mp = Xmydsyx(data["bsm"])
  75. mp.run()
  76. # 专题图
  77. def ztt(data):
  78. mp = Ztt(data)
  79. mp.run()
  80. # 辅助基本农田划定
  81. # def fzJbnt(data):
  82. # root = os.path.dirname(os.path.abspath(__file__))
  83. # jsonData = os.path.join(root, "fzjbnt/data.json")
  84. # with open(jsonData, 'r') as fp:
  85. # data = json.load(fp)
  86. #
  87. # mp = FzJbnt(data)
  88. # mp.run()
  89. if __name__ == "__main__":
  90. try:
  91. log.info("---------------------------------------------------------")
  92. fun = sys.argv[1]
  93. log.info(fun)
  94. if len(sys.argv) == 3:
  95. jsonData = utils.b64Decode(sys.argv[2])
  96. log.info(jsonData)
  97. print(jsonData)
  98. run(fun, json.loads(jsonData))
  99. elif len(sys.argv) == 2:
  100. run(fun, None)
  101. except arcpy.ExecuteError:
  102. print("####ERROR####" + arcpy.GetMessages())
  103. log.error(arcpy.GetMessages())
  104. except:
  105. msg = str(sys.exc_info()).decode('string-escape')
  106. print("####ERROR####" + msg)
  107. log.error(msg)