首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >循环剪辑(数据管理)的ArcMap Python代码使ArcMap崩溃

循环剪辑(数据管理)的ArcMap Python代码使ArcMap崩溃
EN

Stack Overflow用户
提问于 2020-04-17 23:31:42
回答 2查看 284关注 0票数 0

我写了一段代码,用一堆shapefile来裁剪光栅。这一切都取决于clip函数,此时它会将ArcMap崩溃到桌面,而不会出现错误消息。我的代码如下:

代码语言:javascript
复制
import arcpy

# File path to Folder with the Shapefiles
WSin = arcpy.GetParameterAsText(0)

# File path to Folder where the clipped rasters will go
WSrast = arcpy.GetParameterAsText(1)

# File path to Folder where the raster to be clipped is
InRast = arcpy.GetParameterAsText(2)

# Set workspace to WSin
arcpy.env.workspace = WSin

# Create a list of the shapefiles with full file paths
Polys = arcpy.ListFeatureClasses()
Polys = [WSin + "\\" + sub for sub in Polys]

# Set workspace to WSrast
arcpy.env.workspace = WSrast

# Allow Overwriting
arcpy.env.overwriteOutput = True

# Clip Loop
for i in Polys:

    # Strip the shapefile names so they can be used as rasters
    desc = arcpy.Describe(i)
    name = str(desc.name)[:8]
    seper1 = "."
    name = name.split(seper1,1)[0]
    seper2 = "_"
    name = name.split(seper2,1)[0]
    rastname = str(WSrast) + "\\" + str(name) + "_Rast"

    # The problem child
    arcpy.Clip_management(InRast, i, rastname)

不幸的是,我不能分享我的确切数据,因为它是保密的,但我想你应该能够在这里弄清楚一些事情。我假设这是一些我看不到的简单的东西。任何帮助都将不胜感激。

EN

回答 2

Stack Overflow用户

发布于 2020-04-18 01:00:02

可能的问题: ArcMap arcpy.Clip_management需要将封套(实际上是字符串)作为第二个参数,而不是shapefile路径或物理形状)。

https://desktop.arcgis.com/en/arcmap/10.3/tools/data-management-toolbox/clip.htm

因此,您的arcpy.Clip_management代码行应该如下所示:

代码语言:javascript
复制
 arcpy.Clip_management(InRast, "0 10 20 30", rastname)

其中0是xmin,10是ymin,20是xmax,30是ymax,另一个问题是您希望如何获得包络值。shapefiles里面是否只包含一个形状?或者你想通过获取shapefile中所有形状的范围来得到面积?这需要更多的编码,可能使用几何:

https://desktop.arcgis.com/en/arcmap/10.3/analyze/arcpy-classes/extent.htm https://desktop.arcgis.com/en/arcmap/10.3/analyze/arcpy-classes/geometry.htm

票数 1
EN

Stack Overflow用户

发布于 2020-04-18 06:43:36

谢谢Szym。我想通了。我像你说的那样使用了错误的输入。我修改了我的代码,现在看起来像这样(我刚刚修改了for循环部分):

代码语言:javascript
复制
for i in Polys:
    desc = arcpy.Describe(i)
    ext = desc.extent
    name = str(desc.name)[:8]
    seper1 = "."
    name = name.split(seper1,1)[0]
    seper2 = "_"
    name = name.split(seper2,1)[0]
    rastname = str(WSrast) + "\\" + str(name) + "_Rast"
    arcpy.Clip_management(InRast, str(ext), rastname,i,"#","ClippingGeometry")

就像一种护身符。谢谢!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61275290

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档