【问题标题】:Regarding importing .ppm file format in netlogo, as done in cruise model关于在 netlogo 中导入 .ppm 文件格式,就像在 Cruise 模型中所做的那样
【发布时间】:2016-09-12 06:02:40
【问题描述】:

我从 Google 地球中选择了一个小地图区域并将其保存为 jpg 文件。后来我把它转换成 .ppm 文件格式。然后我尝试在 NetLogo 中导入这个 .ppm 文件。但是在以下代码行中发生运行时错误“不允许使用此非标准字符(第 5 行,第 1 个字符)”,并带有文件读取

ask patches [
  set pcolor rgb (file-read / 256) (file-read / 256) (file-read / 256)
]

以下是我转换为 .ppm(便携式像素图)文本图形格式的 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 文件包含非数值。我正在按照汽车巡航模型的步骤进行操作。提前感谢任何帮助。

【问题讨论】:

    标签: gis netlogo


    【解决方案1】:

    在 Netlogo 能够直接导入图像之前,我们在 2004 年编写了巡航模型。我们使用 .ppm 图像格式,因为它是可加载的 ASCII 格式。

    不久之后,Netlogo 添加了import-pcolorsimport-pcolors-rgbimport-drawing 等命令和位图扩展名。

    我建议跳过 PPM 加载过程,直​​接使用 import-pcolors-rgb 加载您的 .jpg。此外,为避免可能影响颜色的压缩伪影,请考虑使用 .png 格式。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-12-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-29
      相关资源
      最近更新 更多