I have a postgresql db using postgis 2.0 and a table of thousands of points, I would like create a polygon of the furthest points originating around a particular central location.
I haven't got a clue how this would be done, any ideas anyone??
Filter and aggregate the points, and return the convex hull of the points.
So to select the points in mytable that are within a distance of 10 from id=123, and return the enclosing polygon:
SELECT ST_ConvexHull(ST_Collect(A.geom))
FROM mytable A, mytable B
WHERE B.id=123 AND ST_DWithin(A.geom, B.geom, 10)
Related
I have a big geometry of a region or country which I want to split. The output should be 10 splitted geometries of one big geometry based on ST_MEMSIZE function of postgis.
For e.g. If threshold of geometry has MEMSIZE 100 and the threshold is 10 then the new table should have 10 splitted geometries. Not sure if a query would do it or if there is postgis function that could do it.
Table
New_Table
and so on.
The result of the below query doesn't show the complete geometry as shown in the image.
select st_subdivide(geom, 200) from regions where region = 'R';
A vertex is 16 bytes. You can then compute how many vertices you need per region and use st_subdivide. The number of regions will however depends on your data complexity and you may have some large region with just 5 vertices surrounded by small polygons with many vertices.
PS: replace 10000 by your threshold
select id,
st_subdivide(geom, floor(st_memsize(geom)/10000/16)::int)
from mylayer;
I have a point column in my PostgreSQL table. Is there a way to extract point's X/Y coordinates separately? I operate with native PostgreSQL data, not PostGIS.
The documentation tells you:
It is possible to access the two component numbers of a point as though the point were an array with indexes 0 and 1. For example, if t.p is a point column then SELECT p[0] FROM t retrieves the X coordinate and UPDATE t SET p[1] = ... changes the Y coordinate.
I'm learning postgis and saw that there is ST_MakeEnvelope to which I can pass my bounding box coordinates:
ST_MakeEnvelope(${params.swLng},${params.swLat},${params.neLng},${params.neLat}, 4326)
However, is there a way to get the results that are closest to the center of the bounding box? Is it possible to combine the bounding box with a radius query?
You can order by distance between your geometries and the centroid of the envelope
SELECT *
FROM myTable
WHERE st_intersects(geom, ST_makeEnvelope(...))
ORDER BY geom <-> st_centroid(ST_makeEnvelope(...))
I'm trying to figure out how to use PostGIS (since I have my polygons stored there already) to generate a set of nonoverlapping polygons.
The source table has two columns (geometry and occurences), geometry is always a valid polygon, occurences is an integer.
The polygons in the table can overlap. For all the overlapping regions (there can generally be more than 2 intersecting polygons) I would like to generate a new polygon (as with ST_Intersection) AND apply an aggregation to the occurences column (MIN/MAX/AVG would be enough)
I can find pairs of overlaps by using ST_Intersects and handle the pairs, but I have trouble reducing multiple intersections.
In the following example, the 3 source rows would actually end up being 7 separate polygons (imagine the circle is actually a POLYGON geometry), the occurences then would be averaged from all interesecting polygons in each case.
I have a function that performs a transform on points.
I've figured out how to convert a polygon into a set of points and transform each point with a custom function I wrote. But I can't figure out how to now convert the points back into a polygon.
Here's my code that returns an array of transformed points. How do I get a polygon from this?
SELECT array_agg(point_geotransform(point((dp).geom))) As p
FROM (SELECT ST_DumpPoints(polygon(circle('((0,0),10)'))::geometry) AS dp
) t;
Ps. If there is a more efficient way of extracting the points, I'd love to know.
This works (excluded the transform so others can see it works):
SELECT polygon(circle('((0,0),10)')) p
UNION ALL
SELECT ST_MakePolygon(ST_MakeLine((point((dp).geom))::geometry))::polygon p
FROM (SELECT ST_DumpPoints(polygon(circle('((0,0),10)'))::geometry) AS dp
) t;
Geometry must be converted to geometry and polygon to polygon, so to speak.