Is there a way to bring data from a PostGIS database into Google Earth to view live?
I know of the asKml
function in PostGIS, but I'm interested to know if it's possible to dynamically load KML-formatted data from PostGIS into Google Earth.
You can do it with GeoServer. Installing and "linking" Geoserver to Postgres/PostGIS database is quite easy.
This can be done by creating a Network Link KML, with the <refreshInterval>
and <viewRefreshMode>
(reference) settings set appropriately. As listed in the example, you'll need a script which returns the new response, in this case by sending the query down to PostGIS to respond with an updated asKml
result.
The asKML function only returns the geometry in KML format - not the entire response. You will still need to write some sort of web service to create valid KML to return to the client.
It is not hard to do but you will need to write out all the XML required in the KML document. The nice part of the asKML function is you don't have to write all that tedious geometry xml tags.
Once you write the service then you can point google-earth at the URL for the service.
You can try FME Desktop or FME Server from Safe Software. If you are using FME Desktop you can schedule the translation from PostGIS to KML. The KML can be pushed to a FTP or a dropbox account directly by FME, so that everytime you have new data in PostGIS, the KML also gets re-written.Read more about dropbox and FME at evangelism.safe.com/fmeevangelist52/
For some idea on FME Server and realtime KML look at this link: http://www.fmepedia.com/index.php/Real-time_Taxi_Cabs_(KML_Network_Link_Example)