I have a Spatial query that combines multiple tables in a postgis database. The individual tables consist of millions of records so breaking each one down with a spatial query vastly improves speed of execution. I have listed only the first part of the query here below: (there are three more join tables)
SELECT m.fid, m.featurecode, m.polygon, m.physicallevel, m.make, z.descriptivegroup, y.descriptivterm, x.theme
FROM
topographicarea as m
LEFT JOIN
(SELECT a.fid, array_to_string(array_agg(c.theme), ','::text) as theme
FROM topographicarea as a, topoarea_theme as c
WHERE a.primary_key=c.fkey_topographicarea
AND a.polygon && ST_MakeEnvelope ( 245850, 642853, 245871, 642917, 27700 )
group by a.fid) as x
ON m.fid=x.fid
LEFT JOIN
(SELECT a.fid, array_to_string(array_agg(b.descriptiveterm), ','::text) as descriptiveterm
FROM topographicarea as a, topoarea_descriptiveterm as b
WHERE a.primary_key = b.fkey_topographicarea
AND a.polygon && ST_MakeEnvelope ( 245850, 642853, 245871, 642917, 27700 )
Questions
(1) How can I pass this query back to postgres every time the project is run so that the features extracted by this query are my source data?
(2) I want to pass in the bounding box (minx, miny, maxx, maxy) so that I can run the project from the command line:
$ fme project.fmw
--DestDataset c:\\data\\test.dwg
--MINX "245850"
--MINY "642853"
--MAXX "245871"
--MAXY "642917"
So that when the project is run the ST_MakEnvelope () part of the sql can be replace with the values I pass in at runtime e.g:
ST_MakeEnvelope ( $(MINX). $,(MINY), $(MAXX), $(MAXY), 27700)
Any help much appreciated!!!
Mike