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?
I am new to Clojure, and I am trying to read a set of data from Yahoo's historical finance API. I've used slurp and reader on other URIs which seem to be fine, but I seem to be unable to read this specific one.
The problem URI: http://ichart.finance.yahoo.com/table.csv?s=WU&a=11&b=15&c=2016&d=11&e=19&f=2016&g=d&ignore=.csv
Accessing this from the browser results in a CSV file with data in it, but slurp/reader returns an empty vector. I've tried:
(def uri-string
(str "http://ichart.finance.yahoo.com/table.csvs=WU&a=11&b=15&c=2016&d=11&e=19&f=2016&g=d&ignore=.csv"))
(slurp uri-string)
and:
(with-open [rdr (clojure.java.io/reader "http://ichart.finance.yahoo.com/table.csv?s=WU&a=11&b=15&c=2016&d=11&e=19&f=2016&g=d&ignore=.csv")] (reduce conj [] (line-seq rdr)))
but neither work. Anyone have any ideas on how to proceed, or what the problem is here? Thanks in advance!
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
I'm trying to include a Google Maps widget in my admin-interface using this snippet on a Linux system (presently running locally on a Bitnami django stack in VMWare Player).
The map renders, but point features (any features really) in my database are not showing up on the map, and when trying to register points through the map interface, I get an error that:
An error occurred when transforming the geometry to the SRID of the geometry form field.
I realized from the geodjango docs that the Googles spatial reference system is not included when initializing the spatialite/sqlite database, and the solution should be to issue the following commands, to add the SRS:
$ python manage shell
>>> from django.contrib.gis.utils import add_srs_entry
>>> add_srs_entry(900913)
However, when I do this from my project directory, I get:
ERROR 6: EPSG PCS/GCS code 900913 not found in EPSG support files. Is this a valid
EPSG coordinate system?
I have confirmed that GDAL, GEOS and PROJ4 is installed, and I have added environment variables GDAL_DATA and PROJ_LIB to my .profile. I have checked the /usr/local/share/gdal/gcs.csv file which appears to not have an entry for 900913 (I have googled for other versions of gcs.csv, but none seem to contain 900913). I assume this is causing the error. However, the cubewerx_extra.wkt in the same directory does have a WKT entry for 900913.
My question is: How do I make add_srs_entry find the right SRS representation in order to add it to my database? Or is there a work-around, e.g. somehow converting the WKT representation and inserting it manually in gcs.csv?
I appreciate any help!
EDIT:
I found a way to manually insert the EPSG 900913 into the spatialite database. The solution is inspired by the sql-statement found at http:// trac.osgeo.org/openlayers/wiki/SphericalMercator (sorry, I don't have enough reputation to post more links) and issued to the database backend using raw sql (as described in the docs at https:// docs.djangoproject.com/en/dev/topics/db/sql/#executing-custom-sql-directly):
from django.db import connection, transaction
cursor = connection.cursor()
sql = "INSERT into spatial_ref_sys (srid, auth_name, auth_srid, ref_sys_name, proj4text) values (900913 ,'EPSG',900913,'Google Maps Global Mercator','+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=#null +no_defs');"
cursor.execute(sql)
transaction.commit_unless_managed()
I've confirmed that the entry is now in the spatial_ref_sys table. But I am still getting the same error when trying to add points in the admin-interface. Points can be added to the map, but when trying to save the feature, I get the error:
An error occurred when transforming the geometry to the SRID of the geometry form field.
Is the above sql statement correct? Is it sufficient, or does the add_srs_entry do other things as well?
Finally it could be a coding problem in my application, I will work on a minimal test-example and post it...
OK, I found the answer to the main question, as also indicated under the edit-post.
For future reference, here is a method how to add the Google spherical projection to a spatialite database (which must be already be spatially enabled):
1) Create a text file with the following content:
BEGIN;
INSERT into spatial_ref_sys (srid, auth_name, auth_srid, ref_sys_name, proj4text) values (900913,'EPSG',900913,'Google Maps Global Mercator','+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=#null +no_defs');
COMMIT;
2) Save the file with a name like init_EPSG900913.sql in the directory holding you spatialite database.
3) Issue the following command to execute the SQL statement on the database:
spatialite some_database.sqlite < init_EPSG900913.sql
Alternative method - From inside django-script or in "python manage.py shell":
from django.db import connection, transaction
cursor = connection.cursor()
sql = "INSERT into spatial_ref_sys (srid, auth_name, auth_srid, ref_sys_name, proj4text) values (900913 ,'EPSG',900913,'Google Maps Global Mercator','+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=#null +no_defs');"
cursor.execute(sql)
transaction.commit_unless_managed()
With either of these two methods, your database will have the Google Maps reference sytstem registered.
It turns out, that the missing EPSG definition was only part of the problem.
The other part was related to the fact that the app is running on a bitnami ubuntu django stack.
When following the installation guide in the geodjango docs on the bitnami ubuntu django stack, all the extra python packages and spatial libraries are installed in the system folders /user/local/..something.. not in the self-contained bitnami environment.
For future reference, make sure to issue the following statements before installing additional python packages:
$ sudo su
$ /opt/bitnami/use_djangostack
Then packages will be installed in the bitnami environment.
Also, when configuring builds of the different spatial libraries with the ./configure command, extra options must be added to place the shared files in the bitnami environment.
I have typically used something like:
$ ./configure --prefix=/opt/bitnami/common
Additional arguments might have to be passed as described in the geodjango docs - but the paths specified in these arguments must be changed to point to the proper subdirectories of /opt/bitnami/...
I downloaded the Australian OSM extract and moved it into a database called gis using osm2pgsql.
I have changed generate_tiles.py to only generate tiles for Australia:
bbox = (-180.0,-90.0, 180.0,90.0)
render_tiles(bbox, mapfile, tile_dir, 0, 5, "World")
minZoom = 10
maxZoom = 16
bbox = (101.1,-6.9,165.5,-45.9)
render_tiles(bbox, mapfile, tile_dir, minZoom, maxZoom)
When I attempt to generate tiles with:
export MAPNIK_MAP_FILE="osm.xml" && export MAPNIK_TILE_DIR="/tmp/tilecache/" && ./z0generate_tiles.py
Lots of directories are created in /tmp/tilecache with png tiles. The tiles have state boundaries and country names and there does appear to be highways.
But.. when I navigate to the address:
http://localhost/osm/tilecache-2.11/index.html
I only see countries and states, but no labels and no streets. I figure it is probably a permissions issue with accessing the postgis data. I have gone into psql and issued:
GRANT ALL PRIVILEGES ON DATABASE gis TO PUBLIC
In /etc/tilecache.cfg I have:
[cache]
type=Disk
base=/tmp/tilecache
[osm]
type=Mapnik
mapfile=/home/(my user_name)/bin/mapnik/my_osm.xml
spherical_mercator=true
tms_type=google
metatile=yes
[basic]
type=WMS
url=http://labs.metacarta.com/wms/vmap0
extension=png
It would seem that mapnik is not able to communicate with postgis. I have logged into postgres and executed:
GRANT ALL PRIVILEGES ON DATABASE gis TO PUBLIC
I generated the my_osm.xml file with the following:
./generate_xml.py osm.xml my_osm.xml --dbname gis --user (uname) --password (pword) --accept-none
It generated without any errors.
That's about as far as I can take it. New files are being created when accessed via the web, they just don't have any road information.
Any ideas?
One comment:
generate_tiles.py and tilecache are different applications and don't know about each other. So, your tilecache config will only be read by the tilecache application. But, if tilecache is used with 'tms_type=google', like you have done, the cache schemes used by each
program should match.
Couple things to check on your missing roads:
Sometime problems with old geos libraries can lead to lacking data imported by osm2pgsql, so make sure there are a lot of rows in the plant_osm_line table:
select count(*) from planet_osm_line;
Also, make sure you are running the latest Mapnik version, at least 0.7.0, ideally 0.7.1.
Try rendering a few maps with nik2img.py and make sure mapnik does now output any warnings that might be causing this - a common issue can be missing proj4 epsg definitions for EPSG:900913