12

I have table with column name,Latitude and Longitude.I want to update this with polygon name and its centroid latitude longitude.I know there is a function in postgis st_centroid(geometry). But I want to enter x value and Y value in a separate column.How can I do this?

  • You want to write x and y of the centroid into new columns/attributes? – underdark Sep 24 '12 at 6:45
  • Yes, I have latitude and longitude columns.But St_centroid returns lat long value in a single column – Sreesha Sep 24 '12 at 6:52
19

Try:

UPDATE polygon_layer SET longitude=ST_X(ST_Centroid(geom)), Latitude=ST_Y(ST_Centroid(geom));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.