gishelper.py 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. # -*- coding: utf-8 -*-
  2. import os
  3. import sys
  4. import json
  5. import utilsgis
  6. import utils
  7. import log
  8. import importlib, sys
  9. importlib.reload(sys)
  10. def run(fun, data):
  11. try:
  12. eval("{0}".format(fun))(data)
  13. # 输出成功信息 做交互用
  14. print("####OK####")
  15. except:
  16. msg = str(sys.exc_info()).decode('string-escape')
  17. print("####ERROR####" + msg)
  18. log.error(msg)
  19. # shp转json
  20. def shp2geojson(data):
  21. shpfile = data["shpfile"]
  22. geojson = data["geojson"]
  23. utilsgis.shp2geojson(shpfile, geojson)
  24. # json转shp
  25. def esriJson2shp(data):
  26. jsonfile = data["json"]
  27. shpfile = data["shpfile"]
  28. utilsgis.esriJson2shp(jsonfile, shpfile)
  29. # json存入SDE
  30. def esriJson2sde(data):
  31. jsonfile = data["json"]
  32. shpfile = data["table"]
  33. utilsgis.esriJson2sde(jsonfile, shpfile)
  34. # shp存入SDE
  35. def shp2sde(data):
  36. shpfile = data["shpfile"]
  37. table = data["table"]
  38. fields = None
  39. if data.get('fields') != None:
  40. fields = data["fields"];
  41. utilsgis.shp2sde(shpfile, table, fields)
  42. # SDE转shp
  43. def sde2shp(data):
  44. table = data["table"]
  45. where = data["where"]
  46. shpfile = data["shpfile"]
  47. utilsgis.sde2shp(table, shpfile, where)
  48. # CAD转SHP
  49. def dwgToShp(data):
  50. dwgfile = data["dwgfile"]
  51. espg = data["espg"]
  52. utilsgis.dwg2shp(dwgfile, espg)
  53. if __name__ == '__main__':
  54. # shp2sde({"shpfile":r"E:\99project\P008KJGH\SVN\branches\eeds\Mxds\Maps\fzxz.shp", "table":"KJGH.T_FZSS_FXRW_GIS",
  55. # "fields":[{"name":"RWBSM","type":"TEXT","value":"aab"},{"name":"RWLX","type":"TEXT","value":"ccd"}] })
  56. # shp2sde({"shpfile":"E:\\99project\\P008KJGH\\SVN\\trunk\\SoureCode\\2.Api\\QM.KJGH.GHSS\\QM.KJGH.GHSS\\files\\temp\\SHP_20210820024201.shp","table":"KJGH.T_FZSS_FXRW_GIS",
  57. # "fields":[{"name":"RWBSM","type":"TEXT","value":"d1b0737c231849dd9130403502c48daa"},{"name":"RWLX","type":"TEXT","value":"辅助选址"}]})
  58. # print(1234567)
  59. # esriJson2sde({"json":"E:\\99project\\P008KJGH\\SVN\\trunk\\SoureCode\\2.Api\\QM.KJGH.GHSS\\QM.KJGH.GHSS\\files\\temp\\SHP_20210820235143.json","table":"KJGH.T_FZSS_FXRW_GIS"})
  60. # log.info('开始入库')
  61. # sde2geojson({"table":"KJGH.T_FZSS_FZXZ_JG_GIS","geojson":"E:\\99project\\aaa.json","where":"\"RWBSM\"='a801628a23fd40d19e1115bba498ab2c'"})
  62. if len(sys.argv) == 3:
  63. fun = sys.argv[1]
  64. jsonData = utils.b64Decode(sys.argv[2])
  65. log.info(jsonData)
  66. run(fun, json.loads(jsonData))