From ab88ba4dc5cfac5a59fd1988c3bc7da2a8ff3e9a Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 30 Jan 2023 16:58:56 +0000 Subject: [PATCH 1/8] [pre-commit.ci] pre-commit autoupdate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/pycqa/isort: 5.11.4 → 5.12.0](https://github.com/pycqa/isort/compare/5.11.4...5.12.0) --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 76c2e53a..03fb7f7a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -47,7 +47,7 @@ repos: hooks: - id: flake8 - repo: https://github.com/pycqa/isort - rev: 5.11.4 + rev: 5.12.0 hooks: - id: isort - repo: https://github.com/mgedmin/check-manifest From eaa1b0310ec3f5351a9f8852003eae54b2ea265c Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 6 Feb 2023 17:01:35 +0000 Subject: [PATCH 2/8] [pre-commit.ci] pre-commit autoupdate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/hakancelikdev/unimport: 33ead41ee30f1d323a9c2fcfd0114297efbbc4d5 → 0.14.1](https://github.com/hakancelikdev/unimport/compare/33ead41ee30f1d323a9c2fcfd0114297efbbc4d5...0.14.1) - [github.com/psf/black: 22.12.0 → 23.1.0](https://github.com/psf/black/compare/22.12.0...23.1.0) --- .pre-commit-config.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 03fb7f7a..f27c9b9d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -29,7 +29,7 @@ repos: hooks: - id: absolufy-imports - repo: https://github.com/hakancelikdev/unimport - rev: 33ead41ee30f1d323a9c2fcfd0114297efbbc4d5 + rev: 0.14.1 hooks: - id: unimport args: [--remove, --include-star-import, --ignore-init, --gitignore] @@ -39,7 +39,7 @@ repos: - id: pyupgrade args: ["--py3-plus", "--py37-plus"] - repo: https://github.com/psf/black - rev: 22.12.0 + rev: 23.1.0 hooks: - id: black - repo: https://github.com/PyCQA/flake8 From 3305e359b9e579ceff667f66acf03f54302e8eb1 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 6 Feb 2023 17:01:56 +0000 Subject: [PATCH 3/8] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- examples/UsageExamples.py | 1 - fastkml/kml.py | 1 - fastkml/mixins.py | 1 - fastkml/styles.py | 1 - fastkml/views.py | 1 - tests/styles_test.py | 1 - 6 files changed, 6 deletions(-) diff --git a/examples/UsageExamples.py b/examples/UsageExamples.py index fa2221c2..552a2d7f 100644 --- a/examples/UsageExamples.py +++ b/examples/UsageExamples.py @@ -13,7 +13,6 @@ def print_child_features(element): if __name__ == "__main__": - fname = "KML_Samples.kml" k = kml.KML() diff --git a/fastkml/kml.py b/fastkml/kml.py index 2b18d466..37af671e 100644 --- a/fastkml/kml.py +++ b/fastkml/kml.py @@ -1772,7 +1772,6 @@ def features(self) -> Iterator[Union[Folder, Document, Placemark]]: """iterate over features""" for feature in self._features: if isinstance(feature, (Document, Folder, Placemark, _Overlay)): - yield feature else: raise TypeError( diff --git a/fastkml/mixins.py b/fastkml/mixins.py index 2ddc0d77..60b56a12 100644 --- a/fastkml/mixins.py +++ b/fastkml/mixins.py @@ -25,7 +25,6 @@ class TimeMixin: - _timespan: Optional[TimeSpan] = None _timestamp: Optional[TimeStamp] = None diff --git a/fastkml/styles.py b/fastkml/styles.py index 5df7a08c..27e36ea6 100644 --- a/fastkml/styles.py +++ b/fastkml/styles.py @@ -130,7 +130,6 @@ def etree_element(self) -> Element: return element def from_element(self, element: Element) -> None: - super().from_element(element) color_mode = element.find(f"{self.ns}colorMode") if color_mode is not None: diff --git a/fastkml/views.py b/fastkml/views.py index f0164027..5f99dde5 100644 --- a/fastkml/views.py +++ b/fastkml/views.py @@ -314,7 +314,6 @@ def roll(self, value) -> None: class LookAt(_AbstractView): - __name__ = "LookAt" _range: Optional[float] = None diff --git a/tests/styles_test.py b/tests/styles_test.py index 5926213b..08835c5b 100644 --- a/tests/styles_test.py +++ b/tests/styles_test.py @@ -92,7 +92,6 @@ def test_icon_style_read(self) -> None: assert icons.heading == 20.0 def test_line_style(self) -> None: - lines = styles.LineStyle( id="id-0", target_id="target-0", From 980fdd944a44d6ef7867ea0bf03f886e3c14150e Mon Sep 17 00:00:00 2001 From: Eric Massip Date: Sat, 11 Mar 2023 08:54:50 +0000 Subject: [PATCH 4/8] Replaced TypeError with warning log for invalid schema type --- fastkml/data.py | 5 ++++- tests/oldunit_test.py | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/fastkml/data.py b/fastkml/data.py index 18ace775..4510fe1b 100644 --- a/fastkml/data.py +++ b/fastkml/data.py @@ -14,6 +14,7 @@ # along with this library; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA """Add Custom Data""" +import logging from typing import Dict from typing import List from typing import Optional @@ -28,6 +29,8 @@ from fastkml.base import _XMLObject from fastkml.types import Element +logger = logging.getLogger(__name__) + class SimpleField(TypedDict): name: str @@ -150,7 +153,7 @@ def append(self, type: str, name: str, display_name: Optional[str] = None) -> No "bool", ] if type not in allowed_types: - raise TypeError( + logger.warning( f"{name} has the type {type} which is invalid. " "The type must be one of " "'string', 'int', 'uint', 'short', " diff --git a/tests/oldunit_test.py b/tests/oldunit_test.py index 76b7ecbf..5bc4fbd5 100644 --- a/tests/oldunit_test.py +++ b/tests/oldunit_test.py @@ -198,6 +198,8 @@ def test_schema(self): assert list(s.simple_fields)[1]["type"] == "float" assert list(s.simple_fields)[1]["name"] == "Float" assert list(s.simple_fields)[1]["displayName"] is None + # 'long' is an invalid value, logs a warning but does not error + s.append("long", "Long", "A Long") def test_schema_data(self): ns = "{http://www.opengis.net/kml/2.2}" # noqa: FS003 From e73399e47802a78989281c5e7f1038a3d1bc44b5 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 27 Mar 2023 16:53:45 +0000 Subject: [PATCH 5/8] [pre-commit.ci] pre-commit autoupdate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - https://github.com/ikamensh/flynt/: 0.77 → 0.78 --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f27c9b9d..a4c2055b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -21,7 +21,7 @@ repos: - id: requirements-txt-fixer - id: trailing-whitespace - repo: https://github.com/ikamensh/flynt/ - rev: "0.77" + rev: "0.78" hooks: - id: flynt - repo: https://github.com/MarcoGorelli/absolufy-imports From 01fc1c8a5670eb50803d25500af496f9ea73c1ee Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 3 Apr 2023 17:06:34 +0000 Subject: [PATCH 6/8] [pre-commit.ci] pre-commit autoupdate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/hakancelikdev/unimport: 0.14.1 → 0.15.0](https://github.com/hakancelikdev/unimport/compare/0.14.1...0.15.0) - [github.com/psf/black: 23.1.0 → 23.3.0](https://github.com/psf/black/compare/23.1.0...23.3.0) --- .pre-commit-config.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a4c2055b..0699468e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -29,7 +29,7 @@ repos: hooks: - id: absolufy-imports - repo: https://github.com/hakancelikdev/unimport - rev: 0.14.1 + rev: 0.15.0 hooks: - id: unimport args: [--remove, --include-star-import, --ignore-init, --gitignore] @@ -39,7 +39,7 @@ repos: - id: pyupgrade args: ["--py3-plus", "--py37-plus"] - repo: https://github.com/psf/black - rev: 23.1.0 + rev: 23.3.0 hooks: - id: black - repo: https://github.com/PyCQA/flake8 From 005c4ca2c7ad3974b430c8366d0c3a1d41f26f64 Mon Sep 17 00:00:00 2001 From: Christian Ledermann Date: Sat, 14 Jan 2023 13:53:29 +0000 Subject: [PATCH 7/8] back to dev, bump version to alpha 5 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 5bfb0fe7..c33d5194 100644 --- a/setup.py +++ b/setup.py @@ -22,7 +22,7 @@ def run_tests(self) -> None: setup( name="fastkml", - version="1.0.alpha.4", + version="1.0.alpha.5", description="Fast KML processing in python", long_description=( open("README.rst").read() From f1bdf23ea35a17e990ed5217702a8ff7aece4520 Mon Sep 17 00:00:00 2001 From: Christian Ledermann Date: Sat, 14 Jan 2023 14:39:56 +0000 Subject: [PATCH 8/8] qualify pygeoif classes with geo. prefix --- fastkml/geometry.py | 105 ++++++++++++++++++++---------------------- tests/oldunit_test.py | 16 +++---- 2 files changed, 58 insertions(+), 63 deletions(-) diff --git a/fastkml/geometry.py b/fastkml/geometry.py index 62b0c5ab..97c7776e 100644 --- a/fastkml/geometry.py +++ b/fastkml/geometry.py @@ -23,15 +23,8 @@ from typing import Union from typing import cast +import pygeoif.geometry as geo from pygeoif.factories import shape -from pygeoif.geometry import GeometryCollection -from pygeoif.geometry import LinearRing -from pygeoif.geometry import LineString -from pygeoif.geometry import MultiLineString -from pygeoif.geometry import MultiPoint -from pygeoif.geometry import MultiPolygon -from pygeoif.geometry import Point -from pygeoif.geometry import Polygon from pygeoif.types import PointType from fastkml import config @@ -40,8 +33,10 @@ logger = logging.getLogger(__name__) -GeometryType = Union[Polygon, LineString, LinearRing, Point] -MultiGeometryType = Union[MultiPoint, MultiLineString, MultiPolygon, GeometryCollection] +GeometryType = Union[geo.Polygon, geo.LineString, geo.LinearRing, geo.Point] +MultiGeometryType = Union[ + geo.MultiPoint, geo.MultiLineString, geo.MultiPolygon, geo.GeometryCollection +] AnyGeometryType = Union[GeometryType, MultiGeometryType] @@ -116,14 +111,14 @@ def __init__( if isinstance( geometry, ( - Point, - LineString, - Polygon, - MultiPoint, - MultiLineString, - MultiPolygon, - LinearRing, - GeometryCollection, + geo.Point, + geo.LineString, + geo.Polygon, + geo.MultiPoint, + geo.MultiLineString, + geo.MultiPolygon, + geo.LinearRing, + geo.GeometryCollection, ), ): self.geometry = geometry @@ -182,11 +177,11 @@ def _etree_coordinates( element.text = " ".join(tuples) return element - def _etree_point(self, point: Point) -> Element: + def _etree_point(self, point: geo.Point) -> Element: element = self._extrude_and_altitude_mode("Point") return self._extracted_from__etree_linearring_5(point, element) - def _etree_linestring(self, linestring: LineString) -> Element: + def _etree_linestring(self, linestring: geo.LineString) -> Element: element = self._extrude_and_altitude_mode("LineString") if self.tessellate and self.altitude_mode in [ "clampToGround", @@ -198,18 +193,18 @@ def _etree_linestring(self, linestring: LineString) -> Element: ts_element.text = "1" return self._extracted_from__etree_linearring_5(linestring, element) - def _etree_linearring(self, linearring: LinearRing) -> Element: + def _etree_linearring(self, linearring: geo.LinearRing) -> Element: element = self._extrude_and_altitude_mode("LinearRing") return self._extracted_from__etree_linearring_5(linearring, element) def _extracted_from__etree_linearring_5( - self, arg0: Union[LineString, LinearRing, Point], element: Element + self, arg0: Union[geo.LineString, geo.LinearRing, geo.Point], element: Element ) -> Element: coords = list(arg0.coords) element.append(self._etree_coordinates(coords)) return element - def _etree_polygon(self, polygon: Polygon) -> Element: + def _etree_polygon(self, polygon: geo.Polygon) -> Element: element = self._extrude_and_altitude_mode("Polygon") outer_boundary = cast( Element, @@ -241,7 +236,7 @@ def _extrude_and_altitude_mode(self, kml_geometry: str) -> Element: self._set_altitude_mode(result) return result - def _etree_multipoint(self, points: MultiPoint) -> Element: + def _etree_multipoint(self, points: geo.MultiPoint) -> Element: element = cast( Element, config.etree.Element( # type: ignore[attr-defined] @@ -252,7 +247,7 @@ def _etree_multipoint(self, points: MultiPoint) -> Element: element.append(self._etree_point(point)) return element - def _etree_multilinestring(self, linestrings: MultiLineString) -> Element: + def _etree_multilinestring(self, linestrings: geo.MultiLineString) -> Element: element = cast( Element, config.etree.Element( # type: ignore[attr-defined] @@ -263,7 +258,7 @@ def _etree_multilinestring(self, linestrings: MultiLineString) -> Element: element.append(self._etree_linestring(linestring)) return element - def _etree_multipolygon(self, polygons: MultiPolygon) -> Element: + def _etree_multipolygon(self, polygons: geo.MultiPolygon) -> Element: element = cast( Element, config.etree.Element( # type: ignore[attr-defined] @@ -274,7 +269,7 @@ def _etree_multipolygon(self, polygons: MultiPolygon) -> Element: element.append(self._etree_polygon(polygon)) return element - def _etree_collection(self, features: GeometryCollection) -> Element: + def _etree_collection(self, features: geo.GeometryCollection) -> Element: element = cast( Element, config.etree.Element( # type: ignore[attr-defined] @@ -283,33 +278,33 @@ def _etree_collection(self, features: GeometryCollection) -> Element: ) for feature in features.geoms: if feature.geom_type == "Point": - element.append(self._etree_point(cast(Point, feature))) + element.append(self._etree_point(cast(geo.Point, feature))) elif feature.geom_type == "LinearRing": - element.append(self._etree_linearring(cast(LinearRing, feature))) + element.append(self._etree_linearring(cast(geo.LinearRing, feature))) elif feature.geom_type == "LineString": - element.append(self._etree_linestring(cast(LineString, feature))) + element.append(self._etree_linestring(cast(geo.LineString, feature))) elif feature.geom_type == "Polygon": - element.append(self._etree_polygon(cast(Polygon, feature))) + element.append(self._etree_polygon(cast(geo.Polygon, feature))) else: raise ValueError("Illegal geometry type.") return element def etree_element(self) -> Element: - if isinstance(self.geometry, Point): + if isinstance(self.geometry, geo.Point): return self._etree_point(self.geometry) - elif isinstance(self.geometry, LinearRing): + elif isinstance(self.geometry, geo.LinearRing): return self._etree_linearring(self.geometry) - elif isinstance(self.geometry, LineString): + elif isinstance(self.geometry, geo.LineString): return self._etree_linestring(self.geometry) - elif isinstance(self.geometry, Polygon): + elif isinstance(self.geometry, geo.Polygon): return self._etree_polygon(self.geometry) - elif isinstance(self.geometry, MultiPoint): + elif isinstance(self.geometry, geo.MultiPoint): return self._etree_multipoint(self.geometry) - elif isinstance(self.geometry, MultiLineString): + elif isinstance(self.geometry, geo.MultiLineString): return self._etree_multilinestring(self.geometry) - elif isinstance(self.geometry, MultiPolygon): + elif isinstance(self.geometry, geo.MultiPolygon): return self._etree_multipolygon(self.geometry) - elif isinstance(self.geometry, GeometryCollection): + elif isinstance(self.geometry, geo.GeometryCollection): return self._etree_collection(self.geometry) else: raise ValueError("Illegal geometry type.") @@ -365,12 +360,12 @@ def _get_coordinates(self, element: Element) -> List[PointType]: for latlon in latlons ] - def _get_linear_ring(self, element: Element) -> Optional[LinearRing]: + def _get_linear_ring(self, element: Element) -> Optional[geo.LinearRing]: # LinearRing in polygon lr = element.find(f"{self.ns}LinearRing") if lr is not None: coords = self._get_coordinates(lr) - return LinearRing(coords) + return geo.LinearRing(coords) return None # type: ignore[unreachable] def _get_geometry(self, element: Element) -> Optional[GeometryType]: @@ -379,11 +374,11 @@ def _get_geometry(self, element: Element) -> Optional[GeometryType]: if element.tag == f"{self.ns}Point": coords = self._get_coordinates(element) self._get_geometry_spec(element) - return Point.from_coordinates(coords) + return geo.Point.from_coordinates(coords) if element.tag == f"{self.ns}LineString": coords = self._get_coordinates(element) self._get_geometry_spec(element) - return LineString(coords) + return geo.LineString(coords) if element.tag == f"{self.ns}Polygon": self._get_geometry_spec(element) outer_boundary = element.find(f"{self.ns}outerBoundaryIs") @@ -395,11 +390,11 @@ def _get_geometry(self, element: Element) -> Optional[GeometryType]: self._get_linear_ring(inner_boundary) for inner_boundary in inner_boundaries ] - return Polygon.from_linear_rings(ob, *[b for b in ibs if b]) + return geo.Polygon.from_linear_rings(ob, *[b for b in ibs if b]) if element.tag == f"{self.ns}LinearRing": coords = self._get_coordinates(element) self._get_geometry_spec(element) - return LinearRing(coords) + return geo.LinearRing(coords) return None def _get_multigeometry(self, element: Element) -> Optional[MultiGeometryType]: @@ -409,11 +404,11 @@ def _get_multigeometry(self, element: Element) -> Optional[MultiGeometryType]: points = element.findall(f"{self.ns}Point") for point in points: self._get_geometry_spec(point) - geoms.append(Point.from_coordinates(self._get_coordinates(point))) + geoms.append(geo.Point.from_coordinates(self._get_coordinates(point))) linestrings = element.findall(f"{self.ns}LineString") for ls in linestrings: self._get_geometry_spec(ls) - geoms.append(LineString(self._get_coordinates(ls))) + geoms.append(geo.LineString(self._get_coordinates(ls))) polygons = element.findall(f"{self.ns}Polygon") for polygon in polygons: self._get_geometry_spec(polygon) @@ -426,34 +421,34 @@ def _get_multigeometry(self, element: Element) -> Optional[MultiGeometryType]: self._get_linear_ring(inner_boundary) for inner_boundary in inner_boundaries ] - ibs: List[LinearRing] = [ib for ib in inner_bs if ib] - geoms.append(Polygon.from_linear_rings(ob, *ibs)) + ibs: List[geo.LinearRing] = [ib for ib in inner_bs if ib] + geoms.append(geo.Polygon.from_linear_rings(ob, *ibs)) linearings = element.findall(f"{self.ns}LinearRing") if linearings: for lr in linearings: self._get_geometry_spec(lr) - geoms.append(LinearRing(self._get_coordinates(lr))) + geoms.append(geo.LinearRing(self._get_coordinates(lr))) clean_geoms: List[AnyGeometryType] = [g for g in geoms if g] if clean_geoms: geom_types = {geom.geom_type for geom in clean_geoms} if len(geom_types) > 1: - return GeometryCollection( + return geo.GeometryCollection( clean_geoms, # type: ignore[arg-type] ) if "Point" in geom_types: - return MultiPoint.from_points( + return geo.MultiPoint.from_points( *clean_geoms, # type: ignore[arg-type] ) elif "LineString" in geom_types: - return MultiLineString.from_linestrings( + return geo.MultiLineString.from_linestrings( *clean_geoms, # type: ignore[arg-type] ) elif "Polygon" in geom_types: - return MultiPolygon.from_polygons( + return geo.MultiPolygon.from_polygons( *clean_geoms, # type: ignore[arg-type] ) elif "LinearRing" in geom_types: - return GeometryCollection( + return geo.GeometryCollection( clean_geoms, # type: ignore[arg-type] ) return None diff --git a/tests/oldunit_test.py b/tests/oldunit_test.py index 5bc4fbd5..13e94e8c 100644 --- a/tests/oldunit_test.py +++ b/tests/oldunit_test.py @@ -16,6 +16,14 @@ import xml.etree.ElementTree import pytest +from pygeoif.geometry import GeometryCollection +from pygeoif.geometry import LinearRing +from pygeoif.geometry import LineString +from pygeoif.geometry import MultiLineString +from pygeoif.geometry import MultiPoint +from pygeoif.geometry import MultiPolygon +from pygeoif.geometry import Point +from pygeoif.geometry import Polygon from fastkml import atom from fastkml import base @@ -24,14 +32,6 @@ from fastkml import kml from fastkml import styles from fastkml.geometry import Geometry -from fastkml.geometry import GeometryCollection -from fastkml.geometry import LinearRing -from fastkml.geometry import LineString -from fastkml.geometry import MultiLineString -from fastkml.geometry import MultiPoint -from fastkml.geometry import MultiPolygon -from fastkml.geometry import Point -from fastkml.geometry import Polygon from fastkml.gx import GxGeometry try: