-
Notifications
You must be signed in to change notification settings - Fork 52
Pre and post bug bash fixes #66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 8 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
b6d4b32
adding docs and navigation for second bug bash
kadolor 276b74b
adding Apache license
kadolor ea72545
fixing pre-commit
kadolor d2719cd
fixing pre-commit
kadolor 5483ce8
[DOCS] changing import statements for notebook and README
kadolor ec1ab95
making markdown docs version of notebook with narrative
kadolor f75ebe7
additional changes, removal of .ipynb
kadolor ccc81ff
Merge branch 'main' into bug-bash
kadolor e2a1a71
continued fixes, removing interactive mode
kadolor bece094
changing introduction
kadolor a5cbc3e
adding markdown file of python quickstart
kadolor c40f423
Adding link to downloadable ipynb
kadolor 227c617
Merge branch 'main' into bug-bash
kadolor 67c3077
Finish applying stashed changes and resolve conflict
kadolor 2590c99
Finish applying stashed changes and resolve conflict
kadolor 02fa793
fixing
kadolor 7136a7d
fix notebook
kadolor b10b081
Update docs/index.md
kadolor 00961d1
fixing styling
kadolor 1f9e342
adding lint to check for pre-commit, adding navigation styling, addin…
kadolor 6b9a819
fixing notebook command
kadolor f677012
adding file
kadolor 5cbbd6f
adding generated file from notebook
kadolor 9d59ae4
adding to requirements.txt
kadolor 9c7d825
changing lint file
kadolor 10c011a
integrating feedback
kadolor 1e99545
changing lint file
kadolor File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,176 @@ | ||
| <!--- | ||
| Licensed to the Apache Software Foundation (ASF) under one | ||
| or more contributor license agreements. See the NOTICE file | ||
| distributed with this work for additional information | ||
| regarding copyright ownership. The ASF licenses this file | ||
| to you under the Apache License, Version 2.0 (the | ||
| "License"); you may not use this file except in compliance | ||
| with the License. You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, | ||
| software distributed under the License is distributed on an | ||
| "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| KIND, either express or implied. See the License for the | ||
| specific language governing permissions and limitations | ||
| under the License. | ||
| --> | ||
|
|
||
| # Python Quickstart | ||
|
|
||
| SedonaDB for Python can be installed from **PyPI**: | ||
|
|
||
| ```shell | ||
| pip install "apache-sedona[db]" | ||
| ``` | ||
|
|
||
| ## Import SedonaDB | ||
|
|
||
| To get started, import the library and connect to a new session. You can run SQL queries directly on the session object. | ||
|
|
||
| ```python | ||
| import sedona.db | ||
|
|
||
| sd = sedona.db.connect() | ||
| sd.sql("SELECT ST_Point(0, 1) as geom").show() | ||
| ``` | ||
|
|
||
| **Output:** | ||
|
|
||
| ```sh | ||
| ┌────────────┐ | ||
| │ geom │ | ||
| │ wkb │ | ||
| ╞════════════╡ | ||
| │ POINT(0 1) │ | ||
| └────────────┘ | ||
| ``` | ||
|
|
||
| ## Spatial Join Example | ||
|
|
||
| A common use case is performing a spatial join. | ||
| In this example, we'll find the country that each city belongs to by checking if the city's point geometry intersects with a country's polygon geometry. | ||
|
|
||
| ### Load Datasets | ||
|
|
||
| First, load the cities and countries parquet files from their URLs into SedonaDB DataFrames. | ||
|
|
||
| ```python | ||
| cities_url = "https://raw.githubusercontent.com/geoarrow/geoarrow-data/v0.2.0/natural-earth/files/natural-earth_cities_geo.parquet" | ||
| countries_url = "https://raw.githubusercontent.com/geoarrow/geoarrow-data/v0.2.0/natural-earth/files/natural-earth_countries_geo.parquet" | ||
|
|
||
| cities = sd.read_parquet(cities_url) | ||
| countries = sd.read_parquet(countries_url) | ||
| ``` | ||
|
|
||
| ### Register Views | ||
|
|
||
| To query these DataFrames using SQL, they must be registered as temporary views in the session. | ||
|
|
||
| ```python | ||
| cities.to_view("cities") | ||
| countries.to_view("countries") | ||
| ``` | ||
|
|
||
| ### Run the Join Query | ||
|
|
||
| Now you can run a SQL query using `ST_Intersects` to join the two views. | ||
|
|
||
| ```python | ||
| # Join the cities and countries tables | ||
| sd.sql(""" | ||
| SELECT | ||
| cities.name AS city, | ||
| countries.name AS country, | ||
| countries.continent | ||
| FROM cities | ||
| JOIN countries | ||
| WHERE ST_Intersects(cities.geometry, countries.geometry) | ||
| """).show() | ||
| ``` | ||
|
|
||
| **Output:** | ||
|
|
||
| ``` | ||
| ┌───────────────┬─────────────────────────────┬───────────────┐ | ||
| │ city ┆ country ┆ continent │ | ||
| │ utf8view ┆ utf8view ┆ utf8view │ | ||
| ╞═══════════════╪═════════════════════════════╪═══════════════╡ | ||
| │ Suva ┆ Fiji ┆ Oceania │ | ||
| ├───────────────┼─────────────────────────────┼───────────────┤ | ||
| │ Dodoma ┆ United Republic of Tanzania ┆ Africa │ | ||
| ├───────────────┼─────────────────────────────┼───────────────┤ | ||
| │ Dar es Salaam ┆ United Republic of Tanzania ┆ Africa │ | ||
| ├───────────────┼─────────────────────────────┼───────────────┤ | ||
| │ Bir Lehlou ┆ Western Sahara ┆ Africa │ | ||
| ... | ||
| └───────────────┴─────────────────────────────┴───────────────┘ | ||
| ``` | ||
|
|
||
| ## Creating a DataFrame Manually | ||
|
|
||
| You can also create a SedonaDB DataFrame from scratch using SQL `VALUES` clauses and geometry functions like `ST_GeomFromWkt`. | ||
|
|
||
| ```python | ||
| df = sd.sql(""" | ||
| SELECT * FROM (VALUES | ||
| ('one', ST_GeomFromWkt('POINT(1 2)')), | ||
| ('two', ST_GeomFromWkt('POLYGON((-74.0 40.7, -74.0 40.8, -73.9 40.8, -73.9 40.7, -74.0 40.7))')), | ||
| ('three', ST_GeomFromWkt('LINESTRING(-74.0060 40.7128, -73.9352 40.7306, -73.8561 40.8484)'))) | ||
| AS t(val, point) | ||
| """) | ||
|
|
||
| # Verify the object type | ||
| type(df) | ||
| ``` | ||
|
|
||
| **Output:** | ||
|
|
||
| ``` | ||
| sedonadb.dataframe.DataFrame | ||
| ``` | ||
|
|
||
| Once created, you can register it as a view and run further spatial operations on it. | ||
|
|
||
| ```python | ||
| df.to_view("fun_table") | ||
| sd.sql("SELECT *, ST_Centroid(point) AS centroid FROM fun_table").show() | ||
| ``` | ||
|
|
||
| **Output:** | ||
|
|
||
| ``` | ||
| ┌───────┬─────────────────────────────────────────────┬────────────────────────────────────────────┐ | ||
| │ val ┆ point ┆ centroid │ | ||
| │ utf8 ┆ wkb ┆ wkb │ | ||
| ╞═══════╪═════════════════════════════════════════════╪════════════════════════════════════════════╡ | ||
| │ one ┆ POINT(1 2) ┆ POINT(1 2) │ | ||
| ├───────┼─────────────────────────────────────────────┼────────────────────────────────────────────┤ | ||
| │ two ┆ POLYGON((-74 40.7,-74 40.8,-73.9 40.8,-73.… ┆ POINT(-73.95000000000002 40.75) │ | ||
| ├───────┼─────────────────────────────────────────────┼────────────────────────────────────────────┤ | ||
| │ three ┆ LINESTRING(-74.006 40.7128,-73.9352 40.730… ┆ POINT(-73.92111155675562 40.7664673976246… │ | ||
| └───────┴─────────────────────────────────────────────┴────────────────────────────────────────────┘ | ||
| ``` | ||
|
|
||
| ## Interactive Mode | ||
|
|
||
| For notebooks or interactive sessions, you can enable **interactive mode**. This eagerly prints the results of queries without requiring an explicit `.show()` call, which is useful for data exploration. | ||
|
|
||
| ```python | ||
| sedona.db.options.interactive = True | ||
| sd.sql("SELECT ST_Point(0, 1) as geom") | ||
| ``` | ||
|
|
||
| **Output:** | ||
|
|
||
| ``` | ||
| ┌────────────┐ | ||
| │ geom │ | ||
| │ wkb │ | ||
| ╞════════════╡ | ||
| │ POINT(0 1) │ | ||
| └────────────┘ | ||
| ``` | ||
|
kadolor marked this conversation as resolved.
Outdated
|
||
|
|
||
| For non-interactive scripts or when working with very large datasets, it's best to leave this option `False` to avoid accidentally pulling large amounts of data. | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.