visualizing 3D data (Z values) or data with z attribute: a solution

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

visualizing 3D data (Z values) or data with z attribute: a solution

gene
After the post of Etienne Tourigny about "Using/visualizing 3D data (Z values)", I realized that it was relatively easy from the Python console with matplotlib or visvis (new pure Python library for visualization of 1D to 4D data, http://code.google.com/p/visvis/).

1) 3D shapefile
 a) with matplotlib.meshgrid
With a 3d point shapefile, the shapely module makes it very easy to extract the z coordinate:

from mpl_toolkits.mplot3d.axes3d import *
import pylab as plt
from matplotlib import cm
from matplotlib.mlab import griddata
import numpy as np
from shapely.wkb import loads
x=[]
y=[]
z=[]
for elem in layer.selectedFeatures():
           geom= elem.geometry()
           wkb = geom.asWkb()
           x.append(loads(wkb).x)
           y.append(loads(wkb).y)
           z.append(loads(wkb).z)

now, with the x,y,z coordinates, we can build a grid/surface with the matplotlib.meshgrid function

xi = np.linspace(min(x), max(x))
yi = np.linspace(min(y), max(y))
X, Y = np.meshgrid(xi, yi)
Z = griddata(x, y, z, xi, yi)

and draw it in a 3D matplotlib window
fig = plt.figure()
ax = Axes3D(fig)
ax.plot_surface(X, Y, Z, rstride=5, cstride=5, cmap=cm.jet,linewidth=1, antialiased=True)
plt.show()


It is also possible to plot the points or the contours in 3D



with visvis
import visvis
visvis.plot(x,y,z, lc='k', ls='', mc='g', mw=2, lw=2, ms='.')
visvis.surf(xi, yi, Z)


b) with splines algorithms from scipy
It is also possible to use other interpolation algorithms like the spline interpolation class BivariateSpline of scipy

with matplotlib

import scipy as sp
from scipy.interpolate import SmoothBivariateSpline
spl = SmoothBivariateSpline(x,y,z)
# construction of the grid/surface
x = np.array(x)
y = np.array(y)
xn, yn = sp.mgrid[x.min():x.max():50j,y.min():y.max():50j]
zspline = spl( xn[:,0], yn[0,:])
fig = plt.figure()
ax = Axes3D(fig)
ax.plot_surface(xn, yn, zspline)
plt.show()

with visvis

import visvis
visvis.surf(xn,yn,zspline)

2) shapefile with z attribute
This is the same thing, but we must use the values ​​of the attribute

Conclusions and a plugin ?
Build a plugin seems a priori to me very complex and time consuming
- plot 3 d points is easy.
- but in other cases, all the scenarios (3D shapefile points, lines or polygons, shapefile with z attribute, interpolation algorithm, ...)  should be considered before
- you need modules like shapely or matplotlib

I do not have much time to write a plugin and personally I'm very happy with the Python console, sorry.



Then, If somebody else wants to go,I can help


Reply | Threaded
Open this post in threaded view
|

Re: visualizing 3D data (Z values) or data with z attribute: a solution

ajay_vsv
This post has NOT been accepted by the mailing list yet.
Dear all,

I would like to make a project about 3D view of a parcel of land (Rajahmundry, Andhrpa Pradesh, India)
On the same, I would like to represent Bore wells depth too.
for this I have
1. CARTOSAT DEM (30m resolution) raster file
2. LISS-III (MSS image-25m resolution) raster file
3. Point layer of sample borewells (in its limits) containing (attributes) depth, size(diameter of bore)
4. Elevation points (using Obtain Elevation tool from Google maps API in QGIS)

Using 1, 2 above I have generated contours and till now I used to represent on 2D only.

I now wish to represent the same with 3D and to represent the bore digging towards down along with the DEM of respective area.!

Using python console I am just started to make it a success...

Suggest me to reach this..