Python脚本在剪辑功能上生成ERROR 999999

时间:2016-09-12 09:38:25

标签: python arcgis clip in-memory-database arcpy

我正在尝试编写一个Python脚本,该脚本采用shapefile文件夹,选择其中一个多边形shapefile中的一个功能,并在该功能上创建一个缓冲区。然后,此功能用于剪切文件夹中的所有形状文件。然后,形状文件全部重新投影并写入地理数据库。

它适用于文件夹中的第一个形状文件,并生成我想要的结果,但当它迭代到下一个shapefile时,它会到达剪辑功能,然后我得到“错误999999:执行函数时出错”。 无法执行(剪辑)“。这是代码:

#Import modules

import arcpy
import os

#Environment settings 

arcpy.env.workspace ="V://Sam//GIS//HämtningarData//fk_12.Sweref_99_TM.Shape//Shape"
arcpy.env.overwriteOutput = True
outFolder = "V://Sam//GIS//Personliga mappar//test//test.gdb"

NAME = "YSTAD"
ystadKod = "_1286"
counter = 0
kommuner = "V://Sam//GIS//HämtningarData//GSD_Fastighetskartor//GSD_Fastightskarta_skane_TM_160908//Shape//ak_12.shp"
ak_buf = "in_memory" + "//ak_buf"
date = "_20160908"

#Select Ystad and create 3km Buffer
#SQL Query
kommunQuery = '"KOMMUNNAMN"' + ' = ' + "'"+ NAME + "'"

# Make a feature layer of ystad that applies the SQL expression
arcpy.MakeFeatureLayer_management(kommuner, "ystadLayer",kommunQuery)

# Process: Buffer
arcpy.Buffer_analysis("ystadLayer", ak_buf, "3 Kilometers", "FULL", "ROUND", "ALL", "", "GEODESIC")

#Iterate feature classes in folder    
FeatureClassList = arcpy.ListFeatureClasses()
for featureClass in FeatureClassList:

# make new feature class name
if "_" in featureClass:
    parts= featureClass.split('_')
    name = parts [0]
    newName = name + ystadKod + date
    print newName

else:
    name = featureClass[:-4]
    newName = name + ystadKod + date
    print newName

outPath = "in_memory" + "//" + newName
print featureClass
print ak_buf
print outPath
arcpy.Clip_analysis(featureClass, ak_buf, outPath)

# Describe the feature class and get its spatial reference   
desc = arcpy.Describe(outPath)
spatialRef = desc.spatialReference

if desc.spatialReference.Name == "Unknown":
    print ('skipped this fc due to undefined coordinate system: ' + newName)
else:
    print spatialRef.Name

    #create new file path
    Result = outFolder +"//" + newName
    #print outPath

    # Set output coordinate system
    outCS = arcpy.SpatialReference(3008)

    # run project tool
    arcpy.Project_management(outPath, Result, outCS)

    # check messages
    print(arcpy.GetMessages())
    arcpy.Delete_management (outPath)

    counter = counter +1
print counter 

我还测试了首先重新投影所有内容然后剪切,但ArcGIS不允许将重新投影的输出保存为“in_memory”。我想让程序自包含,以便可以在不保存本地中间文件的情况下使用它。

更新 - 该脚本适用于具有许多功能的多边形shapefile,但即使它们不包含许多功能,只要它涉及到行或点形状文件,脚本就会失败。有什么想法吗?

0 个答案:

没有答案