Questions tagged «typeerror»

4
无需QGIS,ArcGIS,PostGIS等的Python中的高效空间连接
我正在尝试进行空间连接,类似于此处的示例:是否存在“按位置连接属性”的python选项?。但是,这种方法似乎效率低下/缓慢。即使仅以250点的分数运行它,也要花费近2分钟的时间,而对于> 1,000点的shapefile,它完全失败。有没有更好的方法?我想完全在Python中完成此操作,而无需使用ArcGIS,QGIS等。 我也想知道是否有可能对一个多边形内所有点的属性(即总体)求和,然后将该数量加入到多边形shapefile中。 这是我要转换的代码。我在第9行出现错误: poly['properties']['score'] += point['properties']['score'] 其中说: TypeError:+ =:'NoneType'和'float'不受支持的操作数类型。 如果我将“ + =”替换为“ =”,则可以正常运行,但不会对字段求和。我也尝试过将它们设置为整数,但这也失败了。 with fiona.open(poly_shp, 'r') as n: with fiona.open(point_shp,'r') as s: outSchema = {'geometry': 'Polygon','properties':{'region':'str','score':'float'}} with fiona.open (out_shp, 'w', 'ESRI Shapefile', outSchema, crs) as output: for point in s: for poly in n: if shape(point['geometry']).within(shape(poly['geometry'])): poly['properties']['score']) += point['properties']['score']) …

2
将arcPy结果对象从arcpy.GetCount_management()强制转换为整数?
我试图通过计算shapefile中有多少点来获取数字。这行得通,除非我随后在其他地方使用该数字时遇到麻烦。最终,我将在一些数学(字段计算器)中使用该计数,但是在调试时,我遇到了一个错误,最终将导致我以后的麻烦。 这段代码: TotalPoints = arcpy.GetCount_management(Path_Pts) arcpy.AddMessage(">>>> PROCESS: COUNT PATH POINTS {" + TotalPoints + "}") 给出此错误: TypeError: cannot concatenate 'str' and 'Result' objects 我尝试将其转换为int,但它也不喜欢: TypeError: int() argument must be a string or a number, not 'Result' 因此,我有一个“结果”对象,需要将其转换为数字。 我该怎么做-或者在这里使用ArcPy函数是不必要的还是过于复杂?

2
在GDAL中制作的GeoTIFF在Arc / QGIS中加载时没有最小/最大范围
我正在使用GeoTIFF驱动程序在GDAL中创建一些浮点栅格。当我将生成的图像加载到QGIS或Arc中时,默认的符号系统将最小值设置为-3.40282e38,将最大值设置为3.40282e38,因此栅格看起来完全是灰色的。有没有一种方法可以直接将实际范围写入GeoTIFF,以便在将其加载到GIS程序中时自动很好地缩放直方图?我尝试过创建默认的直方图,如下所示: rasterMin, rasterMax = raster.GetRasterBand(1).ComputeRasterMinMax() raster.GetRasterBand(1).SetDefaultHistogram(rasterMin, rasterMax, 255) 但是我收到一个看起来像是绑定问题的错误: File "/usr/lib/python2.6/dist-packages/osgeo/gdal.py", line 846, in SetDefaultHistogram return _gdal.Band_SetDefaultHistogram(self, *args) TypeError: not a sequence 关于我该怎么办,或者如果我做错了什么建议?

1
在同一个Python脚本中使用ArcPy和PyGRASS工具?
我正在尝试编写一个Python脚本,其中包含不同的ArcPy / ArcGIS命令,并希望将其与GRASS地理处理工具结合使用。 不幸的是,导入GRASS库无效。 import grass.script as grass 结束于错误: Traceback (most recent call last): File "<interactive input>", line 1, in <module> ImportError: No module named script 我知道GRASS GIS安装了它自己的Python版本。是否没有办法结合使用ArcGIS和GRASS GIS安装的Python?我尝试将pygrass模块(或我认为的可能是)复制到C:\ Python26 \ ArcGIS10.0 \ Lib \ site-packages \文件夹中。我收到了不同的错误消息,但仍然无法正常工作。 Traceback (most recent call last): File "<interactive input>", line 1, in <module> File …
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.