Zifceac Iaroslav
Zifceac Iaroslav

Reputation: 11

Create centroid from field POSTGRESQL

I would like to create a centroid from a field that contains all the points that define a polygon. When apply the query for the coordinates is working but when trying to do the same for the field I get Invalid WKT: Invalid number: polygon (line 1)

My field "coord" contains data like: 46.781231 23.489355,46.785255 23.484876,46.786118 23.485407,46.787913 23.486857, 46.781231 23.489355

This one works :

SELECT  ST_centroid(ST_GeometryFromText('polygon((46.781231 23.489355,46.785255 23.484876,46.786118 23.485407,46.787913 23.486857, 46.781231 23.489355))'));

This one doesn't:

SELECT  ST_centroid(ST_GeometryFromText('polygon((coord))'))
from polygon_data;

Upvotes: 1

Views: 87

Answers (1)

Ondra Žižka
Ondra Žižka

Reputation: 46904

From the comments:

ST_centroid(ST_GeometryFromText('polygon(('||coord||'))'))

Works just perfect.

Upvotes: 0

Related Questions