| { |
| "cells": [ |
| { |
| "cell_type": "markdown", |
| "id": "6a8168a4", |
| "metadata": {}, |
| "source": [ |
| "<!---\n", |
| " Licensed to the Apache Software Foundation (ASF) under one\n", |
| " or more contributor license agreements. See the NOTICE file\n", |
| " distributed with this work for additional information\n", |
| " regarding copyright ownership. The ASF licenses this file\n", |
| " to you under the Apache License, Version 2.0 (the\n", |
| " \"License\"); you may not use this file except in compliance\n", |
| " with the License. You may obtain a copy of the License at\n", |
| "\n", |
| " http://www.apache.org/licenses/LICENSE-2.0\n", |
| "\n", |
| " Unless required by applicable law or agreed to in writing,\n", |
| " software distributed under the License is distributed on an\n", |
| " \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n", |
| " KIND, either express or implied. See the License for the\n", |
| " specific language governing permissions and limitations\n", |
| " under the License.\n", |
| "-->\n", |
| "\n", |
| "# Python Quickstart\n", |
| "\n", |
| "SedonaDB for Python can be installed from [PyPI](https://pypi.org):\n", |
| "\n", |
| "```shell\n", |
| "pip install \"apache-sedona[db]\"\n", |
| "```\n", |
| "\n", |
| "If you can import the module and connect to a new session, you're good to go!" |
| ] |
| }, |
| { |
| "cell_type": "code", |
| "execution_count": 1, |
| "id": "a06df76b", |
| "metadata": {}, |
| "outputs": [ |
| { |
| "name": "stdout", |
| "output_type": "stream", |
| "text": [ |
| "┌────────────┐\n", |
| "│ geom │\n", |
| "│ geometry │\n", |
| "╞════════════╡\n", |
| "│ POINT(0 1) │\n", |
| "└────────────┘\n" |
| ] |
| } |
| ], |
| "source": [ |
| "import sedona.db\n", |
| "\n", |
| "sd = sedona.db.connect()\n", |
| "sd.sql(\"SELECT ST_Point(0, 1) as geom\").show()" |
| ] |
| }, |
| { |
| "cell_type": "markdown", |
| "id": "c0d775bd-4cd8-454e-8cb6-9983c5a7ded3", |
| "metadata": {}, |
| "source": [ |
| "## Point in polygon join" |
| ] |
| }, |
| { |
| "cell_type": "code", |
| "execution_count": 2, |
| "id": "a6e1df61-c77f-4829-ab79-3d1b692408e5", |
| "metadata": {}, |
| "outputs": [], |
| "source": [ |
| "cities = sd.read_parquet(\n", |
| " \"https://raw.githubusercontent.com/geoarrow/geoarrow-data/v0.2.0/natural-earth/files/natural-earth_cities_geo.parquet\"\n", |
| ")" |
| ] |
| }, |
| { |
| "cell_type": "code", |
| "execution_count": 3, |
| "id": "ff571cec-5a35-46c1-b0d6-a40fad33a87b", |
| "metadata": {}, |
| "outputs": [ |
| { |
| "name": "stdout", |
| "output_type": "stream", |
| "text": [ |
| "┌──────────────┬───────────────────────────────┐\n", |
| "│ name ┆ geometry │\n", |
| "│ utf8view ┆ geometry │\n", |
| "╞══════════════╪═══════════════════════════════╡\n", |
| "│ Vatican City ┆ POINT(12.4533865 41.9032822) │\n", |
| "├╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤\n", |
| "│ San Marino ┆ POINT(12.4417702 43.9360958) │\n", |
| "├╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤\n", |
| "│ Vaduz ┆ POINT(9.5166695 47.1337238) │\n", |
| "├╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤\n", |
| "│ Lobamba ┆ POINT(31.1999971 -26.4666675) │\n", |
| "├╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤\n", |
| "│ Luxembourg ┆ POINT(6.1300028 49.6116604) │\n", |
| "├╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤\n", |
| "│ Palikir ┆ POINT(158.1499743 6.9166437) │\n", |
| "├╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤\n", |
| "│ Majuro ┆ POINT(171.3800002 7.1030043) │\n", |
| "├╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤\n", |
| "│ Funafuti ┆ POINT(179.2166471 -8.516652) │\n", |
| "├╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤\n", |
| "│ Melekeok ┆ POINT(134.6265485 7.4873962) │\n", |
| "├╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤\n", |
| "│ Bir Lehlou ┆ POINT(-9.6525222 26.1191667) │\n", |
| "└──────────────┴───────────────────────────────┘\n" |
| ] |
| } |
| ], |
| "source": [ |
| "cities.show()" |
| ] |
| }, |
| { |
| "cell_type": "code", |
| "execution_count": 4, |
| "id": "d4741ac1-44aa-4ae0-b2b6-b68e985b5c44", |
| "metadata": {}, |
| "outputs": [], |
| "source": [ |
| "countries = sd.read_parquet(\n", |
| " \"https://raw.githubusercontent.com/geoarrow/geoarrow-data/v0.2.0/natural-earth/files/natural-earth_countries_geo.parquet\"\n", |
| ")" |
| ] |
| }, |
| { |
| "cell_type": "code", |
| "execution_count": 5, |
| "id": "aa7597b5-fb0b-42f2-be96-10a82b5dd76b", |
| "metadata": {}, |
| "outputs": [ |
| { |
| "name": "stdout", |
| "output_type": "stream", |
| "text": [ |
| "┌─────────────────────────────┬───────────────┬────────────────────────────────────────────────────┐\n", |
| "│ name ┆ continent ┆ geometry │\n", |
| "│ utf8view ┆ utf8view ┆ geometry │\n", |
| "╞═════════════════════════════╪═══════════════╪════════════════════════════════════════════════════╡\n", |
| "│ Fiji ┆ Oceania ┆ MULTIPOLYGON(((180 -16.067132663642447,180 -16.55… │\n", |
| "├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤\n", |
| "│ United Republic of Tanzania ┆ Africa ┆ POLYGON((33.90371119710453 -0.9500000000000001,34… │\n", |
| "├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤\n", |
| "│ Western Sahara ┆ Africa ┆ POLYGON((-8.665589565454809 27.656425889592356,-8… │\n", |
| "├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤\n", |
| "│ Canada ┆ North America ┆ MULTIPOLYGON(((-122.84000000000003 49.00000000000… │\n", |
| "├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤\n", |
| "│ United States of America ┆ North America ┆ MULTIPOLYGON(((-122.84000000000003 49.00000000000… │\n", |
| "├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤\n", |
| "│ Kazakhstan ┆ Asia ┆ POLYGON((87.35997033076265 49.21498078062912,86.5… │\n", |
| "├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤\n", |
| "│ Uzbekistan ┆ Asia ┆ POLYGON((55.96819135928291 41.30864166926936,55.9… │\n", |
| "├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤\n", |
| "│ Papua New Guinea ┆ Oceania ┆ MULTIPOLYGON(((141.00021040259185 -2.600151055515… │\n", |
| "├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤\n", |
| "│ Indonesia ┆ Asia ┆ MULTIPOLYGON(((141.00021040259185 -2.600151055515… │\n", |
| "├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤\n", |
| "│ Argentina ┆ South America ┆ MULTIPOLYGON(((-68.63401022758323 -52.63637045887… │\n", |
| "└─────────────────────────────┴───────────────┴────────────────────────────────────────────────────┘\n" |
| ] |
| } |
| ], |
| "source": [ |
| "countries.show()" |
| ] |
| }, |
| { |
| "cell_type": "code", |
| "execution_count": 6, |
| "id": "c18af1fa-3847-4a43-ba1b-2ce99e8505d3", |
| "metadata": {}, |
| "outputs": [], |
| "source": [ |
| "cities.to_view(\"cities\")\n", |
| "countries.to_view(\"countries\")" |
| ] |
| }, |
| { |
| "cell_type": "code", |
| "execution_count": 7, |
| "id": "2cf5941c-ff25-4288-bf0c-983f1cd8125b", |
| "metadata": {}, |
| "outputs": [ |
| { |
| "name": "stdout", |
| "output_type": "stream", |
| "text": [ |
| "┌───────────────┬──────────────────────┬─────────────────────┬───────────────┬─────────────────────┐\n", |
| "│ name ┆ geometry ┆ name ┆ continent ┆ geometry │\n", |
| "│ utf8view ┆ geometry ┆ utf8view ┆ utf8view ┆ geometry │\n", |
| "╞═══════════════╪══════════════════════╪═════════════════════╪═══════════════╪═════════════════════╡\n", |
| "│ Suva ┆ POINT(178.4417073 -… ┆ Fiji ┆ Oceania ┆ MULTIPOLYGON(((180… │\n", |
| "├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤\n", |
| "│ Dodoma ┆ POINT(35.7500036 -6… ┆ United Republic of… ┆ Africa ┆ POLYGON((33.903711… │\n", |
| "├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤\n", |
| "│ Dar es Salaam ┆ POINT(39.266396 -6.… ┆ United Republic of… ┆ Africa ┆ POLYGON((33.903711… │\n", |
| "├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤\n", |
| "│ Bir Lehlou ┆ POINT(-9.6525222 26… ┆ Western Sahara ┆ Africa ┆ POLYGON((-8.665589… │\n", |
| "├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤\n", |
| "│ Ottawa ┆ POINT(-75.7019612 4… ┆ Canada ┆ North America ┆ MULTIPOLYGON(((-12… │\n", |
| "├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤\n", |
| "│ Vancouver ┆ POINT(-123.1235901 … ┆ Canada ┆ North America ┆ MULTIPOLYGON(((-12… │\n", |
| "├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤\n", |
| "│ Toronto ┆ POINT(-79.389458554… ┆ Canada ┆ North America ┆ MULTIPOLYGON(((-12… │\n", |
| "├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤\n", |
| "│ San Francisco ┆ POINT(-122.39959956… ┆ United States of A… ┆ North America ┆ MULTIPOLYGON(((-12… │\n", |
| "├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤\n", |
| "│ Denver ┆ POINT(-104.9859618 … ┆ United States of A… ┆ North America ┆ MULTIPOLYGON(((-12… │\n", |
| "├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤\n", |
| "│ Houston ┆ POINT(-95.348436256… ┆ United States of A… ┆ North America ┆ MULTIPOLYGON(((-12… │\n", |
| "└───────────────┴──────────────────────┴─────────────────────┴───────────────┴─────────────────────┘\n" |
| ] |
| } |
| ], |
| "source": [ |
| "# join the cities and countries tables\n", |
| "sd.sql(\"\"\"\n", |
| "select * from cities\n", |
| "join countries\n", |
| "where ST_Intersects(cities.geometry, countries.geometry)\n", |
| "\"\"\").show()" |
| ] |
| }, |
| { |
| "cell_type": "markdown", |
| "id": "6d4fcb29-35dd-4ff6-933d-e480f1698662", |
| "metadata": {}, |
| "source": [ |
| "## Manually create SedonaDB DataFrames" |
| ] |
| }, |
| { |
| "cell_type": "markdown", |
| "id": "8fd8cae5-0b77-4a09-8b85-33bcc6abb813", |
| "metadata": {}, |
| "source": [ |
| "Let's create a DataFrame with one string column and one geometry column to show some of the functionality of the SedonaDB Python interface." |
| ] |
| }, |
| { |
| "cell_type": "code", |
| "execution_count": null, |
| "id": "6dd816c7-fd3f-4358-b628-ef5e6940c95c", |
| "metadata": {}, |
| "outputs": [], |
| "source": [ |
| "df = sd.sql(\"\"\"\n", |
| "SELECT * FROM (VALUES\n", |
| " ('one', ST_GeomFromWkt('POINT(1 2)')),\n", |
| " ('two', ST_GeomFromWkt('POLYGON((-74.0 40.7, -74.0 40.8, -73.9 40.8, -73.9 40.7, -74.0 40.7))')),\n", |
| " ('three', ST_GeomFromWkt('LINESTRING(-74.0060 40.7128, -73.9352 40.7306, -73.8561 40.8484)')))\n", |
| "AS t(val, point)\"\"\")" |
| ] |
| }, |
| { |
| "cell_type": "code", |
| "execution_count": 9, |
| "id": "fb566114-0f2c-45c7-bc94-2396542c2458", |
| "metadata": {}, |
| "outputs": [ |
| { |
| "name": "stdout", |
| "output_type": "stream", |
| "text": [ |
| "┌───────┬──────────────────────────────────────────────────────────────────────────────────────────┐\n", |
| "│ val ┆ point │\n", |
| "│ utf8 ┆ binary │\n", |
| "╞═══════╪══════════════════════════════════════════════════════════════════════════════════════════╡\n", |
| "│ one ┆ 0101000000000000000000f03f0000000000000040 │\n", |
| "├╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤\n", |
| "│ two ┆ 0103000000010000000500000000000000008052c09a9999999959444000000000008052c06666666666664… │\n", |
| "├╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤\n", |
| "│ three ┆ 010200000003000000aaf1d24d628052c05e4bc8073d5b444007ce1951da7b52c0933a014d845d4440c286a… │\n", |
| "└───────┴──────────────────────────────────────────────────────────────────────────────────────────┘\n" |
| ] |
| } |
| ], |
| "source": [ |
| "df.show()" |
| ] |
| }, |
| { |
| "cell_type": "markdown", |
| "id": "b051dbf5-2fdc-4cf7-9cfc-73d3ca5a5d94", |
| "metadata": {}, |
| "source": [ |
| "Verify that this object is a SedonaDB DataFrame." |
| ] |
| }, |
| { |
| "cell_type": "code", |
| "execution_count": 10, |
| "id": "44574ca0-1a39-4018-9729-ae56c232013c", |
| "metadata": {}, |
| "outputs": [ |
| { |
| "data": { |
| "text/plain": [ |
| "sedonadb.dataframe.DataFrame" |
| ] |
| }, |
| "execution_count": 10, |
| "metadata": {}, |
| "output_type": "execute_result" |
| } |
| ], |
| "source": [ |
| "type(df)" |
| ] |
| }, |
| { |
| "cell_type": "markdown", |
| "id": "d6e7e7b0-bac3-4ce4-8839-a7fa3dd0b4c6", |
| "metadata": {}, |
| "source": [ |
| "Expose the DataFrame as a view and run a SQL operation on the geometry data." |
| ] |
| }, |
| { |
| "cell_type": "code", |
| "execution_count": 11, |
| "id": "aac2295a-68fe-44c4-911a-e049f789ad35", |
| "metadata": {}, |
| "outputs": [], |
| "source": [ |
| "df.to_view(\"fun_table\")" |
| ] |
| }, |
| { |
| "cell_type": "code", |
| "execution_count": 16, |
| "id": "de296b34", |
| "metadata": {}, |
| "outputs": [ |
| { |
| "name": "stdout", |
| "output_type": "stream", |
| "text": [ |
| "┌─────────────┬───────────┬─────────────┐\n", |
| "│ column_name ┆ data_type ┆ is_nullable │\n", |
| "│ utf8 ┆ utf8 ┆ utf8 │\n", |
| "╞═════════════╪═══════════╪═════════════╡\n", |
| "│ val ┆ Utf8 ┆ YES │\n", |
| "├╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌┤\n", |
| "│ point ┆ Binary ┆ YES │\n", |
| "└─────────────┴───────────┴─────────────┘\n" |
| ] |
| } |
| ], |
| "source": [ |
| "sd.sql(\"DESCRIBE fun_table\").show()" |
| ] |
| }, |
| { |
| "cell_type": "code", |
| "execution_count": 18, |
| "id": "09eefd76-b325-4d58-8284-92c2340514b8", |
| "metadata": {}, |
| "outputs": [ |
| { |
| "name": "stdout", |
| "output_type": "stream", |
| "text": [ |
| "┌───────┬─────────────────────────────────────────────┬────────────────────────────────────────────┐\n", |
| "│ val ┆ point ┆ centroid │\n", |
| "│ utf8 ┆ binary ┆ geometry │\n", |
| "╞═══════╪═════════════════════════════════════════════╪════════════════════════════════════════════╡\n", |
| "│ one ┆ 0101000000000000000000f03f0000000000000040 ┆ POINT(1 2) │\n", |
| "├╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤\n", |
| "│ two ┆ 0103000000010000000500000000000000008052c0… ┆ POINT(-73.95 40.75) │\n", |
| "├╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤\n", |
| "│ three ┆ 010200000003000000aaf1d24d628052c05e4bc807… ┆ POINT(-73.92111155675562 40.7664673976246… │\n", |
| "└───────┴─────────────────────────────────────────────┴────────────────────────────────────────────┘\n" |
| ] |
| } |
| ], |
| "source": [ |
| "sd.sql(\"SELECT *, ST_Centroid(ST_GeomFromWKB(point)) as centroid from fun_table\").show()" |
| ] |
| } |
| ], |
| "metadata": { |
| "kernelspec": { |
| "display_name": ".venv (3.13.3)", |
| "language": "python", |
| "name": "python3" |
| }, |
| "language_info": { |
| "codemirror_mode": { |
| "name": "ipython", |
| "version": 3 |
| }, |
| "file_extension": ".py", |
| "mimetype": "text/x-python", |
| "name": "python", |
| "nbconvert_exporter": "python", |
| "pygments_lexer": "ipython3", |
| "version": "3.13.3" |
| } |
| }, |
| "nbformat": 4, |
| "nbformat_minor": 5 |
| } |