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

Joined Geometries not Automatically Cast #336

Open
keithdoggett opened this issue Mar 4, 2021 · 0 comments
Open

Joined Geometries not Automatically Cast #336

keithdoggett opened this issue Mar 4, 2021 · 0 comments

Comments

@keithdoggett
Copy link
Member

In order to determine the properties of a geometry column, the OID::Spatial#parse_sql_type method is called in the SchemaStatements#initialize_type_map method for geometry types. This method parses a sql_type (ex. "geometry(Polygon,4326)") and derives the geo_type, srid, has_z, has_m, and geographic properties from the string.

The problem is that after a join, sql_type comes in as "". This makes it impossible to determine any properties from it and the default properties are passed into the OID::Spatial constructor which can cause unexpected geometry types to appear.

Here is the place where the sql_type comes in.

map.register_type(geo_type) do |_, _, sql_type|
# sql_type is a string that comes from the database definition
# examples:
# "geometry(Point,4326)"
# "geography(Point,4326)"
# "geometry(Polygon,4326) NOT NULL"
# "geometry(Geography,4326)"
geo_type, srid, has_z, has_m, geographic = OID::Spatial.parse_sql_type(sql_type)
OID::Spatial.new(geo_type: geo_type, srid: srid, has_z: has_z, has_m: has_m, geographic: geographic)

This is likely some sort of upstream issue where the data in a join is not being passed properly.

The current workaround is to register an attribute on the target table (described in #334).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant