I want to pick the exact point location. i.e exact lat long value of particular point in a point cloud data on mouse click.
can someone help me out in partial code example.
I want to pick the exact point location. i.e exact lat long value of particular point in a point cloud data on mouse click.
can someone help me out in partial code example.
You should just be able to use viewer.scene.pickPosition.
So you’d use it like:
// Pick position of individual points
var handler = new Cesium.ScreenSpaceEventHandler(viewer.canvas);
handler.setInputAction(function(event) {
var position = viewer.scene.pickPosition(event.position);
// position will be undefined if the user clicks something off the globe
if (Cesium.defined(position)) {
console.log(position);
}
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
``
Here’s a running Sandcastle example.
This will give you a cartesian position. You can then convert that to a long/lat.
Pickposition wont give you the exact location. Has anyone achieved this?
Can you elaborate on what you mean? Do you have a code example or a Sandcastle (https://cesiumjs.org/Cesium/Build/Apps/Sandcastle/) where it’s producing an incorrect result?
Hi Omar,
pickPosition gives you the position based on the depth buffer on the 2D screen. If you use that position to graph a sphere for example and zoom in, you can see the position computed using pickPosition is not the same as the position of the point that was clicked. I am looking to for a way to pick the exact position of a point clicked
Hey Abe,
Can you please show me how you’re testing this? I tried this test you suggested, and I am seeing a sphere in exactly the location I clicked on. Here’s a Sandcastle of this zoomed in on the grand canyon to make it easier to test. Below is an animation of clicking at a couple locations to show how pickPosition returns an accurate result.
Are you seeing different behavior in this code example?
Here’s the animation on imgur if it’s not playing in this forum post: https://imgur.com/qid4WTS
Yes we have the same issue. Our solution was to use a spatialite database to do a spatial query on the point cloud as this was able to bypass the screen-space inaccuracies and the fact that there's no GPU-CPU transfer of point cloud data. Obviously not ideal for many reasons, but it enabled us to show details for the exact location of a point.
Omar, it's the definition of "exact" that's the issue. The buffer will get *very* close, but when dealing with point clouds with an accuracy of 1/10mm, the buffer isn't good enough. Plus it sometimes gives wildly inaccurate values if you're on the very edge of a point (in the order of hundreds of metres inaccurate).
Stuart, thanks for the explanation and posting your current workaround. I see what you mean now. I posted some thoughts in this forum thread on what it would take to get 3D Tiles to save the points on the CPU and do this kind of spatial query:
https://groups.google.com/d/msg/cesium-dev/miFO7Fux1HY/FCk_en1pAwAJ
It looks like we might be prioritizing this soon. I’ll definitely update these thread(s) when there’s progress on it, but I’d also keep an eye on the GitHub/monthly releases.
Stuart, Omar, this is what makes a pickPosition based tool for point clouds the hardest " Plus it sometimes gives wildly inaccurate values if you’re on the very edge of a point (in the order of hundreds of metres inaccurate)." Any idea how to fix this? Thank you!
I appreciate the explanation Abe. I think the solution here would be to save the per-point x/y/z on the CPU and allow retrieving them on click, in the same way the “3D Tiles interactivity” demo on Sandcastle allows you to retrieve building height/specific metadata for each building on click.
I’ve opened a feature request here along with some implementation notes from Sean:
https://github.com/AnalyticalGraphicsInc/cesium/issues/7953
Hopefully we’ll get a chance to implement this soon.