在 python 中使用 gdb 中的栅格数据集
我正在尝试编写一个脚本,用于在 python 中将度数转换为弧度。这是一项常见的任务,随身携带它会很有用。我遇到的问题是输入栅格似乎被作为字符串读取。见下文:
import arcpy
from arcpy import env
from arcpy.sa import *
import math
arcpy.CheckOutExtension("Spatial")
env.workspace = "C:\Users\OJB\Desktop\University\UsingRAS\UsingRas.gdb"
degrad = math.pi / 180
PythonRad = "Aspect_Deg" * degrad
outCos = Cos("PythonRad")
outCos.save("C:\Users\OJB\Desktop\University\UsingRAS\UsingRas.gdb\PyTest")
我得到的错误是:
Traceback (most recent call last):
File "C:/Users/OJB/Desktop/University/UsingRAS/Scripts/DegtoRad", line 11, in <module>
PythonRad = "Aspect_Deg" * degrad
TypeError: can't multiply sequence by non-int of type 'float'
我不确定如何在不使用引号的情况下使用此栅格。我对 Python 很陌生,所以任何帮助将不胜感激。
一切顺利
I'm trying to write a script for converting degrees to radians in python. A common task and it would just be useful to have around. The problem I'm getting is that the input raster appears to be being read as a string. See below:
import arcpy
from arcpy import env
from arcpy.sa import *
import math
arcpy.CheckOutExtension("Spatial")
env.workspace = "C:\Users\OJB\Desktop\University\UsingRAS\UsingRas.gdb"
degrad = math.pi / 180
PythonRad = "Aspect_Deg" * degrad
outCos = Cos("PythonRad")
outCos.save("C:\Users\OJB\Desktop\University\UsingRAS\UsingRas.gdb\PyTest")
The error I get is:
Traceback (most recent call last):
File "C:/Users/OJB/Desktop/University/UsingRAS/Scripts/DegtoRad", line 11, in <module>
PythonRad = "Aspect_Deg" * degrad
TypeError: can't multiply sequence by non-int of type 'float'
I'm not sure how to use this raster without using the quote marks. I'm very new to Python so any help would be appreciated.
All the best
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 arcpy 模块中的栅格对象实例化栅格:
此外,完成后不要忘记检查您的空间分析扩展。
Use a raster object from the arcpy module to instantiate the raster:
Also, don't forget to check your spatial analyst extension back in when you are done.
第一:当您想在字符串中使用
\
字符时,您必须使用另一个\
对其进行转义。所以你的路径看起来像这样:"C:\\Users\\OJB\\Desktop\\University\\UsingRAS\\UsingRas.gdb"
这行:
没有意义,因为你将字符串文字与浮点值相乘。您必须首先检索一个可与您的浮点数相乘的对象。
First: When you want to use the
\
character in your strings, you have to escape it with another\
. So your path would look like this:"C:\\Users\\OJB\\Desktop\\University\\UsingRAS\\UsingRas.gdb"
This line:
Doesn't make sense, as you are multiplying a string literal with a float value. You have to first retrieve an object that is multipliable with your float.