Skip to content

Commit

Permalink
add new AggregatePolygonResult class, that takes csv files as input
Browse files Browse the repository at this point in the history
  • Loading branch information
jdries committed Jan 18, 2022
1 parent 3e761c4 commit baf7b0e
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions openeo_driver/save_result.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import glob
import os
import pathlib
import tempfile
import warnings
from abc import ABC
from pathlib import Path
from shutil import copy
from tempfile import mkstemp
from typing import Union, Dict
from zipfile import ZipFile
Expand Down Expand Up @@ -364,6 +366,27 @@ def to_covjson(self) -> dict:
"ranges": ranges
}

class AggregatePolygonResultCSV(AggregatePolygonResult):

def __init__(self, csv_dir, regions: GeometryCollection, metadata:CollectionMetadata=None):
super().__init__(data={})
if not isinstance(regions, GeometryCollection):
# TODO: raise exception instead of warning?
warnings.warn("AggregatePolygonResult: GeometryCollection expected but got {t}".format(t=type(regions)))
self._csv_dir = csv_dir
self._regions = regions
self._metadata = metadata

def to_csv(self, destination=None):
csv_paths = glob.glob(self._csv_dir + "/*.csv")
print(csv_paths)
if(destination == None):
return csv_paths[0]
else:
copy(csv_paths[0],destination)
return destination



class MultipleFilesResult(SaveResult):
def __init__(self, format: str, *files: Path):
Expand Down

0 comments on commit baf7b0e

Please sign in to comment.