Attach label to rectangle / polygon

Hello,

Is there a way to do attach a label to a rectangle / polygon drawing? Right now my workaround is using the Pin tool and Pin manager to draw below the rectangle, like picture below. I would like to do something like what I’m doing with Pin but using rectangle / polygon WKT and interactor instead.

polygon

To do that, I was trying to trace the code in snap-desktop snap-rcp/actions/vector and snap-rcp/actions/interactors. I found that the rectange/polygon interactors were structured quite differently from Pin placemarks. Probably need to modify the snap-engine code which I was quite reluctant to do so.

Would like some advise on what is the best way to do it? Is it to modify something in the snap-desktop / snap-engine code or write a plugin? Is there any samples to refer to?

Thank you very much for any advice. I’m stuck at this for about a month till date…

There indeed is no way to label geometries in the view. The closest thing you have is that you can create new vector data containers, give them names and place exactly one geometry in them. They will have different colors and you can toggle their display in the layer manager.
Extending SNAP to support the labeling of polygons is possible but requires a bit of effort when done right. However, you are invited to fork SNAP Engine and SNAP Desktop from Github, contribute and later create a pull request. I would then like to point out to you the classes org.esa.snap.ui.product.SimpleFeaturePoint Figure and org.esa.snap.ui.product.SimpleFeatureShapeFigure where the label is drawn / would need to be drawn.
I have created an issue for this in our Issue Tracker : https://senbox.atlassian.net/browse/SNAP-957 .

Hi @TonioF, thank you for the reply and creating an issue for this!
Another workaround I was doing was importing a CSV with the desired fields.

Currently, the “Draw Rectangle Tool” will create a new default geometry layer.
I’m thinking of doing a plugin to allow the “Draw Rectangle Tool” to append to this list by setting the wkt geometry and maybe displaying the label. Would that be a neater approach?

Thanks!