Wednesday, March 7, 2018

Fixing "Cannot resolve symbol Theme" error in Android Studio

If you have ever encountered unusual "cannot resolve symbol" messages with regards to Android resource XML files (an example is the screenshot below), which cannot be resolved by running Android Studio's Build | Clean Project or Build | Rebuild Project menu commands, then fixing the issue is very simple.

To resolve the problem, click on the Sync Project with Gradle Files icon in Android Studio, as shown in the screenshot below, or select Tools | Android | Sync Project with Gradle Files

Processing files will appear and at the end of it, the error messages no longer appear, as shown below.

Monday, February 26, 2018

Use PDAL to register a point cloud to control points

Sometimes, some 3D LiDAR point cloud data are not at the correct location or they are not aligned with other point clouds. When this happens, at least 3 control points from the point cloud and the reference need to be identified and a transformation matrix (usually a 4x4 homogeneous matrix) be calculated.

Once the matrix has been calculated, PDAL's transformation filter can then be used to perform the registration or transformation of the point cloud to the reference.

While PDAL can apply the transformation, it does not have a tool for calculating the matrix. This has to be done externally. This post uses a simple WebApp calculator at this site to calculate a rigid 4x4 transformation matrix given 2 corresponding sets of 3 or more control points.

Identifying 2 sets of corresponding control points

  1. Using a point cloud viewer such as FugroViewer, identify 3 or more source control points from the unregistered point cloud., e.g. p1, p2, p3 and p4.

  2. Using a GPS receiver or from a database, identify the corresponding points from the destination reference system.

Calculating the 4x4 transformation matrix
  1. Open up url in an Internet browser.
  2. In the Source 3D points field, type or paste in the source control point coordinates from the previous section.

  3. In the Destination 3D points field, type or paste in the corresponding control points from the destination reference system from the previous section.
  4. Click Calculate.

    The 4x4 transformation matrix and root mean square error is calculated.

    Note: if the RMSE is large, then there may be some error in the input coordinates.
  5. Using a text editor, create a PDAL pipeline JSON file which specifies the input, filter, and output. Copy and paste the 4x4 transformation matrix into the matrix field in the JSON file as shown below. Replace the commas with blanks. 
0.21095277662308629 0.9774781497556848 -0.00594918357528593 23238.318780198064 
-0.9774332258657229 0.21100438075203337 0.01007175640974158 30100.055196603218 
0.011100225616467532 0.0036902647131527543 0.9999315811282344 32.53070599039722 
0 0 0 1"
   "compression": "laszip",

Running the transformation

  1. In Windows, open up the OSGeo4W command prompt.

    The Administrator: OSGeo4W Shell appears.

  2. In the Command Prompt, type in the following and press RETURN:

    C:> pdal pipeline transform_pipeline.json

    where transform_pipeline.json is the JSON file created in the previous section.

    The point cloud is transformed.

Monday, February 19, 2018

WebApp for calculating the 4x4 transformation matrix between 2 corresponding sets of 3D points

In working with 3D point clouds, one of the task may be to register or transform the point cloud to known ground control points (GCPs) on the ground with corresponding control points in the point cloud. For instance, the screen shot below shows the point cloud with four control points p1, p2, p3, and p4.

Note: At least 3 corresponding set of points are needed to calculate a rigid transformation matrix.

From the point cloud, the from-control points can be measured:

On the ground, the actual ground control points can be obtained, perhaps from a GPS receiver:

With the measured points from the point cloud and the corresponding control points on the ground, a 4x4 homogeneous transformation matrix can be calculated and used to rigidly transform the point cloud to the actual ground coordinate system. 

This WebApp calculator at can be used to calculate the 4x4 transformation matrix, as well as the root mean square error (RMSE) as an indicator of the quality of the control points i.e. the smaller the RMSE, the better they are. The WebApp uses the Numeric Javascript matrix library from for performing the required SVD decomposition to calculate the transformation matrix. Note that the library has some unfixed bugs in the SVD decomposition for certain cases and I may probably replace this with an alternative solution in future.  
  1. Paste the "from control points" into the Source Points text area field. 

  2. Paste the ground control point values into the Destination Points text area field.
  3. Click the Calculate button.

    The resultant transformation matrix appears in the 4x4 Transformation Matrix field. The RMSE for the calculation is displayed in the RMSE field.

Monday, February 12, 2018

Displaying WKT geometry string in QGIS with getWKT plugin

If you want to display the Well Known Text (WKT) string of a selected geometry in QGIS, there is a plug-in getWKT that can be used for this purpose. The screen shot below shows the Plug-in Manager's description of the getWKT plug-in.
 To use the getWKT plug-in, do the following:
  1. In QGIS, click the Select Features by area of single click button. Using the mouse, click on a feature.

    A feature is selected and highlighted in yellow.
  2. Then click the getWKT icon in the tool bar.

    The GetWKT dialog box appears with the WKT string of the selected geometry.

Monday, February 5, 2018

Find the 3x3 transformation matrix given a set of 3D points using Octave

I have 2 corresponding pair of 3 measured 3D points - one original coordinates (let's call as X) and the other destination or reference coordinates (say Y) . I wanted to find the transformation matrix (say A) that can transform the original coordinates to the destination coordinates.

Octave (an open source software alternative to Matlab. See has the tools to determine the 3x3 transformation matrix. This post shows how to perform the calculation.

Given the 3 original measured 3D points X:
x1 = (2, -1, 2)
x2 = (-1, 2, 2)
x3 = (2, 2, -1)

And the 3 measured destination 3D points Y:
y1 = (-2, -9, -30)
y2 = (-23, 12, 9)
y3 = (13, 6, -6)

  1. First, write out the transformation and coordinates in the following form


    where A is the unknown transformation matrix,
    X is a matrix of the original coordinates formed by concatenating the points as column vectors X = [x1, x2, x3]
    Y is a matrix of the destination coordinates formed by concatenating the points as column vectors Y = [y1, y2, y3]
  2. Run Octave. In the command prompt, enter the X matrix values:

    $> X = [2 -1 2; -1 2 2; 2 2 -1]
  3. In the prompt, enter the Y matrix values:

    $> Y = [-2 -23 13; -9 12 6; -30 9 -6]
  4. Now calculate the inverse of X by typing the following into the prompt.

    $> IX = inv(X)
  5. The transformation matrix A can be calculated by simply multiplying the matrix Y with the inverse of X. Type in the following at the prompt:

    $> A = Y * IX
  6. Optional. Use the calculated matrix A and multiply with the original coordinates X and check whether the resultant values matches the measured Y coordinates.

Monday, January 29, 2018

Display CSV (with WKT geometry field) files on Google Maps with this Mapplet

If you want to display a Comma Separated Values (CSV) file with an embedded geometry field in Well Known Text (WKT) format with just an Internet browser, then this Mapplet may be useful to you. Just go to this url with any modern browser such as Chrome, or FireFox. All the processing is done within your browser, that is the CSV file is never uploaded to a server for processing.

  1. To load a CSV file, click on the Import CSV button (in blue color) as shown in the screenshot below. 

    The Import Comma Separated Values (CSV) file dialog box appears.

  2. To load in a CSV file from a local drive, click the Choose File button. Then browse and select a CSV file as shown below.

    Note: You can also copy and paste WKT text into the CSV file field's text area. Or click the Use Sample Data drop up button to load demo WKT data into the text area.

  3. Click Open.

    The file is read and displayed in the text area below the Choose File button. The WKT Geometry column button is populated with the header fields from the CSV file.

    Note: If necessary, choose an appropriate Coordinate System and projection.
  4. Click Start Import.

    The CSV file is loaded and rendered as overlays on the Google Maps backdrop. The name of the file is added to a CSV files combo box.

  5. Optional. Click on the CSV Command drop up button and choose a command to apply to the current CSV layer.

    Fit - Display the current CSV layer within the map
    Fit All - Display all loaded CSV layers within the map
    Toggle display - Toggle the CSV layer display on or off
    Display off - Don't display the current CSV layer
    Display on - Display the current CSV layer
    Remove layer - Unload the current CSV layer

Monday, January 22, 2018

Using QGIS to export CSV files with Well Known Text geometry

QGIS can export feature layers as comma separated values (*.CSV) files with a geometry column in  Well Known Text (WKT) format. This can be very convenient if you want to exchange a small amount of data from one GIS system to another GIS system.

To save a vector feature layer to a WKT CSV file, do the following:

  1. In the legend pane of QGIS, select a layer to export, e.g. forest. Then press the right click of the mouse.

    A pop up menu appears.

  2. In the pop up menu, choose Save As.
  3. The Save vector layer as dialog box appears.

  4. In the Format combo box, choose Comma Separated Values (CSV). In the File name field, click the  Browse button and type in the output file name, e.g. forest.csv.

  5. In the Layer Options group box's GEOMETRY combo box, choose AS_WKT. Click OK.

    The selected vector layer is exported out as a CSV file with a geometry field as WKT format as shown below in a spread sheet.
Related Posts with Thumbnails