Skip to content

Postgis types - #255

Closed
rossini-t wants to merge 6 commits into
npgsql:masterfrom
rossini-t:PostgisTypes
Closed

rossini-t wants to merge 6 commits into
npgsql:masterfrom
rossini-t:PostgisTypes

Conversation

@rossini-t

Copy link
Copy Markdown
Contributor

I've started to implement the most common geometric features of Postgres Spatial Extension as Npgsql Types to easily manage them in npgsql commands. I use it in some private projects, but this is always work in progress. It will be great to have some feedback.

Thanks !

[addendum] Code tested with .NET 4.5 and PostgreSQL 9.1 + Postgis 2.0

@franciscojunior

Copy link
Copy Markdown
Member

That's excellent, @rossini-t !

I'm reviewing your patch.

Would you mind to rebase your work on current master branch? Today github say it can't merge your patch which means it may have some conflicts with current master branch code.

Can you explain better what is the need for the preliminary cast? I have some plans to remove the cast Npgsql is adding to parameters. Did you add this preliminary cast because of Npgsql?

Thanks in advance.

@rossini-t

Copy link
Copy Markdown
Contributor Author

I didn't see that there was conflicts with master (i'm new to githhub), so I will rebase the branch no problems !

Concerning the preliminary cast, you cannot cast an hexstring directly to geometry, so you have to cast it to bytea first, that's the "preliminary" cast. So this is more a pgsql problem.

@rossini-t

Copy link
Copy Markdown
Contributor Author

Hi,
I've rebased my work and done some modifications.
So I'm ready to take some other comments !

@franciscojunior

Copy link
Copy Markdown
Member

That's excellent, @rossini-t !

I'll review your patch and send you my comments.

@franciscojunior

Copy link
Copy Markdown
Member

Hi, @rossini-t !

I think you have your editor to use tabs instead of spaces.
Would you mind to change your editor to use 4 spaces in place of a tab?

Thanks in advance!

@rossini-t

Copy link
Copy Markdown
Contributor Author

Got it !

@roji roji added this to the 2.3 milestone Jul 26, 2014
@roji roji added the feature label Jul 26, 2014
@roji

roji commented Jul 26, 2014

Copy link
Copy Markdown
Member

@franciscojunior, have you had any time to review this? I can take a look as well...

@franciscojunior

Copy link
Copy Markdown
Member

Hi, @roji ! Sorry. I'll have a look at it.
Please, if possible, it would be very good if you also could have a look at it. I think the more reviewers the better :)

@franciscojunior

Copy link
Copy Markdown
Member

I think the code is very good!

The only issue I'm seeing is the need to change the constructor of NpgsqlNativeTypeInfo type and AddType method to add support for the custom casting needed by the geometry type.

@rossini-t , do you think that it would be possible to change the code to maybe use a subclass of NpgsqlNativeTypeInfo to handle the custom casting and maybe add an extension method to handle the AddType method which accepts the preliminary cast parameter?

I think this would make the geometry types handling code self contained regarding this specific requirement. This could even change in the future ( I saw your note about checking another way of making the geometry work without the bytea casting).

Please, have a look at this and check if it is possible and not too much complex.

Thanks in advance.

@rossini-t

Copy link
Copy Markdown
Contributor Author

This looks like feasible !
I will give it a try

@franciscojunior

Copy link
Copy Markdown
Member

Hi, @rossini-t !
I'm reviewing your code!

I think your changes for postgis NativeTypeInfo are very good!

I think you don't need to add a connection string to enable the postgis types.
The client code could check if the postgis extension is installed before trying to use it.
What do you think?

@rossini-t

Copy link
Copy Markdown
Contributor Author

Hi @franciscojunior !
Sorry for the late response.

If we leave this responsability to the user, then we automatically load the backend geometry type, regardless of the extension being installed. Is this behavior accepted ?
Otherwise, at Backendtype loading, I can try to get the Postgis Version and then load the geometry type if no exception occurs.

@franciscojunior

Copy link
Copy Markdown
Member

Hi @franciscojunior !
Sorry for the late response.

No problem! :)

If we leave this responsability to the user, then we automatically load the backend geometry type, regardless of the extension being installed. Is this behavior accepted ?
Otherwise, at Backendtype loading, I can try to get the Postgis Version and then load the geometry type if no exception occurs.

I think there is no problem loading the backend geometry type. With the current PR, NpgsqlDbType will already expose the geometry types and the converters won't add any impact.

When I tried your code, I used a postgresql with no postgis extension installed to see how it would run and it run ok and just skipped the tests as expected (as you added a check for the extension). That's why I think the user can check if the extension is installed or not before using. Also, if she tries to use the postgis code without installing the extension, Postgresql will throw an exception talking about this problem.

What do you think?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Needless whitespace here

@roji

roji commented Sep 11, 2014

Copy link
Copy Markdown
Member

@rossini-t, thanks for this PR, it looks like a very nice addition to Npgsql.

I just did a code review, please take a look at the comments above.

I also have one more general question. Is it really necessary to require the WithPostGis connection string parameter? I do understand that it is currently needed, since the LoadTypeMappings needs to know in advance what types to load OIDs for. But I'd like us to see if it's not possible to have it simply load all types, and this way PostGis is always enabled without a PostGis type. The same, by the way, goes for UseExtendedTypes.

This would mean a more fundamental change in the way we load types. @franciscojunior, do you know anything about this?

@franciscojunior

Copy link
Copy Markdown
Member

I also have one more general question. Is it really necessary to require the WithPostGis connection string parameter? I do understand that it is currently needed, since the LoadTypeMappings needs to know in advance what types to load OIDs for. But I'd like us to see if it's not possible to have it simply load all types, and this way PostGis is always enabled without a PostGis type. The same, by the way, goes for UseExtendedTypes.

I also pointed out this to @rossini-t . I think there is no need to use use a connection string to flag if the postgis types should be used or not.

This would mean a more fundamental change in the way we load types. @franciscojunior, do you know anything about this?

In the case of UseExtendedTypes, I think it is different because they change some of the types returned from Npgsql through the use of different type converters. Unless we get to the conclusion that those extended types are going to be the default for 3.0. In this case I think we can get rid of this connection string parameter and load only the extended types version.

I think @jbcooley has more information about that as he worked in those extended types.

@roji

roji commented Sep 11, 2014

Copy link
Copy Markdown
Member

OK. @rossini-t and @franciscojunior, I'll try to look at modifying the type mapping loading process the way I said. If it can be done we can change the PostGis support to not require the connstring param.

For the UseExtendedTypes let's see what @jbcooley says and treat separately.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The property will actually never returns null. ExecuteScalar will throw an exception because postgis_version will be missing. What behavior is prefered here ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It would be ideal if we could check in some way that PostGis is installed before calling postgis_version(). One idea that comes to mind, is to check whether a PostGis type was found in the type loading phase; if so it means PostGis is installed, right?

If you're OK with doing it this way, then let me look at the refactor of the type loading as I described below (i.e. load all types from Postgresql rather than loading only a preset list. Then you'll simply be able to check whether the PostGis type is mapped to a Postgresql OID. Sounds good?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I agree it is a good approch.

Thank you for taking interest in my code !

@roji

roji commented Sep 13, 2014

Copy link
Copy Markdown
Member

@rossini-t, out of the box your TestConnectionString test fails with the message "WITH POSTGIS is not working". I get a String rather than an OgrPoint from the st_point() query. Can you please confirm that it works on your setup? (I'm using Postgresql 9.3 with PostGis 2.1.3).

Also, if you could rebase you PR on master that would be a great help.

@roji
roji force-pushed the master branch 2 times, most recently from 0b35ef0 to c43b6af Compare September 16, 2014 08:50
Common Postgis  OGR geometries handling.

Implemented a subset of OGR features as native types and their
respective backend/native coding.

Added backend to native validation tests.

Added enumerables tests

Typo in test file.

Common Postgis  OGR geometries handling.

Implemented a subset of OGR features as native types and their
respective backend/native coding.

Added enumerables tests

Typo in test file.

Corrected errors generated by previous merge.

Changed the way NpgsqlConnector loads postgis types

The PostgisVersion property is not used anymore to determine if the
connector should loads postgis types.
The new keyword 'WITH POSTGIS'  in the connection string is used to tell
the connector to load it.

Replaced tabulations to 4 spaces indentation.

Unnecessary call to ToString()

Replacing ToString Call to String casting

Attempt to Postgis NativeTypeInfo specialization

Corrected bad WKB output of OgrPolygon

Corrected bad type id for OgrMultiPoint.

Simplyfing PostgisNativeTypeInfo

Changed masking CastName property to overriding.
Removed unnecessary parameters on PostgisNativeTypeInfo instanciation.

Refactoring Postgis Tests

Removed unnecessary variable in Postgis test

Added explicit casting for  Framework 3.5  compat.

Removed needless spaces

Use of an enum for geometry type matching

Use of an enum for geometry type matching rather than integer.

Changed UsePostgisTypes To AutoProp

Removed comments

Removed env variable for pgis testing.
Maked usePostgisTypes parameter optional for compliance with base code.
@franciscojunior

Copy link
Copy Markdown
Member

Hi, @rossini-t !

Can you check the recent changes we are doing on #390? As we are changing the CastName property to a method GetCastName(int size) which receives a size value, I'd like to know if it has a big impact in your design.

Thanks in advance.

Corrected bug mentionned by @roji  :
npgsql#255 (comment)

The postgis types was actually never loaded.
@rossini-t

Copy link
Copy Markdown
Contributor Author

Hi, @franciscojunior !

As is, it looks like it's only requring to override GetCastName in PostGisNativeTypeInfo to make it returning the right cast name (i.e. bytea::geometry)

@franciscojunior

Copy link
Copy Markdown
Member

Hi, @franciscojunior !

As is, it looks like it's only requring to override GetCastName in PostGisNativeTypeInfo to make it returning the right cast name (i.e. bytea::geometry)

Great! I was worried that this modification would break significantly your code.

I'll keep reviewing your code and #390 .

Thanks for your feedback!

@roji

roji commented Oct 23, 2014

Copy link
Copy Markdown
Member

Just a thought... with all the work that's happening on type read/write in #385, it may be a good idea to wait with this PR for a bit.

@roji
roji force-pushed the master branch 2 times, most recently from e1d8c57 to 1f140e5 Compare January 14, 2015 02:37
@roji

roji commented Feb 6, 2015

Copy link
Copy Markdown
Member

@rossini-t, we're deep in the v3.0 rewrite, where the type system has completely changed. I'm sorry that this means some of your work has been lost... But on the other hand the new type system is much more powerful, efficient and async-compatible.

If you want to resume work on PostGIS support, the type system is probably safe enough to do so; take a look at some existing types and note especially the difference between chunking (variable-length) and simple (fixed-length) type handlers.

It may be a bit too much to include in 3.0, let's wait and see.

@roji

roji commented Mar 12, 2015

Copy link
Copy Markdown
Member

@rossini-t, I'm going to close this PR and open a separate issue for PostGIS implementation. A considerable amount of code can probably be taken from your work in this PR.

Again, sorry about your work not being merged, it was a matter of bad timing and I hope you'll consider continuing work on this for v3.0.

@roji roji closed this Mar 12, 2015
@roji roji mentioned this pull request Mar 12, 2015
@roji roji modified the milestones: 3.0, 3.0-beta1 Mar 30, 2015
@roji roji removed this from the 3.0-beta1 milestone Aug 7, 2015
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.

3 participants