Skip to content

Create a locations with attributes query on the locations table #468

@mgdenno

Description

@mgdenno

Example code:

attribute_names = [row.attribute_name for row in sedona.sql(f"""
    SELECT DISTINCT(attribute_name) FROM local.db.location_attributes
""").collect()]
attribute_names_sql = ", ".join([f"'{name}'" for name in attribute_names])

sedona.sql(f"""
    CREATE OR REPLACE TEMP VIEW locations_view AS (
        WITH location_attributes_pivot AS (
            SELECT *
            FROM (
                SELECT location_id, attribute_name, value
                FROM local.db.location_attributes
            ) src
            PIVOT (
                max(value) FOR attribute_name IN ({attribute_names_sql})
            )
        )
        SELECT l.id, l.name, ST_GeomFromWKB(l.geometry) AS geometry, la.*
        FROM local.db.locations l
        LEFT JOIN location_attributes_pivot la
        ON l.id = la.location_id
        WHERE l.id IS NOT NULL
        AND la.location_id IS NOT NULL
    )
""")

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentationmainThis is an issue that is considered v0.5.0 maintenance and should be merged into mainv0.6-devDenotes that the issue is meant to be merged into the v0.6-beta development branch.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions