有办法吗?
#1 楼
您可以使用“按属性拆分”工具:通过唯一属性拆分输入数据集
有可用的版本:
ArcGIS Pro(适用于所有许可级别)
ArcGIS Desktop 10.8(适用于所有许可级别)
USGS版本(按属性工具拆分) )
#2 楼
如果您具有ArcGIS 10.0或更高版本,则可以使用非常简单的模型来实现。使用Feature Iterator创建模型,其中group by字段是您希望选择的属性,然后将输出发送到复制功能工具使用内联替换来确保唯一的文件名。该模型如下所示:
#3 楼
我无权访问ArcMap 10(仅9.3),但我希望它不会与此有所不同。您可以在Python中创建一个简单的脚本,该脚本检查属性字段是否不同值,然后为每个值对原始Shapefile运行SELECT操作。
如果您不熟悉python脚本,则只需打开IDLE(python GUI)创建一个新文件,然后复制下面的代码。在为my_shapefile修改代码之后,outputdir和my_attribute应该可以正常工作。
# Script created to separate one shapefile in multiple ones by one specific
# attribute
# Example for a Inputfile called "my_shapefile" and a field called "my_attribute"
import arcgisscripting
# Starts Geoprocessing
gp = arcgisscripting.create(9.3)
gp.OverWriteOutput = 1
#Set Input Output variables
inputFile = u"C:\GISTemp\My_Shapefile.shp" #<-- CHANGE
outDir = u"C:\GISTemp\" #<-- CHANGE
# Reads My_shapefile for different values in the attribute
rows = gp.searchcursor(inputFile)
row = rows.next()
attribute_types = set([])
while row:
attribute_types.add(row.my_attribute) #<-- CHANGE my_attribute to the name of your attribute
row = rows.next()
# Output a Shapefile for each different attribute
for each_attribute in attribute_types:
outSHP = outDir + each_attribute + u".shp"
print outSHP
gp.Select_analysis (inputFile, outSHP, "\"my_attribute\" = '" + each_attribute + "'") #<-- CHANGE my_attribute to the name of your attribute
del rows, row, attribute_types, gp
#END
#4 楼
我使用了@AlexandreNeto的脚本,并为ArcGIS 10.x用户更新了它。现在主要是您必须导入“ arcpy”而不是“ arcgisscripting”: # Script created to separate one shapefile in multiple ones by one specific
# attribute
# Example for a Inputfile called "my_shapefile" and a field called "my_attribute"
import arcpy
#Set Input Output variables
inputFile = u"D:\DXF-Export\my_shapefile.shp" #<-- CHANGE
outDir = u"D:\DXF-Export\" #<-- CHANGE
# Reads My_shapefile for different values in the attribute
rows = arcpy.SearchCursor(inputFile)
row = rows.next()
attribute_types = set([])
while row:
attribute_types.add(row.my_attribute) #<-- CHANGE my_attribute to the name of your attribute
row = rows.next()
# Output a Shapefile for each different attribute
for each_attribute in attribute_types:
outSHP = outDir + each_attribute + u".shp"
print outSHP
arcpy.Select_analysis (inputFile, outSHP, "\"my_attribute\" = '" + each_attribute + "'") #<-- CHANGE my_attribute to the name of your attribute
del rows, row, attribute_types
#END
#5 楼
这是执行此操作的一种甚至更简单的方法...它会输出到GDB中。从USGS下载该工具,花了我3分钟的时间完成了1个小时的尝试。
#6 楼
我知道您可以在ModelBuilder中使用迭代器,但是如果您喜欢使用python,这是我想到的。将脚本按参数依次添加到工具箱中,如输入shpfile,字段(多值,从输入获取)和工作区。该脚本将根据您选择的字段将shapefile分成多个shapefile,并将它们输出到您选择的文件夹中。 import arcpy, re
arcpy.env.overwriteOutput = True
Input = arcpy.GetParameterAsText(0)
Flds = "%s" % (arcpy.GetParameterAsText(1))
OutWorkspace = arcpy.GetParameterAsText(2)
myre = re.compile(";")
FldsSplit = myre.split(Flds)
sort = "%s A" % (FldsSplit[0])
rows = arcpy.SearchCursor(Input, "", "", Flds, sort)
for row in rows:
var = []
for r in range(len(FldsSplit)):
var.append(row.getValue(FldsSplit[r]))
Query = ''
Name = ''
for x in range(len(var)):
if x == 0:
fildz = FldsSplit[x]
Name = var[x] + "_"
Query += (""" "%s" = '%s'""" % (fildz, var[x]))
if x > 0:
fildz = FldsSplit[x]
Name += var[x] + "_"
Query += (""" AND "%s" = '%s' """ % (fildz, var[x]))
OutputShp = OutWorkspace + r"\%s.shp" % (Name)
arcpy.Select_analysis(Input, OutputShp, Query)
#7 楼
我终于可以将它与SearchCursor和Select_analysis一起使用了。arcpy.env.workspace = strInPath
# create a set to hold the attributes
attributes=set([])
# ---- create a list of feature classes in the current workspace ----
listOfFeatures = arcpy.SearchCursor(strInPath,"","",strFieldName,"")
for row in listOfFeatures:
attributes.add(row.getValue(strFieldName))
count=1
try:
for row in attributes:
stroOutputClass = strBaseName + "_" +str(count)# (str(row.getValue(strFieldName))).replace('/','_')
strOutputFeatureClass = os.path.join(strOutGDBPath, stroOutputClass)
arcpy.Select_analysis(strInPath,strOutputFeatureClass,strQueryExp)#"["+strFieldName+"]"+"='"+row+"'")
count=count+1
del attributes
except:
arcpy.AddMessage('Error found')
#8 楼
我对ModelBuilder中的“迭代功能选择”工具不熟悉,但是仅导出该代码即可,因为Python代码表明可以使用arcpy对其进行调用。#9 楼
您可以在复制要素(数据管理)中使用几何图形标记(SHAPE @)导出每个要素。import arcpy, os
shp = r'C:\temp\yourSHP.shp'
outws = r'C:\temp'
with arcpy.da.SearchCursor(shp, ["OBJECTID","SHAPE@"]) as cursor:
for row in cursor:
outfc = os.path.join(outws, "fc" + str(row[0]))
arcpy.CopyFeatures_management(row[1], outfc)
#10 楼
您可以使用搜索光标在要素类中循环浏览各个要素,并将几何仅写入唯一的要素类。在本示例中,我使用了美国的要素类,并将状态导出到新的shapefile: import arcpy
# This is a path to an ESRI FC of the USA
states = r'C:\Program Files (x86)\ArcGIS\Desktop10.2\TemplateData\TemplateData.gdb\USA\states'
out_path = r'C:\temp'
with arcpy.da.SearchCursor(states, ["STATE_NAME", "SHAPE@"]) as cursor:
for row in cursor:
out_name = str(row[0]) # Define the output shapefile name (e.g. "Hawaii")
arcpy.FeatureClassToFeatureClass_conversion(row[1], out_path, out_name)
#11 楼
在Arcpy中,光标会选择图层/ TableView选择。根据使用Python代码在ArcGIS for Desktop中获取选定要素列表?,您可以简单地迭代要素选择。但是,如果要使用arcpy进行选择,请使用SelectLayerByAttribute_management工具。
#12 楼
您可以将ModelBuilder用于这种类型的操作。在此示例中,我创建了一个单独的变量“ out_workspace”,该变量用于在“复制功能”中定义输出路径:%out_workspace%\fc_%Value%.shp
评论
我认为此答案的弊端是您不掌握这些属性。我更喜欢gis.stackexchange.com/a/152165/115这样的答案。
– PolyGeo♦
16/09/15在22:52
@PolyGeo好一点,但是,好处是可以将其包装到也需要光标操作的其他工作流程中。
–亚伦♦
16-9-16'1:46
...但是可以使用Select_analysis代替FeatureClassToFeatureClass-这只是一行会更改的代码。
– PolyGeo♦
16 Sep 16'1:51