I'm trying to convert KML to GeoJSON (or some other formats) using ogr2ogr
(look at this question). It's all working fine, except of one problem:
I'm always receiving these metadata attributes with any operation (using org2ogr
or ogrinfo
or Python script)
Name, description, timestamp, begin, end, altitudeMode, tessellate,
extrude, visibility, drawnOrder,icon
But my Schema doesn't have these fields:
<Schema name="distritos_mad" id="distritos_mad">
<SimpleField name="ID" type="float"></SimpleField>
<SimpleField name="CD_GEOCODS" type="string"></SimpleField>
<SimpleField name="NM_SUBDIST" type="string"></SimpleField>
<SimpleField name="Nomes" type="string"></SimpleField>
<SimpleField name="AREA (HA)" type="float"></SimpleField>
<SimpleField name="Pop (2010)" type="float"></SimpleField>
<SimpleField name="Ddem p/km" type="float"></SimpleField>
</Schema>
Looking at LIBKML Drive documentation I realize that this fields are "special fields" and for an unknown reason this fields are included on feature properties.
How can I prevent OGR from writing these feature attributes?
I'm runing this command:
ogr2ogr -f "GeoJSON" C:\out.json C:\in.kml -t_srs EPSG:4326 -dim 2 --config OGR_FORCE_ASCII NO
GDAL 1.11.3, released 2015/09/16
Best Answer
You should be able to just use the
sql
argument inogr2ogr
. For instance, with the following polygon Shapefile with two features and two attributes:Assuming the above Shapefile has been converted to KML, you could do the following:
Which will give the following GeoJSON output:
If you don't pass the
-sql
option you will get all of the additional fields from the KML file.