Finding whether it is water or land according to the coordinates in three js globe

How do I know whether my location is water or land based on x y z coordinates , rotation or other solitons?

my code :

import * as THREE from ‘’;

import { OrbitControls } from ‘’;

const renderer = new THREE.WebGLRenderer({ antialias: true });

renderer.setSize(window.innerWidth, window.innerHeight);


const scene = new THREE.Scene();

const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 100);

camera.position.set(3, 0, 0);

camera.lookAt(0, 0, 0);


const textureLoader = new THREE.TextureLoader();

const texture = textureLoader.load(src);

var orbit = new OrbitControls(camera, renderer.domElement);

const sphereGeometry = new THREE.SphereGeometry(1, 100, 100);

const sphereMaterial = new THREE.MeshBasicMaterial({

vertexColors: THREE.VertexColors,

opacity: 0,

wireframe: false,

map: texture,


const sphere = new THREE.Mesh(sphereGeometry, sphereMaterial);


const geometry = new THREE.BoxGeometry(0.01, 0.01, 0.01);

const material = new THREE.MeshBasicMaterial({ color: “#E00012”, wireframe: true, });

const cube = new THREE.Mesh(geometry, material);

function animate() {





renderer.render(scene, camera);




You could load an image like:

Draw it to a canvas…
Use getImageData to get the pixel data from the canvas…

Take your point, convert it to canvas x/y coordinates…
If you’re using the raycaster to get mouse cursor hit point on sphere… the raycast hit has a .uv field which is the hit coordinate x/y in 0 to 1 space, which you convert to the canvas space by multiplying by canvas width/height…

Look up the pixel from the imageData array, take the brighness value of the pixel and decide based on that if its above or below sea level. This won’t account for rivers though.


Just to add on top of what @manthrax already said, maybe you can try with a texture that accounts for distiguishing between above or under the sea level, like nasa bathymetry or a mix of this and rivers.


I asked the first chat gpt and he suggested this solution, I applied it but it didn’t work correctly, I probably applied it wrong, I will try again, thank you for your help my friend.

1 Like

yeah it can be tricky…

One way to try to figure it out is to drop a bunch of cubes on parts that your code “thinks” are water… then you’ll see the outline of what your algorithm thinks is the water… and compare with the actual visual texture on the sphere…

It might be something as simple as it being flipped on Y or something.