Title: | 2D Cartesian Coordinate Transformation |
---|---|
Description: | Applies affine and similarity transformations on vector spatial data (sp objects). Transformations can be defined from control points or directly from parameters. If redundant control points are provided Least Squares is applied allowing to obtain residuals and RMSE. |
Authors: | German Carrillo |
Maintainer: | German Carrillo <[email protected]> |
License: | GPL (>= 2) |
Version: | 1.1.3 |
Built: | 2024-11-16 02:47:33 UTC |
Source: | https://github.com/gacarrillor/vec2dtransf |
This package provides classes for defining and applying both affine and similarity transformations on vector spatial data (sp objects). Transformations can be defined from control points or directly from parameters. If redundant control points are provided Least Squares is applied allowing to obtain residuals and RMSE.
This package helps to define a transformation object (either similarity or affine) from control points or directly from parameters. Similarity transformations can rotate, shift and scale geometries whereas affine transformations can rotate, shift, scale (even applying different factors on each axis) and skew geometries.
If control points are provided, the 'calculateParameters' method must be used in order to calculate the transformation parameters. If there are more control points than required (2 for similarity and 3 for affine) Least Squares is applied and therefore residuals as well as Root Mean Square Error (RMSE) are available via 'getResiduals' and 'getRMSE' methods. Parameters can always be accessed via 'getParameters' method.
Once parameters are known, sp objects can be transformed by usign the 'applyTransformation' method. Supported sp objects are SpatialPoints, SpatialPointsDataFrame, SpatialLines, SpatialLinesDataFrame, SpatialPolygons and SpatialPolygonsDataFrame.
Additionally, the method 'plotGridTransformation' can plot a grid of points to see the effect of the transformation on a given extent.
German Carrillo (http://geotux.tuxfamily.org)
Maintainer: German Carrillo <[email protected]>
Iliffe, J. and Lott, R. Datums and map projections: For remote sensing,
GIS and surveying. Section 4.5. pp.109-117,135-137, 2008.
UC Davis Soil Resource Laboratory. Case Study: Fixing Bad TIGER Line data
with R and PostGIS.
<URL: http://casoilresource.lawr.ucdavis.edu/drupal/node/433>
Knippers, R. 2D Cartesian coordinate transformations. 2009.
<URL: http://kartoweb.itc.nl/geometrics/Coordinate%20transformations/coordtrans.html>
Pebesma, E. and Bivand, R. sp package:
<URL: http://cran.r-project.org/web/packages/sp/index.html>
Creates objects of class AffineTransformation from control points or directly from parameters
AffineTransformation(controlPoints = data.frame(), parameters = numeric())
AffineTransformation(controlPoints = data.frame(), parameters = numeric())
controlPoints |
data.frame containing control point coordinates arranged in four (4) columns: X source, Y source, X target, Y target. |
parameters |
A vector of six (6) parameters for representing the
transformation, namely: a, b, c, d, e and f, where |
Both controlPoints and parameters are optional, but one has to be given. In the case of the latter, the name of the argument has to be specified, e.g., AffineTransformation(parameters=c(1,2,3,4,5,6))
Object of the class AffineTransformation
German Carrillo
at <- AffineTransformation(parameters=c(1,2,3,4,5,6))
at <- AffineTransformation(parameters=c(1,2,3,4,5,6))
Class to define affine transformations to be applied on sp objects. Affine transformations can rotate, shift, scale (even applying different factors on each axis) and skew geometries.
Objects can be created by calls to the function AffineTransformation.
controlPoints
:Object of class "data.frame"
containing
control point coordinates arranged in four (4) columns: X source,
Y source, X target, Y target.
parameters
:Object of class "numeric"
. A vector of six
(6) parameters for representing the transformation, namely: a, b, c, d,
e and f, where
x' = ax + by + c
y' = dx + ey + f
residuals
:Object of class "matrix"
. Only set if Least
Squares is applied, i.e., if more than three (3) control points were
provided. Residuals are the difference between transformed source
coordinates and target coordinates of control points.
rmse
:Object of class "numericOrNULL"
. Only set if
Least Squares is applied, i.e., if more than three (3) control points
were provided. Root Mean Square Error, useful when comparing two
transformations. It measures the general deviation of transformed source
coordinates with respect to target coordinates of control points. It has
the same units as the coordinates, usually meters.
Class "Cartesian2DCoordinateTransformation"
, directly.
signature(object = "AffineTransformation")
:
Calculate transformation parameters from control points.
German Carrillo
Iliffe, J. and Lott, R. Datums and map projections: For remote sensing, GIS and surveying. Section 4.5.4. pp.115-117, 2008.
showClass("AffineTransformation")
showClass("AffineTransformation")
The main functionality of this package. Applies the transformation to an sp object, which can have geometry type point, line or polygon and can have an associated data.frame.
applyTransformation(object, sp.object)
applyTransformation(object, sp.object)
object |
Object of the class SimilarityTransformation or AffineTransformation |
sp.object |
An object of type: SpatialPoints, SpatialPointsDataFrame, SpatialLines, SpatialLinesDataFrame, SpatialPolygons or SpatialPolygonsDataFrame |
The transformation only affects sp object geometries. Attributes, IDs and other sp object characteristics are preserved.
The transformation can only be applied either on projected spatial data or on spatial data with unknown projection information. Geographic data cannot be transformed due to the nature of the methods (2D Cartesian).
A transformed sp.object
German Carrillo
Pebesma, E. and Bivand, R. sp package:
<URL: http://cran.r-project.org/web/packages/sp/index.html>
sp
, calculateParameters
, SimilarityTransformation-class
, AffineTransformation-class
# From the sp examples: x <- c(1,1,1,2,2,2,3,3,3) y <- c(1,2,3,1,2,3,1,2,3) xy <- cbind(x,y) S <- SpatialPoints(xy) st=SimilarityTransformation(parameters=c(1,0,0.2,-0.2)) trS <- applyTransformation(st, S) trS # Transformed sp object, have a look at the coordinates
# From the sp examples: x <- c(1,1,1,2,2,2,3,3,3) y <- c(1,2,3,1,2,3,1,2,3) xy <- cbind(x,y) S <- SpatialPoints(xy) st=SimilarityTransformation(parameters=c(1,0,0.2,-0.2)) trS <- applyTransformation(st, S) trS # Transformed sp object, have a look at the coordinates
Calculates transformation parameters from control points
calculateParameters(object)
calculateParameters(object)
object |
Object of the class SimilarityTransformation or AffineTransformation |
If control points are provided, the 'calculateParameters' method must be used in order to calculate the transformation parameters. If there are more control points than required (2 for similarity and 3 for affine) Least Squares is applied and therefore residuals as well as Root Mean Square Error (RMSE) are available via 'getResiduals' and 'getRMSE' methods. Parameters can always be accessed via 'getParameters' method.
Modifies the original object
German Carrillo
Iliffe, J. and Lott, R. Datums and map projections: For remote sensing, GIS and surveying. Section 4.5. pp.109-117, 2008.
UC Davis Soil Resource Laboratory. Case Study: Fixing Bad TIGER Line data with R and PostGIS. <URL: http://casoilresource.lawr.ucdavis.edu/drupal/node/433>
SimilarityTransformation
, AffineTransformation
,
getResiduals
, getRMSE
,
getParameters
data(control.points) at <- AffineTransformation(control.points[2:5]) getParameters(at) # Still unknown calculateParameters(at) getParameters(at) # Now there are parameters!
data(control.points) at <- AffineTransformation(control.points[2:5]) getParameters(at) # Still unknown calculateParameters(at) getParameters(at) # Now there are parameters!
Virtual base class for cartesian 2D coordinate transformations such as similarity and affine. Please read the section 'See Also' for further documentation on slots and methods.
A virtual Class: No objects may be created from it.
German Carrillo
SimilarityTransformation-class
,
AffineTransformation-class
This data.frame contains control points for defining a 2D cartesian coordinate transformation. The control points are in both the source and target coordinates.
data(control.points)
data(control.points)
A data.frame consisting on 16 control points with ID, coordinates X and Y from the source dataset and coordinates X and Y from the target dataset.
Retrieves the transformation parameters
getParameters(object)
getParameters(object)
object |
Object of the class SimilarityTransformation or AffineTransformation |
If the transformation object was initialized with control points, parameters can be retreived only after calling the method 'calculateParameters'.
A numeric vector with the transformation parameters.
German Carrillo
Iliffe, J. and Lott, R. Datums and map projections: For remote sensing, GIS and surveying. Section 4.9.3-4. pp.135-137, 2008.
SimilarityTransformation-class
AffineTransformation-class
# From parameters, similarity transformation st <- SimilarityTransformation(parameters=c(1,2,3,4)) getParameters(st) # From parameters, affine transformation at <- AffineTransformation(parameters=c(1,2,3,4,5,6)) getParameters(at) # From control points, affine transformation data(control.points) at2 <- AffineTransformation(control.points[2:5]) getParameters(at2) # Still unknown parameters calculateParameters(at2) getParameters(at2)
# From parameters, similarity transformation st <- SimilarityTransformation(parameters=c(1,2,3,4)) getParameters(st) # From parameters, affine transformation at <- AffineTransformation(parameters=c(1,2,3,4,5,6)) getParameters(at) # From control points, affine transformation data(control.points) at2 <- AffineTransformation(control.points[2:5]) getParameters(at2) # Still unknown parameters calculateParameters(at2) getParameters(at2)
Retrieves the residuals if redundant control points were provided when creating the transformation object
getResiduals(object)
getResiduals(object)
object |
Object of the class SimilarityTransformation or AffineTransformation |
Residuals are determined only if Least Squares is applied, i.e., if more than the required control points were provided. Residuals are the difference between transformed source coordinates and target coordinates of control points.
2-column matrix with coordinate differences
German Carrillo
Iliffe, J. and Lott, R. Datums and map projections: For remote sensing, GIS and surveying. Section 4.9.3-4. pp.135-137, 2008.
SimilarityTransformation-class
AffineTransformation-class
data(control.points) at <- AffineTransformation(control.points[2:5]) calculateParameters(at) getResiduals(at)
data(control.points) at <- AffineTransformation(control.points[2:5]) calculateParameters(at) getResiduals(at)
Retrieves the Root Mean Square Error (RMSE) if redundant control points were provided when creating the transformation object
getRMSE(object)
getRMSE(object)
object |
Object of the class SimilarityTransformation or AffineTransformation |
RMSE is determined only if Least Squares is applied, i.e., if more than the required control points were provided. The RMSE is useful when comparing two transformations. It measures the general deviation of transformed source coordinates with respect to target coordinates of control points. It has the same units as the coordinates, usually meters.
A number representing the RMSE
German Carrillo
SimilarityTransformation-class
,
AffineTransformation-class
data(control.points) at <- AffineTransformation(control.points[2:5]) calculateParameters(at) getRMSE(at)
data(control.points) at <- AffineTransformation(control.points[2:5]) calculateParameters(at) getRMSE(at)
Plots a grid transformed to visualize the effects of the transformation on a given extent
plotGridTransformation(object, bbox, numberOfPoints)
plotGridTransformation(object, bbox, numberOfPoints)
object |
Object of the class SimilarityTransformation or AffineTransformation |
bbox |
An SP bbox object, i.e. a 2x2 matrix with coordinates |
numberOfPoints |
Number of points to represent the grid, perfect squares are recommended. |
The grid is made out of points over the extent defined by bbox. If numberOfPoints has not an integer square root the grid will contain less points.
The grid is transformed using the transformation parameters and displayed over the source grid to see the effects of the transformation.
The source grid is drawn in red whereas the transformed one is green.
This code is based on "Case Study: Fixing Bad TIGER Line data with R and PostGIS" (See References).
German Carrillo
UC Davis Soil Resource Laboratory. Case Study: Fixing Bad TIGER Line data with R and PostGIS. <URL: http://casoilresource.lawr.ucdavis.edu/drupal/node/433>
# From the sp examples: x <- c(1,1,1,2,2,2,3,3,3) y <- c(1,2,3,1,2,3,1,2,3) xy <- cbind(x,y) S <- SpatialPoints(xy) st=SimilarityTransformation(parameters=c(1,0,0.2,-0.2)) plotGridTransformation(st, bbox(S), 25)
# From the sp examples: x <- c(1,1,1,2,2,2,3,3,3) y <- c(1,2,3,1,2,3,1,2,3) xy <- cbind(x,y) S <- SpatialPoints(xy) st=SimilarityTransformation(parameters=c(1,0,0.2,-0.2)) plotGridTransformation(st, bbox(S), 25)
Creates objects of class SimilarityTransformation from control points or directly from parameters
SimilarityTransformation(controlPoints = data.frame(), parameters = numeric())
SimilarityTransformation(controlPoints = data.frame(), parameters = numeric())
controlPoints |
data.frame containing control point coordinates arranged in four (4) columns: X source, Y source, X target, Y target. |
parameters |
A vector of four (4) parameters for representing the
transformation, namely: a, b, c and d, where |
Both controlPoints and parameters are optional, but one has to be given. In the case of the latter, the name of the argument has to be specified, e.g., SimilarityTransformation(parameters=c(1,2,3,4))
Object of the class SimilarityTransformation
German Carrillo
SimilarityTransformation-class
st <- SimilarityTransformation(parameters=c(1,2,3,4))
st <- SimilarityTransformation(parameters=c(1,2,3,4))
Class to define similarity transformations to be applied on sp objects. Similarity transformations can rotate, shift and scale geometries.
Objects can be created by calls to the function SimilarityTransformation.
controlPoints
:Object of class "data.frame"
containing
control point coordinates arranged in four (4) columns: X source,
Y source, X target, Y target.
parameters
:Object of class "numeric"
. A vector of four
(4) parameters for representing the transformation, namely: a, b, c and
d, where
x' = ax + by + c
y' = ay - bx + d
residuals
:Object of class "matrix"
. Only set if Least
Squares is applied, i.e., if more than two (2) control points were
provided. Residuals are the difference between transformed source
coordinates and target coordinates of control points.
rmse
:Object of class "numericOrNULL"
. Only set if
Least Squares is applied, i.e., if more than two (2) control points were
provided. Root Mean Square Error, useful when comparing two
transformations. It measures the general deviation of transformed source
coordinates with respect to target coordinates of control points. It has
the same units as the coordinates, usually meters.
Class "Cartesian2DCoordinateTransformation"
, directly.
signature(object = "SimilarityTransformation")
:
Calculate
transformation parameters from control points.
German Carrillo
Iliffe, J. and Lott, R. Datums and map projections: For remote sensing, GIS and surveying. Section 4.5.3. pp.113-115, 2008.
showClass("SimilarityTransformation")
showClass("SimilarityTransformation")