[gdal-dev] ogr2ogr -f KML parameters
lars.schylberg at blixtmail.se
lars.schylberg at blixtmail.se
Sat Jan 4 04:52:58 PST 2020
I would use ogr sql syntax to select whatever you would like to keep. Experiment first with ogrinfo. Then do it with ogr2ogr. /Lars S.
4 januari 2020 kl. 12:50, "LE LAMER Romain" <rlelamer at hotmail.fr (mailto:rlelamer at hotmail.fr?to=%22LE%20LAMER%20Romain%22%20<rlelamer at hotmail.fr>)> skrev:
Hi,
During a kml export, from a shp, I have many tags that do not interest me and that I would like to delete.
I cannot find the information if it is possible via a parameter in the ogr2org program.
ogr2ogr -f KML output.kml input.shp
Ex:
<?xml version="1.0" encoding="utf-8" ?>
<kml xmlns="http://www.opengis.net/kml/2.2 (http://www.opengis.net/kml/2.2)">
<Document id="root_doc">
<Schema name="gbl_0_0" id="gbl_0_0">
<SimpleField name="DN" type="int"></SimpleField>
</Schema>
<Folder><name>gbl_0_0</name>
<Placemark>
<Style><LineStyle><color>ff0000ff</color></LineStyle><PolyStyle><fill>0</fill></PolyStyle></Style>
<ExtendedData><SchemaData schemaUrl="#gbl_0_0">
<SimpleData name="DN">0</SimpleData>
</SchemaData></ExtendedData>
<LineString><coordinates>-180,90 -168.75,90.0 -168.75,78.75 -180.0,78.75 -180,90</coordinates></LineString>
</Placemark>
<Placemark>
<Style><LineStyle><color>ff0000ff</color></LineStyle><PolyStyle><fill>0</fill></PolyStyle></Style>
<ExtendedData><SchemaData schemaUrl="#gbl_0_0">
<SimpleData name="DN">0</SimpleData>
</SchemaData></ExtendedData>
<LineString><coordinates>-180,90 -168.75,90.0 -168.75,78.75 -180.0,78.75 -180,90</coordinates></LineString>
</Placemark>
<Placemark>
<Style><LineStyle><color>ff0000ff</color></LineStyle><PolyStyle><fill>0</fill></PolyStyle></Style>
<ExtendedData><SchemaData schemaUrl="#gbl_0_0">
<SimpleData name="DN">0</SimpleData>
</SchemaData></ExtendedData>
<LineString><coordinates>-180,90 -168.75,90.0 -168.75,78.75 -180.0,78.75 -180,90</coordinates></LineString>
</Placemark>
</Folder>
</Document></kml>
1 - I don't know why I have the triplicate entries ... Surely my input.shp from QGIS, I must be doing something wrong, but I can correct this via this (which was given to me):
gawk 'BEGIN{PROCINFO["sorted_in"]="@val_num_asc"}/LineString/{A[$0]=NR;next}{A[NR ":" $0]=NR}END{for (i in A) { sub(/^[0-9]+:/,"",i); print i }}' input.kml | gsed '/<Placemark>/{:bc;N;s//Placemark>/&/;tcc;bbc;:cc;/LineString/!d;}’ >input_simp.kml
which gives me :
<?xml version="1.0" encoding="utf-8" ?>
<kml xmlns="http://www.opengis.net/kml/2.2 (http://www.opengis.net/kml/2.2)">
<Document id="root_doc">
<Schema name="gbl_0_0" id="gbl_0_0">
<SimpleField name="DN" type="int"></SimpleField>
</Schema>
<Folder><name>gbl_0_0</name>
<Placemark>
<Style><LineStyle><color>ff0000ff</color></LineStyle><PolyStyle><fill>0</fill></PolyStyle></Style>
<ExtendedData><SchemaData schemaUrl="#gbl_0_0">
<SimpleData name="DN">0</SimpleData>
</SchemaData></ExtendedData>
<LineString><coordinates>-180,90 -168.75,90.0 -168.75,78.75 -180.0,78.75 -180,90</coordinates></LineString>
</Placemark>
</Folder>
</Document></kml>
2 - And we arrive at what is the object of my question, which is to know if via a parameter of ogr2ogr it is possible that it does not write these lines
<Schema name="gbl_0_0" id="gbl_0_0">
<SimpleField name="DN" type="int"></SimpleField>
</Schema>
and
<ExtendedData><SchemaData schemaUrl="#gbl_0_0">
<SimpleData name="DN">0</SimpleData>
</SchemaData></ExtendedData>
which would give me a kml like this
<?xml version="1.0" encoding="utf-8" ?> <kml xmlns="http://www.opengis.net/kml/2.2 (http://www.opengis.net/kml/2.2)"> <Document id="root_doc"> <Folder><name>gbl_0_0</name> <Placemark> <Style><LineStyle><color>ff0000ff</color></LineStyle><PolyStyle><fill>0</fill></PolyStyle></Style> <LineString><coordinates>-180,90 -168.75,90.0 -168.75,78.75 -180.0,78.75 -180,90</coordinates></LineString> </Placemark> </Folder> </Document></kml>
I know it is possible to do it via sed but if I can do without this step it would be a plus
Thanks
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20200104/8957e07a/attachment.html>
More information about the gdal-dev
mailing list