[postgis-devel] KML from PostGIS patch

Eduin Carrillo yecarrillo at yahoo.com
Mon Dec 4 11:02:01 PST 2006


Hi list. 

I were looking for a fast way to produce kml code from PostGIS but AsKML
function were just a Wish
(http://postgis.refractions.net/support/wiki/index.php?WishList) . Finally,
this is a patch for revision 2531 to add the long waited AsKML function to
PostGIS.

I'm not C# programmer, but it works. I just modify AsGML fuction to produce KML
2.0 compliant code.

At the moment, external re-projection to SRS 4326 is needed before apply AsKML
function. This a small sample:


<?php

$query = "SELECT gid, vertimiento, cuerpo, municipio, empresa,
AsKML(Transform(the_geom,4326)) AS kml,
          FROM capa_vertimientos";

$response = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
$response .= "<kml xmlns=\"http://earth.google.com/kml/2.1\">\n";
$response .= "  <Document>\n";
$response .= "  <name>Vertimientos</name>\n";

$result = pg_query($pgconn_siat, $query);
if ($result) {

  while ($row2 = pg_fetch_assoc($result)) {
      $response .= "          <Placemark id=\"" . $row2['gid'] . "\">\n";
      $response .= "            <name> " . $row2['vertimiento'] . " </name>\n";
      $response .= $row2['kml']."\n";
      $response .= "          </Placemark>\n";
  }
}

$response .= "  </Document>\n";
$response .= "</kml>\n";

echo $response;

?>

You can test our Network Link:

http://sig.cas.gov.co/api/earth/kmz/SIG.kml?


Next step can include reprojection. I tried this code but doesn't work:

	geom = (PG_LWGEOM *)DatumGetPointer(DirectFunctionCall2(
		transform, PointerGetDatum(geom), 4326));


---
Eduin Yesid Carrillo
Corporación Autónoma Regional de Santander CAS
Coordinador SIG
yecarrillo at cas.gov.co


__________________________________________________
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ¡gratis! 
Regístrate ya - http://correo.espanol.yahoo.com/ 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: kml_from_postgis.patch
Type: application/octet-stream
Size: 15398 bytes
Desc: pat2083052826
URL: <http://lists.osgeo.org/pipermail/postgis-devel/attachments/20061204/018f3995/attachment.obj>


More information about the postgis-devel mailing list