arcpy 解析土地整治报备坐标点为是矢量面

2023-10-06 03:01

本文主要是介绍arcpy 解析土地整治报备坐标点为是矢量面,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

数据格式:

代码片段:

# coding: utf-8import os
import arcpy
import json
import sysdef set_encoding():a, b, c = sys.stdin, sys.stdout, sys.stderrreload(sys)sys.setdefaultencoding('utf-8')sys.stdin, sys.stdout, sys.stderr = a, b, cdef get_files(root):files = os.listdir(root)return filesdef create_feature(root, workspace, sp_ref):temp_dic_root, database = get_path(workspace)temp_dic = os.path.join(temp_dic_root, "temp_data")if not os.path.exists(temp_dic):os.makedirs(temp_dic)for sourcefile in get_files(root):if not sourcefile.endswith(".txt"):continuefilename = os.path.splitext(sourcefile)[0]out_file = workspace + "\\v_" + filenamejsonfile = os.path.join(temp_dic, filename + ".json")sourcefile = root + "\\" + sourcefilecoordinates = analysis(sourcefile)if create_geojson(jsonfile, coordinates, sp_ref):arcpy.JSONToFeatures_conversion(jsonfile, out_file)arcpy.AddMessage("info: " + filename)else:arcpy.AddWarning("waring: " + filename)def create_geojson(targetfile, coordinates, sp_ref):features_template = {"displayFieldName": "","fieldAliases": {"FID": "FID"},"geometryType": "esriGeometryPolygon","spatialReference": {"wkt": ""},"fields": [{"name": "FID","type": "esriFieldTypeOID","alias": "FID"}],"features": []}features_template["spatialReference"]["wkt"] = sp_reffor fid, item in enumerate(coordinates):features_template["features"].append(get_geometry(fid, item))with open(targetfile, "w") as out_file:out_file.write(json.dumps(features_template))return Truedef get_geometry(fid, rings):feature_template = {"attributes": {"FID": 0}, "geometry": {"rings": []}}feature_template["attributes"]["FID"] = fidtemp = [ring for index, ring in rings.items()]feature_template["geometry"]["rings"].extend(temp)return feature_templatedef analysis(sourcefile):geometry = []rings = {}with open(sourcefile, "r") as in_file:line = in_file.readline()while line:flag1 = "@" in line.replace("\n", "").split(",")flag2 = line.startswith("J")if not (flag1 or flag2):line = in_file.readline()continueif flag1:geometry.append(rings)rings = {}elif flag2:temp = line.split(",")ring_index = temp[1]ring_part = list(map(float, reversed(temp[2:])))if not rings.has_key(ring_index):rings[ring_index] = []rings[ring_index].append(ring_part)line = in_file.readline()geometry.append(rings)geometry.pop(0)return geometrydef get_path(path):temps = path.split('\\')result = []if '.' in temps[-1]:root = "\\".join(temps[0:-1])result.append(root)result.append(temps[-1])return resultif __name__ == "__main__":set_encoding()root = arcpy.GetParameterAsText(0)workspace = arcpy.GetParameterAsText(1)sp_ref = arcpy.GetParameterAsText(2)sp_ref = sp_ref.replace("\'", "\"")create_feature(root, workspace, sp_ref)

 工具参数:

工具界面:

这篇关于arcpy 解析土地整治报备坐标点为是矢量面的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/152681

相关文章

Qt实现网络数据解析的方法总结

《Qt实现网络数据解析的方法总结》在Qt中解析网络数据通常涉及接收原始字节流,并将其转换为有意义的应用层数据,这篇文章为大家介绍了详细步骤和示例,感兴趣的小伙伴可以了解下... 目录1. 网络数据接收2. 缓冲区管理(处理粘包/拆包)3. 常见数据格式解析3.1 jsON解析3.2 XML解析3.3 自定义

使用Python实现矢量路径的压缩、解压与可视化

《使用Python实现矢量路径的压缩、解压与可视化》在图形设计和Web开发中,矢量路径数据的高效存储与传输至关重要,本文将通过一个Python示例,展示如何将复杂的矢量路径命令序列压缩为JSON格式,... 目录引言核心功能概述1. 路径命令解析2. 路径数据压缩3. 路径数据解压4. 可视化代码实现详解1

Golang HashMap实现原理解析

《GolangHashMap实现原理解析》HashMap是一种基于哈希表实现的键值对存储结构,它通过哈希函数将键映射到数组的索引位置,支持高效的插入、查找和删除操作,:本文主要介绍GolangH... 目录HashMap是一种基于哈希表实现的键值对存储结构,它通过哈希函数将键映射到数组的索引位置,支持

Python使用getopt处理命令行参数示例解析(最佳实践)

《Python使用getopt处理命令行参数示例解析(最佳实践)》getopt模块是Python标准库中一个简单但强大的命令行参数处理工具,它特别适合那些需要快速实现基本命令行参数解析的场景,或者需要... 目录为什么需要处理命令行参数?getopt模块基础实际应用示例与其他参数处理方式的比较常见问http

Python利用ElementTree实现快速解析XML文件

《Python利用ElementTree实现快速解析XML文件》ElementTree是Python标准库的一部分,而且是Python标准库中用于解析和操作XML数据的模块,下面小编就来和大家详细讲讲... 目录一、XML文件解析到底有多重要二、ElementTree快速入门1. 加载XML的两种方式2.

Java的栈与队列实现代码解析

《Java的栈与队列实现代码解析》栈是常见的线性数据结构,栈的特点是以先进后出的形式,后进先出,先进后出,分为栈底和栈顶,栈应用于内存的分配,表达式求值,存储临时的数据和方法的调用等,本文给大家介绍J... 目录栈的概念(Stack)栈的实现代码队列(Queue)模拟实现队列(双链表实现)循环队列(循环数组

使用Python从PPT文档中提取图片和图片信息(如坐标、宽度和高度等)

《使用Python从PPT文档中提取图片和图片信息(如坐标、宽度和高度等)》PPT是一种高效的信息展示工具,广泛应用于教育、商务和设计等多个领域,PPT文档中常常包含丰富的图片内容,这些图片不仅提升了... 目录一、引言二、环境与工具三、python 提取PPT背景图片3.1 提取幻灯片背景图片3.2 提取

java解析jwt中的payload的用法

《java解析jwt中的payload的用法》:本文主要介绍java解析jwt中的payload的用法,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录Java解析jwt中的payload1. 使用 jjwt 库步骤 1:添加依赖步骤 2:解析 JWT2. 使用 N

Python中__init__方法使用的深度解析

《Python中__init__方法使用的深度解析》在Python的面向对象编程(OOP)体系中,__init__方法如同建造房屋时的奠基仪式——它定义了对象诞生时的初始状态,下面我们就来深入了解下_... 目录一、__init__的基因图谱二、初始化过程的魔法时刻继承链中的初始化顺序self参数的奥秘默认

Java 正则表达式URL 匹配与源码全解析

《Java正则表达式URL匹配与源码全解析》在Web应用开发中,我们经常需要对URL进行格式验证,今天我们结合Java的Pattern和Matcher类,深入理解正则表达式在实际应用中... 目录1.正则表达式分解:2. 添加域名匹配 (2)3. 添加路径和查询参数匹配 (3) 4. 最终优化版本5.设计思