kml2gmt

Extract GMT table data from Google Earth KML files

Synopsis

gmt kml2gmt [ kmlfiles ] [ -E ] [ -Fs|l|p ] [ -V[level] ] [ -Z ] [ -bobinary ] [ -donodata ] [ -:[i|o] ] [ --PAR=value ]

Note: No space is allowed between the option flag and the associated arguments.

Description

kml2gmt reads a Google Earth KML file and outputs a GMT table file. Only KML files that contain points, lines, or polygons can be processed. This is a bare-bones operation that aims to extract coordinates and possibly the name and description tags of each feature. The main use intended is to capture coordinates modified in Google Earth and then reinsert the modified data into the original GMT data file. For a more complete reformatting, consider using ogr2ogr -f “GMT” somefile.gmt somefile.kml.

Required Arguments

kmlfiles

Name of one or more KML files to work on. If none are given, then standard input is read.

Optional Arguments

-E

Get the altitude from the ExtendData property; z coordinates are then ignored. KML provides more than one mechanism to store information via ExtendData but here we only implemented the <SimpleData name=”string”> variation. Implicitly sets -Z

-Fs|l|p

Specify a particular feature type to output. Choose from points (s), line, or polygon. By default we output all geometries.

-Z

Output the altitude coordinates as GMT z coordinates [Default will output just longitude and latitude].

-V[level]

Select verbosity level [w]. (See full description) (See cookbook information).

-bo[ncols][type] (more …)

Select native binary output.

-donodata (more …)

Replace output columns that equal NaN with nodata.

-:[i|o] (more …)

Swap 1st and 2nd column on input and/or output.

-^ or just -

Print a short message about the syntax of the command, then exit (NOTE: on Windows just use -).

-+ or just +

Print an extensive usage (help) message, including the explanation of any module-specific option (but not the GMT common options), then exit.

-? or no arguments

Print a complete usage (help) message, including the explanation of all options, then exit.

--PAR=value

Temporarily override a GMT default setting; repeatable. See gmt.conf for parameters.

Notes

If polygons are digitized you can enter them in any order. If you have both perimeters and holes we suggest you run the output through gmt spatial -Sh which will determine which polygons are perimeters and holes and organize them so that any holes immediately will follow their perimeters and that their segment headers will contain the -Ph flag and have the reverse handedness. This output may be plotted by plot and the holes will be honored.

Examples

Note: Below are some examples of valid syntax for this module. The examples that use remote files (file names starting with @) can be cut and pasted into your terminal for testing. Other commands requiring input files are just dummy examples of the types of uses that are common but cannot be run verbatim as written.

To extract the lon,lat values from the KML file google.kml, try

gmt kml2gmt google.kml -V > google.txt

To separate the point and polygon geometries from the KML file google.kml, try

gmt kml2gmt google.kml -Fp -V > polygons.txt

gmt kml2gmt google.kml -Fs -V > points.txt