Google Earth with WMS Overlays continued ..

Apologies for the third thread on this topic, but again i need to clear the air and post a fix for the overlay accuracy issue. Paul raised the concern of overlay accuracy in his own script and so it was obvious i should post the solution.

It is a small fix and all that is required is to calculate a ratio of the min/max bounding box coordinates in order to caclulate the height, in pixels, of the image.

For everyone who has their own alternative script working, simply add the following calculation to your variables,

= 800; $ratio1 = ($coords[2] - $coords[0]);  $ratio2 = abs($coords[1] - $coords[3]); $ratio = $ratio1 / $ratio2;  $height = (int)($width / $ratio); ?>

Then all is needed is to reference these $height and $width vars when calling your WMS request, such as …

[1] = "Cadastre";  $WMS[1] = "http://your.server.com/servlet/wms?"; ?>

The problem with hardcoding these variables is that on occasion, the proportion of the returned WMS image does not match the proportions of the bounding box coordinates. In this situation google attempts to stretch the image to fit the given coordinates, and of course, distortion occurs … resulting in overlays which will not fit the base data. This will fix the problem.

Alternatively you can grab the entire example PHP source right here.

Any further questions id be glad to help.

The need for web based GIS to evolve

With all the hype surrounding google/yahoo/msn maps, it has certainly raised the profile of web mapping on the net. No longer do users need to click and wait, they now have sexy looking, responsive interfaces which are actually simple to use. So where does that leave the rest of our clunky, slow, complex web GIS systems?

I have been pondering this thought for quite a while and i think its really a direction GIS needs to look at moving should the situation suit the use of “non-live data”.

We have a tendancy to expect users will always need the most up to date data available, all the time. This of course suits particular situations but i think most will agree that more often than not, static data does the job just as well. Highlighting the needs and expectations of the users using the GIS is the key; assume nothing.

The best way to illustrate the differences in architecture between the new and the old, lets take the standard road map application. It has the standard functionality of zoom and pan, direction routing, search and geocoding.

In the existing GIS mindset, this application would be built using an application server referencing the spatial and attribute databases. Every map zoom, pan and search the users submit will need to be sent in the usual REQUEST <-> RESPONSE communication. It is this communication which effectively kills the responsiveness of any web application using this ‘click and wait’ method. Not only does the user need to send a sometimes detailed request, the server must then

  • parse the request
  • execute its procedures and queries
  • reference the database(s)
  • perform any spatial operations
  • Retrieve the data
  • Perform any reprojections
  • Run cartographic formatting
  • Create the image
  • Send the response

Sound a bit too complex for someone just wanting to pan around the map? Thats because it is.

Fast forward to the past year and all the new players have ditched the old method in favour of visually appealing, quick and responsive interfaces. The one key difference? Architecture.

To give a bit of background, applications such as google maps buy their street data and imagery off a variety of suppliers. This data as soon as it is cut off to google is static. They then generate about 7tb of image tiles and then consume these inside their AJAX (Asynchronous Javascript and XML) frontend. The result? Asynchronous movement.

source:

AJAX applications can send requests to the web server to retrieve only the data that is needed, usually using SOAP or some other XML-based web services dialect, and using JavaScript in the client to process the web server response. The result is more responsive applications, since the amount of data interchanged between the web browser and web server is vastly reduced. Web server processing time is also saved, since a lot of this is done on the computer from which the request came.

In this new architecture, there is still REQUEST<->RESPONSE communication, but the request is made asynchronously (ie. no click and wait) and the request is a simple image retrieval. This simplifies the application in that it only needs to,

  • Parse the request
  • Retrieve the image
  • Send the result

In Australian terms, this is just another way to “skin the cat” (doing the same thing two different ways). There are obvious positives and negatives for both implementations, but in the end its a battle between finding a balance between usability/responsiveness and the data driven applications themselves.

There is a real need out there to realise our shortcomings in the existing implementation and move forward in making these data driven apps more “user friendly”. Think about the following situation and the practicality of using an AJAX solution,

Manually performing a cadastral parcel selection,

  • Current
    • The user sends the active layer and the click coordinates
    • The server parses the request and performs the spatial intersect on the layer
    • It then highlights the parcel and draws the remaining 300 non-selected parcels as an image
    • Server returns the image
  • AJAX implementation
    • The user sends the active layer and the click coordinates
    • The server parses the request and performs the spatial intersect on the layer
    • It then extracts either, the coordinates as GML, or an image with only the selected parcel
    • Server returns the image or GML
    • Client processes the response and overlays the new image/GML over the existing image

Sound familiar? This example can be modified to handle alot of other common situations. If someone was to calculate the statistics, im sure GIS systems on general would create 70% of redundant images due to poorly implemented cache systems, or situations where the whole map is regenerated just to add a single point (or even worse, regenerated when nothing has changed).

So what do we do? Well, unfortunately a lot of the implementation lies with the application developers (Arcims/Mapserver/Geomedia/Geoserver devs, id love to hear your thoughts). The ability to perform a select, for example, without actually retrieving an image of the entire extents is still unavailable on any application as far as i’m aware. If we all just took one step back and looked at our implementations it would be obvious that we do the simplest things (drawing map extents), very very poorly.

My final open question … Do we really need live cadastral layers? If yes, are we really talking about the spatial data, or just the attributes attached to it?

Ka-map is one such implementation of an asynchronous mapserver client. It is capable of generating mapserver tiled images on the fly or from its cache and can easily be scripted to perform “live” attribute retrieval for interrogating the “static” tiled layers.

Adding WMS overlays to Google Earth

Preview

Ingredients

1. Access to a WMS server that can output WGS84 coords (EPSG 4326) .. if you’re unsure, take a look at the capabilities
2. A well set up WMS with view scales (otherwise some retrievals will take a while)

To give a bit of background on how the following code works, Google Earth has the ability to send the bounding box coordinates of your current view to a file, or webpage. Now, for those people whose light bulbs arent going off, this means it is quite easy to create a small bit of code to capture these bbox coordinates and transform them into a WMS request. The WMS output can then be overlaid quite accurately with GE’s sat imagery and tilted, zoomed to your hearts content.

Just before i post the code, please note that i have added additional IP checking functionality to limit who can connect to your WMS reflector script. To add / remove access, simply edit the if ($match[1] line to modify the ip address range. Alternatively feel free to just strip out the ip checking code altogether. Personally, theres nothing worse than someone posting the link and bringing your server to a crawl but to each their own i guess.

Enjoy,

PHP Source (Very simple, no ip checking).

  • This also contains the fix to keep the correct aspect ratio so the images overlay correctly.
  • If you require a mechanism to only switch on layers at certain scales, use the code in this entry.

Id suggest adding the network link using the “When camera stops” refresh option, and set it to a minimum of 4 sec wait time. You should be able to see the following neat folder structure as seen below,

Menu

Any questions or comments, please leave a comment. It will be interesting to see how well Geoserver 1.3 handles its native KML output.

Ka-Map makes it to xml.com

Tyler Mitchell has done an excellent introductory job to ka-map titled “Build AJAX-Based Web Maps Using ka-Map“.

Google Maps provides some very powerful tools, but once you want to add your own data layers, or further customize your own components, it may be easier to use your own toolkits. Tools exist for creating your own AJAX-based web mapping sites and are fairly easy to use. ka-Map coupled with MapServer is a powerful combination of open source web-mapping technologies

If you think google maps is cool, id highly recommended you read this especially if you have little background in AJAX or Mapserver/Mapscript.

10 utils to make opensource gis that little bit easier

In the same vain as my other ArcIMS thread, here are my top 10 utilities (ok so its not really ten) for making my life with OGC apps that little bit easier. If i have missed any which you recommend, please let me know. I have tried to cut the list down to what i think are useful, as there are unfortunately a lot of applications which are not worth the trouble or are incredibly outdated (sorry freegis.org, but the list needs culling guys).

My first and most important tip when getting into opensource GIS …. do not give up. Yes, the documentation is poor most of the time, finding information or help is often frustrating but you will get there. Just the other day i found a solution to a problem i have been having in mapserver in a 2 year old newsgroup post. The information is there, you just gotta dig a little. Carn devs, lets move to a more web based forum instead of increpid old mailinglist applications please.

Desktop Clients
GAIA A free .NET based application capable of consuming WFS / WMS / GML (variety of versions). Suffers from some apparent memory leaks, but otherwise is a great app to debug services.
CADCORP SIS An excellent WFS / WMS / WMC / GML desktop client with all the bells and whistles you could want, short of doing it yourself of course :)

Web Clients
Mapbuilder
Mapbender A PHP/JS frontend quite similar to mapbuilder, but in my eyes, a lot easier to play with / setup. Recommended for customisability and quick setup
Chameleon A highly customizable and adaptable environment for deploying and managing Web mapping applications
Ka-map A frontend that utilises XMLHTTPRequest and mapservers tile generation technology to create a responsive interface much like other AJAX apps such as Google maps or Yahoo maps

Server Applications
Mapserver A CGI (compiled c) application that leverages off existing opensource utilities such as GDAL / OGR and the PROJ4 library. Very quick, well supported.
Geoserver A J2EE application that supports WFS / WFS-T and WMS. Leverages off another opensource package, GeoTools. Excellent web-based configuration frontend, although suffers from lack of WMS features such as raster and SLD support. Highly recommended for WFS and Transactional WFS (WFS-T), WMS support gaining momentum at every release
Deegree Another Java based app, with support for nearly all the major OGC standards. I have only had the pleasure of using the deegree WMS server, but their iGeoPortal product definately looks interesting.
PostGIS Adds support for geographic objects to PostgreSQL. Its a free, opensource alternative to Oracle Spatial / ESRI ArcSDE. Unfortunately i have had little background in using PostGIS, but it comes highly recommended if you do not have the $$ or would like an alternative spatial rdbms, get this.

Server Application Utilities
CITE A test suite is designed to exercise WFS and WMS servers against the requirements in the technical specifications. Its quite funny (or sad) how difficult it is to find the developers CITE results. They might say they are compliant, but trying to find the evidence is another matter.
Maplab Another product in the maptools.org line, maplab assists in the creation, editing and deployment of mapserver mapfiles. The web frontend for creating map files is great for newbies, or for checking changes as you go. The deployment app. (using ROSA) isnt too bad for a quick job either.
Open Geospatial Where would my list be if i didnt list the consortium that gave birth to these standards. Word of warning, the server applications whilst maybe being OGC compliant, often have their own methods of implementing them and or, can also include a lot of extra features. Remember, there is more than one way to skin a cat :)

Conversion utilities
ESRI ArcMap -> UMN Mapserver Similar to GIX, but can convert MXD to mapserver map files instead. Again, be wary. Converting can sometimes be time saving but never assume its going to work straight out the box. Some editing will always be required.
ESRI Arcview -> UMN Mapserver GIX is a great tool for converting arcview projects into a variety of formats (including .map files). Unfortunately the project is not updated as frequently as the mapserver application so it does convert redundant or incorrect syntax. (Still quicker to edit, than to create it from scratch). It also creates referenced reference images and retains any symbology or class definitions. Great tool to have in the belt

… and most important of all, a decent text editor. I recommend ultraedit or textpad. Do not skimp on this, as this is your holy grail. A poor text editor will surely give you headaches in the road ahead :)

If you are having any troubles with anything OGC please get in touch. If i cant solve it, i will hopefully be able to point you in the right direction.

As for those who are interested in the status of Mapserver vs. Geoserver performance benchmarks, they are proceeding nicely. Hopefully we will have some publically available documents for everyone to have a look at soon. The results are not nearly as close as i was expecting ..