Rada Bogdan
Rada Bogdan

Reputation: 352

Convert a single point to a polygon

I want to convert a single point for which I know only longtitude and latitude to a polygon that I could show on Google Maps. It's required to have only 30 meters around the given point.

I am using Postgis and I have tried to create the polygon like this:

select ST_Transform(ST_Expand(ST_Transform(geo::geometry, _ST_BestSRID(geo)), 1, 1), 4326) 

from

ST_Centroid(ST_SetSRID(ST_MakePoint(?, ?), 4326)) as geo

I am using Ruby and I am replacing the ? Signs with the longitude and latitude.

This gives me a polygon but it's too big. I honestly have no idea how to make it smaller so there is only 30 meters around it.

I would appreciate any help.

Upvotes: 0

Views: 703

Answers (1)

JGH
JGH

Reputation: 17836

You could use the buffer function on a geography. It would use the proper coordinate system automatically to approximate the buffer size in meters, and the output would be a circle, not a square:

Select ST_Buffer(ST_SetSRID(ST_MakePoint(?, ?), 4326)::geography, 30);

Upvotes: 1

Related Questions