-
Notifications
You must be signed in to change notification settings - Fork 0
/
OTMVagrantUp.html
1 lines (1 loc) · 39.2 KB
/
OTMVagrantUp.html
1
<html><head><title>OTM Vagrant Up</title><style type="text/css">ol{margin:0;padding:0}.c6{max-width:468pt;background-color:#ffffff;padding:72pt 72pt 72pt 72pt}.c2{color:#222222;font-size:10pt;background-color:#ffffff}.c5{color:#1155cc;text-decoration:underline}.c4{color:inherit;text-decoration:inherit}.c1{height:11pt}.c3{font-weight:bold}.c0{direction:ltr}.title{padding-top:0pt;line-height:1.15;text-align:left;color:#000000;font-size:21pt;font-family:"Trebuchet MS";padding-bottom:0pt}.subtitle{padding-top:0pt;line-height:1.15;text-align:left;color:#666666;font-style:italic;font-size:13pt;font-family:"Trebuchet MS";padding-bottom:10pt}li{color:#000000;font-size:11pt;font-family:"Arial"}p{color:#000000;font-size:11pt;margin:0;font-family:"Arial"}h1{padding-top:10pt;line-height:1.15;text-align:left;color:#000000;font-size:16pt;font-family:"Trebuchet MS";padding-bottom:0pt}h2{padding-top:10pt;line-height:1.15;text-align:left;color:#000000;font-size:13pt;font-family:"Trebuchet MS";font-weight:bold;padding-bottom:0pt}h3{padding-top:8pt;line-height:1.15;text-align:left;color:#666666;font-size:12pt;font-family:"Trebuchet MS";font-weight:bold;padding-bottom:0pt}h4{padding-top:8pt;line-height:1.15;text-align:left;color:#666666;font-size:11pt;text-decoration:underline;font-family:"Trebuchet MS";padding-bottom:0pt}h5{padding-top:8pt;line-height:1.15;text-align:left;color:#666666;font-size:11pt;font-family:"Trebuchet MS";padding-bottom:0pt}h6{padding-top:8pt;line-height:1.15;text-align:left;color:#666666;font-style:italic;font-size:11pt;font-family:"Trebuchet MS";padding-bottom:0pt}</style></head><body class="c6"><p class="c0"><span>This install process uses Vagrant to manage the Virtual Machine, which introduces some particularities (specifically around Postgres) to the install. But you don’t have to use Vagrant with OpenTreeMap if you don’t want to - feel free to use VirtualBox, another VM host, or install OTM right on your webserver.</span></p><p class="c1 c0"><span></span></p><p class="c0"><span class="c3">Step 1: Install Vagrant</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>vagrant up</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>vagrant ssh</span></p><p class="c1 c0"><span></span></p><p class="c0"><span class="c3">Step 2: Git clone!</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>Many of the commands in this installation require root privileges; only switch to the root user prompt with the command below if you’re comfortable with what you’re doing and have room to experiment. We will, so we don’t have to add “sudo” to many of the proceeding commands. You could use “sudo” or change your user’s folder permissions instead.</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>sudo su</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>Make a directory for OpenTreeMap and its main components.</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>mkdir /var/projects/otm</span></p><p class="c0"><span>cd /var/projects/otm</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>Install git and clone the OpenTreeMap repository. As of June 2013, the most recent branch to clone off of is v1.3.</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>apt-get install git</span></p><p class="c0"><span>git clone -b v1.3 git://github.com/azavea/OpenTreeMap.git</span></p><p class="c1 c0"><span></span></p><p class="c0"><span class="c3">Step 3: Set up Python environment and gather dependencies</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>OpenTreeMap is a Django application written mainly in Python, and requires specific versions of a number of other Python libraries to function. Conveniently, a “requirements.txt” file is included in the repository that can be used with the pip installer to download and install these dependencies easily.</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>Copy the requirements.txt file out into your main otm directory.</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>cp OpenTreeMap/requirements.txt requirements.txt</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>Next, we’ll install pip using Python’s older “easy_install” feature.</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>sudo apt-get -y install python-setuptools</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>sudo easy_install pip</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>Now we’ll use pip to install virtualenv, a tool used for creating isolated Python environments. Virtualenv is useful for keeping many different versions of dependencies installed on the same machine without having them conflict with one another. This means OpenTreeMap can have its own library versions, and any other Python applications you have running on your machine can have their separate versions too.</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>sudo pip install virtualenv</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>Create a virtual environment in your otm directory, so you know to what it belongs to.</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>cd /var/projects/otm #if you’re not already there</span></p><p class="c0"><span>virtualenv env #you can call it something more distinctive than “env,” but it’s conveniently short</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>Activate the environment. Notice an “(env)” indicator appears at the beginning of your command prompt line, signifying that you are using this particular environment.</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>source env/bin/activate</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>Next, we’ll use aptitude to get many non-Python libraries we need. It’s a good idea to update your aptitude repositories so Ubuntu knows where to find the libraries we’re going to install.</span></p><p class="c0 c1"><span></span></p><p class="c0"><span>apt-get update</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>sudo apt-get install sendmail</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>apt-get install postgresql</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>apt-get install python-dev build-essential postgresql-server-dev-all</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>apt-get install libgdal1-1.7.0</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>apt-get install libgdal1-dev</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>Finally, we install the required Python dependencies into our virtual environment!</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>pip install -r requirements.txt</span></p><p class="c1 c0"><span></span></p><p class="c0"><span class="c3">Step 4: Install Python bindings for GDAL</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>GDAL is an open source geospatial data transformation library. Unfortunately, something went awry/missing in the packaging of the Python bindings for GDAL 1.7, so the next few lines are tricky. Just trust us.</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>pip install --no-install gdal==1.7.0</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>cd /usr/lib && sudo ln -s libgdal1.7.0.so libgdal.so</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>cd /usr/include/gdal</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>Find the swq.h file in this directory. It (mistakenly) is probably empty. Delete this empty version and make sure it’s gone.</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>rm swq.h</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>Now we have to download the right, non-empty swq.h file to this folder from the Internet...</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>wget </span><span class="c5"><a class="c4" href="http://svn.osgeo.org/gdal/branches/1.7/gdal/ogr/swq.h">http://svn.osgeo.org/gdal/branches/1.7/gdal/ogr/swq.h</a></span><span> > swq.h</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>To finish the installation of the GDAL Python bindings, we’ll run setup.py and pip install again, with the proper include directories.</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>cd /var/projects/otm/env/build/gdal</span></p><p class="c0"><span>python setup.py build_ext --include-dirs=/usr/include/gdal</span></p><p class="c0"><span>pip install --no-download gdal</span></p><p class="c1 c0"><span></span></p><p class="c0"><span class="c3">Step 5: Install PostGIS</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>cd /var/projects/otm/OpenTreeMap</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>sudo apt-get install postgresql-9.1-postgis postgis</span></p><p class="c1 c0"><span></span></p><p class="c0"><span class="c3">Step 6: Install final set of Python dependencies that couldn’t be installed easily through pypi</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>These include django-registration and django-reputation, which are only in bitbucket and Google Code repositories.</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>pip install </span><span class="c5"><a class="c4" href="https://bitbucket.org/ubernostrum/django-registration/downloads/django-registration-0.8-alpha-1.tar.gz">https://bitbucket.org/ubernostrum/django-registration/downloads/django-registration-0.8-alpha-1.tar.gz</a></span></p><p class="c1 c0"><span></span></p><p class="c0"><span>apt-get install subversion</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>cd /var/projects/otm</span></p><p class="c0"><span>mkdir temp</span></p><p class="c0"><span>cd temp</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>svn checkout http://django-reputation.googlecode.com/svn/trunk/ django-reputation</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>cp -r django-reputation/django_reputation/ ..env/lib/python2.7/site-packages/</span></p><p class="c1 c0"><span></span></p><p class="c0"><span class="c3">Step 7: Apply patches.</span></p><p class="c0"><span>fix proj, django-sorting, and django-reputation patches listed in README now</span></p><p class="c1 c0"><span></span></p><p class="c0"><span class="c3">Step 8: Create PostGIS-enabled database template</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>To do this, we’ll need to switch to the Postgres user prompt.</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>su postgres</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>And run the psql prompt. This is where some of the particularities around using Vagrant can come to bite if you’re not careful. Vagrant’s Ubuntu has its Locale set up differently than PostGIS is expecting. If you’re using vagrant, do this.....if not, do these....</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>psql</span></p><p class="c0"><span>## if no vagrant: CREATE DATABASE template_postgis OWNER postgres</span></p><p class="c0"><span>##if vagrant: CREATE DATABASE template_postgis OWNER postgres TEMPLATE template0 ENCODING ‘UTF8’ LC_CTYPE ‘en_US.UTF8’ LC_COLLATE ‘en_US.UTF8’;</span></p><p class="c0"><span>#### locales - see </span><span class="c5"><a class="c4" href="https://help.ubuntu.com/community/Locale">https://help.ubuntu.com/community/Locale</a></span><span> and </span><span class="c5"><a class="c4" href="https://gist.github.com/jschoolcraft/1963369">https://gist.github.com/jschoolcraft/1963369</a></span><span> and </span><span class="c5"><a class="c4" href="http://programming.aiham.net/2011/07/26/changing-locale-of-postgresql-db-cluster/">http://programming.aiham.net/2011/07/26/changing-locale-of-postgresql-db-cluster/</a></span></p><p class="c0"><span>#### bigdeal: </span><span class="c5"><a class="c4" href="http://blog.crowdint.com/2011/08/11/postgresql-in-vagrant.html">http://blog.crowdint.com/2011/08/11/postgresql-in-vagrant.html</a></span></p><p class="c0"><span>l\q</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>Now we need to load PostGIS’ features into our PostGIS template database.</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>psql template_postgis -f /usr/share/postrgesql/9.1/contrib/postgis-1.5/postgis.sql</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>psql template_postgis -f /usr/share/postrgesql/9.1/contrib/postgis-1.5/spatial_ref_sys.sql</span></p><p class="c1 c0"><span></span></p><p class="c0"><span class="c3">Step 9: Create the OpenTreeMap database</span></p><p class="c1 c0"><span class="c3"></span></p><p class="c0"><span>psql</span></p><p class="c0"><span>CREATE USER otm ENCRYPTED PASSWORD ‘otm’;</span></p><p class="c0"><span>CREATE DATABASE otm OWNER otm TEMPLATE template_postgis;</span></p><p class="c0"><span>\c otm</span></p><p class="c0"><span>alter table geometry_columns OWNER TO otm;</span></p><p class="c0"><span>alter table spatial_ref_sys OWNER TO otm;</span></p><p class="c0"><span>####don’t think needed, if so it’s “alter view geometry_columns...” alter view OWNER TO otm;</span></p><p class="c0"><span>\q</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>exit #from postgres user back to your own shell</span></p><p class="c1 c0"><span></span></p><p class="c0"><span class="c3">Step 10: Modify OTM’s local_settings.py file</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>It needs to have your database connection information, and other things.</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>cd /var/projects/otm/OpenTreeMap # if not already</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>cp local_settings.example.py local_settings.py</span></p><p class="c0"><span>nano it</span></p><p class="c0"><span>##################################</span></p><p class="c0"><span>the databases section looks like...</span></p><p class="c0"><span>DATABASES = { ‘default’ : {</span></p><p class="c0"><span>‘NAME’ : ‘otm’,</span></p><p class="c0"><span>‘ENGINE’ : ‘postgis junk’,</span></p><p class="c0"><span>‘USER’ : ‘otm’,</span></p><p class="c0"><span>‘PASSWORD’ : ‘otm’,</span></p><p class="c0"><span>‘HOST’ : ‘localhost’,</span></p><p class="c0"><span>‘PORT’ : ‘5432’,</span></p><p class="c0"><span>}</span></p><p class="c0"><span>}</span></p><p class="c0"><span>#######################################</span></p><p class="c1 c0"><span></span></p><p class="c1 c0"><span></span></p><p class="c0"><span>cd /var/projects/otm/OpenTreeMap</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>######################</span></p><p class="c0"><span>Edit the local_settings.py file. Make sure</span></p><p class="c0"><span>- TEMPLATE_DIRS has the os.path.join(os.path.dirname(__file__), ‘templates’), and that’s where the templates from the repo is</span></p><p class="c0"><span>- STATICFILES_DIRS has the same thing (you will have to add it)</span></p><p class="c0"><span>os.path.join(os.path.dirname(__file__), ‘static’)</span></p><p class="c0"><span>- change the SECRET_KEY</span></p><p class="c0"><span>- change STATIC_ROOT to the same</span></p><p class="c0"><span>- change emails</span></p><p class="c0"><span>###</span></p><p class="c0"><span class="c3">Step 11: Put settings from choices.py into local_settings.py</span></p><p class="c1 c0"><span class="c3"></span></p><p class="c0"><span>wget choices.py from Philadelphia.git on Azavea server</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>cat choices.py >> local_settings.py # this will append the choices to local settings. You could also copy/paste</span></p><p class="c0"><span># may need to add:</span></p><p class="c0"><span>,</span></p><p class="c0"><span>‘pests’: [</span></p><p class="c0"><span>]</span></p><p class="c0"><span>################</span></p><p class="c1 c0"><span></span></p><p class="c0"><span class="c3">Step 12: Run syncdb and migrate</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>python manage.py syncdb</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>## may ask you to create a superuser for django auth. I did. andrewuser/andrewuser</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>python manage.py migrate</span></p><p class="c1 c0"><span></span></p><p class="c0"><span class="c3">Step 13: Test! (Is it alive?)</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>python manage.py runserver # test if it works with /map/, if in vagrant you’ll need to bind 0.0.0.0:8000.</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>Test /_admin_/ - if no CSS shows up, and your ADMIN_MEDIA_ROOT is os.path.join.admin_media, you’ll need:</span></p><p class="c0"><span>ln -s /var/projects/otm/env/lib/python2.7/site-packages/django/contrib/admin/media /var/projects/otm/admin_media</span></p><p class="c1 c0"><span></span></p><p class="c0"><span class="c3">Step 14: Install and configure the nginx HTTP server</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>apt-get install nginx</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>configure nginx as I think I have in /etc/nginx/sites-available, symlink to sites-enabled, etc.</span></p><p class="c1 c0"><span></span></p><p class="c0"><span class="c3">Step 16: Add users and groups and permissions in Django</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>Do the users and groups permission adding on the wiki through the django admin interface.</span></p><p class="c1 c0"><span></span></p><p class="c0"><span class="c3">Step 17: Install Geoserver</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>Use your favorite app server, like Apache Tomcat.</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>apt-get install tomcat7</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>wget </span><span class="c5"><a class="c4" href="http://downloads.sourceforge.net/geoserver/geoserver-2.3.1-war.zip">http://downloads.sourceforge.net/geoserver/geoserver-2.3.1-war.zip</a></span></p><p class="c1 c0"><span></span></p><p class="c0"><span>unzip geoserver-2.3.1-war.zip</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>sudo cp geoserver.war /var/lib/tomcat7/webapps</span></p><p class="c0"><span># you may want to do Kurt’s suggestions about separating the data directory, I did...not sure about the server.xml port change though</span></p><p class="c1 c0"><span></span></p><p class="c0"><span class="c3">Step 18: Wrangle your neighborhood data</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>You will need a set of “neighborhoods” or other geographical boundaries to use with OpenTreeMap. These could be states, counties, municipalities, actual neighborhoods within municipalities, or any combination thereof. Increasingly, you can get these from government open data catalogs, often in “shapefile” format. A shapefile often comes as a .zip file with a number of constituent files (.prj, .dbf, .shp, etc.)</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>Get your hands on a neighborhood shapefile, and unzip it to a directory. You can use a tool called “shp2pgsql” to turn the shapefile into SQL statements to build a table from in PostGIS.</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>A crucial point - many shapefiles from government data catalogs will use a special projection (denoted by EPSG codes), often specific to that area. It can be easier to work with spatial data if it’s all of the same projection. Assuming that the tree locations you’ll eventually import probably are already in latitude and longitude (and unprojected at that - they probably came directly from a GPS), it makes sense to import your neighborhoods into PostGIS as unprojected latitude and longitude too. That’s EPSG code 4326.</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>Replace the “####” below with the EPSG code for your shapefile. Also, when running this command, make sure the directory you’re in has the .shp file as well as the .dbf, .prj, and any other files that were unzipped, and that they all have the same name (aside from the file extension). shp2pgsql will use them all, but it doesn’t matter which file you run the command on. .shp is safe.</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>shp2pgsql -s ####:4326 YOURFILENAMEHERE.shp > YOURFILENAMEHERE.sql</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>Now we can run this SQL file, which will create a table in our database with the same name as the file.</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>sudo -u postgres psql otm -f YOURFILENAMEHERE.sql</span></p><p class="c1 c0"><span></span></p><p class="c0"><span class="c3">Step 19: Insert neighborhood SQL data into treemap_neighborhood table</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>Now, let’s go into psql and select the relevant columns and insert them into the treemap_neighborhood table. Viewing the data in the table we created with PGAdmin on your host might be helpful to determining which columns you’ll need and how to map them to treemap_neighborhood.</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>Keep in mind the way OTM cycles through neighborhoods LINK - you should import your neighborhoods with the smallest geographic areas first into the treemap_neighborhoods table, then municipalities, counties, states, so on and so forth.</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>treemap_neighborhood columns and type</span></p><p class="c0"><span>id - serial primary key</span></p><p class="c0"><span>name - varchar(255)</span></p><p class="c0"><span>region_id - integer</span></p><p class="c0"><span>county - varchar(255)</span></p><p class="c0"><span>state - varchar(2)</span></p><p class="c0"><span>geometry - geometry</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>QUICK WAY:</span></p><p class="c0"><span>sudo su postgres</span></p><p class="c0"><span>psql</span></p><p class="c0"><span>\c otm</span></p><p class="c0"><span>INSERT INTO treemap_neighborhood (id, name, region_id, city, county, state, geometry) SELECT neighborhoods_wgs84.gid, neighborhoods_wgs84.fullhood, 42, ‘Toronto’, ‘’, ‘ON’, neighborhoods_wgs84.the_geom FROM neighborhoods_wgs84;</span></p><p class="c0"><span>#the 42 region_id can be any constant, I think...</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>################SAFE WAY:</span></p><p class="c0"><span>alternative is to create temporary table, insert, check, then select *</span></p><p class="c0"><span>CREATE TABLE temp_nhood (id serial primary key, name varchar(255) NOT NULL, region_id integer NOT NULL, city varchar(255) NOT NULL, county varchar(255) NOT NULL, state varchar(2), geometry geometry);</span></p><p class="c0"><span>INSERT INTO temp_nhood # same as above statement.....</span></p><p class="c0"><span># check the data</span></p><p class="c0"><span>INSERT INTO treemap_neighborhood SELECT * FROM temp_nhood;</span></p><p class="c1 c0"><span></span></p><p class="c0"><span class="c3">Step 19: Create tree_search view</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>cd /var/projects/otm/OpenTreeMap</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>sudo su postgres</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>psql -d otm -a -f scripts/db/create_search_view.sql</span></p><p class="c1 c0"><span></span></p><p class="c0"><span class="c3">Step 20: Grant user “otm” permissions on said view</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>An easy way to run this is via the PGAdmin SQL query window on your host. You could also use the psql prompt within your VM.</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>GRANT SELECT ON tree_search TO otm;</span></p><p class="c1 c0"><span></span></p><p class="c0"><span class="c3">Step 21: Import i-Tree data</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>Import itree spreadsheets WE ARE BACK HERE!!!</span></p><p class="c0"><span>python manage.py itree_import /vagrant/itree/Hydro_Interception.csv hydro_interception_dbh</span></p><p class="c1 c0"><span></span></p><p class="c0"><span class="c3">Step 22: Import species data</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>Determine which species of tree you’re going to allow in your OTM installation, and make a csv file with their information following the template </span><span class="c5"><a class="c4" href="https://github.com/azavea/OpenTreeMap/blob/v1.3/treemap/management/commands/species_import_template.csv">https://github.com/azavea/OpenTreeMap/blob/v1.3/treemap/management/commands/species_import_template.csv</a></span></p><p class="c1 c0"><span></span></p><p class="c0"><span>Then, use the manage.py command to import them.</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>python manage.py speciesimport /vagrant/itree/species_import_toronto.csv</span></p><p class="c1 c0"><span></span></p><p class="c0"><span class="c3">Step 23: Import trees (if you have them yet!)</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>Following the uimport template, make a csv file of whatever beginning inventory you’ve done. Perhaps you can get this information from an open data catalog or a horticultural society in your area.</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>You may want to import this tree information in small chunks to start out if you have hundreds or thousands. The import process may take a long time - 10 seconds per tree is not unheard of.</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>python manage.py uimport /vagrant/itree/small/xaa.csv - got a few Ulmus americanas</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>python manage.py update_aggregates</span></p><p class="c1 c0"><span></span></p><p class="c1 c0"><span></span></p><p class="c0"><span class="c3">Step 22: Add Workspace, Store, and layers in Geoserver</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>Note, you’ll need your nginx proxy configured right to get into the Geoserver admin from your host machine. Default password is admin/geoserver.</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>First, create a new Workspace. To be simple, give it a name of “otm” with a Namespace URI also of “otm”. Hit Save.</span></p><p class="c0"><span>Next, add a new Store. Select the PostGIS option. Put it in the “otm” Workspace you just made. Give it a Data Source Name. This could be “otm-yourcity” or something like that. Give it the right connection parameters, specifying the “otm” database you created earlier and the “otm” user. Other defaults should be fine. Hit Save.</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>Next, go to the Layers tab, click “Add a new resource”. Add it from the “otm:otm-yourcity” Store you just created. In the list of possible layer names that pops up (based on the tables available in your Postgres/PostGIS database), search for the “treemap_neighborhood” layer name and hit “Publish.” Default name and title should be fine, the important bits are the Coordinate Reference Systems and the Bounding Boxes. </span></p><p class="c0"><span>If you imported your neighborhood shapefile as 4326, select that as the native and declared SRS. Next, you should be able to hit “compute from data” and “compute from native bounds” to get the two Bounding Boxes automatically. Save the treemap_neighborhood layer.</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>Now, we need to add a treemap_plot layer. Go through the same steps as you did for the treemap_neighborhood layer, except publish the “treemap_plot” layer. And, importantly, copy/paste the 8 bounding box coordinates from the treemap_neighborhood layer rather than computing them automatically. The treemap_plot layer defines where users are allowed to add plots (and thus trees). We want users to be able to add trees throughout the different neighborhoods.</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>Finally, add a new layer around the “tree_search” view. Assuming the tree data you’ll be importing has unprojected latitude and longitude points, your Declared SRS can be “EPSG:4326” and SRS Handling can be “Force Declared”. Next, for the two Bounding Boxes, you should be able to hit “Compute from data” and “Compute from native bounds.” If you run into errors, go back to step 20 and check that the user you set up for your Store has proper permissions to view the tree_search view.</span></p><p class="c0"><span>Hit Save.</span></p><p class="c1 c0"><span></span></p><p class="c0"><span class="c3">Step 23: Create a Geoserver Layer Group</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>with neighborhoods and plots, and maybe trees too</span></p><p class="c0"><span>go to Data > LAyer groups</span></p><p class="c0"><span>combine neighborhood layer with the plot layer so tilecache only has to cache one layer. We do that with a layer group.</span></p><p class="c0"><span>name otm</span></p><p class="c0"><span>title otm</span></p><p class="c0"><span>workspace otm</span></p><p class="c0"><span>Add layer (ordering does matter. both are valid, but neighborhoods could be on top of trees, or vice versa depending on preference)</span></p><p class="c0"><span>Generate Bounds button</span></p><p class="c0"><span>Save</span></p><p class="c1 c0"><span></span></p><p class="c1 c0"><span></span></p><p class="c0"><span class="c3">Step 24: Add the new tree_search layer to local_settings.py</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>Look for the GEOSERVER_GEO_LAYER parameter. If you kept the defaults, you should set this to ‘otm:tree_search’. IE, workspace:layer.</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>Next, change the GEOSERVER_URL to ‘</span><span class="c5"><a class="c4" href="http://localhost:8000/geoserver/">http://localhost:8000/geoserver/wms</a></span><span>’, assuming that’s the port and location you configured with nginx.</span></p><p class="c1 c0"><span></span></p><p class="c0"><span class="c3">Step 25: Install TileCache</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>cd /var/projects/</span></p><p class="c0"><span>mkdir tilecache</span></p><p class="c0"><span>cd tilecache</span></p><p class="c0"><span>#deactivate - if needed to deactivate current otm env</span></p><p class="c0"><span>virtualenv env # create new one</span></p><p class="c0"><span>source env/bin/activate</span></p><p class="c0"><span>pip install tilecache</span></p><p class="c0"><span>pip install paste</span></p><p class="c0"><span>cp env/TileCache/tilecache.cfg /etc/tilecache.cfg</span></p><p class="c1 c0"><span></span></p><p class="c0"><span class="c3">Step 26: Configure TileCache</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>edit /etc/tilecache.cfg</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>#name tilecache layers CAPITALS of geosever layer names, as a convention</span></p><p class="c0"><span>[OTM]</span></p><p class="c0"><span>url=</span><span class="c5"><a class="c4" href="http://localhost:8080/wms?transparent=true">http://localhost:8080/wms?transparent=true</a></span></p><p class="c0"><span>layers=otm:otm #the name of the layer group</span></p><p class="c0"><span>bbox=# bounding box of the world or of the layer</span></p><p class="c0"><span>srs</span></p><p class="c0"><span>reproject</span></p><p class="c0"><span>levels=22</span></p><p class="c1 c0"><span></span></p><p class="c0"><span class="c3">Step 27: Add tilecache to nginx config</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>cd /etc/nginx/sites-available/</span></p><p class="c0"><span>edit the otm file here.</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>upstream otm {</span></p><p class="c0"><span> server localhost:12000;</span></p><p class="c0"><span>}</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>server {</span></p><p class="c0"><span> listen 8000;</span></p><p class="c1 c0"><span></span></p><p class="c0"><span> location / {</span></p><p class="c0"><span> proxy_pass </span><span class="c5"><a class="c4" href="http://127.0.0.1:12000">http://127.0.0.1:12000</a></span><span>;</span></p><p class="c0"><span> }</span></p><p class="c1 c0"><span></span></p><p class="c0"><span> location /static/ {</span></p><p class="c0"><span> alias /var/projects/otm/OpenTreeMap/static/;</span></p><p class="c0"><span> }</span></p><p class="c1 c0"><span></span></p><p class="c0"><span> location /geoserver {</span></p><p class="c0"><span> proxy_pass http:127.0.0.1:8081/geoserver #canonical is port 8080</span></p><p class="c0"><span> }</span></p><p class="c1 c0"><span></span></p><p class="c0"><span> location /tilecache {</span></p><p class="c0"><span> proxy_pass htpp:127.0.0.1:8082/tilecache; #canonical is port 8081</span></p><p class="c0"><span> }</span></p><p class="c0"><span>}</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>restart nginx</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>sudo service nginx restart</span></p><p class="c1 c0"><span></span></p><p class="c0"><span class="c3">Step 28: Fix TileCache TMS bug</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>cd /var/projects/tilecache/env/lib/python2.7/site-packages/TileCache/Services</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>edit TMS.py</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>add line:</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>….</span></p><p class="c0"><span>elif len(parts) < 2:</span></p><p class="c0"><span> return self.serviceCapabilities(host, self.service.layers)</span></p><p class="c0"><span>else:</span></p><p class="c0"><span> parts = parts[-5:] # this is the line that needs to be added!!!</span></p><p class="c0"><span> layer = self.getLayer(parts[1])</span></p><p class="c0"><span> if len(parts) < 3:</span></p><p class="c0"><span> ….</span></p><p class="c1 c0"><span></span></p><p class="c0"><span class="c3">Step 29: Add TileCache settings to local_settings.py</span></p><p class="c1 c0"><span class="c3"></span></p><p class="c0"><span>cd /var/projects/otm/OpenTreeMap/</span></p><p class="c0"><span>edit local_settings.py</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>look for TILECACHE_URL = “</span><span class="c5"><a class="c4" href="http://localhost:8000/tilecache">http://localhost:8000/tilecache</a></span><span>”</span></p><p class="c0"><span>look for TILECACHE_LAYER = “OTM”</span></p><p class="c1 c0"><span></span></p><p class="c0"><span class="c3">Step 30: Change Bounding Box in local_settings.py</span></p><p class="c1 c0"><span class="c3"></span></p><p class="c0"><span class="c3">Step 31: Change restricted extent in static/js/map.js</span></p><p class="c1 c0"><span class="c3"></span></p><p class="c0"><span>var restr = new OpenLayers.bounds(web mercator junk)</span></p><p class="c0"><span>currently that’s commented out on mine (so it’s unlimited), I need to take the toronto bbox and convert it to web mercator</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>also probably need to adjust the default zoom level somewhere</span></p><p class="c1 c0"><span></span></p><p class="c0"><span class="c3">Step 32: Add missing image files???</span></p><p class="c1 c0"><span class="c3"></span></p><p class="c0"><span class="c3">Step 33: Add values to treemap_benefitvalues table so /search/ stops giving 500 errors</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>The treemap_benefitvalues table is where OpenTreeMap gets its information about the prices of various eco-benefits: KWH of electricity, natural gas savings, etc etc. This information varies from city to city and region to region. To get accurate information for your area, you’ll have to do some research.</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>In addition to displaying the main eco-benefit sidebar on the main page, values in this table are needed to perform tree and neighborhood searches. If you leave it blank, many links will result in 500 server errors. To just get the map working, you can use the default values from phillytreemap.org:</span></p><p class="c1 c0"><span></span></p><p class="c0"><span class="c2">id - 3</span></p><p class="c0"><span class="c2">area - Philadelphia</span></p><p class="c0"><span class="c2">stormwater - 0.0099</span></p><p class="c0"><span class="c2">electricity - 0.1262</span></p><p class="c0"><span class="c2">natural_gas - 1.5</span></p><p class="c0"><span class="c2">co2 - 0.00334</span></p><p class="c0"><span class="c2">ozone - 4.59</span></p><p class="c0"><span class="c2">nox - 4.59</span></p><p class="c0"><span class="c2">pm10 - 8.31</span></p><p class="c0"><span class="c2">sox - 3.48</span></p><p class="c0"><span class="c2">voc - 2.31</span></p><p class="c0"><span class="c2">bvoc - 2.31</span></p><p class="c1 c0"><span></span></p><p class="c1 c0"><span></span></p><p class="c0"><span class="c3">Step 34: Start TileCache</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>cd /var/projects/tilecache/</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>tilecache_http_server.py -p 8082 # or whichever port you put in nginx config</span></p><p class="c1 c0"><span></span></p><p class="c0"><span class="c3">Step 35: Start Django runserver</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>actually deploy with something real though, please. Visit it It works!</span></p><p class="c1 c0"><span></span></p><p class="c0"><span>change SLDs to something better...</span></p></body></html>