Split geometry based on postgis function - postgresql

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;

Related

Proper storage of a uniform, XYZ plane, in Postgres PostGIS

Problem Statement:
Consider a gray scale image taken of a plane. Each pixel is an intensity value (Z).
I have the position in physical space of the top left most pixel. I also have the offset of each X and Y pixel from left to right (X), and up to down (Y). Consider the image to be perfectly non-distorted, so the offset is uniform for every row.
I would like to store these image in a POSTGIS database in a way that allows the user to query a polygon from an image.
Current Implementation:
Currently I believe I am doing something stupid, I create a Multipoint geometry and store each point with ( X Y Z ) using python. Since the image is uniform, I am repeating lots of data (x and y for each point), but this works when querying the database for a polygon, but is an excessive amount of extra data.
Question:
What is the best way to store such data and allow the user to query
a polygon from the image?
Is PostGIS Geometry the correct datatype?
Is the multipoint approach reasonable?

Generate geometries from each intersection and apply aggregation to row

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.

extracting co-ordinates from table and analyzing them

I am working on spatiotemporal data which includes date time and geom columns.
I have extracted x& y co-ordinate but want to find centroid of certain attribute but was not able to do so.
Any ideas?

Storing areas and centers for polygons with postgresql

I have a table containing polygons that I will want to search by areas and centers. There are postgresql methods that calculate the area and centers of polygons, but as I intend to search on them, should I be writing the data to the table to prevent calculation and speed up searches, or would the data be redundant?

creating a polygon from points around a point in postgis

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)