Absolutely.

See attached, a simple plpgsql function that adds header info around the current askml function.

I do this in psql:
-- Set output to unaligned
\a

-- Show only tuples
\t

-- Dump query to a file
\o my_kml_file.kml

-- Run your query
SELECT askml('my_line', 'description', 'SRID=3005;LINESTRING( 1190000 390000, 1200000 390000, 1200000 380000, 1190000 380000, 1190000 390000 )'::geometry);

-- Flush output your file and close the output stream
\o

Loading this file in Google Earth will draw a box around Victoria, BC.

I often collect() geometries from a table and pass those into this function:
SELECT askml('my_title', 'description', collect(the_geom)) FROM my_line table WHERE ....

Cheers,
Kevin

-------------
Kevin Neufeld
Software Developer
Refractions Research Inc.
300-1207 Douglas St.
Victoria, B.C., V8W 2E7

Phone: (250) 383-3022
Email: [EMAIL PROTECTED]



Maciej Skorczewski wrote:
hi all!


How should i use AsKML() function to create KML files (w try show postgis data in google maps nad google earth)

It is posible?


-- Function: public.askml(text, text, geometry)

-- DROP FUNCTION public.askml(text, text, geometry);

CREATE OR REPLACE FUNCTION public.askml(name text, description text, the_geom 
geometry)
  RETURNS text AS
$BODY$
DECLARE
        result text;
BEGIN
        result := '<?xml version=''1.0'' encoding=''UTF-8''?>' || E'\n' ||
                  '<kml xmlns=''http://earth.google.com/kml/2.1''>' || E'\n' ||
                  '<Document>' || E'\n' ||
                  '<name>' || quote_literal(name) || '</name>' || E'\n' ||
                  '<description>' || quote_literal(description) || 
'</description>' || E'\n\n' ||
                  '<Style id=''defaultStyle''>' || E'\n' ||
                  '  <LineStyle>' || E'\n' ||
                  '    <color>ff00ff00</color>' || E'\n' ||
                  '    <width>1</width>' || E'\n' ||
                  '  </LineStyle>' || E'\n' ||
                  '  <PolyStyle>' || E'\n' ||
                  '    <color>5f00ff00</color>' || E'\n' ||
                  '  </PolyStyle>' || E'\n' ||
                  '</Style>' || E'\n\n' ||
                  '<Placemark>' || E'\n' ||
                  '<styleUrl>#defaultStyle</styleUrl>' || E'\n';
        
        result := result || askml(the_geom) || E'\n';

        result := result || 
                  '</Placemark>' || E'\n\n' ||
                  '</Document>' || E'\n' ||
                  '</kml>';
        RETURN result;
END;
$BODY$
  LANGUAGE 'plpgsql' IMMUTABLE;
_______________________________________________
postgis-users mailing list
postgis-users@postgis.refractions.net
http://postgis.refractions.net/mailman/listinfo/postgis-users

Reply via email to