# coordinate transformation problem

Hello everyone,

Here I have an xdmf file, whose data is described in polar coordinate (r, θ, φ) instead of (x, y, z). I want to do a coordinate transformation and display the data in Cartesian coordinate. By typing the following code in programmable filter:

from paraview import vtk

pdi = self.GetPolyDataInput()
pdo = self.GetPolyDataOutput()
newPoints = vtk.vtkPoints()
numPoints = pdi.GetNumberOfPoints()
for i in range(0, numPoints):
coord = pdi.GetPoint(i)
r, theta, phi = coord[:3]
x = r*sin(phi)cos(theta)
y = r
sin(phi)sin(theta)
z = r
cos(phi)
newPoints.InsertPoint(i, x, y, z)
pdo.SetPoints(newPoints)

I get the following error:
Traceback (most recent call last):
File “”, line 22, in
File “”, line 9, in RequestData
AttributeError: ‘vtkCommonDataModelPython.vtkMultiBlockDataSet’ object has no attribute ‘GetPoint’

Does anyone know how should I modify the code or is there any other way to do the coordinate transformation? Thank you so much.

–Yunlin

1 Like

Multiblock datasets do not have a single set of points but rather a set of points for each block. You may either

• change your script to detect multiblocks and iterate over each block, transforming points for each dataset that inherits vtkPointSet or
• use the calculator filter with the “Coordinate Results” checkbox selected and a formula like `xCoord*sin(yCoord)*cos(zCoord)*iHat + ...`; the calculator filter automatically iterates over blocks for you.

The latter is simpler unless you need to perform additional processing.

1 Like

Hi David,
Please excuse my ignorance. After I enter coordsX*sin(coordsY)*cos(coordsZ)iHat + coordsXsin(coordsY)*sin(coordsZ)jHat + coordsXcos(coordsZ)*kHat, the output error message says “Coordinate output specified, but output is not polydata or unstructured grid”, which I am not sure how to deal with. Thank you so much for help.

1 Like

Hi Yunlin,

It sounds like you have image or rectilinear data. These types of data do not store point coordinates explicitly. Instead, the coordinates are inferred from the (i,j,k) indices of the point. Since they aren’t stored explicitly, there is no place for the calculator filter to store its results.

There is a way to get around this in ParaView, but it is very inefficient. Before running the calculator filter, run the “clean to grid” filter. It will convert your data into an unstructured grid which does store point coordinates explicitly. However, this will take up lots of memory. That could be a problem if your dataset is large.

1 Like

Thank you so much David! I think I’ve made it.

Hi David
I have a 2D geometry file which is defined in cartesian coordinate (x,y). Now I want to convert that to 2D cylindrical coordinate (z,r). how can I do that?
thanks

@monica A few things,

1. You can tell a Calculator filter to overwrite point coordinates with its result array using the “Coordinate Results” checkbox. Use iHat, jHat, and kHat to create a vector value for each point, however:
2. r-z cylindrical coordinates are cartesian (assuming θ = constant). Perhaps you meant r-θ coordinates?
3. Next time, please start a new topic rather than responding to an existing one with a new question.
1 Like

This is sorted related. When I do plot over a line. I would like to use the actual coordinates written on the PV files and NOT interpolated values (PV asks for the number of values for the line). Is this possible?