Reputation: 39
I'm building a model which demands me to load shapefiles to netlogo. I've done that and the map that appears on the view corresponds to what it is supposed to. The problem is that the shapefile is not overlapping the the patches. My shapefiles consist of x|y|attribute and I've arround 800 000 lines in the files. The ideal thing was having each line corresponding to a patch but when I execute count patches it has only 1089. And worse, each patch retrieves NaN when I ask for the attribute value. I will paste part of the code that matters to this issue:
globals [ mintempcm-dataset
maxtemphm-dataset
precipitation-dataset
meantemp-dataset
color-list
]
patches-own [
mintempcm
maxtemphm
meantemp
precipitation
]
to setup
ca
gis:load-coordinate-system (word "WGS_84_Geographic.prj")
set maxtemphm-dataset gis:load-dataset "mxtwm.shp"
gis:set-world-envelope (gis:envelope-union-of
(gis:envelope-of maxtemphm-dataset)
)
gis:apply-coverage maxtemphm-dataset "MAXTEMPHM" maxtemphm
ask patches[
set maxtemphm maxtemphm
]
gis:set-drawing-color blue
gis:draw maxtemphm-dataset 1
reset-ticks
end
Am I missing something or doing something wrong? To clarify, I need to make each coordinate of the file correspond to a patch and pass the attribute to the patch.
Thanks.
Upvotes: 1
Views: 413
Reputation: 10301
You can use gis:intersecting
to do this, but it's not very efficient for what you want to do. For an example, I downloaded the airports dataset from this site that has some free gis data. The airports dataset (ne_10m_airports.shp) contains point data for each airport and some info about each airport. To assign some data to patches, see below- some info in comments:
extensions [ gis ]
globals [ airports ]
patches-own [ airport-name ]
to setup
ca
resize-world 0 125 0 50
set-patch-size 5
; Load the dataset
set airports gis:load-dataset "ne_10m_airports.shp"
gis:set-world-envelope gis:envelope-of airports
; For each point listed in 'airports', ask any patches
; that are intersecting that point to take the name
; of the airport that intersects them (since these are points,
; intersection in this case means the airport coordinates
; lie within the patch.
foreach gis:feature-list-of airports [
x ->
ask patches gis:intersecting x [
set airport-name gis:property-value x "NAME"
set pcolor red
]
]
reset-ticks
end
You could do this with the "MAXTEMPHM" value from your temperature datasets. However, your NetLogo world size is something you'll have to play around with to make sure that the number of patches corresponds to the number of points you have- gis:set-world-envelope
only aligns the gis datasets to the NetLogo world, it doesn't affect the patches present. If you have 800000 temperature points you want to load in, you'd need to make your NetLogo world somewhere around 895 patches square, which is a pretty big world. It will take a while to load in the temperature data as described above. It would make things simpler and more efficient (and noticeably faster) to use a raster dataset and gis:apply-raster
.
Upvotes: 1