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

Leave Ordinates.None in PostGisWriter to allow detection #5

Closed

Conversation

roji
Copy link
Contributor

@roji roji commented Dec 7, 2018

PostGisWriter contains CheckOrdinates(), which looks at the given geometry object to check which ordinates it contains; this is done only if HandleOrdinates is set to None (i.e. the user hasn't explicitly requested specific ordinates).

However, the HandleOrdinates property ORs XY into the given value, so when the default constructor sets the property to None it gets translated to XY. This means that CheckOrdinates() never gets called.

This changes the HandleOrdinates property to only OR XY into the given value if it is different from None.

PostGisWriter contains CheckOrdinates(), which looks at the given
geometry object to check which ordinates it contains; this is done
only if HandlOrdinates is set to None (i.e. the user hasn't
explicitly requested specific ordinates).

However, the HandleOrdinates property ORs XY into the given
value, so when the default constructor sets the property to None it
gets translated to XY. This means that CheckOrdinates() never gets
called.

This changes the HandleOrdinates property to only OR XY into the
given value if it is different from None.
@airbreather
Copy link
Member

Hmm. So what you're saying is that this line is actually setting the value to Ordinates.XY, which means that the public Write methods will ignore Z and M entirely, because this check will never call CheckOrdinates.

Subtle... if only we had tests that actually covered that logic 🤦‍♂️. That explains why #4 was needed: the entire method was dead code, so any bugs in there would be masked by the one that this fixes.

This is related to npgsql/npgsql#2255, right?

@roji
Copy link
Contributor Author

roji commented Dec 8, 2018

Hmm. So what you're saying is that this line is actually setting the value to Ordinates.XY, which means that the public Write methods will ignore Z and M entirely, because this check will never call CheckOrdinates.

Not exactly... If you set HandleOrdinates to XYZ from the outside (after the constructor), it gets set correctly and the behavior is ok. The problem is that it's impossible to set HandleOrdinates to None, which should mean that the writer should simply infer the ordinates from the objects it is given (sending sometimes XY, sometimes XYZ based on the init).

This auto-detection, which seems to be the desirable default behavior, is implemented by CheckOrdinates(), which never gets called because it is impossible to set HandleOrdinates to None (since the property setter always adds XY).

@roji
Copy link
Contributor Author

roji commented Dec 8, 2018

Re testing, Npgsql actually has a few tests which it executes against PostgreSQL. We definitely could have some tests in NetTopologySuite for basic stuff, although without actually connecting to PostgreSQL they won't go very far...

@roji
Copy link
Contributor Author

roji commented Dec 8, 2018

I'll be happy to help write tests though.

@roji roji mentioned this pull request Dec 9, 2018
@roji
Copy link
Contributor Author

roji commented Dec 9, 2018

Please hold off reviewing or merging, I've opened a more general discussion on ordinates handling in #8.

@roji
Copy link
Contributor Author

roji commented Jan 19, 2019

Superceded by #9

@roji roji closed this Jan 19, 2019
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.

2 participants