日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

arcpy 土地整治报备坐标文件导出(解决内环问题)

發(fā)布時(shí)間:2023/12/10 编程问答 47 豆豆
生活随笔 收集整理的這篇文章主要介紹了 arcpy 土地整治报备坐标文件导出(解决内环问题) 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

一、工具截圖






二、導(dǎo)出文件

三、腳本

# coding=utf-8 import json import sys import arcpy import osdef set_encoding():"""set system encoding."""a, b, c = sys.stdin, sys.stdout, sys.stderrreload(sys)sys.setdefaultencoding("utf-8")sys.stdin, sys.stdout, sys.stderr = a, b, cdef ring_point_count(feature):"""count point number.:type feature: dict:param feature::return:"""count = 0for ring in feature["geometry"]["rings"]:count += len(ring)return countdef reset_num(coordinate):"""reset last one serial number.:type coordinate: list:param coordinate:"""coordinate[-1][0] = "J1"def load_json(path):"""load json file from disk.:type path: str:param path::return:"""with open(path.decode("utf-8"), "r") as f:return json.load(f)def feature_maps(features, configure):"""get a new feature json of list.:param features::type features: dict:param configure::type configure: dict:return: feature json of list"""maps = []feature_map = []point_max = int(configure["attr-desc"]["point-max-num"])count = 0index = 1for feature in features:rp_count = ring_point_count(feature)if (count + rp_count) > point_max:maps.append(feature_map)feature_map = []count = 0index = 1index_feature = {"index": str(index),"rp_count": str(rp_count),"attributes": feature["attributes"],"rings": feature["geometry"]["rings"]}feature_map.append(index_feature)count += rp_countindex += 1maps.append(feature_map)return mapsdef analyse_overview(feature, configure):"""get a overview info.:type configure: dict:type feature: dict:param feature::param configure::return:"""attributes = feature["attributes"]# 坐標(biāo)點(diǎn)個(gè)數(shù),地塊面積,地塊號(hào),地塊名稱,圖形屬性,圖幅號(hào),地塊用途,備注,@return "{coordinate_count},{area},{plot_num},{plot_name},{attribute},{sheet_designation},{land_use},{remark},@".format(coordinate_count=feature["rp_count"],area=attributes[configure["layer-meta"]["serial-num-field"]],plot_num=attributes[configure["layer-meta"]["area-field"]],plot_name=configure["attr-desc"]["prefix"] + feature["index"],attribute="",sheet_designation="",land_use="",remark=configure["attr-desc"]["layer-remark"])def analyse_coordinates(feature):"""get coordinates from feature.:type feature: dict:param feature::return:"""rings = feature["rings"]coordinates = [[["J" + str(index + 1), str(ring_index + 1), ",".join(list(map(str, coordinate[:])))] for index, coordinate inenumerate(ring)] for ring_index, ring in enumerate(rings)]return coordinatesdef create_dir(path):""":type path: str:param path:"""if not os.path.exists(path.decode("utf-8")):os.makedirs(path.decode("utf-8"))else:arcpy.AddError(path.decode("utf-8") + "目錄已存在")def write_header(f, configure):attr_desc = configure["attr-desc"]f.write("[屬性描述]\n")f.write("格式版本號(hào)=" + attr_desc["version"] + "\n")f.write("數(shù)據(jù)生產(chǎn)單位=" + attr_desc["producer"] + "\n")f.write("數(shù)據(jù)生產(chǎn)日期=" + attr_desc["date"] + "\n")f.write("坐標(biāo)系=" + attr_desc["coordinate"] + "\n")f.write("幾度分帶=" + attr_desc["degree"] + "\n")f.write("投影類型=" + attr_desc["projection"] + "\n")f.write("計(jì)量單位=" + attr_desc["unit"] + "\n")f.write("帶號(hào)=" + attr_desc["degree-num"] + "\n")f.write("精度=" + attr_desc["precision"] + "\n")f.write("轉(zhuǎn)換參數(shù)=" + attr_desc["conversion-parameter"] + "\n")f.write("[地塊坐標(biāo)]\n")def convert(export_info, configure):"""create a new file of coordinates.:type export_info: dict:param export_info:"""geojson = load_json(export_info["jsonfile"])features = geojson["features"]create_dir(export_info["export_dir"])for index, feature_map in enumerate(feature_maps(features, configure)):out_filename = "{0}\\{1}-{2}.txt".format(export_info["export_dir"], export_info["filename"], str(index))with open(out_filename.decode("utf-8"), "w") as f:write_header(f, configure)for feature in feature_map:overview = analyse_overview(feature, configure)f.write(overview)f.write("\n")for coordinate in analyse_coordinates(feature):reset_num(coordinate)for item in coordinate:f.write(",".join(item) + "\n")def analyse_path(workspace, temp_workspace, layer):"""get export information.:type layer: str:type temp_workspace: str:type workspace: str:param workspace::param temp_workspace::param layer::return:"""filename = os.path.basename(layer).split(".")[0]export_info = {"layer": layer,"filename": filename,"jsonfile": "{root}\\{filename}.json".format(root=temp_workspace, filename=filename),"export_dir": "{root}\\{layer_dir}".format(root=workspace, layer_dir=filename)}return export_infodef check_path(workspace, temp_workspace, layers, skip_repeat):"""check whether the path exists.:param workspace::param temp_workspace::param layers::return:"""export_infos = []for layer in layers:export_info = analyse_path(workspace, temp_workspace, layer)if skip_repeat == "true":if os.path.exists(export_info["jsonfile"].decode("utf-8")):continueelif os.path.exists(export_info["export_dir"].decode("utf-8")):continueelse:export_infos.append(export_info)else:if os.path.exists(export_info["jsonfile"].decode("utf-8")):arcpy.AddError(export_info["jsonfile"] + "目錄已存在")elif os.path.exists(export_info["export_dir"].decode("utf-8")):arcpy.AddError(export_info["export_dir"] + "目錄已存在")else:export_infos.append(export_info)return export_infosdef export_json(export_infos):"""export all json file:param export_infos:"""for export_info in export_infos:arcpy.FeaturesToJSON_conversion(export_info["layer"], export_info["jsonfile"])def export_all_file(export_infos, configure):"""export file:param export_infos::param configure:"""for export_info in export_infos:convert(export_info, configure)def export_file(workspace, temp_workspace, layers, configure, skip_repeat):"""export file.:type configure: dict:type layers: list:type temp_workspace: str:type workspace: str:param workspace::param temp_workspace::param layers::param configure:"""arcpy.AddMessage("檢查路徑是否重復(fù)......")export_infos = check_path(workspace, temp_workspace, layers, skip_repeat)arcpy.AddMessage("導(dǎo)出JSON格式......")export_json(export_infos)arcpy.AddMessage("導(dǎo)出標(biāo)準(zhǔn)格式......")export_all_file(export_infos, configure)arcpy.AddMessage("導(dǎo)出完畢")if __name__ == "__main__":set_encoding()workspace = arcpy.GetParameterAsText(0)temp_workspace = arcpy.GetParameterAsText(1)layers = arcpy.GetParameterAsText(2).split(";")skip_repeat = arcpy.GetParameterAsText(3)configure = {"layer-meta": {"serial-num-field": arcpy.GetParameterAsText(4),"area-field": arcpy.GetParameterAsText(5),},"attr-desc": {"version": arcpy.GetParameterAsText(6),"producer": arcpy.GetParameterAsText(7),"date": arcpy.GetParameterAsText(8),"coordinate": arcpy.GetParameterAsText(9),"degree": arcpy.GetParameterAsText(10),"projection": arcpy.GetParameterAsText(11),"unit": arcpy.GetParameterAsText(12),"degree-num": arcpy.GetParameterAsText(13),"precision": arcpy.GetParameterAsText(14),"conversion-parameter": arcpy.GetParameterAsText(15),"prefix": arcpy.GetParameterAsText(16),"point-max-num": arcpy.GetParameterAsText(17),"layer-remark": arcpy.GetParameterAsText(18)},"encode": arcpy.GetParameterAsText(19)}export_file(workspace, temp_workspace, layers, configure, skip_repeat)

總結(jié)

以上是生活随笔為你收集整理的arcpy 土地整治报备坐标文件导出(解决内环问题)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。