XYZ file terrain modeling

The version at Ruby Library Depot is quite outdated.

Download the updated version from SketchUcation.

1 Like

Open the Ruby console (Window >> Ruby Console) and paste the following text into it (then hit Enter):

data = File.open(UI.openpanel("Select TXT File", "~", "Text Files|*.txt;||"),"r")
while(t = data.gets)
  x,y,z = t.chomp.split(' ')
  Sketchup.active_model.active_entities.add_cpoint([x.to_f - 4431377,y.to_f - 5468639,z.to_f])
end

In the fourth line, I have subtracted the smallest X and Y values from each point to create them close to the origin. The coordinates are assumed to be in inches and the magnitude of your data places them at a great distance away (beyond the point where they begin to act funky).

image

image

Thanks for your lines!
What will happen after I choose the File *.txt? In my case the Ruby Consol did not close and no points are available.

It should create the points from the file or the console should give some sort of error. It you’re using the test file you posted, you will need to remove the blank lines.

It’s not supposed to close. If there were no errors, try zooming out to see if maybe the points were created somewhere off screen.

1 Like

Thanks again!
You are right. It depends on the input values where the point cloud is located.
Is there at last any kind of possibility to triangulate the point cloud?

If you can post the entire file (if you don’t mind sharing it), I’ll see about creating a mesh from the data.

It might interest you to know that earlier this year I wrote a DLL importer (for Windows) which takes a number of rectangular raster file formats (containing terrain elevation data) and displays the data in Sketchup. Its a free importer.
You can find it in the Sketchup Community forum Extensions category:
“Sketchup Importer DLL for Norwegian, Swedish and Swiss LIDAR height-data raster cloud maps”.
Note that there are several versions, please observe the latest version. And please observe the accompanying documentation file.
I did successfully test the importer using some very few available Swiss XYZ ASCII (.txt) terrain files, but - as XYZ ASCII (.txt) files was not my main target at the time - the tests were limited. From your very small example.txt it appears that the SWISS format is the same as the one you use, although the grid datum is different.
You might give it a try.

1 Like

Thanks Geo!
This Plugin works great!

For each of you who want to import ASCII-Files in SketchUp, use plugin Geo mentioned. This works for me for a more than 120.000 point cloud.

2 Likes

Bumping this thread again.

I’ve successfully added xzy-coordinates - but how do I transform this to a workable face in Sketchup. I’ve tried TopoShaper, but is there a faster way? It’s takes quite some time to process the 50 000 points I have. (4 hours), and the end result is a somewhat sluggish surface and I wonder if I’ll ever can use the terrain to drape and stamp stuff…

//Josef

Can you post the skp with the points?

Tell us how you did so.
Did you use the Cloud plugin by Didier Bur?

Cloud v8.obxx … SketchUp Plugin by Didier Bur (updated by TIG)

If you use the Cloud plugin by Didier Bur, you’ll notice the option to Triangulate Points.


In my experience, four hours seems rather long.
Again, tell us how you imported the points cloud.

IIRC, this model took about 45 minutes to import points and triangulate.
Import and triangulation via the Cloud plugin by Didier Bur.

In addition to Geo’s solution, there is a way to get your terrain using native sandbox tools + one of TIGs other scripts, cpoints2components

  1. Create a component made of a single vertical line.
  2. Select the component line and all the construction points
  3. Use the cpoints2components script to place component instances at every construction point location
  4. Select all the component instances and EXPLODE
  5. With all the raw virtical lines selected, run the FROM CONTOURS feature from the native SketchUp Sandbox toolset… DONE! :slight_smile:

Using Geo’s example terrain, from start to finish, this took me approx 4 min to generate the terrain.

Cheers
CD

However, the 4 minute time frame doesn’t include the time to import the points cloud.
Seans Point Cloud.txt (858.3 KB)

Thanks Geo… I will see how long it takes with your txt file. I will try the import with PointGadget first :slight_smile:

If using Cloud, it’s best done over a long lunch. :slight_smile:

Yep… you’re right. The import of the points is what takes the longest.

Here are my results:

Import of points using PointGadget = 27min 54sec
Note: Since PG places a point marker component instance instead of just construction
points, once imported, all that is needed is the modification of the contents in one instance
from complext geometry into a single vertical line.

Generation of terrain = 4 + min

1 Like

@JoNoS I’ve successfully used your importer to import sample data from the Bavarian state agency in Germany.

It works great with their free DGM50 data which looks like this:

710000 5560000 622.12
710050 5560000 620.52
710100 5560000 618.88
710150 5560000 617.08

But when I try to import DGM1 data which you have to buy from them I get the error, that the import failed (unfortunately without any error message).

The DGM1 data is UTM32 and looks like this:

288723 5560407 617.54
288721 5560408 617.53
288722 5560408 617.54
288723 5560408 617.57

I don’t see much of a difference in the data formats. Any ideas why this data does not work with your importer?

I noticed that the importer also fails when I delete points from the DGM50 file which worked before. Is there a special kind of shape of number or points which have to be in the file?

Hi –

I am still using my importer for my own projects. Is has not failed me yet…

Anyway, please note that the importer was written for raster files, i.e. a file which contains a rectangular array of regularly sampled values. I believe I made a note of this in the description.

Your first short example is a 4x1 array (in terms of coordinate values). That should work fine.

Your second example is not a rectangular array, so it will - unfortunately - fail. I never attempted to
handle a point cloud situation, for the simple reason that no map sources of mine contains such data.

Now, if you take a raster file and delete certain points, then obviously it will not anymore be a
raster file, thus it will fail. Of course, if you delete a full row (or column for that matter) it will still be a raster file, and it should work.

So then, in your second short example, if you delete the very first point, then this is again a raster file (albeit a short one) and it should work.

I could probably have been better in producing adequate error messages, when analyzing file data contents. If you have a specific data file to share with me I can have a look at what goes on?

@JoNoS : Sorry, I didn’t get an email from your reply.
I figured it out eventually I guess, but my old instructions did not work anymore / were missing when I tried the same again now after 2 years.

For future readers (maybe myself in a few years if my instructions get lost ;-):


From DGM1 ASCII (e.g. opendata from the bavarian state) to SketchUp terrain: (As of 2023)

Download and Preparation of ASCII Data:

Download DGM1 in ASCII format (XYZ) from the desired source. The file should end with .txt.
Coordinate system of data: UTM32 (EPSG:25832)
Tile size: 1km
1st line of the file: 7XX000.50 5XX0999.50 607.55 *(the X are just to hide the location)*

Start QGIS:

Add XYZ Tiles (OpenStreetMap) to later reduce the point data to the relevant area.

Import ASCII Data into QGIS:

Open QGIS.
Go to Layer > Add Layer > Add Text Layer.
Navigate to your ASCII file and import it.
Settings:
    File Format > Custom delimiters > Space
    Record and Fields Options > uncheck "first record has field names"
    Geometry Definition > Point coordinates, select X, Y, Z field
    Geometry CRS: Click on the "Select CRS" icon and select: "EPSG:25832"

Prepare Point Cloud in QGIS (Define Area):

Define Area:
    Use the "Rectangle" tool in the toolbar to draw a rectangle around the area you want to keep. This creates a temporary rectangle you can use as a clipping mask.

Clipping:
    Create a Temporary Layer:
        Go to Layer > Create Layer > New Temporary Scratch Layer.
        Name the layer, e.g., "ClipArea".
        Select "Polygon" as the geometry type.
        Make sure the coordinate system is set to "EPSG:25832" and click OK.
    Draw a Polygon:
        Select the newly created "ClipArea" layer from the layer list.
        Click on the "Edit" tool (a pencil icon) in the toolbar to start editing mode.
        Click on the "Draw Polygon" tool (it looks like a triangle).
        Draw a rectangle or any polygon around the area you want to keep. Click for each corner point and double click to finish drawing.
    Go to Vector > Geoprocessing Tools > Clip.
    For Input Layer, select your point cloud.
    For Overlay layer, select the rectangle you just drew.
    Click on "Run". This creates a new layer containing only the points within the rectangle.

Remove Unused Layers:
    You can now remove the original layer and the rectangle as they're no longer needed. The newly created layer contains the desired data.

Interpolation:

Go to Raster > Analysis > Grid (Nearest neighbor).
    Input Layer: Select the "Clipped" layer.
    Advanced Parameters:
        Z value from field: Select "field_3".
    Click "Run". The new "Interpolated (NN)" layer should display the terrain structure if successful.

Create 3D Print Model:

Install the free "DEMto3D" plugin.
Go to Raster > DEMto3D > DEM 3D printing.
    Layer extend:
        Choose the recently created "interpolated" layer.
        X and Y range: Click on the "Select full extent" icon.
    Model size:
        Spacing (mm): 1000.0
        Scale: Initially choose a value from the dropdown, then change to 1:1.
        This should autofill "width & length" (for an 85x123 area, it should be 85000.0, 123000.0).
        Vertical exaggeration: x1.0.
        Divide model: 1 row x 1 column.
    Model height:
        Height (m): 0
        Base height: Note: For the initial run, you can use a base height of 0. After completion, "lowest and highest height" is displayed. For instance, 605 and 624. Based on this, I chose a base height of -600000 mm and generated a new STL. This results in the height of the imported model in Sketchup not being 625 m but 25 meters, which is better performance-wise.
    Sides:
        Build sides: Yes, Border 0mm.
    Click "Run" and save the result as an STL file. Once finished, the model height will be displayed. For me, e.g., 23000.0mm (as mentioned above, 623 m above sea level, minus 600 m).

Import STL File into SketchUp:

Open SketchUp.
Go to File > Import and search for the STL file.
Import the model into your SketchUp environment.

Result in sketchup:

Hi!

You can use toposhaper from Fredo6.
It’s a paid extension but the best out there!
Important is that the points must be in a group for it to work.

Import the points > select all and make it a group > then use toposhaper from guide point to make the mesh.