Database Reference
In-Depth Information
Rotating geometries
Among the many functions that PostGIS provides, geometry manipulation is a very
powerful addition. In this recipe, we will explore a simple example of using the
ST_Rotate
functiontorotategeometries.Wewilluseafunctionfromthe
Improving
proximity filtering with KNN - advanced
recipe to calculate our rotation values.
Getting ready
ST_Rotate
hasafewvariants:
ST_RotateX
,
ST_RotateY
,and
ST_RotateZ
,with
the
ST_Rotate
function serving as an alias for
ST_RotateZ
. Thus, for two-dimen-
sional cases,
ST_Rotate
is a typical use case.
In the
Improving proximity filtering with KNN - advanced
recipe, our function calcu-
latedtheangletothenearestroadfromabuilding'scentroidoraddresspoint.Wecan
symbolize that building's point according to that rotation factor as a square symbol
but,moreinterestingly,wecanexplicitlybuildtheareaofthatfootprintinrealspace
and rotate it to match our calculated rotation angle.
How to do it...
Recallourfunctionfromthe
Improving proximity filtering with KNN - advanced
recipe:
CREATE OR REPLACE FUNCTION chp04.angle_to_street
(geometry) RETURNS double precision AS $$
WITH index_query as
(SELECT
ST_Distance($1,road.the_geom) as dist,
degrees(ST_Azimuth($1,
ST_ClosestPoint(road.the_geom, $1))) as azimuth
FROM chp04.knn_streets As road
ORDER BY $1 <#> road.the_geom
limit 5)