玩蛇网提供最新Python编程技术信息以及Python资源下载!
您现在的位置: 玩蛇网首页 > Python源码实例 > 正文内容

今天用python实现坐标点生成shp图斑教程

今天来讲讲例用python实现坐标点生成shp图斑的教程,利用坐标点text生成shp图斑同时按照text中的编码对其进行编码,text文件格式见下面代码。
 
 

 

1. [文件] create_polygon.py ~ 1KB

#coding:utf-8
import arcpy
from arcpy import env
env.workspace = 'g:/python'    ## 设置工作空间
file = open('11.txt')        ## 读取text文件
def create_polygon(coord_l):
    point = arcpy.Point()
    array = arcpy.Array()
    featureList = []
    for feature in coord_l:
        for coord in feature:
            point.X = coord[0]
            point.Y = coord[1]
            array.add(point)

        array.add(array.getObject(0))
        polygon = arcpy.Polygon(array)
        array.removeAll()
        featureList.append(polygon)
    return featureList

li = []
for line in file:
    li.append(map(float,line.split()))  ##将坐标导入列表
coord_l = []
code_l = []
for i in range(len(li)):
    if len(li[i]) == 2:
        code_l.append(str(int(li[i][0]))+str(int(li[i][1])))
        coord_l.append([])
    else:
        coord_l[len(coord_l)-1].append([li[i][1],li[i][2]])

poly = create_polygon(coord_l)
arcpy.CopyFeatures_management(poly,'g:/python/polygons.shp')  ##设置生成的shp文件名
arcpy.AddField_management('polygons.shp','code','TEXT')
cur = arcpy.UpdateCursor('polygons.shp')
i = 0
for row in cur:
    row.code = code_l[i]
    cur.updateRow(row)
    i = i + 1
del cur,row



    
    

2. [文件] 示例.txt ~ 368B

0	1	
0	116.362588	39.949164
1	116.37193	39.952262
2	116.377051	39.95446
3	116.378614	39.954585
4	116.385998	39.954972
5	116.400173	39.955179
6	116.400424	39.946979
7	116.401529	39.946938
0	2	
0	116.362848	39.929366
1	116.379925	39.930037
2	116.380006	39.928474
3	116.389905	39.928875
4	116.391208	39.928702
5	116.394783	39.928771
6	116.395385	39.928585

玩蛇网文章,转载请注明出处和文章网址:http://www.iplaypy.com/code/c448.html

相关文章 Recommend

玩蛇网Python互助QQ群,欢迎加入-->: 106381465 玩蛇网Python新手群
修订日期:2017年01月04日 - 15时26分40秒 发布自玩蛇网

我要分享到:

必知PYTHON教程 Must Know PYTHON Tutorials

必知PYTHON模块 Must Know PYTHON Modules