当前位置: 首页 > news >正文

【ArcGIS_Python】使用arcpy脚本将shape数据转换为三维白膜数据

说明:

该专栏之前的文章中python脚本使用的是ArcMap10.6自带的arcpy(好几年前的文章),从本篇开始使用的是ArcGIS Pro 3.3.2版本自带的arcpy,需要注意不同版本对应的arcpy函数是存在差异的

数据准备:准备一个带高度属性的二维面图层shape文件

示例代码说明:

①2D要素类(Polygon)转换为3D要素类(PolygonZ)

②3D要素类(PolygonZ,三维表面)转3D要素类(MultiPatch,体,三维模型)

③3D要素类(MultiPatch)转3D对象场景图层包.slpk数据

# -*- coding: utf-8 -*-
import arcpy
from arcpy import env
import os
import sys
import shutil
import datetime,timestarttime = datetime.datetime.now()
output_dir = 'E:/Dataset/output'
# 检查文件夹是否存在
if os.path.exists(output_dir):# 如果文件夹不为空,则删除其中的所有文件和子文件夹for filename in os.listdir(output_dir):file_path = os.path.join(output_dir, filename)try:if os.path.isfile(file_path) or os.path.islink(file_path):os.unlink(file_path)  # 删除文件或符号链接elif os.path.isdir(file_path):shutil.rmtree(file_path)  # 删除子文件夹及其内容except Exception as e:print(f"无法删除 {file_path}。原因:{e}")print(f"文件夹 '{output_dir}' 已清空。")
else:print(f"文件夹 '{output_dir}' 不存在,无需清空。")
# 设置工作空间
env.workspace = output_dir
# 输入 Shapefile 文件路径
in_features = 'E:/Dataset/build/build.shp'
# 输出 Shapefile 文件名称
out_feature='build3d.shp'
# 设置高度字段
height_field ='height'
arcpy.ddd.FeatureTo3DByAttribute(in_features, out_feature, height_field)
print("2D要素类转换为3D要素类完成,文件类型为PolygonZ")
# 创建要素图层
layer_name_polygonz = "temp_layer_polygonz"  # 临时图层的名称
arcpy.MakeFeatureLayer_management(out_feature, layer_name_polygonz)
print("PolygonZ文件转临时图层文件完成")
# 输出3D要素类路径
output_feature_class='build3dmultipatce.shp'
# 执行 Layer3DToFeatureClass 工具
arcpy.ddd.Layer3DToFeatureClass(layer_name_polygonz,output_feature_class)
print("3D图层转换为3D要素类完成,文件类型为MultiPatch")
out_slpk='buildslpk.slpk'
# 创建要素图层
layer_name_multipatch = "temp_layer_multipatch"  # 临时图层的名称
arcpy.MakeFeatureLayer_management(output_feature_class, layer_name_multipatch)
print("MultiPatch文件转临时图层文件完成")
arcpy.management.Create3DObjectSceneLayerPackage(in_dataset=layer_name_multipatch,# 输入的3D模型数据out_slpk=out_slpk,# 输出的SLPK文件路径out_coor_system=None,# 使用输入数据的坐标系(与ArcGIS Pro默认行为一致)# 输出坐标系(设置为默认,即与输入数据相同)transform_method="",# 不进行坐标转换(与ArcGIS Pro默认行为一致) # 转换方法(可选)texture_optimization="None", # 不进行纹理优化(与ArcGIS Pro默认行为一致)# 纹理优化:ALL | DESKTOP | MOBILE | NONEtarget_cloud_connection=""# 不使用云连接(与ArcGIS Pro默认行为一致)# 目标云连接(可选)
)
print("3D对象场景图层包.slpk数据转换完成")
endtime = datetime.datetime.now()
times=endtime-starttime
times_seconds =times.seconds
print ("用时:",times_seconds,"s")

输出结果示例:

使用脚本完成slpk数据的生成,接下来一般是上传slpk数据到门户网站,发布为三维服务,给出之前的发布结果示例图:

http://www.lryc.cn/news/532670.html

相关文章:

  • 用Python获取股票数据并实现未来收盘价的预测
  • Rust 所有权特性详解
  • Gateway路由匹配规则详解
  • 项目实操:windows批处理拉取git库和处理目录、文件
  • 前端开发知识梳理 - HTMLCSS
  • nginx中的proxy_set_header参数详解
  • MapReduce是什么?
  • Text2Sql:开启自然语言与数据库交互新时代(3030)
  • 《图解设计模式》笔记(五)一致性
  • 华为支付-免密支付接入免密代扣说明
  • React组件中的列表渲染与分隔符处理技巧
  • 【Pytorch和Keras】使用transformer库进行图像分类
  • 快速了解 c++ 异常处理 基础知识
  • deepseek API 调用-python
  • 玩转Gin框架:Golang使用Gin完成登录流程
  • Linux学习笔记16---高精度延时实验
  • vue2:如何动态控制el-form-item之间的行间距
  • deepseek从网络拓扑图生成说明文字实例
  • 两种文件类型(pdf/图片)打印A4半张纸方法
  • HTB:UnderPass[WriteUP]
  • 【deepseek实战】绿色好用,不断网
  • MySQL 进阶专题:索引(索引原理/操作/优缺点/B+树)
  • 用NeuralProphet预测股价:AI金融新利器(附源码)
  • 【Elasticsearch】parent aggregation
  • IDEA使用Auto-dev+DeepSeek 10分钟快速集成,让java开发起飞
  • ASP.NET Core中间件Markdown转换器
  • 使用page assist浏览器插件结合deepseek-r1 7b本地模型
  • 【华为OD-E卷 - 108 最大矩阵和 100分(python、java、c++、js、c)】
  • 【Reading Notes】Favorite Articles from 2025
  • 云计算行业分析