# Calculate irregular area of a heightmap selecting with mouse……

good evening …
I have a heightmap and need to create a method that you select me anywhere in this heightmap to calculate the irregular selected area.
Thank you very much for your time…
stay tuned …
I have heigmap and I want to select any area of the field with the mouse to get the area in square meters

on a projected plan, on the surface and calculate area in meter squares…

You need to stop posting the same question over and over again.

For reference:

DO NOT POST THIS QUESTION AGAIN.

Once is enough. If you want to add information then add information to the original. Asking again is not going to make it more likely to get answered. Just the opposite.

…it seems to me that his main language is not english, so maybe because of that his question/topic name does look a bit confusing…let him be man…

You only see the two topics posted and not the others that I’ve deleted.

Edit: and note he was told to stop once already.

1 Like

ok i am sorry …,
can you help me ?

Given the little information you provided, it sounds like a ton of work for me to write all of that for you from scratch.

you may find the area in square meters of the surface of a heightmap?

Figure out where you’ve clicked.
Implement dragging.
Figure out where you’ve stopped clicking.
area is easily to calculate from those points.

IF you are starting from nothing, given the question, it’s probably too hard for you.

it’s complicated.
I have only heightmap of my city and can not find any example as a guide

I’m not sure what your problem is, because the question is too open, so i will assume that you are in this situation

Where the green square is the area you want to measure and the red dots are known points.
< EDIT >
I just noticed you were talking about an irregular shape, the methods don’t change, though.
But it’s trickier to find which pixels and triangles are inside that area. You could for example split it into known shapes.
< / EDIT >

So, i know two ways that you can go through depending to your situation

Way1: The area is relative to the heightmap, thus in pixel coordinates
Knowing that an heightmap is a set of sampled heights of different points of a surface, and that every sample is represent by a pixel in the image which has a color that represent its height, you start from a pixel and then you take in account two adjacent pixels of the surrounding ones

(note that when we talk about the position of a pixel, we are actually talking about the position of the center of the pixel )

For those 3 pixels you know the position and the color so you can easily translate them back to world coordinates, once you did that you can find the area of the triangle formed by those points, in world coordinates, that is now a part of the area you want to measure.
This is the basic logic, then you have to do this until you fill the desired area, there are probably several algorithms you could use for that.
Then you sum the areas you found and you have done.

Way2: The area is relative to the world
This is easier, but in order to have decent results you should have nearly one vertex per pixel… that is not the case usually, so maybe it’s better if you use way1 and translate the world pos in pixel coordinates before.
For this method, you work only with the mesh, you need to find which triangles have at least one point inside the interest area and calculate their area, sum, end.

Note that both methods (especially the second one) will give you really approximated results.

this is the way I need … thanks …
I’ll try … if you got a code applied to help heightmap for me, this would serve as support.
thanks

please start a code block with 3 backticks and end it with three backticks to make it better readable. many people dont and I dont understand why. would it make far better readable really. Its markdown.

1 Like