[postgis-devel] GeomRound and GeomTrunc functions

strk strk at keybit.net
Fri Jul 2 03:32:11 PDT 2004


On Fri, Jul 02, 2004 at 11:52:21AM +0200, Gino Lucrezi wrote:
> > - Since the inspiration come from ROUND and TRUNC
> >  what about using ROUND and TRUNC instead of
> >  GEOM_ROUND and GEOM_TRUNC for function names ?
> 
> geom_round is the 'internal' C name, the name a PostGIS user sees is GeomRound.
> Indeed, I could have called them this way, PostgreSQL overloading allows it. 
> 
> > - Insipiring functions work on 1-dimensional types
> >  what about making Geometry functions take in
> >  consideration 2 and 3 dimensions ? Do you see
> >  any use of rounding with different values the 3 
> >  dimensions ?
> 
> I didn't think of it. It could be useful in some cases, especially for the Z axis.
> 
> Anyway, it started as something I needed, but it can be improved. Maybe, if you just specify 1 number of digits it will apply to all, if you specify 3 they will be used for x, y and z respectively.
> 
> > - Doesn't SQL provide casting toward numeric data ?
> >  Have you tried defining your funx as taking int2 and
> >  see if postgresql will convert numeric values to int2 ?
> 
> I tried, and it didn't do it automatically.
> If it is defined as FUNCTION GeomRound(geometry, int2) then I have to call it as GeomRound( the_geom, 1::int2 ) which isn't nice.

Maybe if you define the function as taking numeric instead of int2
you'll get all casts for free (I don't think you'll loose much performance)

> 
> > - How would rounding simplify display of geoms ?
> 
> I frequently inspect the geometries as psql will report them.
> 
> Removing needless digits saves space on my monitor and paper when I print them.
> 
> When I display them on a map there is no change, obviously. Maybe I should have used a different verb than "display" :-)
> 
> Gino Lucrezi

Oh, ok. You have no use for  x/y/z differentiation then.

What I've implemented is a generic grid application function.
You specify grid origin and size (x/y only currently).
What you need would be obtained using 10^(-<numdigits>) as grid
size and 0,0 as grid origin. I did not include it into the
distribution because it would need a review for generality
(e.g. the grid origin might be useless, the name might need
 a change [apply-grid], and it might support z as well)

If you want to support its inclusion please give it a try.
You can find it here: http://foo.keybit.net/~strk/apply_grid

--strk;


> Penta Consulting Services Srl
> 



More information about the postgis-devel mailing list