-
Notifications
You must be signed in to change notification settings - Fork 66
Add test data covering different native (geoarrow-based) encodings #204
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
cholmes
merged 9 commits into
opengeospatial:main
from
jorisvandenbossche:example-data-geoarrow
May 28, 2024
Merged
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
6ba4fd4
Add test data covering different native (geoarrow-based) encodings
jorisvandenbossche 7e9eed2
Update test_data/generate_test_data.py
jorisvandenbossche c1f11eb
fix geometry type
jorisvandenbossche 5135493
add .csv extension
jorisvandenbossche ffb547d
add null values
jorisvandenbossche 2981b60
rename csv files
jorisvandenbossche 6c9390f
add back csv files
jorisvandenbossche 3466e1f
properly specify mask when creating the Arrow data
jorisvandenbossche 9c129d1
Merge branch 'main' into example-data-geoarrow
cholmes 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
Binary file not shown.
Binary file not shown.
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,4 @@ | ||
| "col","geometry" | ||
| 0,"LINESTRING (30 10, 10 30, 40 40)" | ||
| 1,"LINESTRING EMPTY" | ||
| 2, |
Binary file not shown.
Binary file not shown.
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,5 @@ | ||
| "col","geometry" | ||
| 0,"MULTILINESTRING ((30 10, 10 30, 40 40))" | ||
| 1,"MULTILINESTRING ((10 10, 20 20, 10 40), (40 40, 30 30, 40 20, 30 10))" | ||
| 2,"MULTILINESTRING EMPTY" | ||
| 3, |
Binary file not shown.
Binary file not shown.
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,5 @@ | ||
| "col","geometry" | ||
| 0,"MULTIPOINT ((30 10))" | ||
| 1,"MULTIPOINT ((10 40), (40 30), (20 20), (30 10))" | ||
| 2,"MULTIPOINT EMPTY" | ||
| 3, |
Binary file not shown.
Binary file not shown.
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,6 @@ | ||
| "col","geometry" | ||
| 0,"MULTIPOLYGON (((30 10, 40 40, 20 40, 10 20, 30 10)))" | ||
| 1,"MULTIPOLYGON (((30 20, 45 40, 10 40, 30 20)), ((15 5, 40 10, 10 20, 5 10, 15 5)))" | ||
| 2,"MULTIPOLYGON (((40 40, 20 45, 45 30, 40 40)), ((20 35, 10 30, 10 10, 30 5, 45 20, 20 35), (30 20, 20 15, 20 25, 30 20)))" | ||
| 3,"MULTIPOLYGON EMPTY" | ||
| 4, |
Binary file not shown.
Binary file not shown.
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,5 @@ | ||
| "col","geometry" | ||
| 0,"POINT (30 10)" | ||
| 1,"POINT EMPTY" | ||
| 2, | ||
| 3,"POINT (40 40)" |
Binary file not shown.
Binary file not shown.
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,5 @@ | ||
| "col","geometry" | ||
| 0,"POLYGON ((30 10, 40 40, 20 40, 10 20, 30 10))" | ||
| 1,"POLYGON ((35 10, 45 45, 15 40, 10 20, 35 10), (20 30, 35 35, 30 20, 20 30))" | ||
| 2,"POLYGON EMPTY" | ||
| 3, |
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,206 @@ | ||
| """ | ||
| Generates example data using pyarrow by running `python generate_test_data.py`. | ||
|
|
||
| You can print the metadata with: | ||
|
|
||
| .. code-block:: python | ||
|
|
||
| >>> import json, pprint, pyarrow.parquet as pq | ||
| >>> pprint.pprint(json.loads(pq.read_schema("example.parquet").metadata[b"geo"])) | ||
| """ | ||
| import json | ||
| import pathlib | ||
| import copy | ||
|
|
||
| import pyarrow as pa | ||
| import pyarrow.parquet as pq | ||
| from pyarrow.csv import write_csv | ||
|
|
||
| from shapely import from_wkt, to_wkb | ||
|
|
||
|
|
||
| HERE = pathlib.Path(__file__).parent | ||
|
|
||
|
|
||
| metadata_template = { | ||
| "version": "1.1.0", | ||
| "primary_column": "geometry", | ||
| "columns": { | ||
| "geometry": { | ||
| "encoding": "WKB", | ||
| "geometry_types": [], | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
|
|
||
| ## Various geometry types with WKB and native (GeoArrow-based) encodings | ||
|
|
||
| def write_encoding_files(geometries_wkt, geometries_geoarrow, geometry_type): | ||
|
|
||
| table = pa.table({"col": range(len(geometries_wkt)), "geometry": geometries_wkt}) | ||
| write_csv(table, HERE / f"data-{geometry_type.lower()}-wkt.csv") | ||
|
|
||
| # WKB encoding | ||
| table = pa.table( | ||
| {"col": range(len(geometries_wkt)), "geometry": to_wkb(from_wkt(geometries_wkt))} | ||
| ) | ||
| metadata = copy.deepcopy(metadata_template) | ||
| metadata["columns"]["geometry"]["geometry_types"] = [geometry_type] | ||
| table = table.replace_schema_metadata({"geo": json.dumps(metadata)}) | ||
| pq.write_table(table, HERE / f"data-{geometry_type.lower()}-encoding_wkb.parquet") | ||
|
jorisvandenbossche marked this conversation as resolved.
|
||
|
|
||
| # native (geoarrow) encoding | ||
| table = pa.table( | ||
| {"col": range(len(geometries_wkt)), "geometry": geometries_geoarrow} | ||
| ) | ||
| metadata["columns"]["geometry"]["encoding"] = geometry_type.lower() | ||
|
jorisvandenbossche marked this conversation as resolved.
|
||
| table = table.replace_schema_metadata({"geo": json.dumps(metadata)}) | ||
| pq.write_table(table, HERE / f"data-{geometry_type.lower()}-encoding_native.parquet") | ||
|
jorisvandenbossche marked this conversation as resolved.
|
||
|
|
||
|
|
||
| # point | ||
|
|
||
| geometries_wkt = [ | ||
| "POINT (30 10)", | ||
| "POINT EMPTY", | ||
| None, | ||
| "POINT (40 40)", | ||
| ] | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should there also be a version of these that contain NULLs or a version that contains Z values?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added some null values! |
||
|
|
||
| point_type = pa.struct( | ||
| [ | ||
| pa.field("x", pa.float64(), nullable=False), | ||
| pa.field("y", pa.float64(), nullable=False) | ||
| ] | ||
| ) | ||
| geometries = pa.array([(30, 10), (float("nan"), float("nan")), (float("nan"), float("nan")), (40, 40)], type=point_type) | ||
|
|
||
| write_encoding_files( | ||
| geometries_wkt, geometries, geometry_type="Point" | ||
|
jorisvandenbossche marked this conversation as resolved.
|
||
| ) | ||
|
|
||
| # linestring | ||
|
|
||
| geometries_wkt = [ | ||
| "LINESTRING (30 10, 10 30, 40 40)", | ||
| "LINESTRING EMPTY", | ||
| None | ||
| ] | ||
|
|
||
| linestring_type = pa.list_(pa.field("vertices", point_type, nullable=False)) | ||
| geometries = pa.array( | ||
| [[(30, 10), (10, 30), (40, 40)], [], []], type=linestring_type) | ||
|
|
||
| write_encoding_files( | ||
| geometries_wkt, geometries, geometry_type="LineString" | ||
|
jorisvandenbossche marked this conversation as resolved.
|
||
| ) | ||
|
|
||
| # polygon | ||
|
|
||
| geometries_wkt = [ | ||
| "POLYGON ((30 10, 40 40, 20 40, 10 20, 30 10))", | ||
| "POLYGON ((35 10, 45 45, 15 40, 10 20, 35 10), (20 30, 35 35, 30 20, 20 30))", | ||
| "POLYGON EMPTY", | ||
| None, | ||
| ] | ||
|
|
||
| polygon_type = pa.list_( | ||
| pa.field("rings", pa.list_( | ||
| pa.field("vertices", point_type, nullable=False) | ||
| ), nullable=False) | ||
| ) | ||
| geometries = pa.array( | ||
| [ | ||
| [[(30, 10), (40, 40), (20, 40), (10, 20), (30, 10)]], | ||
| [[(35, 10), (45, 45), (15, 40), (10, 20), (35, 10)], | ||
| [(20, 30), (35, 35), (30, 20), (20, 30)]], | ||
| [], | ||
| [], | ||
| ], | ||
| type=polygon_type | ||
| ) | ||
|
|
||
| write_encoding_files( | ||
| geometries_wkt, geometries, geometry_type="Polygon" | ||
|
jorisvandenbossche marked this conversation as resolved.
|
||
| ) | ||
|
|
||
| # multipoint | ||
|
|
||
| geometries_wkt = [ | ||
| "MULTIPOINT ((30 10))", | ||
| "MULTIPOINT ((10 40), (40 30), (20 20), (30 10))", | ||
| "MULTIPOINT EMPTY", | ||
| None, | ||
| ] | ||
|
|
||
| multipoint_type = pa.list_(pa.field("points", point_type, nullable=False)) | ||
| geometries = pa.array( | ||
| [ | ||
| [(30, 10)], | ||
| [(10, 40), (40, 30), (20, 20), (30, 10)], | ||
| [], | ||
| [], | ||
| ], | ||
| type=multipoint_type | ||
| ) | ||
|
|
||
| write_encoding_files( | ||
| geometries_wkt, geometries, geometry_type="MultiPoint" | ||
|
jorisvandenbossche marked this conversation as resolved.
|
||
| ) | ||
|
|
||
| # multilinestring | ||
|
|
||
| geometries_wkt = [ | ||
| "MULTILINESTRING ((30 10, 10 30, 40 40))", | ||
| "MULTILINESTRING ((10 10, 20 20, 10 40), (40 40, 30 30, 40 20, 30 10))", | ||
| "MULTILINESTRING EMPTY", | ||
| None, | ||
| ] | ||
|
|
||
| multilinestring_type = pa.list_( | ||
| pa.field("linestrings", linestring_type, nullable=False) | ||
| ) | ||
| geometries = pa.array( | ||
| [ | ||
| [[(30, 10), (10, 30), (40, 40)]], | ||
| [[(10, 10), (20, 20), (10, 40)], | ||
| [(40, 40), (30, 30), (40, 20), (30, 10)]], | ||
| [], | ||
| [], | ||
| ], | ||
| type=multilinestring_type | ||
| ) | ||
|
|
||
| write_encoding_files( | ||
| geometries_wkt, geometries, geometry_type="MultiLineString" | ||
|
jorisvandenbossche marked this conversation as resolved.
|
||
| ) | ||
|
|
||
| # multipolygon | ||
|
|
||
| geometries_wkt = [ | ||
| "MULTIPOLYGON (((30 10, 40 40, 20 40, 10 20, 30 10)))", | ||
| "MULTIPOLYGON (((30 20, 45 40, 10 40, 30 20)), ((15 5, 40 10, 10 20, 5 10, 15 5)))", | ||
| "MULTIPOLYGON (((40 40, 20 45, 45 30, 40 40)), ((20 35, 10 30, 10 10, 30 5, 45 20, 20 35), (30 20, 20 15, 20 25, 30 20)))", | ||
| "MULTIPOLYGON EMPTY", | ||
| None, | ||
| ] | ||
|
|
||
| multipolygon_type = pa.list_(pa.field("polygons", polygon_type, nullable=False)) | ||
| geometries = pa.array( | ||
| [ | ||
| [[[(30, 10), (40, 40), (20, 40), (10, 20), (30, 10)]]], | ||
| [[[(30, 20), (45, 40), (10, 40), (30, 20)]], | ||
| [[(15, 5), (40, 10), (10, 20), (5, 10), (15, 5)]]], | ||
| [[[(40, 40), (20, 45), (45, 30), (40, 40)]], | ||
| [[(20, 35), (10, 30), (10, 10), (30, 5), (45, 20), (20, 35)], | ||
| [(30, 20), (20, 15), (20, 25), (30, 20)]]], | ||
| [], | ||
| [], | ||
| ], | ||
| type=multipolygon_type | ||
| ) | ||
|
|
||
| write_encoding_files( | ||
| geometries_wkt, geometries, geometry_type="MultiPolygon" | ||
|
jorisvandenbossche marked this conversation as resolved.
|
||
| ) | ||
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.