Submitted by dylan on Wed, 2007-05-16 22:00.
We have recently added a KML export function to our online soil survey (Soil-Web). The Google Earth icon is displayed at map scales of 1:35000 or larger, and clicking on it will create a KML file containing the SSURGO polygons within the current viewport. The KML file contains labeled centroids, with links to the map unit descriptions which are normally found on Soil-Web. You will need a current version of Google Earth in order to take advantage of the KML produced by our website.
To use this feature, zoom into a region of interest (at a scale of 1:35000 or larger) and click on the small Google Earth icon in the tool bar. If you have Google Earth installed, you may be prompted by the web browser software to open the resulting file directly in Google Earth. Optionally, download this KMZ file which can be used to seamlessly view soil survey content!
KML Export for Soil-Web The small blue and white icon will export to KML
For large numbers of polygons expect about 2 seconds for KML file generation, with a size ranging from 1 - 4 MB.
2D polygons in Soil-Web: SSURGO polygons (yellow) as normally displayed in our online soil survey.
3D soil polygons as viewed in Google Earth: SSURGO polygons exported from our online soil survey to KML, and displayed in Google Earth.
All of the NCSS digital soil survey information on our site is stored in a PostGIS database, with geometry stored in a projected coordinate system (Albers Equal Area). The asKML() function found in PostGIS 1.2.1 makes converting our geometry to Google Earth compatible KML extremely simple- and it performs the required inverse projection on the fly! The general approach that we are using involves a series of steps, all of which are performed dynamically in PostGIS:
- select geometry overlapping the bounding box defined by the current viewport in AEA coordinates, using the PostGIS spatial indexing system
- compute the intersection between the boinding box and the overlapping polygons
- compute label locations for the new geometry
- convert the polygon geometry to KML
- convert the label geometry to KML
- add styling to the KML chunks with a PHP wrapper
- return a KML file to the browser, after setting the required headers:
header("Pragma: public"); // required
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/kml; charset=utf8");
header('Content-Disposition: attachment; filename="ssurgo.kml"') ;
PHP is used to produce the final styled KML document, which is then returned to the browser. This file can be saved locally and opened with Google Earth. Note that KML can only be exported once you have zoomed in to at least a scale of 1:35000 or more.
Give it a try!