Download the TransBASE project from Github.
Easy enough — just click the Download ZIP button or fork it if you’re savvy Git. I’m not a programmer by training so the project can probably use professional help. Please feel free to contribute.
Setting up an Amazon EC2 instance.
There are many excellent tutorials on the internet for setting up an Amazon EC2 cloud service so I’m going to not spend much time detailing these steps. I’m going to use a Windows machine because I’m lame but the project could definitely be hosted on Ubuntu if you’re into that.
Click Launch Instance to get the following screen.
Select your flavor of server. I’m going to use Windows Server 2008 R2 Base. None of the components that make up TransBASE are Windows specific so you could choose something else here but you’re on your own as far as setting it up.
For this tutorial I’m going to use a micro instance to keep the cost low. If you’re planning on running this in a production environment you will definitely want something more powerful.
Next you will be asked to setup a security group. You will need to allow connections through ports 3389 (make sure you specify only your IP address as being allowed to RDP), 80 (for Apache/PHP), 8080 for Tomcat, and 5432 for PostGIS.
Next you will be shown a review of your instance. Click the Launch button. A splash screen will appear asking you to select a private key that you will use to create a password for your server. Select Create a new key pair, give it a name, and download the .pem file. Save this file somewhere you will remember and in a place where it wont publicly accessible. Click Launch Instance and make yourself a snack — it usually takes 5-10 minutes for the instance to get up and running.
Next you need to assign an Elastic IP. This is prevent the IP address of the instance from being reset any time the instance is turned off. You can also use this static IP address with a DNS (I like namecheap). On the right hand menu click Elastic IPs. Click Allocate New Address towards the top of the screen. On the window that opens select VPC from the dropdown.
A new IP address will be created and added to the main page. Right click the new IP address and select Associate Address. In the window that appears select the instance you just created and click Associate. In this case I’m using 220.127.116.11 as my elastic IP.
Now you can connect to your instance using Remote Desktop, the key you downloaded earlier, and this static IP address. Go back to the Instances page (on the right side menu) and then right click your instance. Click Get Windows Password from the menu.
Right click your instance again and click Connect. A .rdp file will download. Using the password you just obtained, try logging into your instance.
Congrats! You’re now in the cloud.
Preparing the Stack.
The first thing you need to do is disable Internet Explorer’s crazy security settings so you can actually download all the open source components you need for TransBASE. Click the Server Manager button next to the Start Menu. In the Server Manager window click on Configure IE ESC.
In the Internet Explorer Enhanced Security Configuration window turn off IE ESC for both Administrators and Users.
Next you will need to download PostgreSQL/PostGIS. I prefer the package created by EnterpriseDB because it includes Apache (version) with PHP enabled and a stack builder for enabling PostGIS/ODBC in one install. You can download EnterpriseDB’s PostgreSQL installer here (link). If you would like to use PostGIS with ESRI ArcGIS I recommend installing version 9.1 – check out this link for more information.
Run the installer to setup PostgreSQL and click Next.
Select a location to install PostgreSQL. I’m going to go with the default installation location for this tutorial.
Select a location where your data will be stored. Again, I’m going to go with the default.
Create a password for your superuser account. By default this user will be given the name postgres. Make sure you write your password down.
Enter the port number you would like PostgreSQL to listen on. I’m going to use the default of 5432 for this tutorial.
Select a language.
Finally, PostgreSQL is ready to be installed. Click Next to continue.
At the end of the installation you will be prompted to Launch Stack Builder. Make sure this option is checked and click Finish.
Select your installation of PostgreSQL and click Next.
Check the following applications for installation: psqlODBC (if you want to use ODBC with your database); PostGIS 2.0 under spatial extensions; and Apache/PHP v2.4.12 under Web Development. A screen will appear confirming your selected packages. Use the default directory and click Next.
Each package you selected will then install. Click next until finished. For this tutorial I am using the default installation location for all of these components. Please use port 80 for the Apache/PHP server.
When you get to the PostGIS installer make sure “create spatial database” is checked.
Again, select an installation location. It should default to the location of your PostgreSQL folder.
Enter your postgres superuser information and click Next.
At this point you may receive an error message during the PostGIS installation. There seems to be a problem with the EnterpriseDB installer; however, you can click Ignore and continue the installation. The missing .dll doesn’t seem to have any adverse effect of PostGIS.
When asked to register an environmental variable for GDAL_DATA click Yes. GDAL is the library PostGIS uses to do Raster transformations. You can learn more about this cool project here (link).
After the installation of all the packages is complete verify that Apache has been installed correctly by opening your browser and navigating to http://localhost/.
Next click on the Start Menu an open pgAdmin. pgAdmin is a create GUI for accessing and querying your PostgreSQL databases.
Double click on your PostgreSQL instance. You will be prompted for the password you setup during installation. You should see two databases: postgis_template and postgres.
Let’s create a new database for all the data in TransBASE by restoring the pg_dump found on GitHub. Right click on your instance of PostgreSQL and select New Database.
Give it a name. In this tutorial I’ll be using transbase_demo. Set the owner of this new database to be your postgres superuser.
Next click on the Definition tab at the top of the window. Use the postgis_template as the template for this new database. The postgis_template has the PostGIS extension enabled and includes all the internal tables PostGIS will need to create geospatial data. Use UTF8 for encoding. Click OK to create a new empty database.
Right click on transbase_demo and click Restore. In the window that appears select Custom or tar from the dropdown box and navigate to the pg_dump of TransBASE you downloaded off GitHub then click Restore.
You may receive a message that the role “opendata” does not exist. A read-only role is current used on TransBASE with the name opendata. You can create this role at a later time if needed. This error will not impact the tutorial.
Double check that the pg_dump has been restored properly by checking out the tables under the public schema. As of 6/14/2015 39 tables and 36 views should be created.
Create a spatial query to ensure PostGIS is running properly with the new data. Click SQL button in the top tool bar and enter the following SQL statement:
SELECT count(vw_geo_intrsctn_switrs_all_types_cyc_col_prty_vctm.unique_id), geo_bndry_neighborhoods.neighborho FROM vw_geo_intrsctn_switrs_all_types_cyc_col_prty_vctm, geo_bndry_neighborhoods WHERE ST_Intersects (vw_geo_intrsctn_switrs_all_types_cyc_col_prty_vctm.geom, geo_bndry_neighborhoods.geom) GROUP BY geo_bndry_neighborhoods.neighborho ORDER BY count(vw_geo_intrsctn_switrs_all_types_cyc_col_prty_vctm.unique_id) DESC
This query will show a count of cyclist collisions by neighborhood in San Francisco.
Next you will need to setup Windows Firewall to allow incoming and outgoing connections on ports 80, 8080, and 5432. Click on the Start Menu then enter “firewall” in to the search bar and open the Windows Firewall with Advanced Security window.
Click Inbound Rules on the left side of the window then click New Inbound Rule on the left side of the window. Create a new rule that allows a TCP connection on port 5432 then click Next.
In the Action section select Allow the connection then click Next.
In the Action section select Allow the connection then click Next.
Give your new rule a name.
Next you will need to set PostgreSQL to allow connections from any IP address. You can quickly access pg_hba.conf using pgAdmin. Click on Tools, Server Configuration, then click pg_hba.conf.
Double click the top host.
Change the IP Address to 0.0.0.0/0. This will allow any IP Address to connect to this instance of PostgreSQL. You could also limit this IP address to the range of your internal network if desired.
Next you will want to setup Apache Tomcat. Tomcat is a Java servlet that we will use to run Geoserver and MapFish Print. The first step is to install a Java Runtime Environment (JRE). In this tutorial we’ll run Java SE Runtime Environment 8 64bit.
Double click the installation file after it has finished download. We’re going to all Java to install in the default location. Click Install.
After Java has finished we will need to create an environmental variable to our Java environment. In the Control Panel navigate to Systems and Security then Systems – click Advance system settings on the left hand site.
In the System Properties window click the Advance tab.
Click the Environmental Variables button toward the bottom of the window and create a new variable with the name JAVA_HOME and variable value that points to your …\Java\jre folder.
Next we will need to download Tomcat. For this tutorial I’m going to use Tomcat 7. Download the 32/64-bit Windows Service Installer.
After the installer downloads run it and click next when the Tomcat Setup screen appears.
Select the Normal installation and click next.
Use the default settings. In this tutorial Tomcat will be operating on port 8080. Click next.
If you set up your JAVA_HOME environmental variable correctly the Tomcat installer should recognize the location of your JRE’s installation directory. Click Next.
Pick a directory to install Tomcat or use the default location.
When the installation wizard is complete check Run Apache Tomcat and click Finish.
Open your browser and navigate to http://localhost:8080/. If Tomcat has been installed properly you should see the following page:
Next you will need to download a Geoserver web archive (WAR) to run on the Tomcat servlet. You can obtain the WAR file here. Geoserver will allow data stored in PostGIS to be served out in a variety of OGC compliant forms and consumed by a client application.
Download the latest Geoserver WAR (at the time of this writing 2.7.1), unzip the file, and save the .war file into the following directory: C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps.
Next you will need to add a role and user to access Tomcat’s manager interface. Navigate to the following file: C:\Program Files\Apache Software Foundation\Tomcat 7.0\conf\tomcat-users.xml and open the file in a text editor.
<role rolename = “manager-gui”/>
<user username=”manager” password=”[your_pass_word_here]” roles=”manager-gui”/>
Open the Tomcat manager (bottom right side of Windows bar at the bottom of the screen) then stop and start Tomcat.
Navigate to the Tomcat web application manager interface located here: http://localhost:8080/manager/
Log in using the user name and password you created previously.
In the manager interface you should see Geoserver as an application. Double check that the service is running.
Next navigate to the following web address: http://localhost:8080/geoserver. You should see the default Geoserver manager page.
The default user name for logging into Geoserver is “admin” and the password “geoserver.” Make sure to change these to something more secure using the web manager. After you login you should see a screen similar to the one below.
Some of the layer styles used in TransBASE require the Web Protocol Service (WPS) extension. This is not natively installed with Geoserver and will need to be added manually. Please go to the following website and download the appropriate zip file for your version of Geoserver.
Unzip or copy/paste the files you just downloaded to the following folder: C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\geoserver\WEB-INF\lib.
Next you will need to overwrite Geoserver’s workspace with TransBASE’s styles and layers. Copy the following folder from your Github download and paste it in this here: (folder). If asked if you would like to merge and overwrite the existing workspaces folder in Geoserver click yes.
Double click on the workspaces folder and delete all the other folders except transbase_public.
Navigate to the section of XML under <connectionParamters>. Change the following parameters to match your PostGIS instance:
<entry key =“database”>[name_of_your_transbase_database]</entry>
Save this file and restart Tomcat.
Log back into the Geoserver manager and click on the Layers link on the left side of the page. You should now see several layers/views being pulled from your PostGIS instance.
Next you will need to configure Apache and Tomcat to work together on the same port. Some of the pages that make up TransBASE utilize PHP which Apache can easily process. An alternative would be setting up Tomcat to use PHP but I’ve never had any luck getting it to work properly. Navigate to the following — C:\Program Files (x86)\PostgreSQL\EnterpriseDB-ApachePHP\apache\conf — and open httpd.conf in a text editor.
Search for the following modules and uncomment (remove the # sign) in front of them:
Near the top of httpd.conf you will need to set up a virtual host to route traffic for the Tomcat serevlet to Port 8080 while allowing PHP based pages to be processed by Apache Server. Copy the following text under “Listen 80”:
Allow from all
ProxyPass /metadata/metadata.php !
ProxyPass /metadata/connection.php !
ProxyPass /headerimages/rotate.php !
ProxyPass /bugreport/bugpage.php !
ProxyPass /newdatasets/newdatasets.php !
ProxyPass /youtube/youtube.php !
ProxyPass /metatable/metatable.php !
ProxyPass /connection/connection.php !
ProxyPass /faq/faq.php !
ProxyPass /logo/transbase_logo.png !
ProxyPass / http://[your_ip_address]:8080/
ProxyPassReverse / http://[your_ip_address]:8080/
Make sure to replace the bracketed text with your IP address.
The next step is to set up a Connector port on Tomcat to redirect outbound 8080 traffic back to Apache on port 80. Copy the following text into C:\Program Files\Apache Software Foundation\Tomcat 7.0\conf\server.xml under <Connector…>:
maxThreads=”150″ minSpareThreads=”25″ maxSpareThreads=”75″
enableLookups=”false” acceptCount=”100″ connectionTimeout=”20000″/>
Save the file when you’re finished.
Copy and paste the transbase folder into your webapps folder on Tomcat — C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps.
Open C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\transbase\scripts\heron-config\DefaultOptionsWorld.js and open it with a text editor. Use find and replace all to replace “transbasesf.org” with your project’s IP address.
Next copy over the ROOT folder into the webapps folder on Tomcat. If asked, say yes to overwriting any of the existing files in the ROOT folder.
Open up C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\ROOT\index.html in a text editor and change “transbasesf.org” to your domain or IP address.
Next copy all folders in the transbase apache folder over to here: C:\Program Files (x86)\PostgreSQL\EnterpriseDB-ApachePHP\apache\www.
Copy the print-servlet-2.0-SNAPSHOT folder into C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps. In order to enable MapFish Print you will need to open C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\print-servlet-2.0-SNAPSHOT\config.yaml and change the host to your IP address.
MapFish also requires an installation of Python 2.7 to operate. You can find Python here.
Run the installer and click Finish when it has completed.
Open up the Services window and restart both EnterpriseDB ApachePHP and Tomcat.
Navigate to your IP address in a web broswer and it should redirect to the TransBASE web application. Turn a layer on to make sure everything is working properly.
Click the printer icon and verify that MapFish Print is working correctly.
That’s it. The next steps would be to replace data in PostGIS with your own and modify the layers in TransBASE as needed to match your needs.