我从Google Earth中选择了一个小地图区域,并将其保存为jpg文件。后来,我将其转换为.ppm文件格式。然后我尝试在NetLogo中导入这个.ppm文件。但是在下面的代码行中出现了一个运行时错误"This non - standard character is not allowed (line number 5,character 1)“with file-read
ask patches [
set pcolor rgb (file-read / 256) (file-read / 256) (file-read / 256)
]下面是我转换为.ppm (便携pix地图)文本图形格式的jpg。

我正在做的代码是
globals [
mapname
]
to startup ; slow, do just once
init-map
end
to init-map
set mapname "sangamarea"; set mapname "cruise"
create-dat mapname
end
to create-dat [mapfile]
print "..creating patches, I'll print 'done' when completed"
import-ppm mapfile
export-dat mapfile
print "..done!"
end
to import-ppm [ppmfile]
let x 0 let y 0 let scale 0 ;locals [x y scale]
set ppmfile (word ppmfile ".ppm")
file-close-all
file-open ppmfile
set x 1 set y file-read-line
while [first file-read-line = "#"] [set x x + 1]
file-close
file-open ppmfile
repeat x [set x file-read-line]
set x file-read
set y file-read
set scale 1 + file-read
if x != random-xcor and y != random-ycor [print "Oops: need to fix screen-size to match ppm file"]
ask patches [set pcolor rgb (file-read / 256) (file-read / 256) (file-read / 256)]
file-close
cleanup-map
end
to cleanup-map
ask patches with [(floor pcolor) mod 10 = 9] [set pcolor 9.9]
ask patches with [pcolor != 9.9] [set pcolor round pcolor]
ask patches with [pcolor > 120] [set pcolor pcolor - 110]
end
to export-dat [datfile]
set datfile word datfile ".dat"
file-close-all
if file-exists? datfile [file-delete datfile]
file-open datfile
ask patches [file-write floor pcolor if pxcor = max-pxcor [file-print ""]] ;screen-edge-x
file-close
end我不明白为什么错误是,是否我的jpeg图像是大的或可能是.ppm文件包含非数字值。我正在遵循汽车巡航模型的步骤。任何帮助都要提前感谢。
发布于 2016-05-17 12:06:47
在Netlogo能够直接导入图像之前,我们在2004年编写了巡航模型。我们使用.ppm图像格式,因为它是可加载的ASCII码格式。
不久之后,Netlogo添加了import-pcolors、import-pcolors-rgb、import-drawing和位图扩展名等命令。
我建议跳过PPM加载过程,直接用import-pcolors-rgb加载你的.jpg。此外,为了避免可能影响颜色的压缩瑕疵,请考虑使用.png格式。
https://stackoverflow.com/questions/37254069
复制相似问题