aboutsummaryrefslogtreecommitdiffstats
path: root/gis-observation-map
diff options
context:
space:
mode:
authorGuilhem Moulin <guilhem@fripost.org>2023-09-27 20:40:26 +0200
committerGuilhem Moulin <guilhem@fripost.org>2023-09-27 20:54:53 +0200
commitde3ee399872500903f5c7aeedc45e13bccf7235c (patch)
treeb8c63a495ebabad9855c39bd5714b9802905d0b3 /gis-observation-map
parent16332c374f8c134c5413eddb5b490048f7841ce5 (diff)
Convert GeoJSON to GPKG and reproject to EPSG:3006.
Diffstat (limited to 'gis-observation-map')
-rwxr-xr-xgis-observation-map16
1 files changed, 12 insertions, 4 deletions
diff --git a/gis-observation-map b/gis-observation-map
index 481dd3a..0f673fd 100755
--- a/gis-observation-map
+++ b/gis-observation-map
@@ -24,6 +24,7 @@ import json
import re
import requests
import configparser
+import tempfile
from requests.exceptions import HTTPError
from xdg import xdg_config_home
from pathlib import Path
@@ -366,6 +367,8 @@ def getObservations(taxonLists, taxonRedlistCategories, searchFilter):
if obs['type'] == 'FeatureCollection' and 'features' in obs.keys() and type(obs['features']) == list:
print(f'{len(obs["features"])} observations found', file=sys.stderr)
+ if 'name' not in obs.keys() or obs['name'] is None:
+ obs['name'] = 'Observations'
for feat in obs['features']:
if (type(feat) != dict or 'type' not in feat.keys() or feat['type'] != 'Feature'
or 'properties' not in feat.keys() or type(feat['properties']) != dict):
@@ -390,10 +393,15 @@ def getObservations(taxonLists, taxonRedlistCategories, searchFilter):
print(f'WARN: #{tid} {k}: {properties[k]} → {v}', file=sys.stderr)
properties[k] = v
- # TODO generate GPKG instead and reproject to EPSG:3006
- path = projectHome.joinpath('observations.geojson')
- with path.open(mode='w') as fp:
- json.dump(obs, fp, indent=2, ensure_ascii=False)
+ #path = projectHome.joinpath('observations.geojson')
+ #with path.open(mode='w') as fp:
+ # json.dump(obs, fp, indent=2, ensure_ascii=False)
+
+ path = projectHome.joinpath('observations.gpkg')
+ with tempfile.NamedTemporaryFile(suffix='.geojson', mode='w') as fp:
+ json.dump(obs, fp)
+ fp.flush()
+ gdal.VectorTranslate(path.as_posix(), fp.name, reproject=True, dstSRS=target_srs, format='GPKG')
if projectInstance is not None:
query = '''"IsPositiveObservation" AND "IsNaturalOccurrence" AND "CoordinateUncertaintyInMeters" <= 250'''