From ae8885aede571506e73a80c374761f8893cfe54b Mon Sep 17 00:00:00 2001 From: Alireza Adli Date: Wed, 9 Oct 2024 15:46:53 -0400 Subject: [PATCH] Make a temp path for the GeometryFactory --- input_geojson_content.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 input_geojson_content.py diff --git a/input_geojson_content.py b/input_geojson_content.py new file mode 100644 index 0000000..c156439 --- /dev/null +++ b/input_geojson_content.py @@ -0,0 +1,33 @@ +""" +input_geojson_content module +Returns a temporary path to input the GeometryFactory +SPDX - License - Identifier: LGPL - 3.0 - or -later +Copyright © 2024 Concordia CERC group +Project developers: Alireza Adli alireza.adli@mail.concordia.ca +""" +import tempfile +import json + + +class InputGeoJsonContent: + def __init__(self, content): + self.content = content + + @property + def content(self): + return self._content + + @content.setter + def content(self, content): + if isinstance(content, str): + self._content = content + else: + temp_file = \ + tempfile.NamedTemporaryFile( + delete=False, suffix='.geojson', mode='w', encoding='utf8') + try: + json.dump(content, temp_file) + temp_file.flush() + self._content = temp_file.name + finally: + temp_file.close()