当前位置:网站首页>【ArcGIS自定义脚本工具】矢量文件生成扩大矩形面要素
【ArcGIS自定义脚本工具】矢量文件生成扩大矩形面要素
2022-07-03 11:55:00 【Salierib】
系列文章目录: ArcGIS自定义脚本工具
一、功能介绍
批量根据现有的要素(点、线、面)矢量文件(.shp)的范围生成扩大范围的矩形边界面要素文件(.shp)。扩大后面要素的坐标系与输入保持一致。输出矢量文件名格式(E_输入文件名.shp)
二、脚本代码
#!/usr/bin/python
# -*- coding: UTF-8 -*-
""" @File : CreateRetangleSHP.py @Author : salierib @Time : 2022/7/2 10:47 @QQ group: 582151631 @Version: """
import arcpy
import os
import arcgisscripting
shps = arcpy.GetParameterAsText(0)
outdir = arcpy.GetParameterAsText(1)
spacing = arcpy.GetParameterAsText(2)
shps = shps.split(";")
spacing = float(spacing)
def extents(fc):
extent = arcpy.Describe(fc).extent
west = extent.XMin
south = extent.YMin
east = extent.XMax
north = extent.YMax
return west, east, south, north
def text_create(out_txt_path, msg):
txt_file = open(out_txt_path, 'w')
txt_file.write(msg)
def rec_msg(xMin, yMin, xMax, yMax, spacing=0.2):
x1, y1 = xMin - spacing, yMin - spacing
x2, y2 = xMin - spacing, yMax + spacing
x3, y3 = xMax + spacing, yMax + spacing
x4, y4 = xMax + spacing, yMin - spacing
return x1, y1, x2, y2, x3, y3, x4, y4
for shp in shps:
out_corr = arcpy.Describe(shp).spatialReference
basename = os.path.basename(shp)[:-4]
xMin, xMax, yMin, yMax = extents(shp)
x1, y1, x2, y2, x3, y3, x4, y4 = rec_msg(xMin, yMin, xMax, yMax)
msg = """Polygon 0 0 0 {0} {1} 1.#QNAN 1.#QNAN 1 {2} {3} 1.#QNAN 1.#QNAN 2 {4} {5} 1.#QNAN 1.#QNAN 3 {6} {7} 1.#QNAN 1.#QNAN 4 {0} {1} 1.#QNAN 1.#QNAN END""".format(x1, y1, x2, y2, x3, y3, x4, y4, x1, y1)
out_txt = os.path.join(outdir, "E_%s.txt" % basename)
text_create(out_txt, msg)
gp = arcgisscripting.create()
inSep = "."
out_shp = os.path.join(outdir, "E_%s.shp" % basename)
gp.CreateFeaturesFromTextFile(out_txt, inSep, out_shp, out_corr)
三、工具参数
四、工具界面
边栏推荐
猜你喜欢
(构造笔记)ADT与OOP
TOGAF认证自学宝典V2.0
[download attached] password acquisition tool lazagne installation and use
公纵号发送提示信息(用户微服务--消息微服务)
Summary of development issues
(construction notes) ADT and OOP
Basic knowledge of OpenGL (sort it out according to your own understanding)
Shutter widget: centerslice attribute
【ManageEngine】IP地址扫描的作用
剑指Offer03. 数组中重复的数字【简单】
随机推荐
云计算未来 — 云原生
[official MySQL document] deadlock
Record your vulnhub breakthrough record
JVM memory model
If you can't learn, you have to learn. Jetpack compose writes an im app (I)
Flutter Widget : Flow
elastic_ L04_ introduction. md
(构造笔记)从类、API、框架三个层面学习如何设计可复用软件实体的具体技术
Adult adult adult
[combinatorics] permutation and combination (summary of permutation and combination content | selection problem | set permutation | set combination)
Togaf certification self-study classic v2.0
regular expression
(construction notes) grasp learning experience
双链笔记·思源笔记综合评测:优点、缺点、评价
Use of QT OpenGL camera
225. Implement stack with queue
If you can't learn, you have to learn. Jetpack compose writes an im app (II)
Wechat applet - basic content
Dart: About zone
wpa_ cli