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

GeoJSON: expose field names in a more consistent orders when some feature lacks some fields (refs qgis/QGIS#45139) #4552

Merged
merged 2 commits into from
Sep 27, 2021

Conversation

rouault
Copy link
Member

@rouault rouault commented Sep 26, 2021


if( isTherePathFromTo(j, i) )
{
return "can't add edge: this would cause a cycle";
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should you drop both instead and sort these two by some other means? this line will keep the attribute order feature-order-dependant still.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point, but what would you drop if we have edges A->B and B->C, and we now want to insert C->A ?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all three as they can't be treated as definitions? but you can't do that on this same pass as then next feature will push them back. you generally need to build cyclic graph and then cut off cycles explicitly.

other strategies that come to mind:

  • push the edges into a set first, order it alphabetically as tuples, push into current dag. will keep alphabetical ordering in case of conflicts.
  • count number of occurences for each edge, sort by that then alphabetically, push into current dag. will keep most common order in case of conflicts.
  • say "it will be this way" and do nothing, maybe put a note. current one still works. :)

Copy link

@Komzpa Komzpa Sep 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess first option can also be simplified to edge with from < to beats all conflicting edges with from > to. So in your example C->A is dropped in any order of insertion.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe I will keep suggested improvements (thanks for them) for a next time. Conflicting order is a less common case, and cannot be generated with GDAL.

for( int idx: anCurFieldIndices )
{
dag.addNode(idx, apoFieldDefn[idx]->GetNameRef());
if( nPrevFieldIdx != -1 )
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you ever decide to do edge-counting, the n^2 loop with all pairs and not just adjacent neighbors will get more stable voting.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added a commit with a comment in the code pointing to that PR if we need those enhancements

@rouault rouault added this to the 3.4.0 milestone Sep 26, 2021
@rouault rouault merged commit 485cdb4 into OSGeo:master Sep 27, 2021
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

Successfully merging this pull request may close these issues.

None yet

2 participants