Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- REPLACE INTO areahierarki (area,withinArea,dealer,size)
- SELECT
- areas1.id as id,
- areas2.id as withinId,
- res.dealer,
- v_size as size
- FROM
- (SELECT viewable.dealer, Area(Envelope(viewable.poly)) as v_size, Area(Envelope(withinPolys.poly)) as w_size, viewable.area as area1, withinPolys.area as area2 FROM
- (
- SELECT areapolys.*,
- areas.dealer
- FROM main.areapolys
- JOIN areas ON areapolys.area = areas.id
- ) as viewable
- LEFT JOIN areapolys withinPolys ON withinPolys.area != viewable.area
- AND
- (
- (
- Within(viewable.anchor,withinPolys.poly)
- #The containg area should be SIGNIFICANTLY larger to be considered
- AND Area(Envelope(viewable.poly))*10 < Area(Envelope(withinPolys.poly))
- )
- OR
- (
- Within(viewable.poly,withinPolys.poly)
- )
- )
- ) as res
- JOIN areas areas1 ON areas1.id = area1
- LEFT JOIN areas areas2 ON areas2.id = area2
- WHERE areas1.id = 9
- ORDER BY areas2.id IS NOT NULL DESC, w_size ASC
Advertisement
Add Comment
Please, Sign In to add comment