I am new to NetLogo and currently I wish to simulate turtles to move on the road. I have downloaded street map from OpenStreetMap and just converted into shapefile (only roads) so that it is compatible for NetLogo. But as I use GIS extension to import the road and run the code, it seems that NetLogo couldnt find any roads(blue) and so fail to create turtles on the roads.
extensions [gis]
patches-own [vlocation]
to setup
clear-all
ask patches [ set pcolor white ] ;;set background white
end
;;import the road downloaded from OpenstreetMap
to load
let view1 gis:load-dataset "map11_osm_ln.shp"
gis:set-world-envelope gis:envelope-of view1
foreach gis:feature-list-of view1
[
gis:set-drawing-color blue ;;draw road as blue
gis:draw view1 0.5
]
end
to add-turtles
create-turtles 1
ask turtles ;; create turtles on road which is blue only
[
set vlocation one-of patches with [pcolor = blue]
move-to vlocation
]
end
However, I got this error:
MOVE-TO expected input to be an agent but got NOBODY instead.
I have inspected the road(patches) and found that pcolor of the roads are all 9.9 not blue. Is this the reason that NetLogo couldn't find any roads to create turtles? How should I do so that I can create turtles on the road?
Related
I am unable to load raster image into NetLogo 6.2.
Following the code:
extensions [gis]
globals [landcover1]
patches-own [habitatcover]
to setup ;; load in the GIS data
ca
set landcover1 gis:load-dataset "C:/cer_map_test.asc"
gis:set-world-envelope gis:envelope-of landcover1
gis:apply-raster landcover1 habitatcover
colormap
end
to colormap ;;color the landcover
ask patches [
if habitatcover = 1 [set pcolor orange]
if habitatcover = 2 [set pcolor lime]
if habitatcover = 3 [set pcolor brown]
if habitatcover = 4 [set pcolor green]
if habitatcover = 5 [set pcolor black]
]
end
The error message displayed:
Extension exception: error parsing number
error while observer running GIS:LOAD-DATASET
called by procedure SETUP
called by Botão 'setup'
It looks like there's an irregularity with your file that is causing the GIS extension to have trouble parsing one of the numbers.
First, try importing the raster file into ArcMap or QGIS and then re-export it as a new file. That might "just work", or it might help you identify where in the raster file the GIS extension is getting tripped up if those tools have trouble reading it too.
Failing that, you can always open up .asc files in a text editor (they are just plain-text) and manually look around and see if there's anything odd going on.
Either way, I am one of the dev's working on the GIS extension and would love to look at the file in question to see if its a bug on our end that we could fix. Perhaps you could post an issue on the GIS extension github and attach the file there.
I am using the google maps api in a test version to calculate the travel distance between two or more adresses. Now, usually, this is not a problem at all, considering that the distance matrix does exactly that. But when I try to get the distance between two points, let's say Berlin and New York, seperated by sea, I run into problems, the API returns zero_results. I assume this is because the travel mode is "driving" as by default, yet I can not find a more fitting mode in the documentation. https://developers.google.com/maps/documentation/distance-matrix/intro#travel_modes.
Am I using the wrong product? Is there a travel mode I missed? Hope somebody can help me with this, thanks.
The API call I use is
https://maps.googleapis.com/maps/api/distancematrix/json?origins=Berlin&destinations=New+York&key=MY_KEY
The response I get is
{
"destination_addresses" : [ "New York City, New York, USA" ],
"origin_addresses" : [ "Berlin, Deutschland" ],
"rows" : [
{
"elements" : [
{
"status" : "ZERO_RESULTS"
}
]
}
],
"status" : "OK"
}
The currently supported Travel modes are driving, walking, bicycling and transit. So you would probably choose the transit mode as you obviously can't drive, walk or bicycle from Berlin to NY.
For the transit mode, the supported transit_mode values are bus, subway, train, tram and rail. So again, nothing here that allows for crossing the ocean...
I would assume that these are the only possible travel modes you can get today via the API.
I'm making an app with Xamarin.Forms.Maps and then, I need to get all of the steps between two "place id" to make my own polyline. However, when I'm making my request, I get about only thirty five steps.
35 steps.. Between Le Mans (France) and Paris (France).. About 200km but only 35 steps.. The problem isn't that the two points aren't connected to the polyline made, no, the problem is that the polyline get out of the existing road..
Google API direction seems to give me, only, some important information, like important steps, but without following the road.. Does it normal?
PS: This is my request (I use Postman to test it)
https://maps.googleapis.com/maps/api/directions/json?origin=Le Mans&destination=Paris&key=[MY_API_KEY]&travel_mode=DRIVING
Are you using the polyline results in each driving step?
I used your example and got 31 start_location that each contain Encoded Polylines for drawing that path on the map.
The "Take the exit toward Paris-Centre Porte de Bercy" step results in:
"polyline": {
"points": "mn_iHmxqM#[?WA_#Ck#CeAAMGcAEi#Gc#Ke#GUI[IYGSIMIKGECAMIMEA?EAA?A?K?I#A?C?IBE#C#?#C#GBOHEHGJIVIX_#j#"
},
Decoded that is:
The "Take the exit on the left onto Bd Périphérique" step results in 91 points, etc...
There are hundreds and hundreds of locations points within the results, you just have to decode the locations of each driving step and plot them:
Google's Interactive Poly Line Utility
I'd like to highlight all roads around a user in a certain radius.
I've worked out how to get the lat/lng of the roads and even their lengths, but I'm struggling to work out how to draw lines from the start of a road to the end of the same road given only the lat/lng of said road.
countryCode:"GB"
distance:195.450718073417
gid:101823433
isIn:"Portsmouth"
lat:50.79336325
length:58.7727976883358
lng:-1.0940351000000001
name:"Colpoy Street"
oneWay:false
openstreetmapId:12929127
streetType:"RESIDENTIAL"
http://services.gisgraphy.com/street/streetsearch?format=json&lat=50.7913547&lng=-1.0944082&radius=200&streettype=&distance=true
I've seen various solutions of "snapping" to roads, but this requires a start and end lat/lng, I only have the single lat/lng of the road location.
I'm not fussy about the use of mapping API, although I'd prefer to use Leaflet.js/OSM. Is this possible?
You will need a server component that replys your request with the geometry of your desired road. For prototyping, you might use the OverpassAPI and display a geoJSON answer of the desired object in a new Leaflet layer.
Just to clarify: You need to add a new vector layer, as you have to use a seperate datasource with the road network on top of your raster maps.
I have a general model that uses turtles on patches as cities/states in the NetLogo world. I would like to extend the general model to a specific country. I have imported the GIS map into NL. How do I map states in the GIS map to the turtles in NetLogo, so I can run the general model using the exact space/world and data of a specific country?
So for example, in my general model, I create one turtle per patch, assign it variables, perform some analysis and get an output. What I now want to do is to assign variables to each state in the GIS map i.e. make each state in the country on the GIS map a turtle/breed, perform analysis based upon the variables assignment and calculation, take action e.g. kill a state or hatch a state or move a state just as I would kill a turtle, hatch a turtle, move a turtle in my general model based on the NetLogo world.
I hope my question and what I am trying to achieve is clear.
Thank you.
So far all I have been able to do is to load the GIS map into Netlogo. I can see the map and the states of the country defined in Netlogo but I am stuck at getting the states in the map become Netlogo turtles so i can run my model!
here is my code.
extensions [ gis ]
globals [ MYCOUNTRY slope aspect ]
to setup
clear-all
ask patches [ set pcolor green ]
gis:load-coordinate-system ("data/CTRY_adm/CTRY_adm1.prj")
set MYCOUNTRY gis:load-dataset "data/CTRY_adm/CTRY-level_1.shp"
gis:set-world-envelope gis:envelope-of MYCOUNTRY
gis:set-drawing-color white
gis:draw MYCOUNTRY 3
reset-ticks
end