GEOLYTIX / xyz

An open source javascript framework for spatial data and application interfaces.
MIT License
87 stars 25 forks source link

Add st_distance_ab and st_intersects_ab query templates #1218

Closed dbauszus-glx closed 2 months ago

dbauszus-glx commented 2 months ago

Default queries for location field lookup based on the locations geometry.

The entry.nullValue can be used to assign a value if the query does not return a response.

This should make the query_fields plugin redundant.


simon-leech commented 2 months ago

I made a few changes here-

  1. Added qID and geom to the queryparams so you can pass them as true and they are accessed from the layer values.
  2. Added a new query for multiple rows returned (closest distance)
  3. Updated the st_intersect and st_distance queries based on feedback from @danielsawyers

Example config here

"infoj": [
  {
    "title": "Test",
    "inline": true,
    "field": "field",
    "query": "st_intersects_ab",
    "queryparams": {
      "qID": true,
      "id": true,
      "table": true,
      "geom": true,
      "field_b": "field",
      "as": "field",
      "table_b": "schema.table",
      "geom_b": "geom_4326"
    },
    "run": true
  },
  {
    "title": "Distance to X",
    "inline": true,
    "field": "dist",
    "query": "st_distance_ab",
    "queryparams": {
      "qID": true,
      "id": true,
      "table": true,
      "geom": true,
      "table_b": "schema.table",
      "geom_b": "geom_p_4326"
    },
    "run": true
  },
  {
    "display": true,
    "label": "Location Table",
    "type": "dataview",
    "target": "location",
    "query": "st_distance_ab_multiple",
    "queryparams": {
      "qID": true,
      "id": true,
      "table": true,
      "geom": true,
      "as": "field",
      "field_b": "field_name",
      "limit": 10,
      "table_b": "schema.table",
      "geom_b": "geom_p_4326"
    },
    "table": {
      "layout": "fitColumns",
      "columns": [
        {
          "field": "store_name",
          "title": "Name"
        },
        {
          "field": "dist",
          "title": "Distance"
        }
      ]
    }
  }
]
dbauszus-glx commented 2 months ago

@simon-leech The changes do not work. I highly recommend against using the geom lookup. Not all tables have a geom field. Some layer may use a geoms object. In this case it will be impossible to geom: true, and geom:"whatever" would also be recognised as geom: true. In both cases this will mean crunch for the query. Additionally the cognitive load of the queryParams method is pushed over the limit by adding the geom true flag. Using geom: string does have none of these problems.

sonarcloud[bot] commented 2 months ago

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

simon-leech commented 2 months ago

@simon-leech The changes do not work. I highly recommend against using the geom lookup. Not all tables have a geom field. Some layer may use a geoms object. In this case it will be impossible to geom: true, and geom:"whatever" would also be recognised as geom: true. In both cases this will mean crunch for the query. Additionally the cognitive load of the queryParams method is pushed over the limit by adding the geom true flag. Using geom: string does have none of these problems.

Good point @dbauszus-glx - I have removed "geom": true and just using "geom": string is all working :)