I'm trying to build a PostGIS query that uses an alias of the JOIN statement in the FROM statement, but that is not possible. Is there another way to do it?
SELECT DISTINCT
ST_Buffer(
ST_Centroid(geom),
ST_Area(geom))
FROM building AS b, ST_Transform(sg.geometry, 31467) AS geom
LEFT JOIN surface_geometry AS sg ON b.id = sg.cityobject_id WHERE ST_Area(geom) < 100
You can introduce an extra level of subquery.
So currently you have:
SELECT DISTINCT ST_Buffer( ST_Centroid(geom), ST_Area(geom) )
FROM building AS b,
ST_Transform(sg.geometry, 31467) AS geom
LEFT JOIN surface_geometry AS sg ON b.id = sg.cityobject_id
WHERE ST_Area(geom) < 100
(I changed the indentation to make a bit more sense of it, although I still don't understand it: you don't seem to use the values from b anywhere). You need something like:
SELECT DISTINCT ST_Buffer( ST_Centroid(geom), ST_Area(geom) )
FROM (
SELECT ST_Transform(sg.geometry, 31467) AS geom
FROM building AS b
LEFT JOIN surface_geometry AS sg ON b.id = sg.cityobject_id
) x
WHERE ST_Area(geom) < 100
Why would you not try:
SELECT DISTINCT
ST_Buffer(ST_Centroid(ST_Transform(sg.geometry, 31467),
ST_Area(ST_Transform(sg.geometry, 31467)))
FROM building b LEFT JOIN surface_geometry sg ON (b.id = sg.cityobject_id)
WHERE ST_Area(ST_Transform(sg.geometry, 31467)) < 100;
It is also possible that this might work:
SELECT DISTINCT
ST_Buffer(ST_Centroid(geom), ST_Area(geom))
FROM building b LEFT JOIN surface_geometry sg ON (b.id = sg.cityobject_id) INNER JOIN
ST_Transform(surface_geometry.geometry, 31467) geom ON (ST_Area(geom) < 100);
You might want to verify the placement of () as at the moment I have no place to test it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With