aboutsummaryrefslogtreecommitdiffstats
path: root/gis-observation-map
diff options
context:
space:
mode:
authorGuilhem Moulin <guilhem@fripost.org>2023-09-27 21:35:02 +0200
committerGuilhem Moulin <guilhem@fripost.org>2023-09-27 22:14:18 +0200
commit82d87323ad2a3ba06a7f69374433a43ae4d22bfb (patch)
tree34505f6b3e0bbf37b6ea2c5251d501baf5aa5e7a /gis-observation-map
parentde3ee399872500903f5c7aeedc45e13bccf7235c (diff)
Add new option --observation-format to configure observation file format.
Default: GPKG.
Diffstat (limited to 'gis-observation-map')
-rwxr-xr-xgis-observation-map27
1 files changed, 17 insertions, 10 deletions
diff --git a/gis-observation-map b/gis-observation-map
index 0f673fd..ac9baa7 100755
--- a/gis-observation-map
+++ b/gis-observation-map
@@ -67,6 +67,7 @@ parser.add_argument('--project-name', help='Project filename (and title)')
parser.add_argument('--project-home', help='Project home directory')
parser.add_argument('--geometry', nargs='*', default=[], help='Geometry filename(s)')
parser.add_argument('--point', nargs='*', default=[], help=f'Coordinates of interest (X,Y in {target_srs.GetName()})')
+parser.add_argument('--observation-format', default='GPKG', help='Format for the observation file (default: %(default)s)')
args = parser.parse_args()
@@ -365,10 +366,11 @@ def getObservations(taxonLists, taxonRedlistCategories, searchFilter):
if 'crs' not in obs.keys():
print('WARN: GeoJSON output lacks CRS', file=sys.stderr)
+ layername = 'Observations'
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'
+ obs['name'] = layername
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):
@@ -393,15 +395,20 @@ def getObservations(taxonLists, taxonRedlistCategories, searchFilter):
print(f'WARN: #{tid} {k}: {properties[k]} → {v}', file=sys.stderr)
properties[k] = v
- #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')
+ drv = ogr.GetDriverByName(args.observation_format)
+ if drv.name == geojson_drv.name:
+ path = projectHome.joinpath(layername.lower() + '.geojson')
+ with path.open(mode='w') as fp:
+ json.dump(obs, fp, indent=2, ensure_ascii=False)
+ else:
+ with tempfile.NamedTemporaryFile(suffix='.geojson', mode='w') as fp:
+ json.dump(obs, fp)
+ fp.flush()
+
+ suffix = drv.GetMetadataItem(gdal.DMD_EXTENSIONS).split(' ')[0]
+ path = projectHome.joinpath(layername.lower()).with_suffix('.' + suffix)
+ gdal.VectorTranslate(path.as_posix(), fp.name, reproject=True, dstSRS=target_srs, format=drv.name)
+ obs = None
if projectInstance is not None:
query = '''"IsPositiveObservation" AND "IsNaturalOccurrence" AND "CoordinateUncertaintyInMeters" <= 250'''