Search code examples
mapsgiskmlpostgisgoogle-earth

dynamic map managment in google earth


My goal is to display various shapes(polygons, points, linestring) on google maps by using data entered into a Postgis database dynamically(i mean by that we can see modifications in the map in real time). I was looking for a way to do this that used the spatial structure already provided in postgis(already designating if shape is a linestring or polygon, etc) instead of parsing out the coordinates and then re-entering spatial structure in google maps. I saw that google maps api is now compatible with kml data formats. And then I read that i have to convert postgis data to kml format. I've done some reading in the forums about the actual process of converting postgis data to kml via FWTools, but didn't see anything that would help me. I'm new to kml but am familiar with postgis and perl and PHP. Is there a tutorial for the process of converting postgis data to kml? Where can I get started? Thanks for any help


Solution

  • You can get a textual representation of the spatial data from a Postgres DB using a text conversion function, like

    SELECT AsText(MyGemoetry) from MyTable
    

    then you parse the string, create your objects using various API functions - depending on the PostGIS geometry type - and append these object to the main GE plugin object in a DOM like way.

    If you are familiar with JavaScript and have a fundamental knowledge of XML, a good start is http://code.google.com/apis/earth/documentation/reference/

    Don't forget to specify unique ID's to your objects so you can find them later to drop/modify.

    Maybe you can get some inspirations here, display the linked "locator.js" file and look at function PaintSubField(Coord) ... this is another way, bit crude but effective, avoiding to mess around with too many individual parent/child objects and structures

    You also may want to consult sample applications and use the code playground for "rapid prototyping"

    re "realtime" you need at least an event that you can link your generation/redraw routines to.

    Good luck MikeD