Forum

Author Topic: Adding Labels to Polygons Imported from Shapefile (SHP)  (Read 2566 times)

Corensia

  • Jr. Member
  • **
  • Posts: 52
    • View Profile
Adding Labels to Polygons Imported from Shapefile (SHP)
« on: January 03, 2019, 08:42:08 AM »
I have successfully overlaid my orthomosaic image over a geotagged shapefile made up of cadastral polygons thanks to your advice from "http://www.agisoft.com/forum/index.php?topic=6880.0" and it looks great.

Now I am now trying to get Metashape to display the values of one of my shapefile attributes as the label for each polygon without having to manually type in every value. While being time-consuming, manually inputting the label names also puts them over a vertex of the polygon as opposed to being in the center of the polygon (like in QGIS for example). This makes it hard to figure out which polygon the label is attached to since the polygons are all adjacent to each other.

So my questions are:
1) Is there anyway to set the values of a shapefile attribute as the label of every polygon in that shapefile?
2) Is it possible to move the label of the polygon so that it is located at the center of the polygon?

Thank you in advance!

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: Adding Labels to Polygons Imported from Shapefile (SHP)
« Reply #1 on: January 05, 2019, 09:58:44 PM »
Hello Corsenia,

The attribute of the shape can be set as a label via Python script. The following example will find all shapes with NAME attribute and set their label according to the value of this attribute:
Code: [Select]
import Metashape
ATTR = "NAME"
for shape in Metashape.app.document.chunk.shapes:
    if ATTR in shape.attributes.keys():
        shape.label = shape.attributes[ATTR]

As for the position of the shape label in the Model/Ortho/Photo view it is not customizeable in the current version.
Best regards,
Alexey Pasumansky,
Agisoft LLC

Corensia

  • Jr. Member
  • **
  • Posts: 52
    • View Profile
Re: Adding Labels to Polygons Imported from Shapefile (SHP)
« Reply #2 on: January 07, 2019, 03:57:16 AM »
Hello Alexey,

This is exactly what I was looking for and it works perfectly. Thank you so much!