I have a dxf file of 3d contours. after import it does have only layer,x,y attribute and doesn't have Z attribute.
How can I provide Z attribute to create a TIN file?
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It only takes a minute to sign up.Sign up to join this community
Miro's answer will work fine, but if you just want to add a Z value to your attributes table (perhaps for labeling in a map or some other reason), I would start as he suggests:
v.in.dxf - to import contours including z dimension (SQLite works well as an output format)
Now instead of rasterizing, use the field calculator to pull the Z value from the 3D geometry into the attribute table. Because we are dealing with contours all Z values should be the same for a given linestring, so you can simply use the following formula:
z( start_point( $geometry ))
When talking about having only contours in 3D dxf, the proper way is definitely NOT extracting the vertices as XYZ and interpolating the surface from points. That way you lose the information about how are the points connected which at least leads to losing some detail or it can be even worse.
If you use Dxf2xyz and you don't want to lose information I strongly suggest to get the Z values from points back to imported lines as additional attribute Z (Vector / Data management tools / Join attributes by location). After that rasterize the contours (Raster / Conversion / Rasterize) and use Grass / Raster (r.*) / r.surf.contour from Processing / Toolbox.
Or even better, use open source GRASS (comes together with QGIS OSGeo4W installation) - all functions below are now available as tools in QGIS toolbox (In QGIS top menu click on Processing / Toolbox):
v.in.dxf - to import contours including z dimension
In QGIS use field calculator to get z field - z( start_point( $geometry ))
v.to.rast (use=z) - convert lines to raster
r.surf.contour - to linearly interpolate the rest of the surface (DEM) between contours
You can use a free utility (Dxf2xyz 2.0, downloadable from http://www.guthcad.com/freestuff.htm) to convert from both dwg and dxf files to an "xyz" file, i.e. a comma delimited text file containing xyz coordinates. Then you need to change the extension file from ".xyz" to ".txt", before you load the xyz file in QGIS by the button "Add delimited text layer". Then you save the text layer to shapefile to have the points you need to create the TIN file.
Another workaround. Use GRASS GIS command v.to.3d. Create a field in the vector layer, then run v.to.3d with -r option and define the field added before