python arcgis出图,界址点成果表,生成界址点

-- coding: utf-8 --

import win32com.client
import xlrd, time
import xlwt, os, traceback
from site import addsitedir
from sys import executable
import sys, time
from os import path
interpreter = executable
sitepkg = path.dirname(interpreter) + “\temp\Lib\site-packages”
addsitedir(sitepkg)
import math, arcpy, shutil
import sys
reload(sys)
sys.setdefaultencoding(‘utf8’) # 设置默认编码格式为’utf-8’
#计算两点的距离
def distance1(x1, y1, x2, y2):
return math.sqrt((x2-x1)**2+(y2-y1)**2)

def distance(x1, y1, x2, y2):
return math.sqrt((x2-x1)**2+(y2-y1)**2)

#############################添加界址点成果表##############################
def line_width(horiLine, x, y, len1):
hori_Clone = horiLine.clone(“_atrr”)
hori_Clone.elementPositionX = x
hori_Clone.elementPositionY = y
hori_Clone.elementWidth = len1

def line_height(horiLine, x, y, len1):
hori_Clone = horiLine.clone(“_atrr”)
hori_Clone.elementPositionX = x
hori_Clone.elementPositionY = y
hori_Clone.elementHeight = len1

def mian_copy(horiLine, x, y, h, w):
hori_Clone = horiLine.clone(“_atrr”)
hori_Clone.elementPositionX = x
hori_Clone.elementPositionY = y
hori_Clone.elementHeight = h
hori_Clone.elementWidth = w

def text_copy(tText, x, y , text):
tText = tText.clone(“_atrr”)
tText.text = str(text)
tText.elementPositionY =y
tText.elementPositionX = x

def yess(X1, Y1, X2, Y2, tem, len_1):
w = X1 - 1
e = Y1 - 1
x1 = 1
y1 = 1
x2 = X2 - w
y2 = Y2 - e
k = ((y2-y1)/(x2-x1))*(y2-y1)/(x2-x1)

a = 1 + k
b = -2*(1+k)
c = x1*x1*(1+k) - len_1 * len_1*k
x = yes(a, b, c)[tem]
y = (x-x1)*(x2-x1)/(y2-y1) + y1
return y+w, x +e

def jzd_cgb(mapdoc, list_jzd, mj, XMin, YMin, bl):
line_h = arcpy.mapping.ListLayoutElements(mapdoc, “”, “line_h”)[0]
line_s = arcpy.mapping.ListLayoutElements(mapdoc, “”, “line_s”)[0]
text_jzd = arcpy.mapping.ListLayoutElements(mapdoc, “”, “text_jzd”)[0]
text_xy = arcpy.mapping.ListLayoutElements(mapdoc, “”, “text_xy”)[0]
mian = arcpy.mapping.ListLayoutElements(mapdoc, “”, “mian”)[0]
jzdt = arcpy.mapping.ListLayoutElements(mapdoc, “”, “jzdt”)[0]
jzdh = arcpy.mapping.ListLayoutElements(mapdoc, “”, “jzdh”)[0]
# horiLine = arcpy.mapping.ListLayoutElements(mapdoc, “GRAPHIC_ELEMENT”, “app”)[0]
sl = 0
sl_y = 2.1
z_dj = 0#点数
for xys in list_jzd:
sls = sl * 4.72
# list_jzd = list_jzd + list_jzd[:1]
a = len(list_jzd[xys])
##########################
######设置成果表的左下角坐标
#############################
sls_x = sls
sls_y = sl_y
jzd_x = 15.2555 - sls_x
jzd_y = sls_y
z_dj += a
if z_dj >= 15:
sl += 1
sl_y = 2.1
z_dj = 0
else:
sl_y = a * 0.3 + jzd_y + 0.3 + 0.7
print(z_dj)
#############################
###########添加界址点成果表##
############################

    sum_h = a * 0.3 + 0.3 + 0.7
    mian_copy(mian, jzd_x, jzd_y, sum_h, 4.72)
    sum_h = sum_h + jzd_y
    i = 1
    # 放置注记
    for xyz in list_jzd[xys]:
        xy = xyz[1:3]
        xh = xyz[0]
        text_copy(text_xy, jzd_x + 1.495, sum_h - 0.553 - 0.3 * i, '%.3f' % xy[1])  # x
        text_copy(text_xy, jzd_x + 3.005, sum_h - 0.553 - 0.3 * i, '%.3f' % xy[0])  # y
        if i != a:
            bc = round(distance(xy[0], xy[1], list_jzd[xys][i][1], list_jzd[xys][i][2]), 2)
            text_copy(text_xy, jzd_x + 0.38, sum_h - 0.553 - 0.3 * i, 'J%s' % xh)  # 序号
            output_point(xy[0], xy[1], 'J%s' % xh, XMin, YMin, bl, jzdt, jzdh, mj[xys][1])
            if list_jzd[xys][i][0] - xh < 2:
                text_copy(text_xy, jzd_x + 4.2646, sum_h - 0.553 - 0.15 - 0.3 * i, bc)  # 边长
        else:
            text_copy(text_xy, jzd_x + 0.38, sum_h - 0.553 - 0.3 * i, 'J%s' % xh)  # 序号
        line_width(line_h, jzd_x, sum_h - 0.7 - 0.3 * i, 3.72)
        line_width(line_h, jzd_x + 3.72, sum_h - 0.55 - 0.3 * i, 1)
        i += 1
    # 标题右下角的y坐标
    h = a * 0.3 + jzd_y + 0.3
    # 画边长最后一根横线
    # line_width(line_h, 25.9, 2.95, 1)
    # 画界线内面积横线
    line_width(line_h, jzd_x, jzd_y, 4.72)
    line_width(line_h, jzd_x, jzd_y + 0.3, 4.72)
    text_copy(text_xy, jzd_x + 2.402, jzd_y + 0.158, '界线内面积:%s平方米 合%s公顷' % (round(mj[xys][0], 2), round(mj[xys][0] / 10000, 4)))
    # 画标题横线
    line_width(line_h, jzd_x, h, 4.72)
    line_width(line_h, jzd_x, h + 0.3, 4.72)
    line_width(line_h, jzd_x, h + 0.7, 4.72)
    text_copy(text_xy, jzd_x + 0.38, sum_h - 0.553, '点号')
    text_copy(text_xy, jzd_x + 1.495, sum_h - 0.553, 'X')
    text_copy(text_xy, jzd_x + 2.9321, sum_h - 0.553, 'Y')
    text_copy(text_xy, jzd_x + 4.2646, sum_h - 0.553, '边长')
    text_copy(text_jzd, jzd_x + 2.3193, sum_h - 0.2004, '界址点成果表')
    # 画竖线
    height = a * 0.3 + 0.3
    line_height(line_s, jzd_x, jzd_y, height + 0.7)
    line_height(line_s, jzd_x + 0.75, jzd_y + 0.3, height)
    line_height(line_s, jzd_x + 2.27, jzd_y + 0.3, height)
    line_height(line_s, jzd_x + 3.72, jzd_y + 0.3, height)

def select_ssnyd(path_ssnyd, name_zd, value_zd, tj):
list_ssnyd = {}
if tj == 0:
#qry = ‘“FID” LIKE ’ + "’%%‘"
qry = ‘’
else:
qry = ‘“%s” LIKE ’ % name_zd + "’%s’"%value_zd
print qry
xmmc = 1
tem = 1
ye_tem = 1
list1 = {}
list_mj = {}
with arcpy.da.SearchCursor(path_ssnyd, (“SHAPE@”, “SHAPE@AREA”, “SHAPE@XY”, “FID”), qry) as cursor:#, qry
for row in cursor:
list_jzd = []
for part in row[0]:
i = 0
for point in part:
try:
if i == 0:
x = point.X
y = point.Y
list_jzd.append([tem, point.X, point.Y])
tems = tem
tem += 1
if distance1(point.X, point.Y, part[i-1].X, part[i-1].Y) > 2:
if i != len(part) - 1:
list_jzd.append([tem, point.X, point.Y])
tem += 1
except:
pass
i += 1
list_jzd.append([tems, x, y])
ye_tem += 1
mj = round(row[1],2)
list1[ye_tem] = list_jzd
list_mj[ye_tem] = [mj, row[2]]
xmmc += 1
return list1, list_mj

import math
def yes(a, b, c):
# a = float(input(“请输入a的值:”))
# b = float(input(“请输入b的值:”))
# c = float(input(“请输入c的值:”))
d=b**2-4ac
if (d<0):
print(“无解”)
else:
e = math.sqrt(d)
x1=((-b+e)/(2a))#调用math模块中sqrt开平方函数
x2=((-b-e)/(2
a))
return x1, x2

def output_point(x, y, text, XMin, YMin, bl, jzdt, jzdh, xy):
print xy
x = (x - XMin) / bl + 1
y = (y - YMin) / bl + 2.1
x1 = (xy[0] - XMin) / bl + 1
y1 = (xy[1] - YMin) / bl + 2.1
if y > y1:
tem = 0
else:
tem = 1
x1, y1 = yess(x, y, x1, y1, tem, 0.4)
text_copy(jzdh, x1, y1, text)
hori_Clone = jzdt.clone(“_atrr”)
hori_Clone.elementPositionX = x
hori_Clone.elementPositionY = y

def out_put_jpg(path, zty, ztrq, xmmc, sctj, ctgs, fbl, path_ct, list_1, list_scmj, path_adddata, name_zd, value_zd, tj, list_jpg_path):

path_mxd = os.path.join(path, '地类还原', 'rcct1.mxd')
mapdoc = arcpy.mapping.MapDocument(path_mxd)
layers = arcpy.mapping.ListLayers(mapdoc)
listdf = arcpy.mapping.ListDataFrames(mapdoc)
# 替换路径
a, b = os.path.split(path_adddata)
c, d = os.path.splitext(b)
layers[0].replaceDataSource(a, "SHAPEFILE_WORKSPACE", c)
if tj == 0:
    qry = ''
    #qry = '"%s" LIKE ' % name_zd + "'%%'"
else:
    qry = '"%s" LIKE ' % name_zd + "'%s'" % value_zd
    xmmc = value_zd
layers[0].definitionQuery = qry
arcpy.SelectLayerByAttribute_management(layers[0], "ADD_TO_SELECTION", qry)
listdf[0].zoomToSelectedFeatures()  # 缩放至图层
listdf[0].scale = int(listdf[0].scale * 1.6 / 100 + 1) * 100
Extent = listdf[0].extent
XMin = Extent.XMin
XMax = Extent.XMax
YMin = Extent.YMin
YMax = Extent.YMax
bl =(XMax-XMin)/19
jzd_cgb(mapdoc, list_1, list_scmj, XMin, YMin, bl)
arcpy.SelectLayerByAttribute_management(layers[0], "CLEAR_SELECTION")
#设置标题
bt_xmmc = arcpy.mapping.ListLayoutElements(mapdoc, "", "xmmc")[0]
bt_zty = arcpy.mapping.ListLayoutElements(mapdoc, "", "zty")[0]
bt_ztrq = arcpy.mapping.ListLayoutElements(mapdoc, "", "ztrq")[0]
bt_ztrq1 = arcpy.mapping.ListLayoutElements(mapdoc, "", "ztrq1")[0]
if len(xmmc) > 10:
    bt_xmmc.text = '%s\n土地利用总体规划(2010-2020)(局部)' % xmmc
else:
    bt_xmmc.text = '%s土地利用总体规划(2010-2020)(局部)'%xmmc
bt_zty.text = '制图员:%s'%zty
bt_ztrq.text = '制图日期:%s'%ztrq
bt_ztrq1.text = '%s'%ztrq
#输出规划图
yx_jpg = os.path.join(path_ct, 'ght_%s.jpg' % xmmc)
list_jpg_path.append(yx_jpg)
arcpy.mapping.ExportToJPEG(mapdoc, yx_jpg, resolution=int(fbl))
mapdoc.saveACopy(os.path.join(path_ct, 'ght_%s.mxd'% xmmc))

#输出现状图
#移除规划图图例
txtl = arcpy.mapping.ListLayoutElements(mapdoc, "", "txtl_ght")[0]
txtl.elementPositionX = -8
txtl.elementPositionY = 2.1
#添加现状图图例
txtl = arcpy.mapping.ListLayoutElements(mapdoc, "", "txtl_xzt")[0]
txtl.elementPositionX = 1
txtl.elementPositionY = 2.1
if len(xmmc) > 15:
    bt_xmmc.text = '%s2018年度土地利用现状(局部)' % xmmc
else:
    bt_xmmc.text = '%s\n2018年度土地利用现状(局部)' % xmmc
arcpy.mapping.RemoveLayer(listdf[0], layers[1])
layers[2].showLabels = True
yx_jpg = os.path.join(path_ct, 'xzt_%s.jpg' % xmmc)
list_jpg_path.append(yx_jpg)
arcpy.mapping.ExportToJPEG(mapdoc, yx_jpg, resolution=int(fbl))
mapdoc.saveACopy(os.path.join(path_ct, 'xzt_%s.mxd' % xmmc))
del mapdoc

def selecte_zd(path_shp, name_zd):
list1 = []
with arcpy.da.SearchCursor(path_shp, (name_zd)) as cursor:#, qry
for row in cursor:
list1.append(row[0])
return list(set(list1))

def ye_main():
list_jpg_path = []
path = os.path.join(os.path.split(os.path.split(sys.argv[0])[0])[0]).decode(“gbk”)
file2 = open(os.path.join(path, ‘process_data’, ‘output.txt’), ‘w+’)
try:
xmxx = {}
with open(os.path.join(path, ‘process_data’, ‘select_rcct.txt’)) as f:
for line in f.readlines():
list_txt = line.replace(‘\n’, ‘’).split(‘$’)
xmxx[list_txt[0]] = list_txt[1]
zty = xmxx[‘制图员’]
ztrq = xmxx[‘制图日期’]
xmmc = xmxx[‘项目名称’]
sctj = xmxx[‘输出条件’]
ctgs = xmxx[‘出图格式’]
fbl = xmxx[‘分辨率’]
path_ct = xmxx[‘保存路径’]
path_adddata = xmxx[‘出图路径’]
name_zd = xmxx[‘字段名称’]
if sctj == ‘全部输出为一张’:
list_1, list_scmj = select_ssnyd(path_adddata, ‘’, ‘’, 0)
out_put_jpg(path, zty, ztrq, xmmc, sctj, ctgs, fbl, path_ct, list_1, list_scmj, path_adddata, ‘’,‘’,0, list_jpg_path)
else:
list_name_zd = selecte_zd(path_adddata, name_zd)
for value_zd in list_name_zd:
list_1, list_scmj = select_ssnyd(path_adddata, name_zd, value_zd, 1)
out_put_jpg(path, zty, ztrq, xmmc, sctj, ctgs, fbl, path_ct, list_1, list_scmj, path_adddata, name_zd, value_zd, 1, list_jpg_path)
file2.write(‘\n’.join(list_jpg_path))
except:
file2.write(‘出错了’.encode(‘gbk’))
file2.write(‘%s’%traceback.format_exc())

file2.close()

if name == ‘main’:
ye_main()

  • 0
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

DK业

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值