[gdal-dev] Converting KML data with styles to GeoJSON output

Richard Duivenvoorde rdmailings at duif.net
Tue Feb 9 01:35:55 PST 2021


Hi MRRAJESH,

GeoJSON does not contain style information, it is pure data.

KML indeed can contain both data AND styling.

But if you convert KML to GeoJSON, you only get data, because... GeoJSON does not define style/colors.

You need to style/color your geojson in your client.
In clients like: https://geojson.io you can add some styling (see below) but that is not part of the geojson spec, it is (for what I know) client specific. ogr2ogr is only following the standards

Regards,

Richard Duivenvoorde

PS geojson adds some nonstandard css like attributes to make it possible to share geojson with some colors:
load this in https://geojson.io

{
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "properties": {
        "stroke": "#ed0d0d",
        "stroke-width": 2,
        "stroke-opacity": 1,
        "fill": "#336af7",
        "fill-opacity": 0.5
      },
      "geometry": {
        "type": "Polygon",
        "coordinates": [
          [
            [
              40.42968749999999,
              50.736455137010665
            ],
            [
              36.2109375,
              43.83452678223682
            ],
            [
              50.2734375,
              38.8225909761771
            ],
            [
              53.78906249999999,
              42.5530802889558
            ],
            [
              52.03125,
              47.989921667414194
            ],
            [
              50.625,
              50.28933925329178
            ],
            [
              46.05468749999999,
              54.36775852406841
            ],
            [
              40.42968749999999,
              50.736455137010665
            ]
          ]
        ]
      }
    }
  ]
}



On 2/9/21 10:02 AM, MRRAJESH wrote:
> Below are the input sample KML, out GeoJSON, and missing values. 
> 
> *Sample KML:*
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <kml xmlns="http://www.opengis.net/kml/2.2">
>   <Document>
>     
>     <Placemark>
>       <name>Building 41</name>
>       <styleUrl>#transBluePoly</styleUrl>
>       <Polygon>
>         <extrude>1</extrude>
>         <altitudeMode>relativeToGround</altitudeMode>
>         <outerBoundaryIs>
>           <LinearRing>
>             <coordinates> -122.0857412771483,37.42227033155257,17
>               -122.0858169768481,37.42231408832346,17
>               -122.085852582875,37.42230337469744,17
>               -122.0858799945639,37.42225686138789,17
>               -122.0858860101409,37.4222311076138,17
>               -122.0858069157288,37.42220250173855,17
>               -122.0858379542653,37.42214027058678,17
>               -122.0856732640519,37.42208690214408,17
>               -122.0856022926407,37.42214885429042,17
>               -122.0855902778436,37.422128290487,17
>               -122.0855841672237,37.42208171967246,17
>               -122.0854852065741,37.42210455874995,17
>               -122.0855067264352,37.42214267949824,17
>               -122.0854430712915,37.42212783846172,17
>               -122.0850990714904,37.42251282407603,17
>               -122.0856769818632,37.42281815323651,17
>               -122.0860162273783,37.42244918858722,17
>               -122.0857260327004,37.42229239604253,17
>               -122.0857412771483,37.42227033155257,17 
>             </coordinates>
>           </LinearRing>
>         </outerBoundaryIs>
>       </Polygon>
>     </Placemark>
>   </Document>
> </kml>
> 
> *GEOJSON Output:*
> 
> {
> "type": "FeatureCollection",
> "name": "kml_geometry_style",
> "crs": { "type": "name", "properties": { "name":
> "urn:ogc:def:crs:OGC:1.3:CRS84" } },
> "features": [
> { "type": "Feature", "properties": { "Name": "Building 41", "altitudeMode":
> "relativeToGround", "tessellate": -1, "extrude": 1, "visibility": -1 },
> "geometry": { "type": "Polygon", "coordinates": [ [ [ -122.085741277148301,
> 37.422270331552568, 17.0 ], [ -122.085816976848093, 37.422314088323461, 17.0
> ], [ -122.085852582875006, 37.422303374697442, 17.0 ], [
> -122.085879994563896, 37.422256861387893, 17.0 ], [ -122.085886010140896,
> 37.422231107613797, 17.0 ], [ -122.085806915728796, 37.422202501738553, 17.0
> ], [ -122.085837954265301, 37.42214027058678, 17.0 ], [
> -122.085673264051906, 37.422086902144081, 17.0 ], [ -122.085602292640701,
> 37.42214885429042, 17.0 ], [ -122.085590277843593, 37.422128290487002, 17.0
> ], [ -122.085584167223701, 37.422081719672462, 17.0 ], [
> -122.085485206574106, 37.42210455874995, 17.0 ], [ -122.085506726435199,
> 37.422142679498243, 17.0 ], [ -122.085443071291493, 37.422127838461719, 17.0
> ], [ -122.085099071490404, 37.42251282407603, 17.0 ], [
> -122.085676981863202, 37.422818153236513, 17.0 ], [ -122.086016227378295,
> 37.422449188587223, 17.0 ], [ -122.085726032700407, 37.422292396042529, 17.0
> ], [ -122.085741277148301, 37.422270331552568, 17.0 ] ] ] } }
> ]
> }
> 
> *MISSING part:*
> 
> 
> 
> 
> 
> --
> Sent from: http://osgeo-org.1560.x6.nabble.com/GDAL-Dev-f3742093.html
> _______________________________________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org
> https://lists.osgeo.org/mailman/listinfo/gdal-dev
> 



More information about the gdal-dev mailing list