-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Add gdal vector sort #13351
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
base: master
Are you sure you want to change the base?
Add gdal vector sort #13351
Conversation
| { | ||
| OGRFeature *poSrcFeature = srcFeatures[iSrcFeature].get(); | ||
|
|
||
| // Tried just using poSrcFeature->SetFDefnUnsafe and plugging |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
call SetFID(OGRNullFID) should likely allow you to use SetFDefnUnsafe
|
|
||
| bool Process(OGRLayer &srcLayer, OGRLayer &dstLayer) override | ||
| { | ||
| std::vector<std::unique_ptr<OGRFeature>> features; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it would be great if we had a way of dealing with layers that don't fit in RAM (but where the hilbertCodes vector would still fit). That would likely involve using a temporary storage like I did in the Parquet driver where when with the SORT_BY_BBOX layer creation option is used, a temporary GeoPackage file is created., for source layers that don't have efficient GetFeature() implementation.
This remark is not to be implemented in the context of this PR.
| @pytest.fixture() | ||
| def alg(): | ||
| return gdal.GetGlobalAlgorithmRegistry()["vector"]["sort"] | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to be added tests on layers without geometry fields, or with features without geometry
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where the features without geometry will be placed? First, last, or removed?
| const OGRFeature *poFeature = features[i].get(); | ||
| const OGRGeometry *poGeom = poFeature->GetGeometryRef(); | ||
|
|
||
| if (poGeom != nullptr) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| if (poGeom != nullptr) | |
| if (poGeom != nullptr && !poGeom->IsEmpty()) |
| { | ||
| const OGRFeature *poFeature = features[i].get(); | ||
| const OGRGeometry *poGeom = poFeature->GetGeometryRef(); | ||
| if (poGeom == nullptr) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| if (poGeom == nullptr) | |
| if (poGeom == nullptr || poGeom->IsEmpty()) |
| public: | ||
| static constexpr const char *NAME = "sort"; | ||
| static constexpr const char *DESCRIPTION = | ||
| "Spatially order the features a layer"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...on a layer?
Adds a
gdal vector sortcommand to sort features spatially using either a Hilbert curve or a depth-first traversal of an STRtree. Code still needs to be cleaned up but comments on the concept are welcome.Only argument is
--method [hilbert,strtree]. I think we could also have--fieldsthat would be mutually exclusive with--methodif a user wants to sort on an attribute instead.Input parcel dataset, colored on row number:
Hilbert-sorted:
STRtree-sorted: