|
7 | 7 | "source": [
|
8 | 8 | "# DuckDB Spatial\n",
|
9 | 9 | "\n",
|
10 |
| - "This is a short example notebook to show how to use [DuckDB Spatial](https://duckdb.org/docs/extensions/spatial.html) with Lonboard. We'll create a [HeatmapLayer](https://developmentseed.org/lonboard/latest/api/layers/heatmap-layer/) with NYC Taxi data. \n", |
| 10 | + "This is a short example notebook to show how to use [DuckDB Spatial](https://duckdb.org/docs/extensions/spatial.html) with Lonboard. We'll create a [HeatmapLayer](https://developmentseed.org/lonboard/latest/api/layers/heatmap-layer/) with NYC Taxi data.\n", |
11 | 11 | "\n",
|
12 |
| - "For full information on how to use DuckDB with Lonboard, [refer to the documentation](https://developmentseed.org/lonboard/latest/ecosystem/duckdb/)." |
| 12 | + "For full information on how to use DuckDB with Lonboard, [refer to the documentation](https://developmentseed.org/lonboard/latest/ecosystem/duckdb/).\n" |
13 | 13 | ]
|
14 | 14 | },
|
15 | 15 | {
|
|
22 | 22 | "id": "453b95d2-cb02-4507-bd4a-57ef30278298",
|
23 | 23 | "metadata": {},
|
24 | 24 | "source": [
|
25 |
| - "" |
| 25 | + "\n" |
26 | 26 | ]
|
27 | 27 | },
|
28 | 28 | {
|
|
33 | 33 | "outputs": [],
|
34 | 34 | "source": [
|
35 | 35 | "import duckdb\n",
|
| 36 | + "\n", |
36 | 37 | "from lonboard import HeatmapLayer, Map"
|
37 | 38 | ]
|
38 | 39 | },
|
|
41 | 42 | "id": "e89f04b2-0b22-4d8a-a7cd-9d37d4ac6323",
|
42 | 43 | "metadata": {},
|
43 | 44 | "source": [
|
44 |
| - "Create a database connection and install and load the Spatial extension:" |
| 45 | + "Create a database connection and install and load the Spatial extension:\n" |
45 | 46 | ]
|
46 | 47 | },
|
47 | 48 | {
|
|
65 | 66 | "\n",
|
66 | 67 | "There are a few incorrect location values in this dataset with longitude/latitude near \"null island\" at (0, 0), so we pass in bounding-box filtering around the New York City region.\n",
|
67 | 68 | "\n",
|
68 |
| - "Then we execute this query in our connection." |
| 69 | + "Then we execute this query in our connection.\n" |
69 | 70 | ]
|
70 | 71 | },
|
71 | 72 | {
|
|
77 | 78 | "source": [
|
78 | 79 | "sql = \"\"\"\n",
|
79 | 80 | "CREATE TABLE rides AS\n",
|
80 |
| - "SELECT \n", |
| 81 | + "SELECT\n", |
81 | 82 | " *,\n",
|
82 | 83 | " ST_Point(dropoff_longitude, dropoff_latitude) as geometry\n",
|
83 |
| - "FROM \"https://d37ci6vzurychx.cloudfront.net/trip-data/yellow_tripdata_2010-03.parquet\" \n", |
| 84 | + "FROM \"https://d37ci6vzurychx.cloudfront.net/trip-data/yellow_tripdata_2010-03.parquet\"\n", |
84 | 85 | "WHERE\n",
|
85 | 86 | " dropoff_longitude >= -74.6087 AND\n",
|
86 | 87 | " dropoff_latitude >= 40.2738 AND\n",
|
|
97 | 98 | "id": "53b67335-4560-41a7-8329-1cef2d952c84",
|
98 | 99 | "metadata": {},
|
99 | 100 | "source": [
|
100 |
| - "Inspecting this table, we can see a variety of columns, plus our `geometry` column:" |
| 101 | + "Inspecting this table, we can see a variety of columns, plus our `geometry` column:\n" |
101 | 102 | ]
|
102 | 103 | },
|
103 | 104 | {
|
|
115 | 116 | "id": "85f78761-b1b8-49a1-be25-b13f104b6071",
|
116 | 117 | "metadata": {},
|
117 | 118 | "source": [
|
118 |
| - "To pass this data into Lonboard, we can pass a string query or \"relation object\" into the `from_duckdb` class method, plus a reference to our connection. Here the `con.table(\"rides\")` call creates a relation that refers to the entire `rides` table." |
| 119 | + "To pass this data into Lonboard, we can pass a string query or \"relation object\" into the `from_duckdb` class method, plus a reference to our connection. Here the `con.table(\"rides\")` call creates a relation that refers to the entire `rides` table.\n" |
119 | 120 | ]
|
120 | 121 | },
|
121 | 122 | {
|
|
144 | 145 | "id": "9fbce4ad-02ce-406c-9003-93f084e5a5c3",
|
145 | 146 | "metadata": {},
|
146 | 147 | "source": [
|
147 |
| - "DuckDB Spatial does not currently export coordinate reference system information, but in this case we know the data is already in the EPSG:4326 (WGS84) coordinate system, so we can ignore the generated warning." |
| 148 | + "DuckDB Spatial does not currently export coordinate reference system information, but in this case we know the data is already in the EPSG:4326 (WGS84) coordinate system, so we can ignore the generated warning.\n" |
148 | 149 | ]
|
149 | 150 | },
|
150 | 151 | {
|
|
154 | 155 | "source": [
|
155 | 156 | "The heatmap by default assigns a weight of 1 to each row, so the heatmap shows the unweighted density of rides. We can change this by modifying the [`get_weight`](https://developmentseed.org/lonboard/latest/api/layers/heatmap-layer/#lonboard.HeatmapLayer.get_weight) attribute.\n",
|
156 | 157 | "\n",
|
157 |
| - "Let's weight the heatmap by the cost of the ride. We can do this by passing in a column from `total_amount`. We can access this column by selecting a table with only that data:" |
| 158 | + "Let's weight the heatmap by the cost of the ride. We can do this by passing in a column from `total_amount`. We can access this column by selecting a table with only that data:\n" |
158 | 159 | ]
|
159 | 160 | },
|
160 | 161 | {
|
|
172 | 173 | "id": "1d011e61-b82c-474f-972c-9c4bbb654895",
|
173 | 174 | "metadata": {},
|
174 | 175 | "source": [
|
175 |
| - "We want a single column to pass in to the layer, so we select the `total_amount` column:" |
| 176 | + "We want a single column to pass in to the layer, so we select the `total_amount` column:\n" |
176 | 177 | ]
|
177 | 178 | },
|
178 | 179 | {
|
|
190 | 191 | "id": "c6483078-c296-40ff-ac5f-534cac768dee",
|
191 | 192 | "metadata": {},
|
192 | 193 | "source": [
|
193 |
| - "Then we assign this onto the `get_weight` accessor" |
| 194 | + "Then we assign this onto the `get_weight` accessor\n" |
194 | 195 | ]
|
195 | 196 | },
|
196 | 197 | {
|
|
208 | 209 | "id": "1a9c8255-17ee-4f71-84a7-b33dd86c94dd",
|
209 | 210 | "metadata": {},
|
210 | 211 | "source": [
|
211 |
| - "Note that the heatmap around airports such as LaGuardia is now darker. There are fewer total rides dropping off at the airport, but each one is expensive!" |
| 212 | + "Note that the heatmap around airports such as LaGuardia is now darker. There are fewer total rides dropping off at the airport, but each one is expensive!\n" |
212 | 213 | ]
|
213 | 214 | }
|
214 | 215 | ],
|
|
228 | 229 | "name": "python",
|
229 | 230 | "nbconvert_exporter": "python",
|
230 | 231 | "pygments_lexer": "ipython3",
|
231 |
| - "version": "3.11.4" |
| 232 | + "version": "3.11.8" |
232 | 233 | },
|
233 | 234 | "widgets": {
|
234 | 235 | "application/vnd.jupyter.widget-state+json": {
|
|
0 commit comments