-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement pygeoapi datasets serve for dwca
- Loading branch information
Showing
17 changed files
with
212 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
metadata_catalogue/datasets/csw/migrations/0007_remove_cswconfig_language.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Generated by Django 4.2.7 on 2023-11-15 13:46 | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("csw", "0006_remove_cswconfig_contact_address_and_more"), | ||
] | ||
|
||
operations = [ | ||
migrations.RemoveField( | ||
model_name="cswconfig", | ||
name="language", | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
from .deserializer import to_metadata | ||
from .mapping import to_content |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# import csv | ||
import xml.etree.ElementTree as ET | ||
|
||
from bs4 import BeautifulSoup | ||
from django.db import transaction | ||
|
||
|
||
def to_vrt(layername): | ||
root = ET.Element("OGRVRTDataSource") | ||
layer = ET.Element("OGRVRTLayer", attrib={"name": layername}) | ||
root.append(layer) | ||
|
||
src_data_source = ET.Element("SrcDataSource") | ||
src_data_source.text = "{{SOURCE}}" | ||
layer.append(src_data_source) | ||
|
||
# field = ET.Element("Field", attrib={ | ||
# "src": "", | ||
# "name": "" | ||
# }) | ||
# layer.append(field) | ||
|
||
srs = ET.Element("LayerSRS") | ||
srs.text = "WGS84" | ||
layer.append(srs) | ||
|
||
geo_field = ET.Element( | ||
"GeometryField", | ||
attrib={ | ||
"encoding": "PointFromColumns", | ||
"x": "decimalLongitude", | ||
"y": "decimalLatitude", | ||
}, | ||
) | ||
layer.append(geo_field) | ||
geo_type = ET.Element("GeometryType") | ||
geo_type.text = "wkbPoint" | ||
geo_field.append(geo_type) | ||
|
||
return ET.tostring(root, encoding="utf-8").decode("utf-8") | ||
|
||
|
||
def to_content(xml_path, dataset): | ||
meta_path = xml_path / "meta.xml" | ||
if not meta_path.is_file(): | ||
raise Exception("There should be one meta.xml file") | ||
with open(str(meta_path)) as meta: | ||
soup = BeautifulSoup(meta, features="lxml-xml") | ||
with transaction.atomic(): | ||
content = dataset.content | ||
|
||
data_file_path = xml_path / soup.find("location").text | ||
if not data_file_path.is_file(): | ||
raise Exception(f"Missing file {data_file_path} declared in meta.xml") | ||
# with open(str(data_file_path)) as data_file: | ||
# reader = csv.reader(data_file, delimiter='\t') | ||
# for row in reader: | ||
# headers = row | ||
# break | ||
|
||
# fields = {f['index']: f['term'].split('/')[-1] for f in soup.find_all('field')} | ||
# fields[soup.find('id')['index']] = "id" | ||
content.gdal_vrt_definition = to_vrt(data_file_path.stem) | ||
content.remote_source = data_file_path.name | ||
content.save() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Generated by Django 4.2.7 on 2023-11-15 13:46 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
import metadata_catalogue.core.fields | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("datasets", "0008_serviceinfo_language"), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="Content", | ||
fields=[ | ||
("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")), | ||
("gdal_vrt_definition", models.TextField(blank=True, null=True)), | ||
( | ||
"dataset", | ||
metadata_catalogue.core.fields.AutoOneToOneField( | ||
on_delete=django.db.models.deletion.CASCADE, related_name="content", to="datasets.dataset" | ||
), | ||
), | ||
], | ||
), | ||
] |
17 changes: 17 additions & 0 deletions
17
metadata_catalogue/datasets/migrations/0010_content_remote_source.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Generated by Django 4.2.7 on 2023-11-15 14:02 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("datasets", "0009_content"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="content", | ||
name="remote_source", | ||
field=models.TextField(blank=True, null=True), | ||
), | ||
] |
22 changes: 22 additions & 0 deletions
22
metadata_catalogue/datasets/migrations/0011_alter_dataset_fetch_url_alter_dataset_source.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Generated by Django 4.2.7 on 2023-11-17 09:04 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("datasets", "0010_content_remote_source"), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name="dataset", | ||
name="fetch_url", | ||
field=models.TextField(blank=True, null=True, verbose_name="URL of the resource to fetch"), | ||
), | ||
migrations.AlterField( | ||
model_name="dataset", | ||
name="source", | ||
field=models.TextField(blank=True, null=True), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from django.urls import path, re_path | ||
|
||
from .views import get_dataset_vrt_view | ||
|
||
urlpatterns = [ | ||
path("<uuid:dataset_uuid>/definition.vrt", get_dataset_vrt_view, name="get-dataset-vrt"), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from django.http import HttpResponse, HttpResponseNotFound | ||
|
||
from .models import Dataset | ||
|
||
|
||
def get_dataset_vrt_view(request, dataset_uuid): | ||
try: | ||
dataset = Dataset.objects.select_related("content").get(uuid=dataset_uuid) | ||
content = dataset.content.gdal_vrt_definition.replace("{{SOURCE}}", dataset.content.get_gdal_vrt_source()) | ||
return HttpResponse(content, content_type="text") | ||
except Dataset.DoesNotExist: | ||
return HttpResponseNotFound() |