Skip to content

Commit

Permalink
pin pygeoif to 0.7, fix flake8 (geopython#61)
Browse files Browse the repository at this point in the history
* Revert "pygeoif 1.0.0"

This reverts commit 5ebe1e5.

* pin to pygeoif 0.7

* fix flake8
  • Loading branch information
tomkralidis authored Oct 17, 2022
1 parent e90c913 commit 1f187c0
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 45 deletions.
4 changes: 2 additions & 2 deletions pygeofilter/backends/django/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ def between(lhs: F, low: Union[F, Value], high: Union[F, Value],

def like(lhs: F, pattern: str, nocase: bool = False, not_: bool = False,
mapping_choices: Optional[Dict[str, Dict[str, str]]] = None) -> Q:
""" Create a filter to filter elements according to a string attribute using
wildcard expressions.
""" Create a filter to filter elements according to a string attribute
using wildcard expressions.
:param lhs: the field to compare
:type lhs: :class:`django.db.models.F`
Expand Down
4 changes: 2 additions & 2 deletions pygeofilter/backends/evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def adopt(self, node, *sub_args):
)

def adopt_result(self, result: Any) -> Any:
"""Interface function for adopting the final evaluation result if necessary.
Default is no-op.
"""Interface function for adopting the final evaluation result
if necessary. Default is no-op.
"""
return result
2 changes: 1 addition & 1 deletion pygeofilter/backends/sql/evaluate.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def spatial_operation(self, node, lhs, rhs):
@handle(ast.BBox)
def bbox(self, node, lhs):
func = SPATIAL_COMPARISON_OP_MAP[ast.SpatialComparisonOp.INTERSECTS]
rhs = f"ST_GeomFromText('POLYGON(({node.minx} {node.miny}, {node.minx} {node.maxy}, {node.maxx} {node.maxy}, {node.maxx} {node.miny}, {node.minx} {node.miny}))')"
rhs = f"ST_GeomFromText('POLYGON(({node.minx} {node.miny}, {node.minx} {node.maxy}, {node.maxx} {node.maxy}, {node.maxx} {node.miny}, {node.minx} {node.miny}))')" # noqa
return f"{func}({lhs},{rhs})"

@handle(ast.Attribute)
Expand Down
8 changes: 4 additions & 4 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 import shape
from pygeoif.geometry import as_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 = shape(geom).wkt
wkt = as_shape(geom).to_wkt()
search = re.search(r"SRID=(\d+);", wkt)
sridtxt = "" if search else "SRID=4326;"
return func.ST_GeomFromEWKT(f"{sridtxt}{wkt}")
Expand Down Expand Up @@ -142,8 +142,8 @@ def between(lhs, low, high, negate=False):


def like(lhs, rhs, case=False, negate=False):
""" Create a filter to filter elements according to a string attribute using
wildcard expressions.
""" Create a filter to filter elements according to a string attribute
using wildcard expressions.
:param lhs: the field to compare
:param rhs: the wildcard pattern: a string containing any number of '%'
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 import shape
from pygeoif.geometry import as_shape


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

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


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

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


Expand Down
2 changes: 1 addition & 1 deletion requirements-test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pyproj
rtree
pygml
dateparser
pygeoif
pygeoif==0.7
lark
elasticsearch
elasticsearch-dsl
9 changes: 6 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@

# get version number
# from https://github.com/mapbox/rasterio/blob/master/setup.py#L55
with open(os.path.join(os.path.dirname(__file__), 'pygeofilter/__init__.py')) as f:
init_py = os.path.join(os.path.dirname(__file__), 'pygeofilter/__init__.py')
with open(init_py) as f:
for line in f:
if line.find("__version__") >= 0:
version = line.split("=")[1].strip()
Expand All @@ -48,10 +49,12 @@
with open('README.md') as f:
readme = f.read()

description='pygeofilter is a pure Python parser implementation of OGC filtering standards' # noqa

setup(
name='pygeofilter',
version=version,
description='pygeofilter is a pure Python parser implementation of OGC filtering standards',
description=description,
long_description=readme,
long_description_content_type="text/markdown",
author='Fabian Schindler',
Expand All @@ -63,7 +66,7 @@
install_requires=[
"dateparser",
"lark<1.0",
"pygeoif>=1.0.0",
"pygeoif==0.7",
"dataclasses;python_version<'3.7'",
] if not on_rtd else [],
extras_require={
Expand Down
28 changes: 17 additions & 11 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.from_polygons(
geometry.Polygon([(1, 1), (2, 2), (0, 3), (1, 1)])
geometry.MultiPolygon(
[geometry.Polygon([(1, 1), (2, 2), (0, 3), (1, 1)])]
).__geo_interface__
),
),
Expand All @@ -435,9 +435,11 @@ def test_touches_attr_multilinestring():
ast.Attribute("geometry"),
values.Geometry(
normalize_geom(
geometry.MultiLineString.from_linestrings(
geometry.LineString([(1, 1), (2, 2)]),
geometry.LineString([(0, 3), (1, 1)]),
geometry.MultiLineString(
[
geometry.LineString([(1, 1), (2, 2)]),
geometry.LineString([(0, 3), (1, 1)]),
]
).__geo_interface__
),
),
Expand All @@ -462,9 +464,11 @@ def test_crosses_attr_multilinestring():
ast.Attribute("geometry"),
values.Geometry(
normalize_geom(
geometry.MultiLineString.from_linestrings(
geometry.LineString([(1, 1), (2, 2)]),
geometry.LineString([(0, 3), (1, 1)]),
geometry.MultiLineString(
[
geometry.LineString([(1, 1), (2, 2)]),
geometry.LineString([(0, 3), (1, 1)]),
]
).__geo_interface__
)
),
Expand All @@ -489,9 +493,11 @@ def test_overlaps_attr_multilinestring():
ast.Attribute("geometry"),
values.Geometry(
normalize_geom(
geometry.MultiLineString.from_linestrings(
geometry.LineString([(1, 1), (2, 2)]),
geometry.LineString([(0, 3), (1, 1)]),
geometry.MultiLineString(
[
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.from_polygons(
geometry.MultiPolygon([
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.from_linestrings(
geometry.MultiLineString([
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.from_linestrings(
geometry.MultiLineString([
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.from_linestrings(
geometry.MultiLineString([
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.from_polygons(
geometry.MultiPolygon([
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.from_linestrings(
geometry.MultiLineString([
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.from_linestrings(
geometry.MultiLineString([
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.from_linestrings(
geometry.MultiLineString([
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.from_polygons(
geometry.MultiPolygon([
geometry.Polygon([(1, 1), (2, 2), (0, 3), (1, 1)])
).__geo_interface__
]).__geo_interface__
),
),
ast.Attribute('geometry'),
Expand Down

0 comments on commit 1f187c0

Please sign in to comment.