From 1dbe21e4ce0f9b0e276a23e2cd148c668e075534 Mon Sep 17 00:00:00 2001 From: Guilhem Moulin Date: Thu, 28 Sep 2023 18:18:12 +0200 Subject: New flag --no-observations to avoid querying Artdatabanken. --- gis-observation-map | 268 +++++++++++++++++++++++++++------------------------- 1 file changed, 137 insertions(+), 131 deletions(-) (limited to 'gis-observation-map') diff --git a/gis-observation-map b/gis-observation-map index 8153c9f..fbd9146 100755 --- a/gis-observation-map +++ b/gis-observation-map @@ -96,7 +96,9 @@ parser_geom.add_argument('--point', nargs='*', metavar='Y,X', default=[], help=f'Coordinates of interest (in {target_srs.GetName()})') parser_geom.add_argument('--margin', metavar='N', type=int, help='Margin (in meters) around geometry envelopes') -parser_obs = parser.add_argument_group('Observation file') +parser_obs = parser.add_argument_group('Observations') +parser_obs.add_argument('--no-observations', action='store_true', + help='Do not fetch observations within the area(s) of interest') parser_obs.add_argument('--observation-file', type=Path, metavar='NAME', help='Observation file name relative to --project-home') parser_obs.add_argument('--observation-format', metavar='FORMAT', @@ -113,6 +115,9 @@ parser_filter.add_argument('--until', metavar='YYYY-MM-DD', args = parser.parse_args() +if args.no_observations and (args.observation_file is not None or args.observation_format is not None): + parser.error('--no-observations is mutually exclusive with --observation-*') + if args.project_home is not None and args.project_name is not None: QgsApplication.setPrefixPath('/usr/bin/qgis', True) qgs = QgsApplication([], False) @@ -671,142 +676,143 @@ def getTaxonRedlistCategories(taxonLists, i): taxonRedlistCategories[j] = c return taxonRedlistCategories -geographicsFilter = { - 'geometries': geometricFilter(geometries), - 'maxAccuracy': 2500, - 'considerObservationAccuracy': True, - 'considerDisturbanceRadius': False -} -taxonLists, taxonRedlistCategories, taxonListIds = getTaxonLists() - -# https://github.com/biodiversitydata-se/SOS/blob/master/Docs/SearchFilter.md -searchFilter = { - 'geographics': geographicsFilter, - 'determinationFilter': 'NoFilter', - 'notRecoveredFilter': 'DontIncludeNotRecovered', - 'occurrenceStatus': 'Present', - 'verificationStatus': 'BothVerifiedAndNotVerified', - 'output': { - 'fields': [ - # https://github.com/biodiversitydata-se/SOS/blob/master/Docs/SearchFilter.md#fields - # https://github.com/biodiversitydata-se/SOS/blob/master/Docs/Observation.md - 'dataProviderId', - 'datasetName', - #'basisOfRecord', - 'rightsHolder', - - 'modified', - 'sensitive', - 'measurementOrFacts', - 'projects', - - 'occurrence.occurrenceId', - 'occurrence.occurrenceRemarks', - 'occurrence.recordedBy', - 'occurrence.reportedBy', - 'occurrence.reportedDate', - 'occurrence.occurrenceStatus', - 'occurrence.activity', - 'occurrence.behavior', - 'occurrence.biotope', - 'occurrence.biotopeDescription', - 'occurrence.lifeStage', - 'occurrence.reproductiveCondition', - 'occurrence.sex', - 'occurrence.associatedMedia', - 'occurrence.associatedReferences', - 'occurrence.individualCount', - 'occurrence.organismQuantityInt', - 'occurrence.organismQuantityUnit', - 'occurrence.sensitivityCategory', - 'occurrence.isNaturalOccurrence', - 'occurrence.isNeverFoundObservation', - 'occurrence.isNotRediscoveredObservation', - 'occurrence.isPositiveObservation', - 'occurrence.substrate.description', - 'occurrence.substrate.name', - 'occurrence.length', - 'occurrence.weight', - 'occurrence.url', - - 'event.startDate', - 'event.endDate', - 'event.habitat', - 'event.eventRemarks', - 'event.discoveryMethod', - 'event.measurementOrFacts', - 'event.fieldNotes', - - 'identification.verified', - 'identification.uncertainIdentification', - 'identification.verificationStatus', - 'identification.confirmedBy', - 'identification.confirmedDate', - 'identification.identifiedBy', - 'identification.dateIdentified', - 'identification.verifiedBy', - 'identification.determinationMethod', - 'identification.identificationRemarks', - - 'location.locality', - 'location.county', - 'location.municipality', - 'location.coordinateUncertaintyInMeters', - - 'taxon.id', - 'taxon.scientificName', - 'taxon.scientificNameAuthorship', - 'taxon.vernacularName', - 'taxon.genus', - 'taxon.family', - 'taxon.order', - 'taxon.class', - 'taxon.phylum', - 'taxon.kingdom', - - 'taxon.attributes.taxonCategory', - 'taxon.attributes.organismGroup', - - 'taxon.attributes.redlistCategory', - ] +if not args.no_observations: + geographicsFilter = { + 'geometries': geometricFilter(geometries), + 'maxAccuracy': 2500, + 'considerObservationAccuracy': True, + 'considerDisturbanceRadius': False + } + taxonLists, taxonRedlistCategories, taxonListIds = getTaxonLists() + + # https://github.com/biodiversitydata-se/SOS/blob/master/Docs/SearchFilter.md + searchFilter = { + 'geographics': geographicsFilter, + 'determinationFilter': 'NoFilter', + 'notRecoveredFilter': 'DontIncludeNotRecovered', + 'occurrenceStatus': 'Present', + 'verificationStatus': 'BothVerifiedAndNotVerified', + 'output': { + 'fields': [ + # https://github.com/biodiversitydata-se/SOS/blob/master/Docs/SearchFilter.md#fields + # https://github.com/biodiversitydata-se/SOS/blob/master/Docs/Observation.md + 'dataProviderId', + 'datasetName', + #'basisOfRecord', + 'rightsHolder', + + 'modified', + 'sensitive', + 'measurementOrFacts', + 'projects', + + 'occurrence.occurrenceId', + 'occurrence.occurrenceRemarks', + 'occurrence.recordedBy', + 'occurrence.reportedBy', + 'occurrence.reportedDate', + 'occurrence.occurrenceStatus', + 'occurrence.activity', + 'occurrence.behavior', + 'occurrence.biotope', + 'occurrence.biotopeDescription', + 'occurrence.lifeStage', + 'occurrence.reproductiveCondition', + 'occurrence.sex', + 'occurrence.associatedMedia', + 'occurrence.associatedReferences', + 'occurrence.individualCount', + 'occurrence.organismQuantityInt', + 'occurrence.organismQuantityUnit', + 'occurrence.sensitivityCategory', + 'occurrence.isNaturalOccurrence', + 'occurrence.isNeverFoundObservation', + 'occurrence.isNotRediscoveredObservation', + 'occurrence.isPositiveObservation', + 'occurrence.substrate.description', + 'occurrence.substrate.name', + 'occurrence.length', + 'occurrence.weight', + 'occurrence.url', + + 'event.startDate', + 'event.endDate', + 'event.habitat', + 'event.eventRemarks', + 'event.discoveryMethod', + 'event.measurementOrFacts', + 'event.fieldNotes', + + 'identification.verified', + 'identification.uncertainIdentification', + 'identification.verificationStatus', + 'identification.confirmedBy', + 'identification.confirmedDate', + 'identification.identifiedBy', + 'identification.dateIdentified', + 'identification.verifiedBy', + 'identification.determinationMethod', + 'identification.identificationRemarks', + + 'location.locality', + 'location.county', + 'location.municipality', + 'location.coordinateUncertaintyInMeters', + + 'taxon.id', + 'taxon.scientificName', + 'taxon.scientificNameAuthorship', + 'taxon.vernacularName', + 'taxon.genus', + 'taxon.family', + 'taxon.order', + 'taxon.class', + 'taxon.phylum', + 'taxon.kingdom', + + 'taxon.attributes.taxonCategory', + 'taxon.attributes.organismGroup', + + 'taxon.attributes.redlistCategory', + ] + } } -} - -# https://artfakta.se/artinformation/taxa/biota-0/detaljer -kingdomIds = { - 'Animalia': 5000001, - 'Archaea': 5000082, - 'Bacteria': 5000052, - 'Chromista': 5000055, - 'Fungi': 5000039, - 'Plantae': 5000045, - 'Protozoa': 5000060, - 'Viruses': 5000083, - 'Algae': 6001047, -} - -searchFilter['taxon'] = { - 'ids': list(map(lambda k: kingdomIds[k], ['Fungi', 'Plantae'])), - 'includeUnderlyingTaxa': True, - # https://github.com/biodiversitydata-se/SOS/blob/master/Docs/SearchFilter.md#taxon-lists - 'taxonListIds': taxonListIds, - 'taxonListOperator': 'Filter' -} -if args.data_provider is not None: - searchFilter['dataProvider'] = { - 'ids': mapDataProviders(args.data_provider) + # https://artfakta.se/artinformation/taxa/biota-0/detaljer + kingdomIds = { + 'Animalia': 5000001, + 'Archaea': 5000082, + 'Bacteria': 5000052, + 'Chromista': 5000055, + 'Fungi': 5000039, + 'Plantae': 5000045, + 'Protozoa': 5000060, + 'Viruses': 5000083, + 'Algae': 6001047, } -if args.since is not None or args.until is not None: - searchFilter['date'] = { - # https://github.com/biodiversitydata-se/SOS/blob/master/Docs/SearchFilter.md#date-filter - 'startDate': args.since, - 'endDate': args.until, - 'dateFilterType': 'OverlappingStartDateAndEndDate' + searchFilter['taxon'] = { + 'ids': list(map(lambda k: kingdomIds[k], ['Fungi', 'Plantae'])), + 'includeUnderlyingTaxa': True, + # https://github.com/biodiversitydata-se/SOS/blob/master/Docs/SearchFilter.md#taxon-lists + 'taxonListIds': taxonListIds, + 'taxonListOperator': 'Filter' } -getObservations(taxonLists, taxonRedlistCategories, searchFilter) + if args.data_provider is not None: + searchFilter['dataProvider'] = { + 'ids': mapDataProviders(args.data_provider) + } + + if args.since is not None or args.until is not None: + searchFilter['date'] = { + # https://github.com/biodiversitydata-se/SOS/blob/master/Docs/SearchFilter.md#date-filter + 'startDate': args.since, + 'endDate': args.until, + 'dateFilterType': 'OverlappingStartDateAndEndDate' + } + + getObservations(taxonLists, taxonRedlistCategories, searchFilter) topo_maps = ['Topografi 10', 'Topografi 50', 'Topografi 100'] if args.topo_basedir is not None and projectInstance is not None: -- cgit v1.2.3