-
Notifications
You must be signed in to change notification settings - Fork 139
feat: Add geography support #228
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 all commits
Commits
Show all changes
130 commits
Select commit
Hold shift + click to select a range
839965e
Rename refs in files
7b9dd6b
Move package
dc70785
more renaming
ca88aaa
Expose dialect and types
d0f9bd4
explain the weird registration
c35a686
fixed: No longer need `test_pybigquery_sqla` schema, we generte rando…
b2636d6
document that we obsolete pybigquery
9a82e92
get _type_map from the base module.
33da56c
fix import
073293f
Warn if an old (non-empty) version of pybigquery is installed.
3555943
Add __version__
b3d022b
fixed names
af5242a
Updated the way the path to __init__.py is computed
2a0f6a0
Updated copyright statements with new package name
b0458cc
Define the version in version.py
95c1bc3
skip coverage for code handling pybigquery hanging around
159f618
blacken/lint
e2d6021
Merge branch 'master' into sqlalchemy-bigquery-197
e5dc64b
merge upstream
a0eeeff
Merge remote-tracking branch 'origin/sqlalchemy-bigquery-197' into sq…
5975e16
merge upstream
132fcd1
Update .repo-metadata.json
jimfulton 741f3a4
Merge branch 'master' into sqlalchemy-bigquery-197
20bc572
Merge branch 'master' into sqlalchemy-bigquery-197
8bfe4f9
Start at documentation.
840bd0a
system test that reproduces the GeoAlchemy2 core totorial.
d86d0cc
Added the geography extra
694d48f
Install geoalchemy2 and shapely for system tests when running Python 3.9
6624368
Initial geography support
7b22d8e
Added more examples and an installation note.
a574587
added wkb conversion prop and improved the wkr prop to return an object
f76ac54
Handle ST_GEOGFROMTEXT calls for bound geoography and GEOGRAPHY type …
a195937
Adjust imports and naming to reflect that we're not using custo class…
1a9f614
Added ORM test
4c6c745
MOAR tests
21a2148
blacken/lint and don't get Geography from .geography
2d10d1e
fixed type map, so introspection works.
374b8f7
Arrange that string arguments are coerced to geography when calling s…
d54059e
blacken
edab551
We don't need to explicitly convert strings to geography using WKT
dc0e2d1
Update to reflect automatic string coersion
eb9acc5
Added missing copyright header
96fcb0b
removed leftover from moving back to pybigquery
2c468f7
blacken
a166cd6
import WKY from geography
136e0d8
Added missing copyright
f2ff791
Go back to inheriting from geoalchemy2 classes
c08847e
Go back to using inherited types
0bf4a0d
Fixed RST heading level
3b4aac4
Tie in geography doc.
166d3fd
typo
6d4e763
need geoalchemy2 for unit tests too
0b451f5
comment tweak
c5cccb3
unit test version of the core system test
dedf4e0
added missing shapely imports and use WKB's wkt property in bind proc…
af67d86
Actually test inserting WKTs
8b730c2
Actually test inserting WKTs -- and more edge-case tests
111257c
Add last_query fixture to make it easier to look at recent queries
f4ab586
add a test for st_... functions that don't take geographies and lever…
9a90695
blacken/lint
55169fb
Merge branch 'master' into geography2
f8cb3bc
cleanup "extra" tables to limit test interaction
79e65f6
use lake as geography table name
047be9c
blacken
fa0233e
merge upstream
bae06c7
Add link to WGS83/SRID definition
0384a20
Refactored docs before including generated api documentation
cc085e1
MOAR documentation and refactored so WKB only takes a data argument
b9a84d3
install geoalchemy2 and shapely for docs so we can import and documen…
6ebfb51
refactored docs for for better navigation and to document the geograp…
c449885
added missing licence file
feb5910
Try to make owlbot/synth do the needsful for extras
c823c24
say the magic word
b0d0346
Updated some tests to reflect movement of responsibility.
74504ed
blacken
7908dd9
Updated owlbot to leverage extras config and added geoalchemy2 and sh…
2d71565
Added test for coverage
88f097b
explain why uppercase
6eb1c9c
simplify with importskip
0ce34d9
Use importskip rather than skipping based on Python version
22bff6b
Set up snippets
2e1fc9a
first wrong stab at README
c3bfb71
Revert "first wrong stab at README"
b07b95a
typo
8b9a0c3
Add geopandas example
bcac124
Merge branch 'master' into pandas-samples
5d95268
removed unused sys import
4105f7e
Added the missing CRS argument.
5b14b47
Merge branch 'pandas-samples' of github.com:jimfulton/python-bigquery…
01e8c99
Removed sphinx roles that aren't understood bt setuptools.
467569c
Added START and END, but I don't know what I'm doing. :)
02f4b54
merge upstream/master
0ab7d52
merge upstream/master
64a26a6
Keep pybigquery history pypi link
c6d1cc3
🦉 Updates from OwlBot
gcf-owl-bot[bot] 47636fe
🦉 Updates from OwlBot
gcf-owl-bot[bot] 6e6164e
Merge branch 'master' into pandas-samples
tswast 0aed0cb
Removed the api module
3ac10f8
added missing comma
9b49a87
we decided not to have a shim, so get rid of the check for it.
9c31524
fixed indentation
117319f
typo
9481e4e
Update pybigquery/geography.py
jimfulton f8dd5b6
Merge branch 'master' into geography2
abe9886
Show how to install the extra
jimfulton b9987d4
More info on why we won't need pytest-rerunfailures
2a9715a
Merge branch 'geography2' of github.com:jimfulton/python-bigquery-sql…
382c226
removed extra rst file
5f821e3
Added missing import and added module docstring
24a7e59
More docs reorg
1b7be89
fixed some heading levels and also highlight that older versions are …
657054f
lint
b6067ef
Force unique column labels (shouldn't ne necessary)
9283c2c
typo
edff38d
fixed snippet tags
b32571b
merge geograph2
0dedb8f
rename pybigquery to sqlalchemy-bigquery
c0d6203
Merge branch 'pandas-samples' into geography3
6267b04
Remove samples we don't want people to see :)
3022b94
Fixed spelling of sqlalchemy_bigquery
6343bee
Changed the geometry doc to use snippets
04c09e5
Added missing licence file
8e9c35a
blacken
2b654f0
lint
79f8fe2
lint
6eec1f4
merge master
943a40b
compute all extras
f17d82e
blacken
8bc686e
use `use_labels` to work around another related flakey test.
23b631f
Merge branch 'master' into geography2
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 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,87 @@ | ||
Working with Geographic data | ||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
BigQuery provides a `GEOGRAPHY data type | ||
<https://cloud.google.com/bigquery/docs/reference/standard-sql/data-types#geography_type>`_ | ||
for `working with geographic data | ||
<https://cloud.google.com/bigquery/docs/gis-data>`_, including: | ||
|
||
- Points, | ||
- Linestrings, | ||
- Polygons, and | ||
- Collections of points, linestrings, and polygons. | ||
|
||
Geographic data uses the `WGS84 | ||
<https://earth-info.nga.mil/#tab_wgs84-data>`_ coordinate system. | ||
|
||
To define a geography column, use the `GEOGRAPHY` data type imported | ||
from the `sqlalchemy_bigquery` module: | ||
|
||
.. literalinclude:: samples/snippets/geography.py | ||
:language: python | ||
:dedent: 4 | ||
:start-after: [START bigquery_sqlalchemy_create_table_with_geography] | ||
:end-before: [END bigquery_sqlalchemy_create_table_with_geography] | ||
|
||
BigQuery has a variety of `SQL geographic functions | ||
<https://cloud.google.com/bigquery/docs/reference/standard-sql/geography_functions>`_ | ||
for working with geographic data. Among these are functions for | ||
converting between SQL geometry objects and `standard text (WKT) and | ||
binary (WKB) representations | ||
<https://en.wikipedia.org/wiki/Well-known_text_representation_of_geometry>`_. | ||
|
||
Geography data is typically represented in Python as text strings in | ||
WKT format or as `WKB` objects, which contain binary data in WKB | ||
format. Querying geographic data returns `WKB` objects and `WKB` | ||
objects may be used in queries. When | ||
calling spatial functions that expect geographic arguments, text | ||
arguments are automatically coerced to geography. | ||
|
||
Inserting data | ||
~~~~~~~~~~~~~~ | ||
|
||
When inserting geography data, you can pass WKT strings, `WKT` objects, | ||
or `WKB` objects: | ||
|
||
.. literalinclude:: samples/snippets/geography.py | ||
:language: python | ||
:dedent: 4 | ||
:start-after: [START bigquery_sqlalchemy_insert_geography] | ||
:end-before: [END bigquery_sqlalchemy_insert_geography] | ||
|
||
Note that in the `lake3` example, we got a `WKB` object by creating a | ||
`WKT` object and getting its `wkb` property. Normally, we'd get `WKB` | ||
objects as results of previous queries. | ||
|
||
Queries | ||
~~~~~~~ | ||
|
||
When performing spacial queries, and geography objects are expected, | ||
you can to pass `WKB` or `WKT` objects: | ||
|
||
.. literalinclude:: samples/snippets/geography.py | ||
:language: python | ||
:dedent: 4 | ||
:start-after: [START bigquery_sqlalchemy_query_geography_wkb] | ||
:end-before: [END bigquery_sqlalchemy_query_geography_wkb] | ||
|
||
In this example, we passed the `geog` attribute of `lake2`, which is a WKB object. | ||
|
||
Or you can pass strings in WKT format: | ||
|
||
.. literalinclude:: samples/snippets/geography.py | ||
:language: python | ||
:dedent: 4 | ||
:start-after: [START bigquery_sqlalchemy_query_geography_text] | ||
:end-before: [END bigquery_sqlalchemy_query_geography_text] | ||
|
||
Installing geography support | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
To get geography support, you need to install `sqlalchemy-bigquery` | ||
with the `geography` extra, or separately install `GeoAlchemy2` and | ||
`shapely`. | ||
jimfulton marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
.. code-block:: console | ||
|
||
pip install 'sqlalchemy-bigquery[geography]' |
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 |
---|---|---|
|
@@ -3,7 +3,9 @@ | |
:maxdepth: 2 | ||
|
||
README | ||
geography | ||
alembic | ||
reference | ||
|
||
Changelog | ||
--------- | ||
|
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,12 @@ | ||
API Reference | ||
^^^^^^^^^^^^^ | ||
|
||
Geography | ||
~~~~~~~~~ | ||
|
||
.. autoclass:: sqlalchemy_bigquery.geography.GEOGRAPHY | ||
:exclude-members: bind_expression, ElementType, bind_processor | ||
|
||
.. automodule:: sqlalchemy_bigquery.geography | ||
:members: WKB, WKT | ||
:exclude-members: GEOGRAPHY |
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 @@ | ||
../samples |
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
Empty file.
Empty file.
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,20 @@ | ||
# Copyright (c) 2021 The sqlalchemy-bigquery Authors | ||
# | ||
# Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
# this software and associated documentation files (the "Software"), to deal in | ||
# the Software without restriction, including without limitation the rights to | ||
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
# the Software, and to permit persons to whom the Software is furnished to do so, | ||
# subject to the following conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be included in all | ||
# copies or substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
|
||
__version__ = "1.0.0-a1" |
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,48 @@ | ||
# Copyright (c) 2021 The sqlalchemy-bigquery Authors | ||
# | ||
# Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
# this software and associated documentation files (the "Software"), to deal in | ||
# the Software without restriction, including without limitation the rights to | ||
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
# the Software, and to permit persons to whom the Software is furnished to do so, | ||
# subject to the following conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be included in all | ||
# copies or substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
""" | ||
SQLAlchemy dialect for Google BigQuery | ||
""" | ||
|
||
from google.cloud import bigquery | ||
import pytest | ||
import sqlalchemy | ||
import test_utils.prefixer | ||
|
||
prefixer = test_utils.prefixer.Prefixer("python-bigquery-sqlalchemy", "tests/system") | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def client(): | ||
return bigquery.Client() | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def dataset_id(client: bigquery.Client): | ||
project_id = client.project | ||
dataset_id = prefixer.create_prefix() | ||
dataset = bigquery.Dataset(f"{project_id}.{dataset_id}") | ||
dataset = client.create_dataset(dataset) | ||
yield dataset_id | ||
client.delete_dataset(dataset_id, delete_contents=True) | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def engine(dataset_id): | ||
return sqlalchemy.create_engine(f"bigquery:///{dataset_id}") |
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.