Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

php -> asp

Status
Not open for further replies.

chinedu

Technical User
Mar 7, 2002
241
US
dear experts.
Forgive me for taxing you with this task.
This seems like a straightforward php while loop and normally, I can write a while loop in asp but this seems a bit too complicated for me.
Can someone please, please assist with the interpretation?

Thanks a lot in advance


Code:
#don't flip the order of the rows (pop vs shift) 'This means comment in asp
$speak_elev = 0;
$li = '';
while ( $li = array_shift($ascii) )
{  #first begin
 #ignore first return value after splitting on white space
  #data = split(" ", $li);
  array_shift($data);
  while ( list($key,$elev) = each ($data) )
    { # end second begin
     if ( $elev < $base_elev )
       {
        echo "$base_elev "; ' This means response.write in asp
       }
     elseif ( $elev > $cap_elev )
       {
        echo "$cap_elev ";   ' This means response.write in asp
       }
     else
       {
        echo "$elev " ; ' This means response.write in asp
        if ( $elev > $peak_elev ) { $speak_elev = $elev; }
       }
    } # end second begin
     echo "\n"; 'I believe this means response.write "<br>" in asp
} #end first begin
 
As far as i can see i think that algorithm it's not entirely correct.
If the $ascii it would be an array then array_shift it would return as well an array there for you cant use then a split over an array value.
If you can explain what the algorithm does or the working code would be easyer to make an equivalent.

________
George, M
Searches(faq333-4906),Carts(faq333-4911)
 
hi Shaddow,
After I got scolded for dumping too much code, I have always been reluctant to do so.
In any case, the code is a simulation of a surface 3D modeling using a web map application.
Since the original php guy is no longer here, it is really difficult to get line by line explanation of what he did.

So please bear with me for dumping the working code (php version)

Hopefully, you can look at the ascii definition at the middle of the code and see what the whole code is supposed to be doing.
Thanks for the help!

Code:
<?php
header("Content-Type: x-world/x-vrml");
header("Content-Disposition: inline; filename=fulton_3d.wrl;");
$inputfile = tempnam("temp/","ftemp");

# strip web server from $img
if ( substr($img,0,5) == 'http:' )
{
  preg_match("/http:\/\/[^\/]+(\/.*)$/",$img,$match) ;
#  $img = $match[1];
}

$win_array = split(" ",$win);
$w = $win_array[2] - $win_array[0];
$h = $win_array[3] - $win_array[1];
$mapsize_array = split(" ",$mapsize);
$mapext_array = split(" ",$mapext);

$vert_exag = 1.0;

#shading intensity factor
$factor = 15;

# reduced sampling factor for Elevations
$red_factor = 5.0;

#clipping bounds for elevations
$base_elev = 600;
$cap_elev = 2000;

$zspacing = ($factor * $red_factor);
$xspacing = ($factor * $red_factor);

#zoom speed realtes to workd_size
$world_size = 5;
$scale = $world_size/$mapsize_array[0];

$mapwidth = floor($mapsize_array[0]/$red_factor);
$mapheight = floor($mapsize_array[1]/$red_factor);


$ch = curl_init("[URL unfurl="true"]http://fwms.gis.fc/ms4.0/mapserv?map=/web/wms/ms/terrain/mapserv.map&mode=map&layers=dem&map_imagetype=AAIGrid&mapsize=$mapwidth+$mapheight&mapext=".str_replace("[/URL] ","+",$mapext));
$fp = fopen($inputfile,"w");
curl_setopt($ch,CURLOPT_FILE,$fp);
curl_setopt($ch,CURLOPT_HEADRER,0);
curl_setopt($ch,CURLOPT_VERBOSE,0);
curl_exec($ch);
curl_close($ch);
fclose($fp);

$ascii = file($inputfile);
echo "#VRML V2.0 utf8\n\n";
$ncols = 0;
$nrows = 0;

# get NCols
$data = split("[ /t]",array_shift($ascii));
$ncols = array_pop($data);

#get NRows
$data = split("[ /t]",array_shift($ascii));
$nrows = array_pop($data);

$yscale = $scale*$vert_exag*($zspacing/$nrows);

# skip 3 lines
array_shift($ascii);
array_shift($ascii);
array_shift($ascii);

	echo "
	WorldInfo
	{
	  info
	    [
	    \"A 3D model\"
            \"based on the extents \"
	    \"$mapext\"
	    ]
	title \"3D Surface Model\"
	}

Background
  {
  groundColor
    [
    0.100000 0.470000 0
    ]
  skyColor
    [
    0.079999 0.420000 0.715000
    ]
  }

Viewpoint
  {
  fieldOfView 0.949998
  orientation -1 0 0 0.660372
  position 0 ".($yscale*1500)." ".($nrows*$scale*$zspacing/1.2)."
  description \"North\"
  }

Viewpoint
  {
  description \"Flat View\"
  fieldOfView 0.949998
  orientation -0.02 -0.99 -0.01 1.62
  position ".(-1*$ncols*$scale*$xspacing/2)." ".($yscale*200)." 0
  }

Viewpoint
  {
  fieldOfView 0.949998
  orientation 0.155 0.975 0.155 4.54
  position ".(-1*$ncols*$scale*$xspacing/1.4)." ".($yscale*1500)." 0
  description \"West\"
  }

		Transform
  		{
  		children
    	[
		Shape
		{
			appearance Appearance
			{
				texture ImageTexture
				{
		   			url \"$img\"
					repeatS TRUE
					repeatT TRUE
				}
				textureTransform TextureTransform
				{
					scale 1 -1
				}
				material Material
				{
					diffuseColor 0.7 0.7 0.7
				}
			}
			geometry ElevationGrid
			{
				solid       FALSE
				ccw         FALSE
				xDimension  $ncols
				zDimension  $nrows
				xSpacing  $xspacing
				zSpacing  $zspacing
				height
				[ ";
# dont flip the order of the rows (pop vs shift)
$peak_elev = 0;
$li = '';
while ( $li = array_shift($ascii) )
{
        # ignore first return value after splitting on whitespace
        $data = split(" ",$li);
        array_shift($data);
	while ( list($key,$elev) = each($data) )
	{
                if ( $elev < $base_elev )
                {
                  echo "$base_elev ";
                }
		elseif ( $elev > $cap_elev )
                {
                  	echo "$cap_elev ";
                }
                else
                {
			echo "$elev ";
			if ( $elev > $peak_elev ) { $peak_elev = $elev; }
	 	}
	}
   echo "\n";
}

$yscale = $scale*$vert_exag*($zspacing/$nrows);
echo "    ]
       }
     }
   ]
   translation ".((($ncols/2)*$xspacing)*$scale*-1)." ".
        (($peak_elev*$yscale)*-1)." ".
        ((($nrows/2)*$zspacing)*$scale*-1)."
   rotation 0 0 -1 0
   scale $scale ".($yscale)." $scale
}

DirectionalLight
  {
  direction 0.3 -1 0
  intensity 0.75
  ambientIntensity 0.15
  }
";

unlink ($inputfile);
?>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top