[postgis-users] Newbie questions: SRIDs, function return values
David William Bitner
david.bitner at gmail.com
Thu May 15 12:48:36 PDT 2008
This is where a slightly less easy to use implementation that I put in the
PostGIS Wiki as a PL/PGSQL function presents a slightly more robust approach
to the problem. The use of this function simply returns the UTM SRID for
the appropriate zone for a point that you pass in (note: this could be
expanded to be center of extent or whatever pretty easily). So the use of
this would be:
select blah from a,b where
st_dwithin(transform(a.the_geom,utmzone(a.the_geom)),transform(b.the_geom,utmzone(a.the_geom)),100);
While being quite a bit more verbose, at least this approach holds the zone
constant. Granted it is still rife with the problem of geometries being a
distance similar to the size of a UTM zone or more apart or sizes similar to
UTM zones, but it at least holds to one zone per comparison.
David
CREATE OR REPLACE FUNCTION utmzone(geometry) RETURNS integer AS $BODY$
declare geomgeog geometry; zone int; pref int; begin
geomgeog:=transform($1,4326); if (y(geomgeog))>0 then pref:=32600;
else pref:=32700; end if;
zone:=floor((x(geomgeog)+180)/6)+1; return zone+pref; end; $BODY$
LANGUAGE 'plpgsql' immutable;
On Thu, May 15, 2008 at 9:57 AM, Paul Ramsey <pramsey at cleverelephant.ca>
wrote:
> The danger of this approach is that it falls apart as people start
> pushing the limits...
>
> select blah from a, b where st_dwithin(st_utm(a.geom),st_utm(b.goem),100)
>
> It's a pandora's box... as are all things geodetic
>
> p
>
> On Thu, May 15, 2008 at 7:45 AM, Markus Schaber <schabi at logix-tt.com>
> wrote:
> > Hi, Paul,
> >
> > "Paul Ramsey" <pramsey at cleverelephant.ca> wrote:
> >
> >> There's no universal answer to this, but I have long thought that a
> >> simple answer suitable for may people would be a ST_UTM(geom) wrapper
> >> on transform that picks the appropriate UTM zone for a given geometry.
> >> It would work perfectly well for any collection of small objects. It
> >> would fall apart for larger things like states and countries that are
> >> of similar size to a UTM zone.
> >
> > The function could simply use the centroid of the bounding box, that
> > shoul be fast enough.
> >
> >
> > Regards,
> > Markus
> >
> > --
> > Markus Schaber | Logical Tracking&Tracing International AG
> > Dipl. Inf. | Software Development GIS
> >
> > Fight against software patents in Europe! www.ffii.org
> > www.nosoftwarepatents.org
> > _______________________________________________
> > postgis-users mailing list
> > postgis-users at postgis.refractions.net
> > http://postgis.refractions.net/mailman/listinfo/postgis-users
> >
> _______________________________________________
> postgis-users mailing list
> postgis-users at postgis.refractions.net
> http://postgis.refractions.net/mailman/listinfo/postgis-users
>
--
************************************
David William Bitner
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20080515/7cca8755/attachment.html>
More information about the postgis-users
mailing list