[Gdal-dev] xyz to gdal

uli uli.mueller at gmx.ch
Thu Jul 22 11:36:59 EDT 2004


In the meantime I have done exactly what Jason Nielsen proposed by means 
of an awk script. Although it is thought only for GaussKrueger-System 
and 5-digit ("%5.1f") z-values, it may be easily adapted to other systems.
Frank: It would however be nice to have this format in GDAL, maybe with 
support for irregularly spaced points...
Uli
-- 
geOps GeoInformatics
Stephanienstr. 4
D-79100 Freiburg

###############################################################################
# xyz2ascii.awk
#
# Purpose:  AWK script to convert xyz ASCII data to ArcInfo-ASCII-Grid
#           Expects three space-delimited columns with xyz data
#           Expects coordinates with seven relevant digits (originally 
made for German Gauss Krueger system...) and z-values with 5 digits.
#           Only for regularly spaced grids
#           Accounts for missing data
#           call with parameters e.g. -v ncols=500 -v xmin=2600000 -v 
ymin=5500000 -v cellsize=20 -v no_data=-9999
# Author:   Uli Müller, uli at geops.de
#
###############################################################################
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
###############################################################################

#create header
BEGIN {

	print ("ncols " ncols);
	print ("nrows " ncols);
	print ("xllcorner " xmin);
	print ("yllcorner " ymin);
	print ("cellsize " cellsize);
	print ("nodata_value " no_data);	
#create empty grid	
   for (y = 1; y <= ncols; y++)
     {ycoord=ymin+((y-1)*cellsize);
     	for (x = 1; x <= ncols; x++)
     	{ xcoord=xmin+((x-1)*cellsize);
     		grid[substr(xcoord,1,7),substr(ycoord,1,7)] = no_data;
     }
   }
}
#fill grid with data where available
{
  	grid[substr($1,1,7),substr($2,1,7)] = $3;
}
#write data from top to bottom row
END  {
   for (y = ncols; y >= 1; y--)
     {ycoord=ymin+((y-1)*cellsize);
     	for (x = 1; x <= ncols; x++)
     	{ xcoord=xmin+((x-1)*cellsize);
     		#printf"%7.0f ",xcoord;
     		#printf"%7.0f ",ycoord;
     		if (x!=ncols) {printf"%5.1f ",grid[xcoord,ycoord]} else \
     		{printf"%5.1f\n",grid[xcoord,ycoord]}
     }
   }

}



Jason M. Nielsen wrote:

> Quoting uli <uli.mueller at gmx.ch>:
> 
> 
>>Hi
>>I need to convert lots of ASCII XYZ files to GDAL. Is there any utility 
>>to accomplish this in batch mode? I would like not having to go for any 
>>large GIS packages like GRASS. I have found gdal2xyz.py, but I would 
>>need it the other way round.
>>Uli
>>
>>
>>_______________________________________________
>>Gdal-dev mailing list
>>Gdal-dev at xserve.flids.com
>>http://xserve.flids.com/mailman/listinfo/gdal-dev
>>
> 
> 
> 
> If you can get the xyz data in an ArcGRID (AAIGrid) format you can easily
> transform that to others such as img.
> 
> For example:
> 
> gdal_translate foo.AAIGrid foo.img -of HFA
> 
> It wouldnt be too difficult to make a program translate the xyz to the arcgrid.
>     Just sort into rows of Y(northing) by columns X(easting) starting with max Y
> min X at the beginning. For each X in Y write out the elevations then start a
> new line on each new Y of elevations. Of course if you do not have NO_DATA
> points represented in the xyz data then you will have to watch for those missing
> entities and make sure to add them in the arcgrid file otherwise your data will
> be "skewed". ie: Current Y exceeds previous Y by more than cellsize(distance
> between each grid point). The same applies to X.
> 
> 
> 





More information about the Gdal-dev mailing list