Skip to content

Commit 2b08624

Browse files
Fixed getSamplingFeatureDatasets issue #130
1 parent dd1ec35 commit 2b08624

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

odm2api/ODM2/services/readService.py

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,11 @@ def __init__(self, affiliation, person, org):
7474

7575
class SamplingFeatureDataSet():
7676
datasets={}
77-
def __init__(self, samplingfeature, datasetresults):
77+
related_features={}
78+
def __init__(self, samplingfeature, datasetresults, relatedfeatures):
7879
sf = samplingfeature
7980

81+
self.SamplingFeature = sf
8082
self.SamplingFeatureID = sf.SamplingFeatureID
8183
self.SamplingFeatureUUID = sf.SamplingFeatureUUID
8284
self.SamplingFeatureTypeCV = sf.SamplingFeatureTypeCV
@@ -88,11 +90,13 @@ def __init__(self, samplingfeature, datasetresults):
8890
self.ElevationDatumCV = sf.ElevationDatumCV
8991
self.FeatureGeometryWKT = sf.FeatureGeometryWKT
9092
self.assignDatasets(datasetresults)
93+
self.assignRelatedFeatures(relatedfeatures)
9194

92-
print(self.datasets)
9395

96+
print(self.datasets)
9497

9598
def assignDatasets(self, datasetresults):
99+
self.datasets = {}
96100
for dsr in datasetresults:
97101
if dsr.DataSetObj not in self.datasets:
98102
#if the dataset is not in the dictionary, add it and the first result
@@ -107,6 +111,14 @@ def assignDatasets(self, datasetresults):
107111
self.datasets[dsr.DataSetObj].append(res)
108112

109113

114+
def assignRelatedFeatures(self, relatedfeatures):
115+
self.related_features = {}
116+
for related in relatedfeatures:
117+
if related.SamplingFeatureTypeCV == 'Site':
118+
self.related_features = related
119+
120+
121+
110122

111123

112124
class ReadODM2(serviceBase):
@@ -875,7 +887,7 @@ def getDataSetsValues(self, ids=None, codes=None, uuids=None, dstype=None):
875887
return None
876888

877889

878-
def getSamplingFeatureDatasets(self, ids=None, codes=None, uuids=None, dstype=None):
890+
def getSamplingFeatureDatasets(self, ids=None, codes=None, uuids=None, dstype=None, type=None):
879891
"""
880892
Retrieve a list of Datasets associated with the given sampling feature data.
881893
@@ -904,16 +916,20 @@ def getSamplingFeatureDatasets(self, ids=None, codes=None, uuids=None, dstype=No
904916

905917

906918
# make sure one of the three arguments has been sent in
907-
if all(v is None for v in [ids, codes, uuids]):
908-
raise ValueError('Expected samplingFeatureID OR samplingFeatureUUID OR samplingFeatureCode argument')
919+
# if all(v is None for v in [ids, codes, uuids, type]):
920+
# raise ValueError('Expected samplingFeatureID OR samplingFeatureUUID OR samplingFeatureCode OR samplingFeatureType '
921+
# 'argument')
909922

910923
sf_query = self._session.query(SamplingFeatures)
924+
if type:
925+
sf_query = sf_query.filter(SamplingFeatures.SamplingFeatureTypeCV == type)
911926
if ids:
912927
sf_query = sf_query.filter(SamplingFeatures.SamplingFeatureID.in_(ids))
913928
if codes:
914929
sf_query = sf_query.filter(SamplingFeatures.SamplingFeatureCode.in_(codes))
915930
if uuids:
916931
sf_query = sf_query.filter(SamplingFeatures.SamplingFeatureUUID.in_(uuids))
932+
917933
sf_list = []
918934
for sf in sf_query.all():
919935
sf_list.append(sf)
@@ -934,7 +950,9 @@ def getSamplingFeatureDatasets(self, ids=None, codes=None, uuids=None, dstype=No
934950

935951
vals = q.all()
936952

937-
sfds.append(SamplingFeatureDataSet(sf, vals))
953+
related = self.getRelatedSamplingFeatures(sf.SamplingFeatureID)
954+
955+
sfds.append(SamplingFeatureDataSet(sf, vals, related))
938956
except Exception as e:
939957
print('Error running Query: {}'.format(e))
940958
return None

0 commit comments

Comments
 (0)