You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 6227a9b
Browse filesBrowse the repository at this point in the historyBrowse files
List and delete use the same `hotdata indexes` commands as in the search skill; only **`--type sorted`** is the analytics focus here.
111
+
List and delete use the same `hotdata indexes` commands as in the search skill; only **`--type sorted`** is the analytics focus here. With `--async`, track the build via **`hotdata jobs list`** (see **`hotdata`** skill → Jobs).
- Prefer predictable `--catalog` / `--table`values, e.g. catalog `chain_db` + table `chain_<topic>_<YYYYMMDD>` (the chain table is named by `databases load --table`, not a `--name` flag).
88
88
- Record long-lived chains in **context:DATAMODEL → Derived tables (Chain)** with the **full** SQL name you use (`database.schema.table`).
89
89
- Promote join/grain findings to **context:DATAMODEL** when they should be shared or persisted (**`hotdata`** skill).
Use this skill when working with geospatial data in Hotdata. Hotdata supports a subset of PostGIS-style functions using**PostgreSQLdialect SQL**. This reference is dataset-agnostic — apply it to any table with geometry columns.
9
+
Hotdatasupports a subset of PostGIS-style functions in**PostgreSQL-dialect SQL**. This skill is dataset-agnostic — apply it to any table with geometry columns.
-**Fully qualify tables** as `<connection>.<schema>.<table>` (or `<catalog>.<schema>.<table>` for a managed database) — every `<table>` placeholder below means a qualified name.
22
+
-**PostgreSQL dialect:** double-quote any non-lowercase identifier (e.g. `"GeoID"`).
23
+
- Discover candidate tables/columns with **`hotdata tables list --connection-id <id>`** (see core skill).
12
24
13
25
---
14
26
15
-
## Geometry Columns
27
+
## Geometry columns
16
28
17
-
Most geospatial datasets in Hotdata carry one or both of:
29
+
Most geospatial tables in Hotdata carry one or both of:
18
30
19
31
| Column | Type | Description |
20
32
|---|---|---|
21
33
|`wkb_geometry`|`Binary`| WKB-encoded geometry (polygon, point, multipolygon, etc.) |
|`ST_GeometryType(geom)`| e.g. `ST_Polygon`, `ST_MultiPolygon`, `ST_Point`|
67
-
|`ST_IsValid(geom)`| boolean |
68
-
|`ST_NumPoints(geom)`| integer |
69
-
|`ST_NPoints(geom)`| integer (alias for ST_NumPoints) |
70
-
|`ST_X(point)`| longitude (float) |
71
-
|`ST_Y(point)`| latitude (float) |
72
-
|`ST_Centroid(geom)`| point geometry |
53
+
## Functions
73
54
74
-
### Measurement
55
+
Common building blocks (full catalog, the unsupported set + workarounds, and unit conversions: **[references/functions.md](references/functions.md)**):
75
56
76
-
| Function | Unit | Notes |
77
-
|---|---|---|
78
-
|`ST_Area(geom)`| degrees² | Multiply by `111000 * 111000` for m², then `* 10.7639` for ft² |
79
-
|`ST_Length(geom)`| degrees | Multiply by `111000` for approximate meters |
80
-
|`ST_Distance(geom_a, geom_b)`| degrees | Multiply by `111000` for approximate meters |
81
-
82
-
> **No meter-native measurements:**`::geography` cast is not supported. All measurements are in decimal degrees. The conversion factor ~111,000 m/degree is accurate at mid-latitudes (~30–50°N/S) and degrades toward the poles.
**Key limits** (see reference for the full list + workarounds): no `::geography` cast — **measurements are in decimal degrees**, convert with the factors in the reference (distance `× 111000` ≈ meters at mid-latitudes; **area is only order-of-magnitude**). No `ST_Buffer`, `ST_DWithin`, `ST_MakeEnvelope`, `ST_Union`, `ST_Transform`, or GeoJSON I/O — use the documented substitutes.
123
64
124
65
---
125
66
126
-
## Common Patterns
67
+
## Common patterns
127
68
128
-
### Check geometry types in a table
69
+
### Geometry types in a table
129
70
130
71
```sql
131
72
SELECT ST_GeometryType(ST_GeomFromWKB(wkb_geometry)) AS geom_type, COUNT(*)
Use `ST_GeomFromText` with a closed WKT polygon ring:
80
+
Use `ST_GeomFromText` with a **closed** WKT polygon ring (repeat the first vertex):
140
81
141
82
```sql
142
83
WHERE ST_Within(
@@ -145,9 +86,7 @@ WHERE ST_Within(
145
86
)
146
87
```
147
88
148
-
**Vertex order:**`(minLon minLat, maxLon minLat, maxLon maxLat, minLon maxLat, minLon minLat)` — close the ring by repeating the first point.
149
-
150
-
**Faster alternative** using the precomputed bbox struct (no WKB parsing):
89
+
**Faster** on large tables — filter the precomputed bbox struct (no WKB parsing); use the `ST_Within` form when you need centroid-in-polygon precision:
151
90
152
91
```sql
153
92
WHERE wkb_geometry_bbox['xmin'] >=<minLon>
@@ -156,129 +95,72 @@ WHERE wkb_geometry_bbox['xmin'] >= <minLon>
156
95
AND wkb_geometry_bbox['ymax'] <=<maxLat>
157
96
```
158
97
159
-
Use the bbox approach for large tables where WKB parsing is expensive; use `ST_Within` when you need centroid-in-polygon precision.
160
-
161
-
### Point-in-polygon test
98
+
### Point-in-polygon
162
99
163
100
```sql
164
101
SELECT*
165
102
FROM<table>
166
-
WHERE ST_Contains(
167
-
ST_GeomFromWKB(wkb_geometry),
168
-
ST_MakePoint(<lon>, <lat>)
169
-
)
103
+
WHERE ST_Contains(ST_GeomFromWKB(wkb_geometry), ST_MakePoint(<lon>, <lat>))
170
104
```
171
105
172
-
### Nearest neighbors (closest N features to a point)
0 commit comments