I have GeoJson file with roads data as Linestrings. I want to load it in Cesium Sandcastle and make a custom line styles. In order to do so, lines have to be Polylines, not Linestrings. Is there a way to transform Linestring to Polyline for GeoJson format?

This is the whole code:

//Add terrain
var viewer = new Cesium.Viewer('cesiumContainer');
var cesiumTerrainProviderMeshes = new Cesium.CesiumTerrainProvider({
    url : 'https://assets.agi.com/stk-terrain/v1/tilesets/world/tiles',
    requestWaterMask : true,
    requestVertexNormals : true
viewer.terrainProvider = cesiumTerrainProviderMeshes;
viewer.scene.globe.depthTestAgainstTerrain = true;

//Load with default styling
Sandcastle.addToolbarButton('Default styling', function() {
    Cesium.GeoJsonDataSource.clampToGround = true;
    var dataRoads = Cesium.GeoJsonDataSource.load('../../SampleData/ceste_rab_okvir.geojson');

//Apply custom graphics after load 
Sandcastle.addToolbarButton('Custom styling', function() {
    //Seed the random number generator for repeatable results

    Cesium.GeoJsonDataSource.clampToGround = true;
    var promise = Cesium.GeoJsonDataSource.load('../../SampleData/ceste_rab_okvir.geojson'); //data loaded from local folder
    promise.then(function(dataSource) {

        //Get the array of entities
        var entities = dataSource.entities.values;

        var colorHash = {};
        for (var i = 0; i < entities.length; i++) {
            //For each entity, create a random color based on the road class
            var entity = entities[i];
            var roadClass = entity.fclass;
            var color = colorHash[roadClass];
            if (!color) {
                color = Cesium.Color.fromRandom({
                    alpha : 1.0
                colorHash[roadClass] = color;

            //Set the polygon material to our random color.
            //THIS IS THE PROBLEM
            entity.polyline.material = color;
    }).otherwise(function(error) {
        //Display any errrors encountered while loading

//Reset the scene when switching demos.
Sandcastle.reset = function() {

Did you mean polyline to polygon? currently Cesium does not support polyline geometry as ground primitive. If You want to draw lines that appear clamped to the terrain you can use the "Corridor geometry" as an alternative (see Cesuim documents).

But since you're loading GeoJSON file you should convert the geometry into polygons. You can import your data to ARCGIS/QGIS and convert your data from polylines to polygons, but if your data have a z index make sure to remove it so that {clampToTerain: true} works.

Removing the z index can be tricky in QGIS if you're not familier with GDAL(Here), so if you have ARCGIS it is a much easier process.you can follow the solution provided in this (link).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.