One of the new features coming in PostGIS 3.1 is fixed precision support.
This new feature will require compilation with not yet released GEOS 3.9.
There are a couple of functions already in PostGIS 3.1 that have this new feature -- they are ST_Subdivide, ST_Union, ST_SymDifference, ST_Union, and ST_UnaryUnion as summarized in
What's new in PostGIS 3.1.
To take advantage of these new to die for features, you'll need to have compiled your PostGIS with development GEOS 3.9 which is planned for release
around the same time we get around to releasing PostGIS 3.1. Windows users can download binaries with GEOS 3.9 support from
PostGIS windows experimental binaries
The ST_Union feature should improve a lot of cases where people ran into topological exceptions. Perhaps I'll demonstrate that in a separate article once I've given it a test drive.
For a first glimpse, let's look at how fixed precision support affects ST_Subdivide function.
In PostGIS 3.1, if you are running GEOS 3.9, you will have at your disposal an additional argument called gridsize
I'll give you a quick demonstration of how this works by chopping up my lovely state of Massachusetts which is part of Census state boundary file
Census state boundaries
Original Geometry looks like this:
SELECT geom
FROM states
WHERE stusps = 'MA';
Double-precision subdivide
The old way, using double-precision coordinate system - this will yield 39 numbered rows:
SELECT f.ord, f.sd_geom
FROM states,
ST_Subdivide(states.geom, 300) WITH ORDINALITY AS f(sd_geom,ord)
WHERE stusps = 'MA';
and looks like this:
Fixed Precision Subdivide
Now let's try this using a fixed scale precision of 0.001 degrees. As with most things PostGIS the units of the gridsize is in the units of your spatial reference system.
In this case we have NAD 83 long/lat, so we are setting the fixed precision to 0.001 degrees.
SELECT f.ord, f.sd_geom
FROM states ,
ST_Subdivide(states.geom, 300,0.001) WITH ORDINALITY AS f(sd_geom,ord)
WHERE stusps = 'MA';
and looks like this
The result is we end up with 10 rows instead of 39. You might be able to make out the edges are a bit smoother than the earlier image. This is because in a fixed precision, when the geometry is overlaid on the fixed grid the points smaller than a gridsize apart become
one resulting in fewer points thus longer stretch of area before you hit a 300 subdivide point threshold and also a smoother image.
As you increase the grid size, you'll get a more pixelated result. Here we ramp up our grid size to 0.1 degrees and end up with PacMan fidelity.
The result is 2 rows of very pixelated geometries.
SELECT f.ord, f.sd_geom
FROM states,
ST_Subdivide(states.geom, 300,0.1) WITH ORDINALITY AS f(sd_geom,ord)
WHERE stusps = 'MA';
and looks like this