2

I'd like to do some arbitrary rotation of spatial objects in spatialite (accessed through QGIS). In PostGIS I'd use something like:

...
SELECT geom AS ST_Rotate(geom, radians, originX, originY)

Is there an equivalent in spatialite?


Edit: after the answer and some more research, managed to find a way of mimicing ST_Rotate using ShiftCoords and RotateCoords, rotating by 45° around the centroid in the example below:

SELECT ShiftCoords(RotateCoords(ShiftCoords(GEOMETRY, 
 -X(Centroid(GEOMETRY)), -Y(Centroid(GEOMETRY))), 45), 
 X(Centroid(GEOMETRY)), Y(Centroid(GEOMETRY))) AS geom from TABLE
2

There is no direct equivalent, however you should be able to do something similar with a combination of RotateCoords() which rotates the geometry (in degrees, rather than radians), ShiftCoords() and ScaleCoords().

Here is an example, simplified from the test suite:

SELECT AsText(RotateCoords(geom, 0)), AsText(RotateCoords(geom, 90.0)), AsText(RotateCoords(geom, 180.0)), AsText(RotateCoords(geom, -90)) FROM (SELECT GeomFromText("POLYGON((0 0, 1 1, 1 2, -1 1, 0 0))") as geom) dummy;
POLYGON((0 0, 1 1, 1 2, -1 1, 0 0))
POLYGON((0 0, 1 -1, 2 -1, 1 1, 0 0))
POLYGON((0 0, -1 -1, -1 -2, 1 -1, 0 0))
POLYGON((0 0, -1 1, -2 1, -1 -1, 0 0))
  • Thanks - looks like I need to create a custom function that shifts the centroid (or centre of extent) to 0,0, does the rotation, then shifts back. – Simbamangu Aug 12 '14 at 7:09
  • ... except that it turns out there is no way to make custom functions in SQLite. – Simbamangu Aug 12 '14 at 10:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.