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

v.out.ogr: fixes ERROR: Unable to create OGR spatial reference with Shapefile export and expands unit tests #3869

Open
wants to merge 22 commits into
base: main
Choose a base branch
from

Conversation

ldesousa
Copy link
Contributor

This PR is incremental on PR #3848. Please merge that one before merging this one.

@github-actions github-actions bot added vector Related to vector data processing Python Related code is in Python C Related code is in C module tests Related to Test Suite labels Jun 17, 2024
@ldesousa ldesousa requested a review from wenzeslaus June 17, 2024 13:53
@veroandreo veroandreo changed the title Issue#2187 v.out.ogr: add basic unit test (cont.) Jun 18, 2024
@veroandreo veroandreo added this to the 8.5.0 milestone Jun 18, 2024
@@ -324,7 +324,6 @@ int main(int argc, char *argv[])
inwkt = NULL;
}
proj_destroy(source_crs);
Ogr_projection = NULL;
Copy link
Member

Choose a reason for hiding this comment

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

Are you making the actual change or just adding tests? Do the test fail without the change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is indeed the main change, the new test is a consequence of this change. The new test fails against the main branch, but succeeds on this branch. This is why the PR is incremental on #3848.

Copy link
Member

Choose a reason for hiding this comment

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

This change looks incorrect to me, because if the OSRImportFromWkt() call at line 331 below is made, it will crash in non-debug GDAL builds.
Perhaps you also need to do "Ogr_projection = OSRNewSpatialReference(NULL)" to re-instanciate the object, probably within the if (inwkt) branch below
And you likely also need to do a OSRDestroySpatialReference(Ogr_projection) before nullifying the pointer to avoid a memory leak

Copy link
Contributor Author

@ldesousa ldesousa Jul 1, 2024

Choose a reason for hiding this comment

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

@rouault This is my interpretation of your comment:
https://github.com/ldesousa/grass/blob/b2ab84646a9aa4a869c97167cc6a954beb14201c/vector/v.out.ogr/main.c#L327

The tests fail with this alternative formulation. Whatever is happening inside OSRImportFromWkt it seems to require a fully set "instance" of OSRNewSpatialReference. Or perhaps I am missing something else. Please advise.

Btw, I believe the tests are not run with GDAL in debug mode. At least on my system shouldn't be the case.

Copy link
Member

Choose a reason for hiding this comment

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

yes, that's on the good track. But you are still missing a OSRDestroySpatialReference(Ogr_projection) before Ogr_projection = NULL to avoid a memory leak

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rouault This is not the right track, because the tests fail. Putting it another way: why is the Ogr_projection = NULL instruction necessary?

Copy link
Member

Choose a reason for hiding this comment

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

@ldesousa ah, I was mostly speaking from a point of view of using the OGR API. Why the functionality doesn't work as expected here is not obvious to me. Let's try to find a moment in the next days to look at that behind the same screen

Copy link
Contributor Author

@ldesousa ldesousa Jul 2, 2024

Choose a reason for hiding this comment

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

@rouault Today the tests are passing, yesterday I might have been running them from the wrong branch, my apologies. This is the latest formulation, let me know if it meets your guidance:
https://github.com/ldesousa/grass/blob/5a7ade03f84cd7718db3a2cfb1d476f5ccc65866/vector/v.out.ogr/main.c#L327

dbase = env["GISDBASE"].replace("'", "").replace(";", "")
rmtree(f"{dbase}/{self.temp_location}", ignore_errors=True)

def test_1(self):
Copy link
Member

Choose a reason for hiding this comment

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

Please name the test according to the tested format or whatever this is testing. Short one-sentence docstring would be nice, but not needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added a new commit with these changes.

@ldesousa ldesousa changed the title v.out.ogr: add basic unit test (cont.) v.out.ogr: fixes #2187 and expands unit tests Jun 18, 2024
@echoix echoix changed the title v.out.ogr: fixes #2187 and expands unit tests v.out.ogr: fixes ERROR: Unable to create OGR spatial reference with Shapefile export and expands unit tests Jun 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C Related code is in C module Python Related code is in Python tests Related to Test Suite vector Related to vector data processing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug] v.out.ogr: ERROR: Unable to create OGR spatial reference with Shapefile export
5 participants