Project

General

Profile

« Previous | Next » 

Revision 4726

schemas/vegbien.sql: Split locationdetermination into locationcoords and locationplace, so that coordinate determinations can be made separately from place determinations

View differences:

vegbien.sql
534 534

  
535 535

  
536 536
--
537
-- Name: locationdetermination; Type: TABLE; Schema: public; Owner: -; Tablespace: 
537
-- Name: locationcoords; Type: TABLE; Schema: public; Owner: -; Tablespace: 
538 538
--
539 539

  
540
CREATE TABLE locationdetermination (
541
    locationdetermination_id integer NOT NULL,
540
CREATE TABLE locationcoords (
541
    locationcoords_id integer NOT NULL,
542 542
    location_id integer NOT NULL,
543 543
    latitude double precision,
544 544
    longitude double precision,
......
547 547
    verbatimcoordinates text,
548 548
    footprintgeometry_dwc text,
549 549
    coordsaccuracy double precision,
550
    namedplace_id integer,
551 550
    identifier_id integer,
552 551
    determinationdate timestamp with time zone,
553 552
    isoriginal boolean DEFAULT false NOT NULL,
......
557 556

  
558 557

  
559 558
--
560
-- Name: TABLE locationdetermination; Type: COMMENT; Schema: public; Owner: -
559
-- Name: COLUMN locationcoords.footprintgeometry_dwc; Type: COMMENT; Schema: public; Owner: -
561 560
--
562 561

  
563
COMMENT ON TABLE locationdetermination IS 'VegBank''s place table.';
562
COMMENT ON COLUMN locationcoords.footprintgeometry_dwc IS 'DwC''s footprintWKT field. "A Well-Known Text (WKT) representation of the shape (footprint, geometry) that defines the Location" (http://rs.tdwg.org/dwc/terms/#footprintWKT).';
564 563

  
565 564

  
566 565
--
567
-- Name: COLUMN locationdetermination.footprintgeometry_dwc; Type: COMMENT; Schema: public; Owner: -
566
-- Name: COLUMN locationcoords.coordsaccuracy; Type: COMMENT; Schema: public; Owner: -
568 567
--
569 568

  
570
COMMENT ON COLUMN locationdetermination.footprintgeometry_dwc IS 'DwC''s footprintWKT field. "A Well-Known Text (WKT) representation of the shape (footprint, geometry) that defines the Location" (http://rs.tdwg.org/dwc/terms/#footprintWKT).';
569
COMMENT ON COLUMN locationcoords.coordsaccuracy IS 'Accuracy of latitude/longitude or footprint geometry, in meters. This should generally be at least 1 m, which is the accuracy of the best GPSes.';
571 570

  
572 571

  
573 572
--
574
-- Name: COLUMN locationdetermination.coordsaccuracy; Type: COMMENT; Schema: public; Owner: -
575
--
576

  
577
COMMENT ON COLUMN locationdetermination.coordsaccuracy IS 'Accuracy of latitude/longitude or footprint geometry, in meters. This should generally be at least 1 m, which is the accuracy of the best GPSes.';
578

  
579

  
580
--
581 573
-- Name: locationevent; Type: TABLE; Schema: public; Owner: -; Tablespace: 
582 574
--
583 575

  
......
670 662

  
671 663

  
672 664
--
665
-- Name: locationplace; Type: TABLE; Schema: public; Owner: -; Tablespace: 
666
--
667

  
668
CREATE TABLE locationplace (
669
    locationplace_id integer NOT NULL,
670
    location_id integer NOT NULL,
671
    namedplace_id integer NOT NULL
672
);
673

  
674

  
675
--
676
-- Name: TABLE locationplace; Type: COMMENT; Schema: public; Owner: -
677
--
678

  
679
COMMENT ON TABLE locationplace IS 'VegBank''s place table.';
680

  
681

  
682
--
673 683
-- Name: method; Type: TABLE; Schema: public; Owner: -; Tablespace: 
674 684
--
675 685

  
......
1126 1136
--
1127 1137

  
1128 1138
CREATE VIEW analytical_db_view AS
1129
    SELECT datasource.organizationname AS "dataSourceName", taxonpath.family, taxonpath.genus, taxonpath.species, COALESCE(taxonpath.scientificnamewithauthor, taxonpath.scientificname) AS taxon, taxonpath.scientificnameauthor AS "taxonAuthor", taxonpath.variety AS "taxonMorphospecies", country.placename AS country, stateprovince.placename AS "stateProvince", county.placename AS "countyParish", taxonoccurrence.verbatimcollectorname AS collector, plantobservation.collectionnumber AS "collectionNumber", array_to_string(ARRAY[identifiedby.givenname, identifiedby.middlename, identifiedby.surname], ' '::text) AS "identifiedBy", aggregateoccurrence.collectiondate AS "observationDate", location.authorlocationcode AS "plotCode", location.area AS "plotAreaHa", method.name AS "plotMethod", locationdetermination.latitude, locationdetermination.longitude, location.elevation AS elevation_m, taxonoccurrence.iscultivated AS "isCultivated", taxonoccurrence.cultivatedbasis AS "isCultivatedReason", aggregateoccurrence.cover AS "pctCover" FROM (((((((((((((((((((location JOIN party datasource ON (((datasource.party_id = location.datasource_id) AND (datasource.organizationname IS NOT NULL)))) JOIN locationdetermination USING (location_id)) LEFT JOIN namedplace_ancestor continent_ancestor ON ((continent_ancestor.namedplace_id = locationdetermination.namedplace_id))) LEFT JOIN namedplace continent ON (((continent.namedplace_id = continent_ancestor.ancestor_id) AND (continent.rank = 'continent'::placerank)))) LEFT JOIN namedplace_ancestor country_ancestor ON ((country_ancestor.namedplace_id = locationdetermination.namedplace_id))) LEFT JOIN namedplace country ON (((country.namedplace_id = country_ancestor.ancestor_id) AND (country.rank = 'country'::placerank)))) LEFT JOIN namedplace_ancestor stateprovince_ancestor ON ((stateprovince_ancestor.namedplace_id = locationdetermination.namedplace_id))) LEFT JOIN namedplace stateprovince ON (((stateprovince.namedplace_id = stateprovince_ancestor.ancestor_id) AND (stateprovince.rank = 'stateProvince'::placerank)))) LEFT JOIN namedplace_ancestor county_ancestor ON ((county_ancestor.namedplace_id = locationdetermination.namedplace_id))) LEFT JOIN namedplace county ON (((county.namedplace_id = county_ancestor.ancestor_id) AND (county.rank = 'county'::placerank)))) JOIN locationevent USING (location_id)) JOIN method USING (method_id)) JOIN taxonoccurrence USING (locationevent_id)) JOIN taxondetermination USING (taxonoccurrence_id)) LEFT JOIN party identifiedby ON ((identifiedby.party_id = taxondetermination.party_id))) JOIN taxonpath USING (taxonpath_id)) LEFT JOIN aggregateoccurrence USING (taxonoccurrence_id)) LEFT JOIN plantobservation USING (aggregateoccurrence_id)) LEFT JOIN specimenreplicate USING (plantobservation_id));
1139
    SELECT datasource.organizationname AS "dataSourceName", taxonpath.family, taxonpath.genus, taxonpath.species, COALESCE(taxonpath.scientificnamewithauthor, taxonpath.scientificname) AS taxon, taxonpath.scientificnameauthor AS "taxonAuthor", taxonpath.variety AS "taxonMorphospecies", country.placename AS country, stateprovince.placename AS "stateProvince", county.placename AS "countyParish", taxonoccurrence.verbatimcollectorname AS collector, plantobservation.collectionnumber AS "collectionNumber", array_to_string(ARRAY[identifiedby.givenname, identifiedby.middlename, identifiedby.surname], ' '::text) AS "identifiedBy", aggregateoccurrence.collectiondate AS "observationDate", location.authorlocationcode AS "plotCode", location.area AS "plotAreaHa", method.name AS "plotMethod", locationcoords.latitude, locationcoords.longitude, location.elevation AS elevation_m, taxonoccurrence.iscultivated AS "isCultivated", taxonoccurrence.cultivatedbasis AS "isCultivatedReason", aggregateoccurrence.cover AS "pctCover" FROM ((((((((((((((((((((location JOIN party datasource ON (((datasource.party_id = location.datasource_id) AND (datasource.organizationname IS NOT NULL)))) JOIN locationcoords USING (location_id)) JOIN locationplace USING (location_id)) LEFT JOIN namedplace_ancestor continent_ancestor ON ((continent_ancestor.namedplace_id = locationplace.namedplace_id))) LEFT JOIN namedplace continent ON (((continent.namedplace_id = continent_ancestor.ancestor_id) AND (continent.rank = 'continent'::placerank)))) LEFT JOIN namedplace_ancestor country_ancestor ON ((country_ancestor.namedplace_id = locationplace.namedplace_id))) LEFT JOIN namedplace country ON (((country.namedplace_id = country_ancestor.ancestor_id) AND (country.rank = 'country'::placerank)))) LEFT JOIN namedplace_ancestor stateprovince_ancestor ON ((stateprovince_ancestor.namedplace_id = locationplace.namedplace_id))) LEFT JOIN namedplace stateprovince ON (((stateprovince.namedplace_id = stateprovince_ancestor.ancestor_id) AND (stateprovince.rank = 'stateProvince'::placerank)))) LEFT JOIN namedplace_ancestor county_ancestor ON ((county_ancestor.namedplace_id = locationplace.namedplace_id))) LEFT JOIN namedplace county ON (((county.namedplace_id = county_ancestor.ancestor_id) AND (county.rank = 'county'::placerank)))) JOIN locationevent USING (location_id)) JOIN method USING (method_id)) JOIN taxonoccurrence USING (locationevent_id)) JOIN taxondetermination USING (taxonoccurrence_id)) LEFT JOIN party identifiedby ON ((identifiedby.party_id = taxondetermination.party_id))) JOIN taxonpath USING (taxonpath_id)) LEFT JOIN aggregateoccurrence USING (taxonoccurrence_id)) LEFT JOIN plantobservation USING (aggregateoccurrence_id)) LEFT JOIN specimenreplicate USING (plantobservation_id));
1130 1140

  
1131 1141

  
1132 1142
--
......
1139 1149
For each placerank value, replace regexp ".*" with:
1140 1150
-----
1141 1151
LEFT JOIN namedplace_ancestor AS $0_ancestor
1142
ON $0_ancestor.namedplace_id = locationdetermination.namedplace_id
1152
ON $0_ancestor.namedplace_id = locationcoords.namedplace_id
1143 1153
LEFT JOIN namedplace AS $0
1144 1154
ON $0.namedplace_id = $0_ancestor.ancestor_id
1145 1155
AND $0.rank = ''$0''
......
1661 1671

  
1662 1672

  
1663 1673
--
1664
-- Name: locationdetermination_locationdetermination_id_seq; Type: SEQUENCE; Schema: public; Owner: -
1674
-- Name: locationcoords_locationcoords_id_seq; Type: SEQUENCE; Schema: public; Owner: -
1665 1675
--
1666 1676

  
1667
CREATE SEQUENCE locationdetermination_locationdetermination_id_seq
1677
CREATE SEQUENCE locationcoords_locationcoords_id_seq
1668 1678
    START WITH 1
1669 1679
    INCREMENT BY 1
1670 1680
    NO MINVALUE
......
1673 1683

  
1674 1684

  
1675 1685
--
1676
-- Name: locationdetermination_locationdetermination_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
1686
-- Name: locationcoords_locationcoords_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
1677 1687
--
1678 1688

  
1679
ALTER SEQUENCE locationdetermination_locationdetermination_id_seq OWNED BY locationdetermination.locationdetermination_id;
1689
ALTER SEQUENCE locationcoords_locationcoords_id_seq OWNED BY locationcoords.locationcoords_id;
1680 1690

  
1681 1691

  
1682 1692
--
......
1767 1777

  
1768 1778

  
1769 1779
--
1780
-- Name: locationplace_locationplace_id_seq; Type: SEQUENCE; Schema: public; Owner: -
1781
--
1782

  
1783
CREATE SEQUENCE locationplace_locationplace_id_seq
1784
    START WITH 1
1785
    INCREMENT BY 1
1786
    NO MINVALUE
1787
    NO MAXVALUE
1788
    CACHE 1;
1789

  
1790

  
1791
--
1792
-- Name: locationplace_locationplace_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
1793
--
1794

  
1795
ALTER SEQUENCE locationplace_locationplace_id_seq OWNED BY locationplace.locationplace_id;
1796

  
1797

  
1798
--
1770 1799
-- Name: method_method_id_seq; Type: SEQUENCE; Schema: public; Owner: -
1771 1800
--
1772 1801

  
......
3268 3297

  
3269 3298

  
3270 3299
--
3271
-- Name: locationdetermination_id; Type: DEFAULT; Schema: public; Owner: -
3300
-- Name: locationcoords_id; Type: DEFAULT; Schema: public; Owner: -
3272 3301
--
3273 3302

  
3274
ALTER TABLE locationdetermination ALTER COLUMN locationdetermination_id SET DEFAULT nextval('locationdetermination_locationdetermination_id_seq'::regclass);
3303
ALTER TABLE locationcoords ALTER COLUMN locationcoords_id SET DEFAULT nextval('locationcoords_locationcoords_id_seq'::regclass);
3275 3304

  
3276 3305

  
3277 3306
--
......
3296 3325

  
3297 3326

  
3298 3327
--
3328
-- Name: locationplace_id; Type: DEFAULT; Schema: public; Owner: -
3329
--
3330

  
3331
ALTER TABLE locationplace ALTER COLUMN locationplace_id SET DEFAULT nextval('locationplace_locationplace_id_seq'::regclass);
3332

  
3333

  
3334
--
3299 3335
-- Name: method_id; Type: DEFAULT; Schema: public; Owner: -
3300 3336
--
3301 3337

  
......
3737 3773

  
3738 3774

  
3739 3775
--
3740
-- Name: locationdetermination_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
3776
-- Name: locationcoords_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
3741 3777
--
3742 3778

  
3743
ALTER TABLE ONLY locationdetermination
3744
    ADD CONSTRAINT locationdetermination_pkey PRIMARY KEY (locationdetermination_id);
3779
ALTER TABLE ONLY locationcoords
3780
    ADD CONSTRAINT locationcoords_pkey PRIMARY KEY (locationcoords_id);
3745 3781

  
3746 3782

  
3747 3783
--
3748
-- Name: locationdetermination_unique; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
3749
--
3750

  
3751
ALTER TABLE ONLY locationdetermination
3752
    ADD CONSTRAINT locationdetermination_unique UNIQUE (location_id, namedplace_id);
3753

  
3754

  
3755
--
3756 3784
-- Name: locationevent_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
3757 3785
--
3758 3786

  
......
3777 3805

  
3778 3806

  
3779 3807
--
3808
-- Name: locationplace_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
3809
--
3810

  
3811
ALTER TABLE ONLY locationplace
3812
    ADD CONSTRAINT locationplace_pkey PRIMARY KEY (locationplace_id);
3813

  
3814

  
3815
--
3816
-- Name: locationplace_unique; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
3817
--
3818

  
3819
ALTER TABLE ONLY locationplace
3820
    ADD CONSTRAINT locationplace_unique UNIQUE (location_id, namedplace_id);
3821

  
3822

  
3823
--
3780 3824
-- Name: method_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
3781 3825
--
3782 3826

  
......
4261 4305

  
4262 4306

  
4263 4307
--
4308
-- Name: locationcoords_unique; Type: INDEX; Schema: public; Owner: -; Tablespace: 
4309
--
4310

  
4311
CREATE UNIQUE INDEX locationcoords_unique ON locationcoords USING btree (location_id, (COALESCE(identifier_id, 2147483647)));
4312

  
4313

  
4314
--
4264 4315
-- Name: locationevent_accessioncode_index; Type: INDEX; Schema: public; Owner: -; Tablespace: 
4265 4316
--
4266 4317

  
......
4857 4908

  
4858 4909

  
4859 4910
--
4860
-- Name: locationdetermination_identifier_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
4911
-- Name: locationcoords_identifier_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
4861 4912
--
4862 4913

  
4863
ALTER TABLE ONLY locationdetermination
4864
    ADD CONSTRAINT locationdetermination_identifier_id_fkey FOREIGN KEY (identifier_id) REFERENCES party(party_id) ON UPDATE CASCADE ON DELETE CASCADE;
4914
ALTER TABLE ONLY locationcoords
4915
    ADD CONSTRAINT locationcoords_identifier_id_fkey FOREIGN KEY (identifier_id) REFERENCES party(party_id) ON UPDATE CASCADE ON DELETE CASCADE;
4865 4916

  
4866 4917

  
4867 4918
--
4868
-- Name: locationdetermination_location_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
4919
-- Name: locationcoords_location_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
4869 4920
--
4870 4921

  
4871
ALTER TABLE ONLY locationdetermination
4872
    ADD CONSTRAINT locationdetermination_location_id_fkey FOREIGN KEY (location_id) REFERENCES location(location_id) ON UPDATE CASCADE ON DELETE CASCADE;
4922
ALTER TABLE ONLY locationcoords
4923
    ADD CONSTRAINT locationcoords_location_id_fkey FOREIGN KEY (location_id) REFERENCES location(location_id) ON UPDATE CASCADE ON DELETE CASCADE;
4873 4924

  
4874 4925

  
4875 4926
--
4876
-- Name: locationdetermination_namedplace_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
4877
--
4878

  
4879
ALTER TABLE ONLY locationdetermination
4880
    ADD CONSTRAINT locationdetermination_namedplace_id_fkey FOREIGN KEY (namedplace_id) REFERENCES namedplace(namedplace_id) ON UPDATE CASCADE ON DELETE CASCADE;
4881

  
4882

  
4883
--
4884 4927
-- Name: locationevent_datasource_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
4885 4928
--
4886 4929

  
......
4977 5020

  
4978 5021

  
4979 5022
--
5023
-- Name: locationplace_location_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
5024
--
5025

  
5026
ALTER TABLE ONLY locationplace
5027
    ADD CONSTRAINT locationplace_location_id_fkey FOREIGN KEY (location_id) REFERENCES location(location_id) ON UPDATE CASCADE ON DELETE CASCADE;
5028

  
5029

  
5030
--
5031
-- Name: locationplace_namedplace_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
5032
--
5033

  
5034
ALTER TABLE ONLY locationplace
5035
    ADD CONSTRAINT locationplace_namedplace_id_fkey FOREIGN KEY (namedplace_id) REFERENCES namedplace(namedplace_id) ON UPDATE CASCADE ON DELETE CASCADE;
5036

  
5037

  
5038
--
4980 5039
-- Name: method_covermethod_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
4981 5040
--
4982 5041

  

Also available in: Unified diff