NetLogo-与导入的GIS shapefile不对齐 [英] NetLogo - misalignment with imported GIS shapefiles

查看:472
本文介绍了NetLogo-与导入的GIS shapefile不对齐的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个NetLogo模型,其中每个动物都占据一个区域",其中属于该动物的所有色块都与该动物具有相同的颜色.然后,我在NetLogo中使用R扩展名在每个区域周围创建一个最小凸多边形(MCP),并将这些多边形导出为shapefile.然后,使用GIS扩展名将GIS文件导入回NetLogo.我对此的理由与我之前发布的问题有关(

I've got a NetLogo model in which each animal occupies a "territory", wherein all patches that belong to the animal are the same color as the animal. I then use the R extension in NetLogo to create a minimum convex polygon (MCP) surrounding each territory and export those polygons as a shapefile. I then import the GIS file back into NetLogo using the GIS extension. My rationale for this is related to this question I posted before (NetLogo - applying values to patches within polygons). That is, I can use gis:intersecting to give a variable to those patches that fall within the GIS-imported polygons. The process of creating the MCP, exporting, and importing is done at each time step because the territory updates each tick. All works well except that the imported shapefile does not align perfectly with the original polygons. The attached image shows this, where the blue outlines are from the imported shapefile. . I've tried gis:set-world-envelope (list min-pxcor max-pxcor min-pycor max-pycor) but to no avail. Does anybody know if I'm doing something wrong or if it is error inherent to exporting and then importing a shapefile for which no projection exists? Any help here would be great because having them align would solve several issues, including the previous post. The whole code is pretty long so I've attached some snippets below that are most relevant. Thanks!

extensions [r gis ] 

breed [females female]

globals
[
  hr-dataset
]    

females-own 
[ 
  Name 
  X 
  Y
]

patches-own 
[ 
  is-hr?
]

to setup 
  clear-all
  r:clear 
  ...
  ask n-of 5 patches 
  [ 
    sprout-females 1
    [ 
      ...
      set X (list pxcor) 
      set Y (list pycor) 
    ] 
  ] 
  reset-ticks 
end 

to go 
  ...
  expand
  calc-homerange
  tick 
end

to expand 
  repeat 10
  [
    ask females
    [
      move-to target
      set X lput pxcor X
      set Y lput pycor Y
    ]
  ]
end

to calc-homerange
  r:eval "library(adehabitatHR)"
  r:eval "library(sp)"
  r:eval "library(rgdal)"

  ; create an empty data.frame"
  r:eval "turtles <- data.frame()"

  ; merge the Name, X- and Y-lists of all females to one big data.frame
  ask females
  [
    (r:putdataframe "turtle" "X" X "Y" Y)     
    r:eval (word "turtle <- data.frame(turtle, Name = '" Name "')")
    r:eval "turtles <- rbind(turtles, turtle)"
  ]

  ; create SpatialPointsDataFrame
  r:eval "spdf <- SpatialPointsDataFrame(turtles[1:2], turtles[3])" 
  r:eval "homerange <- mcp(spdf, percent = 100)"
  r:eval "writeOGR(homerange, '.', 'homerange-rgdal', overwrite_layer = TRUE, driver = 'ESRI Shapefile')"

mark-homeranges
end

to mark-homeranges
  clear-drawing
  ...
  set hr-dataset gis:load-dataset "C:/Program Files (x86)/NetLogo 5.0.4/homerange-rgdal.shp"
  gis:set-world-envelope (list min-pxcor max-pxcor min-pycor max-pycor)    
  gis:set-drawing-color blue
  gis:draw hr-dataset 2
  ask patches gis:intersecting hr-dataset
  [
    set is-hr? true
  ]
end

推荐答案

很好的截屏,感谢您的提供,它使问题易于理解.看起来好像离原点越远,差异越严重,就像错误从原点辐射出来一样.

Nice screen shot, thanks for providing that, it makes the problem easy to grasp. It looks like the farther from the origin, the worse the discrepancy is, like the error is radiating out from the origin.

我知道GIS扩展文档建议使用gis:set-world-envelope (list min-pxcor max-pxcor min-pycor max-pycor),但我想知道它是否正确. min/max-pxcor/pycor是最小和最大斑块坐标,而不是最小和最大乌龟坐标.因此,例如,如果max-pxcor为10,则乌龟的x坐标可以高达10.499999 [...],如果min-pxcor为-10,则乌龟的x坐标可以低至-10.5.因此world-width是21,而不是20.

I know the GIS extension documentation recommends gis:set-world-envelope (list min-pxcor max-pxcor min-pycor max-pycor), but I have to wonder if it's actually correct. min/max-pxcor/pycor are the minimum and maximum patch coordinates, not the minimum and maximum turtle coordinates. So for example if max-pxcor is 10, then a turtle's x coordinate can be as high as 10.499999[...], and if min-pxcor is -10, a turtle's x coordinate can be as low -10.5. Thus world-width is 21, not 20.

也许尝试将其更改为gis:set-world-envelope (list min-pxcor - 0.5 max-pxcor + 0.5 min-pycor - 0.5 max-pycor + 0.5),然后查看是否可以解决该问题.或者,如果不能完全解决问题,请尝试翻转符号,或尝试使用1代替0.5.从屏幕快照中可以肯定地看出问题是一个1或0.5的错误.

Maybe try changing it to gis:set-world-envelope (list min-pxcor - 0.5 max-pxcor + 0.5 min-pycor - 0.5 max-pycor + 0.5) and see if that fixes it. Or if it doesn't fix it exactly, try flipping the signs or try 1 instead of 0.5. It sure looks from the screen shot like the problem is an off-by-one or off-by-0.5 error.

这篇关于NetLogo-与导入的GIS shapefile不对齐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆