Tag Archives: PHP

Realtime Bus Map Using OpenLayers and KML

12 Jan

The City of Albuquerque posts a KML file every minute that shows the location of a bus. Using OpenLayers and Open Street Map, I built a map to display route 157.

I needed the KML to be stored locally do I created a PHP script to grab the file. In the HTML, I called the script using . It runs, saves the KML and then OpenLayers displays it.

I would like to use $_GET to allow the passing of a route # to find your bus and a QRCode on the bus sign.

See the map.


Calling Python From PHP: A GIS Example

12 Nov

I showed in a past post how you could use Python and CherrPy to make web based GIS applications. While I think this is a great way to develop, I currently have WAMP installed and can run PHP through Apache without any extra configuration. I decided to take a look at how I could run my Python GIS Scripts through a PHP based website. It turns out that it is a rather simple task:

<?php exec(“C:\python25\python mygi.py”); ?>

That is all there is to it. Now let me give you an example of how I would use this:

  1. I want to create a website where a person can select one of my shapefiles and a toolbox and then have the output sent back to them. If you want you could even let them upload their own file then you run the tools on it – if they wanted the results for their ArcGIS Online maps and lacked processing tools.
  2. For simplicity, I will default to the Gi* toolbox.
  3. When they click submit, I will generate the Python code in the PHP and then run the script. Doing this allows me to customize all of my Python scripts based on user preference. I can plug user input in to all of my functions.
  4. Lastly, the website will hand back the zipped files.

Here is the code for the form.

<H3>Enter a file to run Gi*</H3>
<form name=”input” action=”gi.php” method=”get”>
Shapefile: <input type=”text” name=”shp”><br>
<input type=”submit” value=”Submit”>

Simply a text box to enter a file name and a submit button. The for calls gi.php, which contains:

<H1>Running Gi*</H1>
<h2>On file <?php echo $_GET[“shp”];  ?>

$py= fopen(‘mygi.py’, ‘w+’);
$header=’import arcgisscripting’.”\n”.’import zipfile’.”\n”;
$gp = ‘gp = arcgisscripting.create()’.”\n”.’gp.workspace = “C:\wamp\www\output”‘.”\n”;
$hs=’hs = gp.HotSpots(“‘.$_GET[“shp”].'”, “Score”, “HotSpots.shp”, “Fixed Distance Band”, “Euclidean Distance”, “None”, “2500”, “#”, “#”)’.”\n”;
$z=’zipped = zipfile.ZipFile(“C:\wamp\www\output\hotspots.zip”, mode=”w”)’.”\n”.’zipped.write(“C:\wamp\www\output\hotspots.shp”)’.”\n”.’zipped.write(“C:\wamp\www\output\hotspots.shx”)’.”\n”.’zipped.write(“C:\wamp\www\output\hotspots.prj”)’.”\n”.’zipped.write(“C:\wamp\www\output\hotspots.shp.xml”)’.”\n”.’zipped.write(“C:\wamp\www\output\hotspots.sbx”)’.”\n”.’zipped.write(“C:\wamp\www\output\hotspots.sbn”)’.”\n”.’zipped.write(“C:\wamp\www\output\hotspots.dbf”)’.”\n”.’zipped.close()’;

<H3>Wrote Python….Executing</H3>

<?php exec(“C:\python25\python mygi.py”); ?>


<a href=”/output/HotSpots.zip”>hotspots.zip</a>


The first thing the script does is print the name of the file they entered as an <H2>. Then the PHP opens a python file and writes the code. It then executes the code and returns an HREF to the zipfile. To make the actual Python code clear, I will include it:

import arcgisscripting
import zipfile

gp = arcgisscripting.create()
gp.workspace = “C:\wamp\www\output”
hs = gp.HotSpots(“Input.shp”, “Score”, “HotSpots.shp”, “Fixed Distance Band”, “Euclidean Distance”, “None”, “2500”, “#”, “#”)

zipfile.ZipFile(“C:\wamp\www\output\hotspots.zip”, mode=”w”)

I am still on Arc 9.3. That’s why you see the import of arcgisscripting. I believe in 10 it’s arcpy.

Revit Editor iPhone App

14 Mar

In a previous post I showed how to Edit Revit Data Through the Web using Apache, PHP, and MySQL. The webpage ran on mobile devices, but I have thrown together an iPhone specific version of the webpage for mobile field data collection.

After editing the model through the web, you can see your changes on the full site.

The address for the iPhone App is HERE.

Here is what the app looks like. One note, after clicking submit in the app you will see a screen that says “undefined.” This is because I am still missing a final page. I am thinking to either take you back to the form or show the results of your edit. I haven’t modified the page because it is built of the same script as my full website. For these examples I piggy back on other apps I have built to make for a rapid development.

Link a QR Code to a Database

2 Feb

In an earlier post, I showed how to link a QR Code to a map by using PHP _GET. This allowed me to pass variables to a script and have the script run in realtime to update the page. I am going to do the same thing in this post, but the data I pass will be used in a SQL statement to retrieve data from the database.

I think this would be a great tool for a facility to use to inventory their equipment. Lets say I have a swamp cooler on the roof of my building — I live in New Mexico. I am on the roof and I need to know something about this particular unit. I can scan a QR Code on the side of the unit, it will then pull up a website that displays everything about this unit: The manufacturer, when it was installed, when it was last serviced, what was done to this unit during the last service, when it is beyond its useful life. On the same page, I could have a form that allows me to update the data. I can enter todays date  as the new last serviced date and put a description of what I did – changed the pad and oiled motor. The next time the code was scanned, this data would be available.

Since I have a room database from Revit already setup, I am going to show how to connect a QR Code to this database to retrieve the room properties. To modify this to work on any other object, just change the database connection.

I wrote a PHP script called get.php. This script selects all the data from a rooms table in a MySQL database where the room number is from the QR Code: SELECT * FROM rooms WHERE number = $_GET[roomchosen].

_GET[roomchosen] is the PHP call to pull the data from the URL that was sent via the QR Code. Here is he full code:

Now I just need a QR Code that has the URL to the script and sends the room number: http://room.educationalfacilityplanning.com/get.php?roomchosen=3. This URL will select room 3. I have 6 rooms in this database, so feel free to change the URL to any number 1-6. If you don’t know where to make a QR Code just google “QR Code Generator” or go to http://www.qrstuff.com/.

Here is my QR Code for room 3.


To link to any database, you can pass a part or a full SQL statement through a URL using PHP _GET. Assign your swamp cooler and id=12345. Create a QR Code with the url http://YourDomain.com/swampCoolerGet.php?id=12345. In your script have a statement:  SELECT * FROM swampcoolers WHERE id = $_GET[id].

Don’t forget to add a form for updating the data to make this perfect for facility management.


Modify Revit Model Data Through the Web

10 Jan

In my post on Programming for Architects I mention how I can use PHP to edit Revit model data.  In this post, I will briefly explain how this is done and point you to a very simple website demonstrating the results.

1) Export your Revit model to a datababse using RevitDBLink. If you don’t care about bringing the results back in you can export a single schedule to CSV and create a database table from that, or export the whole model any way you wish.

2) Download a WAMP stack. WAMP stands for Windows, Apache, MySQL and PHP. You can get the entire stack here:  WAMP Server.

3) Create a webpage in the WWW directory that has a form and whatever else you want to display. The form should call a PHP file. Mine calls insert.php to change the values and a popup.php file to display data. Name the HTML file index.html.

4) Create a PHP file that updates the database.  This is where you need to be able to code, or at least copy and modify code from the web.

5) Start Apache and browse to http://localhost/           to see it in action.

I have a very simple example running on my website. Click on a room to see the current properties. Change the values and click submit. Reclick on a room to see the changes. Currently, this edits the database in real time but requires a user to open Revit and bring the database back in. I see this as a good thing because it adds a layer of protection. It allows the user to import a specific table (rooms) and preview the changes prior to importing.

Happy Hacking.