Skip to content

Commit

Permalink
Merge pull request geopython#56 from drnextgis/pygeoif
Browse files Browse the repository at this point in the history
pygeoif 1.0.0
  • Loading branch information
tomkralidis authored Oct 17, 2022
2 parents 3dbcccc + 5ebe1e5 commit e90c913
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 41 deletions.
4 changes: 2 additions & 2 deletions pygeofilter/backends/sqlalchemy/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from typing import Callable, Dict

from sqlalchemy import and_, func, not_, or_
from pygeoif.geometry import as_shape
from pygeoif import shape


def parse_bbox(box, srid: int = None):
Expand All @@ -19,7 +19,7 @@ def parse_bbox(box, srid: int = None):


def parse_geometry(geom):
wkt = as_shape(geom).to_wkt()
wkt = shape(geom).wkt
search = re.search(r"SRID=(\d+);", wkt)
sridtxt = "" if search else "SRID=4326;"
return func.ST_GeomFromEWKT(f"{sridtxt}{wkt}")
Expand Down
6 changes: 3 additions & 3 deletions pygeofilter/values.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from datetime import date, time, datetime, timedelta
from typing import Any, List, Union, Optional

from pygeoif.geometry import as_shape
from pygeoif import shape


@dataclass
Expand All @@ -43,7 +43,7 @@ def __geo_interface__(self):

def __eq__(self, o: object) -> bool:
return (
as_shape(self).__geo_interface__ == as_shape(o).__geo_interface__
shape(self).__geo_interface__ == shape(o).__geo_interface__
)


Expand Down Expand Up @@ -73,7 +73,7 @@ def __geo_interface__(self):

def __eq__(self, o: object) -> bool:
return (
as_shape(self).__geo_interface__ == as_shape(o).__geo_interface__
shape(self).__geo_interface__ == shape(o).__geo_interface__
)


Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
install_requires=[
"dateparser",
"lark<1.0",
"pygeoif",
"pygeoif>=1.0.0",
"dataclasses;python_version<'3.7'",
] if not on_rtd else [],
extras_require={
Expand Down
28 changes: 11 additions & 17 deletions tests/parsers/cql2_json/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,8 +408,8 @@ def test_within_multipolygon_attr():
assert result == ast.GeometryWithin(
values.Geometry(
normalize_geom(
geometry.MultiPolygon(
[geometry.Polygon([(1, 1), (2, 2), (0, 3), (1, 1)])]
geometry.MultiPolygon.from_polygons(
geometry.Polygon([(1, 1), (2, 2), (0, 3), (1, 1)])
).__geo_interface__
),
),
Expand All @@ -435,11 +435,9 @@ def test_touches_attr_multilinestring():
ast.Attribute("geometry"),
values.Geometry(
normalize_geom(
geometry.MultiLineString(
[
geometry.LineString([(1, 1), (2, 2)]),
geometry.LineString([(0, 3), (1, 1)]),
]
geometry.MultiLineString.from_linestrings(
geometry.LineString([(1, 1), (2, 2)]),
geometry.LineString([(0, 3), (1, 1)]),
).__geo_interface__
),
),
Expand All @@ -464,11 +462,9 @@ def test_crosses_attr_multilinestring():
ast.Attribute("geometry"),
values.Geometry(
normalize_geom(
geometry.MultiLineString(
[
geometry.LineString([(1, 1), (2, 2)]),
geometry.LineString([(0, 3), (1, 1)]),
]
geometry.MultiLineString.from_linestrings(
geometry.LineString([(1, 1), (2, 2)]),
geometry.LineString([(0, 3), (1, 1)]),
).__geo_interface__
)
),
Expand All @@ -493,11 +489,9 @@ def test_overlaps_attr_multilinestring():
ast.Attribute("geometry"),
values.Geometry(
normalize_geom(
geometry.MultiLineString(
[
geometry.LineString([(1, 1), (2, 2)]),
geometry.LineString([(0, 3), (1, 1)]),
]
geometry.MultiLineString.from_linestrings(
geometry.LineString([(1, 1), (2, 2)]),
geometry.LineString([(0, 3), (1, 1)]),
).__geo_interface__
),
),
Expand Down
16 changes: 8 additions & 8 deletions tests/parsers/cql_json/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,9 +509,9 @@ def test_within_multipolygon_attr():
assert result == ast.GeometryWithin(
values.Geometry(
normalize_geom(
geometry.MultiPolygon([
geometry.MultiPolygon.from_polygons(
geometry.Polygon([(1, 1), (2, 2), (0, 3), (1, 1)])
]).__geo_interface__
).__geo_interface__
),
),
ast.Attribute('geometry'),
Expand All @@ -533,10 +533,10 @@ def test_touches_attr_multilinestring():
ast.Attribute('geometry'),
values.Geometry(
normalize_geom(
geometry.MultiLineString([
geometry.MultiLineString.from_linestrings(
geometry.LineString([(1, 1), (2, 2)]),
geometry.LineString([(0, 3), (1, 1)]),
]).__geo_interface__
).__geo_interface__
),
),
)
Expand All @@ -557,10 +557,10 @@ def test_crosses_attr_multilinestring():
ast.Attribute('geometry'),
values.Geometry(
normalize_geom(
geometry.MultiLineString([
geometry.MultiLineString.from_linestrings(
geometry.LineString([(1, 1), (2, 2)]),
geometry.LineString([(0, 3), (1, 1)]),
]).__geo_interface__
).__geo_interface__
)
),
)
Expand All @@ -581,10 +581,10 @@ def test_overlaps_attr_multilinestring():
ast.Attribute('geometry'),
values.Geometry(
normalize_geom(
geometry.MultiLineString([
geometry.MultiLineString.from_linestrings(
geometry.LineString([(1, 1), (2, 2)]),
geometry.LineString([(0, 3), (1, 1)]),
]).__geo_interface__
).__geo_interface__
),
),
)
Expand Down
16 changes: 8 additions & 8 deletions tests/parsers/ecql/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,9 +328,9 @@ def test_within_multipolygon_attr():
result = parse('WITHIN(MULTIPOLYGON(((1 1,2 2,0 3,1 1))), geometry)')
assert result == ast.GeometryWithin(
values.Geometry(
geometry.MultiPolygon([
geometry.MultiPolygon.from_polygons(
geometry.Polygon([(1, 1), (2, 2), (0, 3), (1, 1)])
]).__geo_interface__,
).__geo_interface__,
),
ast.Attribute('geometry'),
)
Expand All @@ -341,10 +341,10 @@ def test_touches_attr_multilinestring():
assert result == ast.GeometryTouches(
ast.Attribute('geometry'),
values.Geometry(
geometry.MultiLineString([
geometry.MultiLineString.from_linestrings(
geometry.LineString([(1, 1), (2, 2)]),
geometry.LineString([(0, 3), (1, 1)]),
]).__geo_interface__,
).__geo_interface__,
),
)

Expand All @@ -354,10 +354,10 @@ def test_crosses_attr_multilinestring():
assert result == ast.GeometryCrosses(
ast.Attribute('geometry'),
values.Geometry(
geometry.MultiLineString([
geometry.MultiLineString.from_linestrings(
geometry.LineString([(1, 1), (2, 2)]),
geometry.LineString([(0, 3), (1, 1)]),
]).__geo_interface__,
).__geo_interface__,
),
)

Expand All @@ -367,10 +367,10 @@ def test_overlaps_attr_multilinestring():
assert result == ast.GeometryOverlaps(
ast.Attribute('geometry'),
values.Geometry(
geometry.MultiLineString([
geometry.MultiLineString.from_linestrings(
geometry.LineString([(1, 1), (2, 2)]),
geometry.LineString([(0, 3), (1, 1)]),
]).__geo_interface__,
).__geo_interface__,
),
)

Expand Down
4 changes: 2 additions & 2 deletions tests/parsers/jfe/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,9 @@ def test_within_multipolygon_attr():
assert result == ast.GeometryWithin(
values.Geometry(
normalize_geom(
geometry.MultiPolygon([
geometry.MultiPolygon.from_polygons(
geometry.Polygon([(1, 1), (2, 2), (0, 3), (1, 1)])
]).__geo_interface__
).__geo_interface__
),
),
ast.Attribute('geometry'),
Expand Down

0 comments on commit e90c913

Please sign in to comment.