-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7351452
commit 3397434
Showing
10 changed files
with
250 additions
and
35 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,29 @@ | ||
use geoarrow::array::CoordType; | ||
use pyo3::exceptions::PyValueError; | ||
use pyo3::prelude::*; | ||
|
||
#[derive(Debug, Clone, Copy)] | ||
pub enum PyCoordType { | ||
Interleaved, | ||
Separated, | ||
} | ||
|
||
impl<'a> FromPyObject<'a> for PyCoordType { | ||
fn extract(ob: &'a PyAny) -> PyResult<Self> { | ||
let s: String = ob.extract()?; | ||
match s.to_lowercase().as_str() { | ||
"interleaved" => Ok(Self::Interleaved), | ||
"separated" => Ok(Self::Separated), | ||
_ => Err(PyValueError::new_err("Unexpected coord type")), | ||
} | ||
} | ||
} | ||
|
||
impl From<PyCoordType> for CoordType { | ||
fn from(value: PyCoordType) -> Self { | ||
match value { | ||
PyCoordType::Interleaved => Self::Interleaved, | ||
PyCoordType::Separated => Self::Separated, | ||
} | ||
} | ||
} |
This file contains 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 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 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 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 @@ | ||
import pyarrow as pa | ||
import shapely | ||
from geoarrow.rust.core import from_shapely, from_wkb, to_shapely, to_wkb | ||
from shapely.testing import assert_geometries_equal | ||
|
||
|
||
def test_wkb_round_trip(): | ||
geoms = shapely.points([0, 1, 2, 3], [4, 5, 6, 7]) | ||
geo_arr = from_shapely(geoms) | ||
wkb_arr = to_wkb(geo_arr) | ||
assert pa.array(shapely.to_wkb(geoms, flavor="iso")) == pa.array(wkb_arr) | ||
assert_geometries_equal(geoms, to_shapely(from_wkb(wkb_arr))) |
This file contains 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,27 @@ | ||
import pyarrow as pa | ||
import shapely | ||
from geoarrow.rust.core import from_wkt, to_shapely | ||
from shapely.testing import assert_geometries_equal | ||
|
||
|
||
def test_from_wkt(): | ||
s = [ | ||
"POINT (3 2)", | ||
"POINT (0 2)", | ||
"POINT (1 4)", | ||
"POINT (3 2)", | ||
"POINT (0 2)", | ||
"POINT (1 4)", | ||
] | ||
shapely_arr = shapely.from_wkt(s) | ||
geo_arr = from_wkt(pa.array(s)) | ||
assert_geometries_equal(shapely_arr, to_shapely(geo_arr)) | ||
|
||
|
||
def test_from_wkt_chunked(): | ||
s1 = ["POINT (3 2)", "POINT (0 2)", "POINT (1 4)"] | ||
s2 = ["POINT (3 2)", "POINT (0 2)", "POINT (1 4)"] | ||
ca = pa.chunked_array([pa.array(s1), pa.array(s2)]) | ||
shapely_arr = shapely.from_wkt(s1 + s2) | ||
geo_arr = from_wkt(ca) | ||
assert_geometries_equal(shapely_arr, to_shapely(geo_arr)) |
Oops, something went wrong.