Skip to content

Commit 0848966

Browse files
sudan45ranjan-stha
authored andcommitted
feature(pdc): add geojson link in assests
1 parent 52047c7 commit 0848966

File tree

4 files changed

+14
-23
lines changed

4 files changed

+14
-23
lines changed

pystac_monty/sources/common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ class PDCDataSourceType(BaseModel):
101101
uuid: str
102102
hazard_data: Union[File, Memory]
103103
exposure_detail_data: Union[File, Memory]
104-
geojson_data: Union[File, Memory]
104+
geojson_path: str
105105

106106

107107
@dataclass

pystac_monty/sources/pdc.py

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,15 @@ class PDCDataSource(MontyDataSourceV3):
6060
uuid: str
6161
hazard_file_path: str
6262
exposure_detail_file_path: str
63-
geojson_file_path: str
63+
geojson_path: str
6464
hazard_data: Union[str, dict]
6565
exposure_detail_data: Union[str, dict]
66-
geojson_data: Union[str, dict]
6766

6867
def __init__(self, data: PDCDataSourceType):
6968
super().__init__(data)
7069
self.source_url = data.source_url
7170
self.uuid = data.uuid
71+
self.geojson_path = data.geojson_path
7272

7373
def handle_file_data():
7474
if os.path.isfile(data.hazard_data.path):
@@ -81,11 +81,6 @@ def handle_file_data():
8181
else:
8282
raise ValueError("File path does not exist")
8383

84-
if os.path.isfile(data.geojson_data.path):
85-
self.geojson_file_path = data.geojson_data.path
86-
else:
87-
raise ValueError("File path does not exist")
88-
8984
def handle_memory_data(): ...
9085

9186
input_data_type = data.hazard_data.data_type
@@ -109,12 +104,6 @@ def get_exposure_detail_data(self) -> typing.Union[dict, str]:
109104
self.exposure_detail_data = json.loads(f.read())
110105
return self.exposure_detail_data
111106

112-
def get_geojson_data(self) -> typing.Union[dict, str]:
113-
if self.root.geojson_data.data_type == DataType.FILE:
114-
with open(self.geojson_file_path, "r", encoding="utf-8") as f:
115-
self.geojson_data = json.loads(f.read())
116-
return self.geojson_data
117-
118107
def get_input_data_type(self) -> DataType:
119108
return self.root.hazard_data.data_type
120109

@@ -136,7 +125,7 @@ def __init__(self, pdc_data_src: PDCDataSource, geocoder: MontyGeoCoder):
136125
self.uuid = pdc_data_src.uuid
137126
self.hazards_data = pdc_data_src.get_hazard_data()
138127
self.exposure_detail = pdc_data_src.get_exposure_detail_data()
139-
self.geojson_data = pdc_data_src.get_geojson_data()
128+
self.geojson_path = pdc_data_src.geojson_path
140129

141130
# NOTE Assigning -1 to episode_number incase of failure just to ignore the item formation (see make_items method)
142131

@@ -210,7 +199,6 @@ def make_source_event_item(self, pdc_hazard_data: HazardEventValidator, pdc_expo
210199
"start_datetime": startdate.isoformat(),
211200
"end_datetime": enddate.isoformat(),
212201
"category_id": pdc_hazard_data.category_ID,
213-
"geometry_geojson": self.geojson_data,
214202
},
215203
)
216204

@@ -233,6 +221,9 @@ def make_source_event_item(self, pdc_hazard_data: HazardEventValidator, pdc_expo
233221
if monty.country_codes:
234222
monty.compute_and_set_correlation_id(hazard_profiles=self.hazard_profiles)
235223

224+
if self.geojson_path:
225+
item.add_asset("Maps", Asset(href=self.geojson_path, media_type="geojson", title="Polygon"))
226+
236227
if pdc_hazard_data.snc_url:
237228
item.add_asset("report", Asset(href=pdc_hazard_data.snc_url, media_type="html", title="Report"))
238229
return item

tests/extensions/cassettes/test_pdc/PDCTest.test_transformer_0.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ interactions:
147147
Content-Type:
148148
- application/json; charset=utf-8
149149
Date:
150-
- Wed, 18 Jun 2025 04:08:11 GMT
150+
- Fri, 20 Jun 2025 05:28:29 GMT
151151
ETag:
152152
- '"68362515-231e"'
153153
Last-Modified:
@@ -163,15 +163,15 @@ interactions:
163163
X-Cache-Hits:
164164
- '0'
165165
X-Fastly-Request-ID:
166-
- e7b9f5b68bd8462c8beba27f2e1a6cf71d7c2a4d
166+
- de23d8c8a122141971216fb495b2fc60ed762ea2
167167
X-GitHub-Request-Id:
168-
- 6E63:127D91:3CBB0:4F555:68523BAA
168+
- 674C:381396:A3FF8:C3B4B:6854F17C
169169
X-Served-By:
170-
- cache-maa10228-MAA
170+
- cache-maa10225-MAA
171171
X-Timer:
172-
- S1750219691.974225,VS0,VE236
172+
- S1750397309.817887,VS0,VE244
173173
expires:
174-
- Wed, 18 Jun 2025 04:18:11 GMT
174+
- Fri, 20 Jun 2025 05:38:28 GMT
175175
x-proxy-cache:
176176
- MISS
177177
status:

tests/extensions/test_pdc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def load_scenarios(scenarios: List[dict]) -> List[PDCTransformer]:
3131
path=scenario_item[1]["exposure_detail_file_path"],
3232
data_type=DataType.FILE,
3333
),
34-
geojson_data=File(path=scenario_item[1]["geojson_file_path"], data_type=DataType.FILE),
34+
geojson_path=scenario_item[1]["geojson_file_path"],
3535
)
3636
)
3737
transformers.append(PDCTransformer(pdc_data_source, geocoder))

0 commit comments

Comments
 (0)