Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Geometry inconsistencies [vector.cpp] #4

Open
rodolfolotte opened this issue Aug 31, 2017 · 4 comments
Open

Geometry inconsistencies [vector.cpp] #4

rodolfolotte opened this issue Aug 31, 2017 · 4 comments

Comments

@rodolfolotte
Copy link

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

@rodolfolotte rodolfolotte changed the title Geometry inconsistences [vector.cpp] Geometry inconsistencies [vector.cpp] Aug 31, 2017
@cbalint13
Copy link
Owner

@rodolfolotte ,

Can check with latest commit ? I fixed statistics computation (corrupted by parallel computation).

Thanks for your interest in this little piece of software !

@rodolfolotte
Copy link
Author

Perfect @cbalint13, seems correct now!
Still, we have the issue of the duplicate features:
screenshot-1
which is more related to the vector processing. As soon as I find a solution, I will submit here... or even a pull-request!

Cheers!

@cbalint13
Copy link
Owner

@rodolfolotte ,

  • Regarding those small (spurious) geometries i will look a bit more in depth.
  • PRs are always welcome !

Thank you much for you efforts !

@rodolfolotte
Copy link
Author

Yeap, sure! As soon I have the "ComputeGeometries" method done, I will pull-request!

Thank you! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants