Skip to content

Joined Geometries not Automatically Cast #336

@keithdoggett

Description

@keithdoggett

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).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions