Creating an ASCII Text file for ArcGIS from existing Terrain

What I need is a MAXScript that will sample an existing terrain on a grid

that is n columns by n rows with a specified interval for each. For

example: 10 columns by 10 rows with 10m between each column and 10m

between each row.

All the script needs to do is start with a point in the upper left hand

corner of the array, project a test ray in the negative Z direction, once

that ray intersects with the terrain below write that elevation along

with the point number to a .txt file and then move the point to the next

position to the right (based on the spacing interval), renumber the

point, and repeat the same output process.

Once the point gets to the end of the column it needs to go back to the

far left and begin again on the next row, keeping the numbering

consistent. The numbering for the array would begin with "Point01" in

the upper left hand corner and go from left to right until it reaches the

bottom right of the array. In this example of a 10 x 10 array the last

point number would be "Point100" which would be the last point on the far

right of the last row.

For a small array I could create points in 3dsMax and use the 'Move to

Surface' script, then export the positions myself to a text file but the

arrays I'm dealing with for this particular project are thousands of

columns x thousands of rows. This results in millions of points in the

array. Figured if I could get someone to help me out with a script that

would move, rename, and output one point that traveled around the terrain

in an array fasion, it would be an easier approach to obtaining the

elevation data in a text format.

Comments

Comment viewing options

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

I get it now. I looked at

I get it now. I looked at the file again and saw that in the areas where there is no terrain hit, the script still creates the point. Can we get it to print the output for "No data value" like the rest of the points? Print the x value, y value, and then -999 (or whatever is specified in the UI) for the z for those points?

miauu's picture

The points are crated just to

The points are crated just to show you where they are in the terrain. I expected that you will remove this line(that creates the points) from the script, because creating all those points slow down the performance. I will add checkbox to allows you to create or not points in both places - terain and "nothing". This covers question 2) In the infoFile all points are written - you can see for example - point234 -999 this ie "no data point" - the point that touching the terrain. Also will include the "no data point" - question 1)
The script do not use those points. It create them after the rayHit is executed. So there is no need of them, but they are a good visual representation of what happens.
[quote] Also, how difficult would it be to still be able to specify the first start point of the array like you could in the first script? [/quote]

In the first script you can't define the starting point. When you look your scene in TOP viewport, the starting point is at top left part of your selection of objects.

[quote] And can we format the data to print as follows: PointNumber,x,y,z [/quote]
Yes. Will add this.

todd21st's picture

Also, how difficult would it

Also, how difficult would it be to still be able to specify the first start point of the array like you could in the first script?

And can we format the data to print as follows:
PointNumber,x,y,z

with no brackets?

I know I'm asking for a lot and I do appreciate your patience.

todd21st's picture

Very very cool! This script

Very very cool! This script is really turning out to be amazing! I love the ArcGIS_Exporter_v11.ms....looks like we're getting there. Two things though:

1) When creating the array I need each column & each row to have the same number of points respectively like the image below shows...

http://call21st.com/goofy7012/screenShot.png

Where there are no terrain tiles for the points to be dropped on, there still needs to be points created and just placed at the "No data value" elevation. This way each row and column will have the same number of points.

2) Is it possible to drop a line of code in to not create the points? This way once I get the array set up and have it working like I want, I can push the button to not create the points for the final and larger array. I'd like this feature since originally you said Max could do this function without having to generate actual geometry, points, etc. I think this would be a really cool option.

Looks great so far just these couple of things and I think we'll be there. Let me know what you think.

Thanks A Million!

Todd Davis

miauu's picture
Graph's picture

well here's a faster version

well here's a faster version of it:

(
 
	local theTerrain= $TerrainMesh
 
	local nRows = 50
	local nCols = 50
 
	local projectionDir = [0,0,-1]
 
	local borderMargin = 0.0001
 
	/********************/
	/********************/
 
	local rm = RayMeshGridIntersect() 
	rm.Initialize 10 
	rm.addNode theTerrain 
	rm.buildGrid()
 
	local terrainBBSize = theTerrain.max-theTerrain.min - [borderMargin*2,borderMargin*2,0]
 
	local stepSizeX  = terrainBBSize.x/(nRows-1) as float
	local stepSizeY = terrainBBSize.x/(nCols-1) as float
 
	local minX = theTerrain.min.x+borderMargin
	local minY = theTerrain.min.y+borderMargin
	local maxZ = theTerrain.max.z
 
	local pointArr = for y = 0 to nCols-1 collect
	(
		for x = 0 to nRows-1 collect
		(
			local thePos = point3 (minX+x*stepSizeX) (minY+y*stepSizeY) maxZ
			local theHitsCount = rm.intersectRay thePos projectionDir false
 
			if theHitsCount > 0 then
			(
				local theIndex = rm.getClosestHit()
				local dist = rm.getHitDist theIndex
 
				thePos.z -= dist
				thePos
			)
			else
			(
				thePos
			)
		)
	)
 
	print pointArr
 
	for x in pointArr do for y in x do point pos:y wireColor:orange;
 
)

as it's a static object/collection you can use the RayMeshGridIntersect class wich is significantly faster, just something to note for the future :)

Raphael 'Insanto' Steves
http://Graph.Net84.Net

todd21st's picture

Many thanks my friend. I'll

Many thanks my friend. I'll be sure that our company makes a donation for your efforts.

miauu's picture

I will do it later this

I will do it later this night. :)

todd21st's picture

I do appreciate all your help

I do appreciate all your help and once my boss returns from a business trip I'm sure I can get him to make a donation on your web page.

Comment viewing options

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