Revision 7361
Added by Aaron Marcuse-Kubitza about 12 years ago
vegbien.sql | ||
---|---|---|
1584 | 1584 |
"decimalLatitude" double precision, |
1585 | 1585 |
"decimalLongitude" double precision, |
1586 | 1586 |
"coordinateUncertaintyInMeters" double precision, |
1587 |
geovalid integer, |
|
1588 |
"isNewWorld" integer, |
|
1587 |
geovalid_bien integer,
|
|
1588 |
"isNewWorld_bien" integer,
|
|
1589 | 1589 |
"locationID" text NOT NULL, |
1590 | 1590 |
"elevationInMeters" double precision, |
1591 | 1591 |
"plotArea_ha" double precision, |
1592 | 1592 |
"samplingProtocol" text, |
1593 | 1593 |
"dateCollected" date, |
1594 |
"higherPlantGroup" higher_plant_group, |
|
1594 |
"higherPlantGroup_bien" higher_plant_group,
|
|
1595 | 1595 |
family text, |
1596 | 1596 |
genus text, |
1597 | 1597 |
"speciesBinomial" text, |
1598 | 1598 |
"taxonName" text, |
1599 | 1599 |
"scientificNameAuthorship" text, |
1600 | 1600 |
"scientificNameWithMorphospecies" text, |
1601 |
threatened integer, |
|
1601 |
threatened_bien integer,
|
|
1602 | 1602 |
"identifiedBy" text, |
1603 | 1603 |
"growthForm" growthform, |
1604 |
cultivated integer, |
|
1605 |
"cultivatedBasis" text, |
|
1604 |
cultivated_bien integer,
|
|
1605 |
"cultivatedBasis_bien" text,
|
|
1606 | 1606 |
"coverPercent" double precision, |
1607 | 1607 |
"individualCount" bigint, |
1608 | 1608 |
"individualCount_1cm_or_more" bigint, |
... | ... | |
1628 | 1628 |
"decimalLatitude" double precision, |
1629 | 1629 |
"decimalLongitude" double precision, |
1630 | 1630 |
"coordinateUncertaintyInMeters" double precision, |
1631 |
"coordinateSource" coordinatesource, |
|
1632 |
"georeferenceProtocol" text, |
|
1633 |
geovalid integer, |
|
1634 |
"isNewWorld" integer, |
|
1631 |
"coordinateSource_bien" coordinatesource,
|
|
1632 |
"georeferenceProtocol_bien" text,
|
|
1633 |
geovalid_bien integer,
|
|
1634 |
"isNewWorld_bien" integer,
|
|
1635 | 1635 |
"projectID" text, |
1636 | 1636 |
"locationID" text NOT NULL, |
1637 | 1637 |
"locationName" text, |
... | ... | |
1641 | 1641 |
"plotArea_ha" double precision, |
1642 | 1642 |
"samplingProtocol" text, |
1643 | 1643 |
"dateCollected" date, |
1644 |
"higherPlantGroup" higher_plant_group, |
|
1644 |
"higherPlantGroup_bien" higher_plant_group,
|
|
1645 | 1645 |
family text, |
1646 | 1646 |
genus text, |
1647 | 1647 |
"speciesBinomial" text, |
1648 | 1648 |
"taxonName" text, |
1649 | 1649 |
"scientificNameAuthorship" text, |
1650 | 1650 |
"scientificNameWithMorphospecies" text, |
1651 |
threatened integer, |
|
1651 |
threatened_bien integer,
|
|
1652 | 1652 |
"identifiedBy" text, |
1653 | 1653 |
"growthForm" growthform, |
1654 |
cultivated integer, |
|
1655 |
"cultivatedBasis" text, |
|
1654 |
cultivated_bien integer,
|
|
1655 |
"cultivatedBasis_bien" text,
|
|
1656 | 1656 |
"recordedBy" text, |
1657 | 1657 |
"recordNumber" text, |
1658 | 1658 |
"coverPercent" double precision, |
... | ... | |
1673 | 1673 |
-- |
1674 | 1674 |
|
1675 | 1675 |
CREATE VIEW analytical_aggregate_view AS |
1676 |
SELECT analytical_stem.datasource, analytical_stem.country, analytical_stem."stateProvince", analytical_stem.county, analytical_stem."decimalLatitude", analytical_stem."decimalLongitude", analytical_stem."coordinateUncertaintyInMeters", analytical_stem.geovalid, analytical_stem."isNewWorld", analytical_stem."locationID", analytical_stem."elevationInMeters", analytical_stem."plotArea_ha", analytical_stem."samplingProtocol", analytical_stem."dateCollected", analytical_stem."higherPlantGroup", analytical_stem.family, analytical_stem.genus, analytical_stem."speciesBinomial", analytical_stem."taxonName", analytical_stem."scientificNameAuthorship", analytical_stem."scientificNameWithMorphospecies", analytical_stem.threatened, analytical_stem."identifiedBy", analytical_stem."growthForm", analytical_stem.cultivated, analytical_stem."cultivatedBasis", sum(analytical_stem."coverPercent") AS "coverPercent", count(analytical_stem."diameterBreastHeight_cm") AS "individualCount", count((analytical_stem."diameterBreastHeight_cm" >= _cm_to_m((1)::double precision))) AS "individualCount_1cm_or_more", count((analytical_stem."diameterBreastHeight_cm" >= _cm_to_m((2.5)::double precision))) AS "individualCount_2_5cm_or_more", count((analytical_stem."diameterBreastHeight_cm" >= _cm_to_m((10)::double precision))) AS "individualCount_10cm_or_more" FROM analytical_stem GROUP BY analytical_stem.datasource, analytical_stem.country, analytical_stem."stateProvince", analytical_stem.county, analytical_stem."decimalLatitude", analytical_stem."decimalLongitude", analytical_stem."coordinateUncertaintyInMeters", analytical_stem.geovalid, analytical_stem."isNewWorld", analytical_stem."locationID", analytical_stem."elevationInMeters", analytical_stem."plotArea_ha", analytical_stem."samplingProtocol", analytical_stem."dateCollected", analytical_stem."higherPlantGroup", analytical_stem.family, analytical_stem.genus, analytical_stem."speciesBinomial", analytical_stem."taxonName", analytical_stem."scientificNameAuthorship", analytical_stem."scientificNameWithMorphospecies", analytical_stem.threatened, analytical_stem."identifiedBy", analytical_stem."growthForm", analytical_stem.cultivated, analytical_stem."cultivatedBasis";
|
|
1676 |
SELECT analytical_stem.datasource, analytical_stem.country, analytical_stem."stateProvince", analytical_stem.county, analytical_stem."decimalLatitude", analytical_stem."decimalLongitude", analytical_stem."coordinateUncertaintyInMeters", analytical_stem.geovalid_bien, analytical_stem."isNewWorld_bien", analytical_stem."locationID", analytical_stem."elevationInMeters", analytical_stem."plotArea_ha", analytical_stem."samplingProtocol", analytical_stem."dateCollected", analytical_stem."higherPlantGroup_bien", analytical_stem.family, analytical_stem.genus, analytical_stem."speciesBinomial", analytical_stem."taxonName", analytical_stem."scientificNameAuthorship", analytical_stem."scientificNameWithMorphospecies", analytical_stem.threatened_bien, analytical_stem."identifiedBy", analytical_stem."growthForm", analytical_stem.cultivated_bien, analytical_stem."cultivatedBasis_bien", sum(analytical_stem."coverPercent") AS "coverPercent", count(analytical_stem."diameterBreastHeight_cm") AS "individualCount", count((analytical_stem."diameterBreastHeight_cm" >= _cm_to_m((1)::double precision))) AS "individualCount_1cm_or_more", count((analytical_stem."diameterBreastHeight_cm" >= _cm_to_m((2.5)::double precision))) AS "individualCount_2_5cm_or_more", count((analytical_stem."diameterBreastHeight_cm" >= _cm_to_m((10)::double precision))) AS "individualCount_10cm_or_more" FROM analytical_stem GROUP BY analytical_stem.datasource, analytical_stem.country, analytical_stem."stateProvince", analytical_stem.county, analytical_stem."decimalLatitude", analytical_stem."decimalLongitude", analytical_stem."coordinateUncertaintyInMeters", analytical_stem.geovalid_bien, analytical_stem."isNewWorld_bien", analytical_stem."locationID", analytical_stem."elevationInMeters", analytical_stem."plotArea_ha", analytical_stem."samplingProtocol", analytical_stem."dateCollected", analytical_stem."higherPlantGroup_bien", analytical_stem.family, analytical_stem.genus, analytical_stem."speciesBinomial", analytical_stem."taxonName", analytical_stem."scientificNameAuthorship", analytical_stem."scientificNameWithMorphospecies", analytical_stem.threatened_bien, analytical_stem."identifiedBy", analytical_stem."growthForm", analytical_stem.cultivated_bien, analytical_stem."cultivatedBasis_bien";
|
|
1677 | 1677 |
|
1678 | 1678 |
|
1679 | 1679 |
-- |
... | ... | |
2483 | 2483 |
-- |
2484 | 2484 |
|
2485 | 2485 |
CREATE VIEW analytical_stem_view AS |
2486 |
SELECT source.shortname AS datasource, sourcelist.name AS "institutionCode", specimenreplicate.collectioncode_dwc AS "collectionCode", specimenreplicate.catalognumber_dwc AS "catalogNumber", specimenreplicate.sourceaccessioncode AS "occurrenceID", canon_place.country, canon_place.stateprovince AS "stateProvince", datasource_place.county, location.locationnarrative AS locality, CASE WHEN canon_place.geovalid THEN coordinates.latitude_deg ELSE county_centroids.latitude END AS "decimalLatitude", CASE WHEN canon_place.geovalid THEN coordinates.longitude_deg ELSE county_centroids.longitude END AS "decimalLongitude", CASE WHEN canon_place.geovalid THEN coordinates.coordsaccuracy_m ELSE _km_to_m(county_centroids.error_km) END AS "coordinateUncertaintyInMeters", CASE WHEN canon_place.geovalid THEN 'source data'::coordinatesource WHEN (county_centroids.row_num IS NOT NULL) THEN 'georeferencing'::coordinatesource ELSE NULL::coordinatesource END AS "coordinateSource", CASE WHEN canon_place.geovalid THEN NULL::text WHEN (county_centroids.row_num IS NOT NULL) THEN 'county centroid'::text ELSE NULL::text END AS "georeferenceProtocol", (canon_place.geovalid)::integer AS geovalid, ("newWorldCountries"."isNewWorld")::integer AS "isNewWorld", COALESCE(project.sourceaccessioncode, project.projectname) AS "projectID", COALESCE(location.sourceaccessioncode, NULLIF(array_to_string(ARRAY[COALESCE(parent_location.sourceaccessioncode, parent_location.authorlocationcode), location.authorlocationcode], '; '::text), ''::text)) AS "locationID", COALESCE(parent_location.authorlocationcode, location.authorlocationcode) AS "locationName", CASE WHEN (parent_location.location_id IS NOT NULL) THEN location.authorlocationcode ELSE NULL::text END AS subplot, plantobservation.authorplantcode AS "individualCode", COALESCE(location.elevation_m, parent_location.elevation_m) AS "elevationInMeters", _m2_to_ha(location.area_m2) AS "plotArea_ha", method.name AS "samplingProtocol", COALESCE(locationevent.obsstartdate, parent_event.obsstartdate, aggregateoccurrence.collectiondate) AS "dateCollected", family_higher_plant_group.higher_plant_group AS "higherPlantGroup", taxonverbatim.family, taxonverbatim.genus, ((taxonverbatim.genus || ' '::text) || taxonverbatim.specific_epithet) AS "speciesBinomial", taxonverbatim.taxonname AS "taxonName", taxonverbatim.author AS "scientificNameAuthorship", NULLIF(array_to_string(ARRAY[COALESCE(taxonverbatim.genus, taxonverbatim.family), COALESCE(taxonverbatim.specific_epithet, taxonverbatim.morphospecies)], ' '::text), ''::text) AS "scientificNameWithMorphospecies", ((threatened_taxonlabel.taxonlabel_id IS NOT NULL))::integer AS threatened, identifiedby.fullname AS "identifiedBy", taxonoccurrence.growthform AS "growthForm", (((cultivated_family_locations.country IS NOT NULL) OR _or(taxonoccurrence.iscultivated, location.iscultivated)))::integer AS cultivated, CASE WHEN (taxonoccurrence.iscultivated IS NOT NULL) THEN taxonoccurrence.cultivatedbasis WHEN (location.iscultivated IS NOT NULL) THEN NULL::text ELSE NULL::text END AS "cultivatedBasis", collector.fullname AS "recordedBy", plantobservation.authorplantcode AS "recordNumber", _fraction_to_percent(aggregateoccurrence.cover_fraction) AS "coverPercent", _m_to_cm(stemobservation.diameterbreastheight_m) AS "diameterBreastHeight_cm", stemobservation.height_m, stemobservation.tag, stemobservation.xposition_m AS "organismX_m", stemobservation.yposition_m AS "organismY_m", taxonoccurrence.sourceaccessioncode AS "taxonOccurrenceID", taxonoccurrence.authortaxoncode AS "authorTaxonCode", plantobservation.sourceaccessioncode AS "individualObservationID", stemobservation.authorstemcode AS "authorStemCode" FROM (((((((((((((((((((((((((((source JOIN location USING (source_id)) LEFT JOIN locationevent USING (location_id)) LEFT JOIN location parent_location ON ((parent_location.location_id = location.parent_id))) LEFT JOIN locationplace ON ((locationplace.location_id = COALESCE(parent_location.location_id, location.location_id)))) LEFT JOIN place datasource_place USING (place_id)) LEFT JOIN place canon_place ON ((canon_place.place_id = datasource_place.canon_place_id))) LEFT JOIN coordinates ON ((coordinates.coordinates_id = canon_place.coordinates_id))) LEFT JOIN "newWorld".iso_code_gadm ON ((iso_code_gadm."GADM country" = canon_place.country))) LEFT JOIN "newWorld"."newWorldCountries" ON (("newWorldCountries"."isoCode" = iso_code_gadm."2-digit iso code"))) LEFT JOIN geoscrub.county_centroids ON ((((canon_place.country = 'United States'::text) AND (county_centroids.state = canon_place.stateprovince)) AND (county_centroids.county = canon_place.county)))) LEFT JOIN taxonoccurrence USING (locationevent_id)) LEFT JOIN locationevent parent_event ON ((parent_event.locationevent_id = locationevent.parent_id))) LEFT JOIN project ON ((project.project_id = COALESCE(locationevent.project_id, parent_event.project_id)))) LEFT JOIN method ON ((method.method_id = COALESCE(locationevent.method_id, parent_event.method_id)))) LEFT JOIN party collector ON ((collector.party_id = taxonoccurrence.collector_id))) LEFT JOIN aggregateoccurrence USING (taxonoccurrence_id)) LEFT JOIN plantobservation USING (aggregateoccurrence_id)) LEFT JOIN stemobservation USING (plantobservation_id)) LEFT JOIN specimenreplicate USING (plantobservation_id)) LEFT JOIN sourcelist ON ((sourcelist.sourcelist_id = specimenreplicate.institution_id))) LEFT JOIN taxondetermination ON (((taxondetermination.taxonoccurrence_id = taxonoccurrence.taxonoccurrence_id) AND taxondetermination.iscurrent))) LEFT JOIN party identifiedby ON ((identifiedby.party_id = taxondetermination.party_id))) LEFT JOIN taxonverbatim USING (taxonverbatim_id)) LEFT JOIN taxonlabel USING (taxonlabel_id)) LEFT JOIN family_higher_plant_group ON ((family_higher_plant_group.family = taxonverbatim.family))) LEFT JOIN cultivated_family_locations ON (((cultivated_family_locations.family = taxonverbatim.family) AND (cultivated_family_locations.country = canon_place.country)))) LEFT JOIN threatened_taxonlabel ON ((threatened_taxonlabel.taxonlabel_id = taxonlabel.taxonlabel_id)));
|
|
2486 |
SELECT source.shortname AS datasource, sourcelist.name AS "institutionCode", specimenreplicate.collectioncode_dwc AS "collectionCode", specimenreplicate.catalognumber_dwc AS "catalogNumber", specimenreplicate.sourceaccessioncode AS "occurrenceID", canon_place.country, canon_place.stateprovince AS "stateProvince", datasource_place.county, location.locationnarrative AS locality, CASE WHEN canon_place.geovalid THEN coordinates.latitude_deg ELSE county_centroids.latitude END AS "decimalLatitude", CASE WHEN canon_place.geovalid THEN coordinates.longitude_deg ELSE county_centroids.longitude END AS "decimalLongitude", CASE WHEN canon_place.geovalid THEN coordinates.coordsaccuracy_m ELSE _km_to_m(county_centroids.error_km) END AS "coordinateUncertaintyInMeters", CASE WHEN canon_place.geovalid THEN 'source data'::coordinatesource WHEN (county_centroids.row_num IS NOT NULL) THEN 'georeferencing'::coordinatesource ELSE NULL::coordinatesource END AS "coordinateSource_bien", CASE WHEN canon_place.geovalid THEN NULL::text WHEN (county_centroids.row_num IS NOT NULL) THEN 'county centroid'::text ELSE NULL::text END AS "georeferenceProtocol_bien", (canon_place.geovalid)::integer AS geovalid_bien, ("newWorldCountries"."isNewWorld")::integer AS "isNewWorld_bien", COALESCE(project.sourceaccessioncode, project.projectname) AS "projectID", COALESCE(location.sourceaccessioncode, NULLIF(array_to_string(ARRAY[COALESCE(parent_location.sourceaccessioncode, parent_location.authorlocationcode), location.authorlocationcode], '; '::text), ''::text)) AS "locationID", COALESCE(parent_location.authorlocationcode, location.authorlocationcode) AS "locationName", CASE WHEN (parent_location.location_id IS NOT NULL) THEN location.authorlocationcode ELSE NULL::text END AS subplot, plantobservation.authorplantcode AS "individualCode", COALESCE(location.elevation_m, parent_location.elevation_m) AS "elevationInMeters", _m2_to_ha(location.area_m2) AS "plotArea_ha", method.name AS "samplingProtocol", COALESCE(locationevent.obsstartdate, parent_event.obsstartdate, aggregateoccurrence.collectiondate) AS "dateCollected", family_higher_plant_group.higher_plant_group AS "higherPlantGroup_bien", taxonverbatim.family, taxonverbatim.genus, ((taxonverbatim.genus || ' '::text) || taxonverbatim.specific_epithet) AS "speciesBinomial", taxonverbatim.taxonname AS "taxonName", taxonverbatim.author AS "scientificNameAuthorship", NULLIF(array_to_string(ARRAY[COALESCE(taxonverbatim.genus, taxonverbatim.family), COALESCE(taxonverbatim.specific_epithet, taxonverbatim.morphospecies)], ' '::text), ''::text) AS "scientificNameWithMorphospecies", ((threatened_taxonlabel.taxonlabel_id IS NOT NULL))::integer AS threatened_bien, identifiedby.fullname AS "identifiedBy", taxonoccurrence.growthform AS "growthForm", (((cultivated_family_locations.country IS NOT NULL) OR _or(taxonoccurrence.iscultivated, location.iscultivated)))::integer AS cultivated_bien, CASE WHEN (taxonoccurrence.iscultivated IS NOT NULL) THEN taxonoccurrence.cultivatedbasis WHEN (location.iscultivated IS NOT NULL) THEN NULL::text ELSE NULL::text END AS "cultivatedBasis_bien", collector.fullname AS "recordedBy", plantobservation.authorplantcode AS "recordNumber", _fraction_to_percent(aggregateoccurrence.cover_fraction) AS "coverPercent", _m_to_cm(stemobservation.diameterbreastheight_m) AS "diameterBreastHeight_cm", stemobservation.height_m, stemobservation.tag, stemobservation.xposition_m AS "organismX_m", stemobservation.yposition_m AS "organismY_m", taxonoccurrence.sourceaccessioncode AS "taxonOccurrenceID", taxonoccurrence.authortaxoncode AS "authorTaxonCode", plantobservation.sourceaccessioncode AS "individualObservationID", stemobservation.authorstemcode AS "authorStemCode" FROM (((((((((((((((((((((((((((source JOIN location USING (source_id)) LEFT JOIN locationevent USING (location_id)) LEFT JOIN location parent_location ON ((parent_location.location_id = location.parent_id))) LEFT JOIN locationplace ON ((locationplace.location_id = COALESCE(parent_location.location_id, location.location_id)))) LEFT JOIN place datasource_place USING (place_id)) LEFT JOIN place canon_place ON ((canon_place.place_id = datasource_place.canon_place_id))) LEFT JOIN coordinates ON ((coordinates.coordinates_id = canon_place.coordinates_id))) LEFT JOIN "newWorld".iso_code_gadm ON ((iso_code_gadm."GADM country" = canon_place.country))) LEFT JOIN "newWorld"."newWorldCountries" ON (("newWorldCountries"."isoCode" = iso_code_gadm."2-digit iso code"))) LEFT JOIN geoscrub.county_centroids ON ((((canon_place.country = 'United States'::text) AND (county_centroids.state = canon_place.stateprovince)) AND (county_centroids.county = canon_place.county)))) LEFT JOIN taxonoccurrence USING (locationevent_id)) LEFT JOIN locationevent parent_event ON ((parent_event.locationevent_id = locationevent.parent_id))) LEFT JOIN project ON ((project.project_id = COALESCE(locationevent.project_id, parent_event.project_id)))) LEFT JOIN method ON ((method.method_id = COALESCE(locationevent.method_id, parent_event.method_id)))) LEFT JOIN party collector ON ((collector.party_id = taxonoccurrence.collector_id))) LEFT JOIN aggregateoccurrence USING (taxonoccurrence_id)) LEFT JOIN plantobservation USING (aggregateoccurrence_id)) LEFT JOIN stemobservation USING (plantobservation_id)) LEFT JOIN specimenreplicate USING (plantobservation_id)) LEFT JOIN sourcelist ON ((sourcelist.sourcelist_id = specimenreplicate.institution_id))) LEFT JOIN taxondetermination ON (((taxondetermination.taxonoccurrence_id = taxonoccurrence.taxonoccurrence_id) AND taxondetermination.iscurrent))) LEFT JOIN party identifiedby ON ((identifiedby.party_id = taxondetermination.party_id))) LEFT JOIN taxonverbatim USING (taxonverbatim_id)) LEFT JOIN taxonlabel USING (taxonlabel_id)) LEFT JOIN family_higher_plant_group ON ((family_higher_plant_group.family = taxonverbatim.family))) LEFT JOIN cultivated_family_locations ON (((cultivated_family_locations.family = taxonverbatim.family) AND (cultivated_family_locations.country = canon_place.country)))) LEFT JOIN threatened_taxonlabel ON ((threatened_taxonlabel.taxonlabel_id = taxonlabel.taxonlabel_id)));
|
|
2487 | 2487 |
|
2488 | 2488 |
|
2489 | 2489 |
-- |
Also available in: Unified diff
schemas/vegbien.sql: analytical_stem_view: derived terms: Added _bien suffix per Brad's request (https://projects.nceas.ucsb.edu/nceas/projects/bien/wiki/Spot-checking#Brad-Boyles-comments)