r - NetLogo - misalignment with imported GIS shapefiles -


i've got netlogo model in each animal occupies "territory", wherein patches belong animal same color animal. use r extension in netlogo create minimum convex polygon (mcp) surrounding each territory , export polygons shapefile. import gis file netlogo using gis extension. rationale related question posted before (netlogo - applying values patches within polygons). is, can use gis:intersecting give variable patches fall within gis-imported polygons. process of creating mcp, exporting, , importing done @ each time step because territory updates each tick. works except imported shapefile not align original polygons. attached image shows this, blue outlines imported shapefile. enter image description here. i've tried gis:set-world-envelope (list min-pxcor max-pxcor min-pycor max-pycor) no avail. know if i'm doing wrong or if error inherent exporting , importing shapefile no projection exists? here great because having them align solve several issues, including previous post. whole code pretty long i've attached snippets below relevant. thanks!

extensions [r gis ]   breed [females female]  globals [   hr-dataset ]      females-own  [    name    x    y ]  patches-own  [    is-hr? ]  setup    clear-all   r:clear    ...   ask n-of 5 patches    [      sprout-females 1     [        ...       set x (list pxcor)        set y (list pycor)      ]    ]    reset-ticks  end   go    ...   expand   calc-homerange   tick  end  expand    repeat 10   [     ask females     [       move-to target       set x lput pxcor x       set y lput pycor y     ]   ] end  calc-homerange   r:eval "library(adehabitathr)"   r:eval "library(sp)"   r:eval "library(rgdal)"    ; create empty data.frame"   r:eval "turtles <- data.frame()"    ; merge name, x- , y-lists of females 1 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  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, providing that, makes problem easy grasp. looks farther origin, worse discrepancy is, error radiating out origin.

i know gis extension documentation recommends gis:set-world-envelope (list min-pxcor max-pxcor min-pycor max-pycor), have wonder if it's correct. min/max-pxcor/pycor minimum , maximum patch coordinates, not minimum , maximum turtle coordinates. example if max-pxcor 10, turtle's x coordinate can high 10.499999[...], , if min-pxcor -10, turtle's x coordinate can low -10.5. world-width 21, not 20.

maybe try changing gis:set-world-envelope (list min-pxcor - 0.5 max-pxcor + 0.5 min-pycor - 0.5 max-pycor + 0.5) , see if fixes it. or if doesn't fix exactly, try flipping signs or try 1 instead of 0.5. sure looks screen shot problem off-by-one or off-by-0.5 error.


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

How to get multiresult with multicondition in Sql Server -