some relational operators intersection –result are all those tuples that are present in both of...
TRANSCRIPT
Some relational operators
• intersection– result are all those tuples that are present in
both of the “input” relationsMarried couplesBob MaryJim DebbieJanice Tom
Fayetteville ResidentsJim DebbieFrank JoanFred Elaine
IntersectionJim Debbie
UnionMarried couplesBob MaryJim DebbieJanice Tom
Fayetteville ResidentsJim DebbieFrank JoanFred Elaine
UNIONBob MaryJim DebbieJanice TomFrank JoanFred Elaine
DifferenceMarried couplesBob MaryJim DebbieJanice Tom
Fayetteville ResidentsJim DebbieFrank JoanFred Elaine
DIFFERENCEBob MaryJanice Tom
Join
• parcel, owner• PARCEL(Parcel_ID, SIZE, Use, ETC…, Owner-ID)• OWNER(Owner-ID, Last_name, First_name, Street,
Town, ZIP)• JOIN• 123 240 acres, agricultural, Jones, Bob, Main,
Weddington, 23456• 567 1 acre, residential, Smith, Bill, College,
Fayetteville, 72701
Cartesian product• Important term “Cartesian product”
– results when two (or more) relations are “joined”
– see example on page 481– important concept because can be the
unexpected result of a join operation
Suppose we have our parcel data base
• owner table, parcel table etc.
• we wish to have list of all owned parcels
• suppose we have 4 owners and 6 parcels
• we could have a Cartesian product that had 24 “parcel owner” tuples even though there are only six parcels
Relational Projection
• selection of particular single attribute (COLUMNS) from a relation
• OWNER(Owner-ID, Last_name, First_name, Street, Town, ZIP)
• PROJECT Last_name– Smith
– Jones
– Brown
Restriction aka selection
• selection of particular tuples (ROWS) based on a criteria or condition– parcels larger than 200 acres
• the condition is called a predicate
Division
• given two tables • Desired_Land_USE(land-use) - where land use is
agriculture and timber• PARCEL(Parcel_ID, SIZE, Use, ETC…, Owner-
ID)• DIVISION
– result those parcels where Use is either agriculture or timber
Different operations
• can be grouped by – whether they operate on tuples or attributes
• all ate tuples except for projection
– how many relations they involve• single relation
– conditional selection
– restriction
– projection
• multiple relations (2..N)– joins
• binary - two relations– all others
Normalization• can be viewed essentially as the reduction of repetition in relations
– ex:• Not normalized
– PARCELS(Parcel-ID, Owner, Size,….» 123 SMITH 200» 123 JONES 200» 123 BROWN» 345 WATER» 555 WHITE
• Normalize– PARCEL(Parcel-ID, Size, Etc, ….– OWNER(Last_name, First_Name, Parcel-ID, etc…)
• Fully Normalized– PARCEL(Parcel-ID, Size, etc….)– OWNERSHIP(Parcel-ID, Owner-ID)– OWNERS(Owner-ID, Last_name, First_name, …..)
For spatial data
• Non-normalized spatial data– POLYGON(Polygon-ID,Segment-ID)
– COORD(Segment_ID,Start-X, Start-Y, End-X, End-Y)
– Example– Segment Start-X, Start-Y, End-X, End-Y
– 1 2 2 3 5
– 2 3 5 4 2
– 3 4 2 2 2
• What if we want to edit file and change location of one vertex?
• We must be sure to edit two records
Normalized spatial data– POLYGON(Polygon-ID,Segment-ID)– SEGMENT(Segment-ID, Start-point-ID, End-point-ID)– COORDS(Point-ID, X, Y)– SEGMENTS
• Segment-ID Start-point-ID End-point-ID
• 1 11 12
• 2 12 13
• 3 13 11
– COORDS• Point-ID X Y
• 11 2 2
• 12 3 5
• 13 4 2
Structured query language in geomatics
• SELECT <attribute list>
• FROM <table list>
• WHERE <condition>
Parcel Database Structure
Obtain addresses of neighbors of Anne
The SQL statement
Perimeter of Ann’s parcel• SELECT A.Parcel-ID• SUM(SQR ((D.X -E.X) * (D.X - E.X) + (D.Y - E.Y) * (D.Y -
E.Y)))• FROM OWNERS-PARCEL A, PARCEL-SEGMENT B,
SEGMENT-ENDPOINTS C, COORDINATES D, COORDINATES E
• WHERE A.Owner_name = ‘Ann”• AND A.Parcel-ID = B.Parcel-ID• AND B.Segment-ID = C.Segment-ID• AND C.Point1-ID = D.Point-ID• AND C.Point2-ID = E.Point-ID
Address of Parcel 345• SELECT Street-ID
• FROM PARCEL_SEGMENT, STREET-SEGMENT
• WHERE Parcel-ID = 345
• AND PARCEL-SEGMENT.Segment-ID = STREET-SEGMENT.Segment-ID
• SELECT Street-Name
• FROM PARCEL_SEGMENT, STREET-SEGMENT, STREET
• WHERE Parcel-ID = 345
• AND PARCEL-SEGMENT.Segment-ID = STREET-SEGMENT.Segment-ID
• AND STREET-SEGMENT.Street-ID = STREET.Street-ID