Create a grid mesh from text file

Hi,
In France IGN give for free some .asc files.
https://geoservices.ign.fr/documentation/diffusion/telechargement-donnee...
This is simple .asc files like :
ncols 3
nrows 5
xllcorner 849997.500000000000
yllcorner 6360002.500000000000
cellsize 5.000000000000
NODATA_value -99999.00
133.00 134.00 135.00
133.00 134.00 135.00
133.00 134.00 135.00
133.00 134.00 135.00
133.00 134.00 135.00
Values are separated by spaces.
In reality, ncols =1000 and nrows=1000
(xcorner, ycorner) is the position of the first point (origine).
So I would like to create a mesh grid :
read first line, first value, create a vertex ( or place first vertex of the grid ) at origine with z=first value
read first line, second value, create a vertex ( or place second vertex of the grid ) at origine + cell size with z=second value
(...)
Same for each line.
As there is a lot of data, I would like to be able to skip some values : ncol divided by a value. Same for nrows.
As 3dsmax don't like very big model, I would like to be able to "move" origine value.
I made an ugly UI to give an idea.
Thanks. I think it could help a few people.

Next step is a batch importer, as there can be a lot of files... ;-)

AttachmentSize
request1.jpg91.31 KB

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
jahman's picture

.

(
	f = openFile @"...\test_ori_0.txt"
 
	LF = #()
	l = readline f ; LF = filterString l " " ; NCOLLO = LF[2] as float
	l = readline f ; LF = filterString l " " ; NROWWO = LF[2] as float
	l = readline f ; LF = filterString l " " ; XCORNER = LF[2] as float
	l = readline f ; LF = filterString l " " ; YCORNER = LF[2] as float
	l = readline f ; LF = filterString l " " ; CELLSIZE = LF[2] as float
	l = readline f
	--format "COLONNE :%  LIGNE :% XCORNER :% YCORNER :% CELLSIZE :%\n" NCOLLO NROWWO XCORNER YCORNER CELLSIZE
 
	---- test values :
	NCOLLO =1000
	NROWWO =1000
	----------------------
 
	NCOLL = (NCOLLO - 1)
	NROWW = (NROWWO - 1)
 
	PL = plane()
	PL.length = NROWW * CELLSIZE
	PL.width= NCOLL * CELLSIZE
	PL.lengthsegs = NROWW
	PL.widthsegs = NCOLL
	convertToMesh PL
 
	COL = 1
	ROW = 1
	VERT = 1
	COUNT = 1	
 
	try ( destroydialog ::progressTest ) catch()
	global progressTest = rollout progressTest "IGN asc"
	(
		spinner sNCOLLO "COL:" range:[0,1000,NCOLLO] align:#right type:#integer fieldwidth:100
		spinner sNROWW "ROW:" range:[0,1000,NROWWO] align:#right type:#integer fieldwidth:100
		spinner sXCORNER "XC:" range:[-1000000,1000000,XCORNER] align:#right fieldwidth:100
		spinner sYCORNER "YC:" range:[-1000000,1000000,YCORNER] align:#right fieldwidth:100
		spinner sCELLSIZE "CELL:" range:[.01,100,CELLSIZE] align:#right fieldwidth:100
		progressbar doit_prog color:green 
		button doit "APPLY" 
		on doit pressed do
		with undo off 
		with redraw off
		(
			t1=timestamp();hf = heapfree
 
			for R=1 to NROWWO do
			(
				doit_prog.value = 100.*R/NROWWO -- this is slow and if you have 10000 rows progress will update 10000 times which is nonsence
				l = readline f -- reads a line of 1000 values
				LF = filterString l " " -- converts it to array of 1000 string values
 
				for C=1 to NCOLLO do
				(
					-- this is wrong
-- 					VAL = LF[COUNT]as float 
 
					VAL = LF[ C ]as float					
					setVert PL VERT [((COL-1)*CELLSIZE),((ROW-1)*CELLSIZE),VAL] 
					COL  += 1
					VERT += 1
				)
				ROW +=1
				COL = 1
				COUNT = 1
			)
			doit_prog.value = 0 -- when ready, reset the progress bar to 0%
			redrawViews()
			update PL
			format "Time: %sec. Mem: %\n" ((timestamp()-t1)/1000 as float) (hf-heapfree)
		)
 
		on progressTest close do 
		(
			close f
		)
	)--rollout
	createDialog progressTest 200 200
)--undo off
titane357's picture

Thanks again ! Just to say,

Thanks again ! Just to say, mesh was inverted in y axis, I corrected it !

AttachmentSize
thank_jahman_2.jpg 1.89 MB
jahman's picture

.

You made it. Congratulations! ;)

titane357's picture

WAW !!! Thank you soooo much

WAW !!! Thank you soooo much Jahman !
Works at lightspeed, and yours is working ( mine was repeatiting same row of values )
I can open all files now, and now I'm going to try ( ah ah ) to make the script more usable for my work.

AttachmentSize
thank_jahman.jpg 383.17 KB

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.