Skip to content

Commit

Permalink
#7 handle footprintWKT datasets
Browse files Browse the repository at this point in the history
  • Loading branch information
nicokant committed Dec 20, 2023
1 parent cd94436 commit 4e6c844
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
6 changes: 6 additions & 0 deletions metadata_catalogue/datasets/libs/darwincore/mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,17 @@ def to_content(xml_path, dataset):
for extension in soup.find_all("extension"):
extensions.append(SourceLayer(extension, xml_path, extension=True))

geometry_field = None
for _wkt in soup.findAll("field", {"term": "http://rs.tdwg.org/dwc/terms/footprintWKT"}):
geometry_field = "footprintWKT"
break

ctx = {
"core": core,
"extensions": extensions,
"source": dataset.fetch_url,
"layer_name": settings.GEOAPI_DWCA_LAYER_NAME,
"geometry_field": geometry_field,
}
content.gdal_vrt_definition = render_to_string("vrt/definition.xml", ctx)
content.save()
2 changes: 1 addition & 1 deletion metadata_catalogue/datasets/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def get_metadata(self):

def get_content(self):
if hasattr(self, "content"):
return self.metadata
return self.content
else:
return Content.objects.create(dataset=self)

Expand Down
10 changes: 9 additions & 1 deletion metadata_catalogue/templates/vrt/definition.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,16 @@
</OGRVRTDataSource>]]>
</SrcDataSource>
<SrcSQL>select * from {{ core }}{% for ext in extensions %} join {{ ext }} on {{ ext }}.{{ ext.id }}={{ core }}.{{ core.id }}{% endfor %}</SrcSQL>
<GeometryField encoding="PointFromColumns" x="decimalLongitude" y="decimalLatitude">
{% if geometry_field == "footprintWKT" %}
<GeometryField encoding="WKT" field="footprintWKT" reportSrcColumn="false">
<SRS>WGS84</SRS>
</GeometryField>
{% else %}
<GeometryField encoding="PointFromColumns" x="decimalLongitude" y="decimalLatitude" reportSrcColumn="false">
<GeometryType>wkbPoint</GeometryType>
<SRS>WGS84</SRS>
</GeometryField>
{% endif %}
<LayerSRS>WGS84</LayerSRS>
</OGRVRTLayer>
</OGRVRTDataSource>

0 comments on commit 4e6c844

Please sign in to comment.