Untitled Document
Home

Consultancy / services
Projects
Development
Training
Support
Products
Portfolio/media
Download

Links
Contact

 

Part 2 - A control interface to FME

By Hans van der Maarel - Red Geographics
March 2007

The Problem

So I have set up a spatial database and some FME workbenches to make clips out of that, described in the first part of this series of articles.. But I'm not entirely satisfied yet. If I want to produce a clip, I need to look up the lat/lon coordinates of the area that I want to clip. There's bound to be a better way to do that. Of course I could use FME Objects to write my own little application, but that requires knowledge of one of several programming languages that I'm not familiar with. Too much hassle for such a seemingly simple thing.

The Solution

I noticed there's a number of commands in PHP that allow a script to execute an external application. So on my Windows-based test computer, that could be a Windows application. So that means I can control FME and supply parameters that I enter in my browser. But if I can manually enter those coordinates, there should also be a way to supply them in a bit more of a visual way... such as drawing a rectangle on a map (I'm a cartographer after all...).

So I set up this little Google Maps page:

You can browse around the map, look at map, satellite and hybrid views, just like any Google Maps Mashup. However, once you click inside the map view, a little form pops up at the bottom with the lower left and upper right coordinates of the currently visible area. This is, through an extra intermediate step which will be explained below, linked to an FME workbench. You can change the coordinates if you like and supply a destination directory. These are all defined as published parameters in the workbench.

The source code for this php script is:

<?php
include_once('config.php');
?>

<html>
<head>
<title>Define clip area</title>
<script src="http://maps.google.com/maps?file=api&v=2&key=<?php echo $google_maps_key ?>" type="text/javascript"></script>
</head>
<body>
<p><strong>Define clip area</strong></p>

<div id="map" style="width: 800px; height: 600px"></div>
<script type="text/javascript">
//<![CDATA[

var map = new GMap(document.getElementById("map"));
map.addControl(new GLargeMapControl());
map.addControl(new GMapTypeControl());
map.addControl(new GScaleControl());
map.centerAndZoom(new GLatLng(0, 0), 15);

GEvent.addListener(map, 'click', function(overlay, point) {
var bounds = map.getBoundsLatLng();
output.innerHTML = "<form name=form1 method=post action=runfme.php>"
+ "<table><tr><td></td><td>Lower left</td><td>Upper right</td></tr>"
+ "<tr><td>X (lon.)</td><td><input type=text name=llx value=" + bounds.minX + "></td>"
+ "<td><input type=text name=urx value=" + bounds.maxX + "></td></tr>"
+ "<tr><td>Y (lat.)</td><td><input type=text name=lly value=" + bounds.minY + "></td>"
+ "<td><input type=text name=ury value=" + bounds.maxY + "></td></tr></table>"
+ "Destination directory: <input type=text name=destdataset><br><input type=submit value=\"Start FME\"><input type=reset>";
}

);
//]]>
</script>
<div id="output"></div>
</body>
</html>

If you copy this, be careful of line-breaks and stuff like that. The config.php that is referred to only contains a variable for my Google Maps key (using a construction like that makes it easier to deploy Google Maps applications to different servers.

Clicking "Start FME" fires up a second php script (runfme.php). This collects the 5 parameters and sends them off to a command line. Once FME is done processing, the output will be displayed in the browser window:

Note that it will show the same output as when FME is run from the command line.

And the source code:

<html>
<head>
<title>Output</title>
</head>
<body>
<?php

echo "FME is being started...";

echo "<pre>";
passthru ("fme clip.fmw --LLY " . $lly . " --LLX " . $llx . " --URY " . $ury . " --URX " . $urx . " --DestDataset_SHAPE " . $destdataset);
echo "</pre>";
?>
<hr>
<a href="fmestarter.php">Back</a>
</body>
</html>

So that's all there is to it. The LLY, LLX, URY and URX parameters point to the search envelope MySQL input settings. The rest of the workbench clip.fmw is just a simply MySQL to Shape translation.

To prove it actually worked, I imported the resulting Shapefiles in the FME Viewer and here's the result:

Room for expansion?

There certainly is room to improve upon this. For starters, the defining of the area of interest in Google Maps is rather basic. A more intuitive means would be through drawing a rectangle on the Google Maps interface to define the area you want to clip. There's at least one add-on that could be used for this: GZoom. Aside from that there are of course security matters that should be adressed, an up-to-date firewall is certainly recommended, since the php script can access a Windows application directly.

So thanks to a spatial database and a clever little control interface, I now have a system that I can use to produce a clip from a larger dataset in a matter of seconds.

If, after reading this, you have any questions about this setup or FME in general, feel free to contact me.


Index : Media : A control interface to FME
©2007 - Red Geographics - Terms of service