No subject
Mon Mar 16 11:32:08 PDT 2009
run the projects.php code.=20
<?php
header("Content-type: application/vnd.google-earth.kml xml kml");
header('Content-Disposition: attachment; filename=3D"g_loc.kml"');
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: cache, must-revalidate");
header("Pragma: public");
echo "<?xml version=3D\"1.0\" encoding=3D\"UTF-8\"?>"; echo "<kml
xmlns=3D\"http://earth.google.com/kml/2.1\">";
echo "<Document>";
echo "<name>'A Network Link to Google Earth'</name>"; echo
"<NetworkLink>"; echo "<name>'GCS Projects'</name>"; echo
"<flyToView>1</flyToView>"; echo "<Link>"; echo
"<href>http://localhost:8080/projects.php</href>";
echo "completed execution of projects"; =09
echo "<refreshMode>onInterval</refreshMode>";
echo "<refreshInterval>30</refreshInterval>";
echo "</Link>";
echo "</NetworkLink>";
echo "</Document>";
echo "</kml>";
?>
Thereafter I am able to connect to the database
//Projects.php
<?php
// connect to database
include('connection.php');
// start your kml document.
$response =3D "<?xml version=3D\"1.0\" encoding=3D\"UTF-8\"?>"; =
$response .=3D
"<kml xmlns=3D\"http://earth.google.com/kml/2.1\">";
$response .=3D "<Document>\n";
$sql=3D"SELECT gcs_projects.project_num, astext(proj_geom) AS location
FROM gcs_projects"; $myresult =3D pg_exec($db_handle, $sql); echo
"executed sql";
for ($i=3D0; $i<=3Dpg_numrows($myresult); $i++) {
$my_label=3Dpg_result($myresult, $i, 0);
$my_location =3D pg_result($myresult, $i, 1);
// extract the geometry
$geometry =3D str_replace("POINT(","", pg_result($myresult, $i, 1));
$geometry =3D str_replace(")","",$geometry);
$coordinate =3D explode(" ",$geometry);
$lon=3D$coordinate[0];
$lat=3D$coordinate[1];
$altitude=3D1000;
// continue filling your document
$response .=3D "<Placemark>";
$response .=3D "<name>$my_label=3Di</name>";
$response .=3D "<description><![CDATA[your
description]]></description>";
$response .=3D "<Style>";
$response .=3D "<IconStyle>";
$response .=3D "<scale>1</scale>";
$response .=3D "<Icon>";
$response .=3D "<href>C:/water.png</href>";
$response .=3D "</Icon>";
$response .=3D "</IconStyle";
$response .=3D "<LabelStyle>";
$response .=3D "<color>ff00ffff</color>";
$response .=3D "<scale>0.9</scale>";
$response .=3D "</LabelStyle>";
$response .=3D "</Style>";
$response .=3D "<Point>";
$response .=3D "<coordinates>$lon,$lat,$altitude</coordinates>";
$response .=3D "</Point>";
$response .=3D "</Placemark>";
=20
=20
=20
} // result loop
$response .=3D "</Document>"; // close your document
$response .=3D "</kml>\n"; // close your kml
echo $response; // feed it to the network link
pg_close($db_handle); // don't forget to close the
connection...
echo "connection closed";
?>
The contents of the g_loc.kml is as follows:=20
<?xml version=3D"1.0" encoding=3D"UTF-8"?><kml
xmlns=3D"http://earth.google.com/kml/2.1">
<Document>
<name>'A Network Link to Google Earth'</name>
<NetworkLink><name>'GCS Projects'</name>
<flyToView>1</flyToView>
<Link><href>http://localhost:8080/projects.php</href>
completed execution of projects
<refreshMode>onInterval</refreshMode>
<refreshInterval>30</refreshInterval>
</Link>
</NetworkLink>
</Document></kml>
Obviously the geometries are not being written to the KML file. Am I
missing a step to write each geometry in the for loop.=20
// SELECT ST_AsKML(ST_GeomFromText('POINT($lon,$lat))',4326));
Also, at the point you are extracting the geometry, you have a variable
named $g. This is supposed to be $i.=20
I am obviously missing an important step. Your help will be appreciated.
Thanks,
Chetna
-----Original Message-----
From: postgis-users-bounces at postgis.refractions.net
[mailto:postgis-users-bounces at postgis.refractions.net] On Behalf Of
Pedro Doria Meunier
Sent: 16 November 2009 02:13 PM
To: PostGIS Users Discussion
Subject: Re: [postgis-users] Google Earth/PostGIS integration
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi Chetna,
Quick answer: yes you can! :)
Through *network link* in Google Earth.
Take the following example (in PHP, use you favourite "poison" ):
1st part - Create the network link to feed to Google Earth
<?php
header("Content-type: application/vnd.google-earth.kml xml kml");
header('Content-Disposition: attachment; filename=3D"g_loc.kml"');
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: cache, must-revalidate");
header("Pragma: public");
echo "<?xml version=3D\"1.0\" encoding=3D\"UTF-8\"?>";
echo "<kml xmlns=3D\"http://earth.google.com/kml/2.1\">";
echo "<Document>";
echo "<name>"._("My Network Link")."</name>";
echo "<NetworkLink>";
echo "<name>"._("My Description")."</name>";
echo "<flyToView>1</flyToView>";
echo "<Link>";
echo
"<href>$mysite/show_my_thing.php?param1=3D$param1&param2=3D$param2</h=
ref
>";
echo "<refreshMode>onInterval</refreshMode>";
echo "<refreshInterval>30</refreshInterval>";
echo "</Link>";
echo "</NetworkLink>";
echo "</Document>";
echo "</kml>";
?>
2nd part - Get your data:
<?php
// connect to database
include('./include/my_database_connection_script.php');
// start your kml document.
$response =3D "<?xml version=3D\"1.0\" encoding=3D\"UTF-8\"?>";
$response .=3D"<kml xmlns=3D\"http://earth.google.com/kml/2.1\">";
$response .=3D "<Document>";
$sql=3D"SELECT my_label, astext(my_geom_field) AS location FROM =
my_table";
$myresult =3D pg_exec($connection, $sql);
for ($i=3D0; $i<pg_numrows($myresult); $i++) {
$my_label=3Dpg_result($myresult, $i, 0);
$my_location =3D pg_result($myresult, $i, 1);
// extract the geometry
$geometry =3D str_replace("POINT(","", pg_result($myresult, $g, 1));
$geometry =3D str_replace(")","",$geometry);
$coordinate =3D explode(" ",$geometry);
$lon=3D$coordinate[0];
$lat=3D$coordinate[1];
// continue filling your document
$response .=3D "<Placemark>";
$response .=3D "<name>$my_label</name>";
$response .=3D "<description><![CDATA[your
description]]></description>";
$response .=3D "<Style>";
$response .=3D "<IconStyle>";
$response .=3D "<scale>1</scale>";
$response .=3D "<Icon>";
$response .=3D "<href>$my_site/$my_icon</href>";
$response .=3D "</Icon>";
$response .=3D "</IconStyle";
$response .=3D "<LabelStyle>";
$response .=3D "<color>ff00ffff</color>";
$response .=3D "<scale>0.9</scale>";
$response .=3D "</LabelStyle>";
$response .=3D "</Style>";
$response .=3D "<Point>";
$response .=3D "<coordinates>$lon,$lat,$altitude</coordinates>";
$response .=3D "</Point>";
$response .=3D "</Placemark>";
} // result loop
$response .=3D "</Document>"; // close your document
$response .=3D "</kml>"; // close your kml
echo $response; // feed it to the network
link
pg_close($connection); // don't forget to close the
connection...
?>
This is an example for POINT geometry, of course. Other types are as
easily managed as this.
Your "interface" would be Google Earth :]
You can of course have some "middleware" in a form of a php web page
that allows users to select what they want and then feed it to Google
Earth.
Hope this helps,
BR,
Pedro Doria Meunier
On 11/16/2009 10:49 AM, Chetna Parbhoo wrote:
>
> I am currently creating a spatial database for a SME. Their project
> data is currently within folders (including all GIS data). I have
> been doing a bit of research when I came across PostgreSQL and
> PostGIS. I plan to use PostGreSQl with PostGIS as a spatial
> extender. I have installed the PostGreSQL and PostGIS as well as
> viewed data stored in the database with QGIS. I need an easy method
> whereby the employees in the company can access data from the
> database on a user friendly interface. Everyone in the company is
> familiar with Google Earth. Is there a way that I can link Google
> Earth with PostGIS to achieve this?=20
>
>=20
>
> Many thanks.
>
>=20
>
>=20
>
> Chetna Parbhoo
>
> GIS specialist
>
> chetna at gcs-sa.biz <mailto:chetna at gcs-sa.biz>
>
>=20
>
> 63 Wessel Road Woodmead
> PO Box 2597 Rivonia 2128
> South Africa
>
>
> Tel +27(0)11 803 5726
> Fax +27(0)11 803 5745
>
> www.gcs-sa.biz <http://www.gcs-sa.biz/>
>
>=20
>
>
>
> _______________________________________________
> postgis-users mailing list
> postgis-users at postgis.refractions.net
> http://postgis.refractions.net/mailman/listinfo/postgis-users
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org/
iEYEARECAAYFAksBQccACgkQ2FH5GXCfxAviywCfZY0R/zgoQogO9kSA8f+NaqZ5
J5wAoIFi+IbdEfVAY336xCXd9d/5ct30
=3DoXxJ
-----END PGP SIGNATURE-----
_______________________________________________
postgis-users mailing list
postgis-users at postgis.refractions.net
http://postgis.refractions.net/mailman/listinfo/postgis-users