Monday, 5 February 2018

Creating circle in PostGIS?


I'm using PostGIS 1.5.2, with geometries in SRID:900913. I need create a circles using a list of points as centre, with a radius of 600 kilometers. I'm using this query:


INSERT INTO circles (geom) (
SELECT ST_Buffer(point, 600000, 'quad_segs=8')
FROM points
);


But circles created have not 600 kilometers of radius (radius is near this length, but not exactly).


Are there other methods to create circles in PostGIS?


NOTE: Information represented is from Spain. Correct projection is 4326, but client use Google rasters, so I am storing data in 900913 to avoid reprojections and increase performance.



Answer



Try this:


 SELECT ST_Transform(geometry( 
ST_Buffer(geography(
ST_Transform( point, 4326 )),
600000)),
900913) FROM points`


This flips into geography then uses the inbuilt SRID selection to (ironically) flip back into geometry where a good planar buffer is run then flips back. The trouble with your approach in Mercator is that Mercator doesn't preserve distance. Using a more appropriate local projection gives better results, and that is what happens in the above method.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...