简体   繁体   English

ArcGIS 10 python - 条件语句检查以查看栅格值是否在集合中

[英]ArcGIS 10 python - Conditional statement checking to see if a raster value is in a set

I am attempting to create a raster based on input from another raster. 我试图根据另一个栅格的输入创建一个栅格。 If a raster value is equal to a number included in a set() than I want it to be 1, else 0 如果栅格值等于set()中包含的数字,那么我希望它为1,否则为0

I've attempted the following: 我尝试过以下方法:

 ConfusedRaster = arcpy.Con(inraster in repeatSet, 1, 0)

and

 ConfusedRaster = arcpy.Con(inraster, 1, 0, "inraster in repeatSet")

Neither of these work. 这些都不奏效。 I believe they don't work because the where clause only accepts Map Algebra expressions: ArcGIS Help 我相信它们不起作用,因为where子句只接受Map Algebra表达式: ArcGIS Help

There are two other ways I can think of doing this. 我还可以考虑另外两种方法来做这件事。 One being converting it to a NumPyArray and working with that. 一个是将它转换为NumPyArray并使用它。 The other is looping through the set and creating a raster object for each value in the set. 另一个是循环遍历集合并为集合中的每个值创建栅格对象。 After the loop has finished merge them. 循环完成后合并它们。

Does anyone have any suggestions or comments on how to go about this? 有没有人对如何解决这个问题有任何建议或意见?

Thank you 谢谢

I was searching for an answer to the similar issue and developed a way using the SQL clause in 'ExtractByAttributes'. 我正在寻找类似问题的答案,并使用'ExtractByAttributes'中的SQL子句开发了一种方法。

repeatList = list(repeatSet)
ras1 = arcpy.sa.ExtractByAttributes(inraster, 'VALUE IN (' + str(repeatList).strip('[]') + ')') 
ConfusedRaster = arcpy.sa.Con(arcpy.sa.IsNull(ras1) == 0, 1, 0)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM