英文:
Postgres: how to use query in ST_TRANSLATE
问题
I can provide a translation of the code-related content:
我想要将ST_TRANSLATE函数应用于由以下SQL语句组成的几何图形:
select st_astext(geom) from pieces where name='Large1'
然而,显然这是不可能的,但我不明白为什么,因为前面查询的结果是`TRIANGLE((0 0,0.707106781186548 0,0 0.707106781186548,0 0))`,所以像这样做应该有效:
select st_asewkt(
st_translate(
select st_asewkt(
st_rotate(geom, -pi(), st_centroid(geom)))
from (
select (
select st_astext(geom)
from pieces where name='Large1') :: geometry as geom) as foo,
0.707106781, 1.207106781)) as g;
但实际上并不起作用。我得到的错误是:
`LINE 1: select st_asewkt(st_translate(st_astext(select st_astext(geo...`
这似乎表明我不能在ST_Translate中使用查询。我该如何解决这个问题?
Please note that this is a translation of the code-related content only, as you requested. If you have any specific questions or need further assistance, please feel free to ask.
英文:
I want to give the ST_TRANSLATE function a geometry composed by
select st_astext(geom) from pieces where name='Large1'
This is apparently not possible though, but I do not understand why since the result of the previous query is TRIANGLE((0 0,0.707106781186548 0,0 0.707106781186548,0 0))
so, doing something like:
select st_asewkt(
st_translate(
select st_asewkt(
st_rotate(geom, -pi(), st_centroid(geom)))
from (
select (
select st_astext(geom)
from pieces where name='Large1') :: geometry as geom) as foo,
0.707106781, 1.207106781)) as g;
should work, but it doesn't. The error I get is:
LINE 1: select st_asewkt(st_translate(st_astext(select st_astext(geo...
which gives the impression that I cannot use a query in ST_Translate.
How should I do this?
答案1
得分: 0
你需要在内部选择语句周围添加额外的括号:
SELECT st_translate((select ...), 0.707106781, 1.207106781);
话虽如此,你也可以直接使用几何图形进行操作,无需在几何图形和文本之间来回转换。
你还可以跳过所有子查询:
SELECT st_asewkt(
st_translate(
st_rotate(geom, -pi(), st_centroid(geom)),
0.707106781, 1.207106781))
FROM pieces
WHERE name='Large1';
英文:
You would have to add an extra set of parentheses around the inner select(s)
SELECT st_translate((select ...),0.707106781, 1.207106781);
That being said, you could also work with geometries directly, there is no need to go back and forth between geometry and text.
You can also skip all the subqueries:
select st_asewkt(
st_translate(
st_rotate(geom, -pi(), st_centroid(geom)),
0.707106781, 1.207106781))
from pieces
where name='Large1';
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论