zoukankan      html  css  js  c++  java
  • arcpy利用XY创建点


    # -*- coding: utf-8 -*-
    """
    Created on Sun Apr 7 15:32:24 2019
    @author:
    """

    # XYTableToPoint.py
    # Description: Creates a point feature class from input table

    # import system modules
    import arcpy
    import csv
    # Set environment settings
    import os
    rootdir =
    outpath=

    list = os.listdir(rootdir) #列出文件夹下所有的目录与文件
    for i in range(0,len(list)):
    path = os.path.join(rootdir,list[i])
    print path
    if os.path.isfile(path):
    # Set the local variables
    outputname = path[40:57]+"_"+path[58:73]+".shp"
    print outputname
    spatRef = arcpy.SpatialReference("WGS 1984") #"WGS 1984"
    in_table = path
    with open(in_table,'rb') as csvfile:
    reader = csv.reader(csvfile)
    column1 = [row[0] for row in reader]
    with open(in_table,'rb') as csvfile:
    reader = csv.reader(csvfile)
    column2 = [row[1] for row in reader]
    with open(in_table,'rb') as csvfile:
    reader = csv.reader(csvfile)
    end_lon = [row[2] for row in reader]
    with open(in_table,'rb') as csvfile:
    reader = csv.reader(csvfile)
    end_lat = [row[3] for row in reader]
    with open(in_table,'rb') as csvfile:
    reader = csv.reader(csvfile)
    distance = [row[4] for row in reader]
    with open(in_table,'rb') as csvfile:
    reader = csv.reader(csvfile)
    speed = [row[5] for row in reader]
    with open(in_table,'rb') as csvfile:
    reader = csv.reader(csvfile)
    angle = [row[6] for row in reader]
    with open(in_table,'rb') as csvfile:
    reader = csv.reader(csvfile)
    u = [row[7] for row in reader]
    with open(in_table,'rb') as csvfile:
    reader = csv.reader(csvfile)
    v = [row[8] for row in reader]

    out_feature_class = "ice vector"
    x_coords = column1 #"longitude"
    y_coords = column2 # "latitude"
    fc=arcpy.CreateFeatureclass_management(outpath, outputname, "POINT", "","","", spatRef)
    arcpy.AddField_management(outpath+"\"+outputname, "start_lon", "DOUBLE")
    arcpy.AddField_management(outpath+"\"+outputname, "start_lat", "DOUBLE")
    arcpy.AddField_management(outpath+"\"+outputname, "end_lon", "DOUBLE")
    arcpy.AddField_management(outpath+"\"+outputname, "end_lat", "DOUBLE")
    arcpy.AddField_management(outpath+"\"+outputname, "distance", "DOUBLE")#m
    arcpy.AddField_management(outpath+"\"+outputname, "speed", "DOUBLE")
    arcpy.AddField_management(outpath+"\"+outputname, "angle", "DOUBLE")
    arcpy.AddField_management(outpath+"\"+outputname, "u", "DOUBLE")
    arcpy.AddField_management(outpath+"\"+outputname, "v", "DOUBLE")
    cursor=arcpy.InsertCursor(fc,["SHAPE@XY"]) # Add the point geometry to the feature vertex = arcpy.CreateObject("Point") vertex.X = line[0] vertex.Y =line[1] feature.shape = vertex # Add attributes feature.leibie = "shumu" # write to shapefile cursor.insertRow(feature) del cursor del fc
    num=0
    for x in x_coords:
    feature = cursor.newRow() # Add the point geometry to the feature vertex = arcpy.CreateObject("Point") vertex.X = line[0] vertex.Y =line[1] feature.shape = vertex # Add attributes feature.leibie = "shumu" # write to shapefile cursor.insertRow(feature) del cursor del fc
    # Add the point geometry to the feature
    vertex = arcpy.CreateObject("Point")
    vertex.X = float(x)
    vertex.Y = float(y_coords[num])
    feature.shape = vertex
    feature.start_lon = float(x)
    feature.start_lat = float(y_coords[num])
    feature.end_lon = float(x)
    feature.end_lat = float(y_coords[num])
    feature.distance = float(distance[num])
    feature.speed = float(speed[num])
    feature.angle = float(angle[num])
    feature.u = float(u[num])
    feature.v = float(v[num])
    #print vertex.X,vertex.Y,vertex.speed
    cursor.insertRow(feature)
    num=num+1
    arcpy.DefineProjection_management(outpath+"\"+outputname,spatRef)
    # Add attributes
    #z_coords = "elevation"

    # Make the XY event layer...
    # =============================================================================
    # =============================================================================

    # newfc="newpoint.shp"
    # arcpy.CreateFeatureclass_management(outpath, newfc, "Point")
    # cursor=arcpy.da.InsertCursor(newfc, ["SHAPE@"])
    # array=arcpy.Array()

    #
    # # Print the total rows
    # print(arcpy.GetCount_management(out_feature_class))
    # =============================================================================
    # =============================================================================
    --------------------- 

  • 相关阅读:
    CMDB服务器管理系统【s5day92】:服务器管理回顾
    主机管理+堡垒机系统开发:需求讨论(一)
    saltstack主机管理项目:今日总结(六)
    saltstack主机管理项目:动态调用插件解析-模块解析(五)
    saltstack主机管理项目:编写插件基类-获取主机列表-提取yaml配置文件(四)
    saltstack主机管理项目:计主机管理项目命令分发器(三)
    saltstack主机管理项目:主机管理项目需求分析(一)
    saltstack主机管理项目:主机管理项目架构设计(二)
    CMDB服务器管理系统【s5day89】:采集资产之整合资产
    CMDB服务器管理系统【s5day89】:采集资产之汇报信息
  • 原文地址:https://www.cnblogs.com/hyhy904/p/11001419.html
Copyright © 2011-2022 走看看