Skip to content
This repository was archived by the owner on May 18, 2025. It is now read-only.
This repository was archived by the owner on May 18, 2025. It is now read-only.

Geometry inconsistencies [vector.cpp] #4

@rodolfolotte

Description

@rodolfolotte

Hi everyone, whats up?

cbalint13, well done for the code! Easy and fast implementation!

Im extending this code to extract basic geometries attributes from the segments, such as area, perimeter, width, elongation, rectangularity, so on. So, taking a look in vector.cpp file, I have noticed that the SavePolygon method agregates labelpixels.at(k) as an AREA value, which is somehow incorrect. I opened the final .shp file in QGIS to compare the results. Most of the AREA fields does not match with the $area outcomes from QGIS. I really did not get the meaning of these values.

Another issue is the multring==0 | 1 parameter. This made me crazy until find out what was going on. I mean... Some of the labels delivered by LSC algorithm, for instance, are disjoint, i.e, "different polygon" but same id. So... Reviewing following for-loop:

printf("Write File: %s (polygon)\n", OutFilename);
for (size_t k = 0; k < m_labels; k++) {...}

I see that a OGRFeature is created for each ring of a same Polygon, which would end up in many duplicate features in .shp file. Plus... each duplicate feature keeps the all attributes (avg, std, area, etc) respect to the first (multiring==0) feature.

So, in the end of the for-loop, instead of everytime create a new feature, I changed to set the feature:

if (liLayer->CreateFeature(liFeature) != OGRERR_NONE)
{
    printf("\nERROR: Failed to create feature in vector layer.\n");
    exit(1);
}
OGRFeature::DestroyFeature(liFeature);

to

if (multiring == 1)
    {      
      OGRFeature *auxFeature = liLayer->GetFeature(k-1);      
      OGRPolygon *auxPolygon = (OGRPolygon *) auxFeature->GetGeometryRef();         
      auxPolygon->addRing(&rings);
      auxFeature->SetGeometry(auxPolygon);
      
      if (liLayer->SetFeature(auxFeature) != OGRERR_NONE)
      {
         printf("\nERROR: Failed to set feature in vector layer.\n");
         exit(1);
      }
    }
    else
    {            
      polygon.addRing(&rings);
      liFeature->SetGeometry(&polygon);

      if (liLayer->CreateFeature(liFeature) != OGRERR_NONE)
      {
        printf("\nERROR: Failed to create feature in vector layer.\n");
        exit(1);
      }
      OGRFeature::DestroyFeature(liFeature);
    }

but still... not working! Any better idea and solution for those issues, I would appreciate!

Thank you so much!

Rodolfo

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions