Storing and Retrieving Coordinates from CZML

1. A concise explanation of the problem you’re experiencing.

I have a CZML file that define polylines. The coordinates for the polylines look like this…

polyline: {
positions: {
cartographicDegrees: [-1.87, -3.02, 0, -4.43, 1.28, 0]
},
material: {
solidColor: {
color: {
rgba: [255, 0, 0, 255]
}
}
},
width: 2,
clampToGround: true
}

``

I need to grab those coordinates to display them elsewhere on my GUI…

I sort out my polylines into an array and pick them up like this…

var pos = mylines[0].polyline.positions;

``

then I have two helper functions to convert the from cartesian coordinates and then place them in another array.

$.each( pos._value, function( key, value ) {
c3 = Cesium.Ellipsoid.WGS84.cartesianToCartographic(value)
c2 = parseCartographic(c3);
console.log("c2: " + c2);
cart.push(c2);
});

function parseCartographic(str) {
var res = str.toString().split(",");
var ret = “[” +res[0].replace("(","") + “,” + res[1].replace("(","") + “]”;
return ret ;
}

``

The cart variable comes out looking like this

**"cart: [[-0.030368728984701332, -0.05270894341022874],[0.01710422666954443, 0.03036872898470134]]"**

Why are the coordinates all jacked up?

2. A minimal code example. If you’ve found a bug, this helps us reproduce and repair it.

see above

3. Context. Why do you need to do this? We might know a better way to accomplish your goal.

I want to draw a line based on this first line I get.

4. The Cesium version you’re using, your operating system and browser.

1.47, Windows10, latest Firefox.

Any help you can provide would be appreciated. Thanks,

Jody

The values returned by cartesianToCartographic() are in radians not degrees. Here’s what I did.
var czml = [{

“id” : “document”,

“name” : “CZML Geometries: Polyline”,

“version” : “1.0”

}, {

“id” : “redLine”,

“name” : “Red line clamped to terain”,

“polyline” : {

“positions” : {

“cartographicDegrees” : [

-75, 35, 0,

-125, 35, 0

]

},

“material” : {

“solidColor” : {

“color” : {

“rgba” : [255, 0, 0, 255]

}

}

},

“width” : 5,

“clampToGround” : true

}

}];

var viewer = new Cesium.Viewer(‘cesiumContainer’);

var dataSourcePromise = Cesium.CzmlDataSource.load(czml);

dataSourcePromise.then(function(dataSource) {

viewer.dataSources.add(dataSource);

viewer.zoomTo(dataSource);

var entities = dataSource.entities.values;

for (var i = 0; i < entities.length; i++) {

var entity = entities[i];

var xyzArray = entity.polyline.positions.valueOf();

var llhArray = Cesium.Ellipsoid.WGS84.cartesianArrayToCartographicArray(xyzArray);

for (var j = 0; j < llhArray.length; j++) {

var llh = llhArray[j];

console.log(’(’ + llh.longitude * Cesium.Math.DEGREES_PER_RADIAN + ', ’ + llh.latitude * Cesium.Math.DEGREES_PER_RADIAN + ', ’ + llh.height + ‘)’);

}

}

});

``

Hope that helps.

Scott

Awesome. Thanks!!