[GRASS-dev] GRASS Python Ctypes: Write Raster produces No null file error!!

Sudipta Sarkar sdptsarkar2 at gmail.com
Mon Apr 11 09:25:58 EDT 2011


Dear List Users,

Please help me solve the following, I am entirely new to the whole Python-GRASS-Ctypes issue so please bear with me. 

I am trying to develop an application using Python Ctypes hooks to GRASS C libraries. Have done most of the part but getting stuck in the end where i try to write off my output file as GRASS raster. I am giving the relevant part below along with the error I am getting:

    ptype = POINTER(c_float)
    MA.resize(bands,rows,cols)
    for b in range(bands):
	ofn = "madresult." + str(b)
	out_fd = Rast_open_new(ofn,FCELL_TYPE)
	if out_fd < 0:
	    G_fatal_error("Unable to create raster map <%s>", ofn)
    	out_rast = Rast_allocate_buf(FCELL_TYPE)
	out_rast = cast(c_void_p(out_rast), ptype)
   	for row_n in range(rows):
	    for col_n in range(cols):
		if math.isnan(MA[b,row_n,col_n]):
		    Rast_set_null_value(out_rast[col_n],1,FCELL_TYPE)
		else:
		    out_rast[col_n] = MA[b,row_n,col_n]
	    Rast_put_row(out_fd,out_rast,FCELL_TYPE)
	G_free(out_rast)
	Rast_close(out_fd)
	
where MA is a numpy.ndarray, bands, rows and cols are all integer type variables and are self explanatory i believe. 

When it comes to executing the line "Rast_close(out_fd)" I am getting the error: "ERROR: No null file for <madresult.0>"

How do I write the null file? I have some experience in developing GRASS raster modules in C and there I never had to write any null file explicitly so whats going wrong over here? Any help from all you GRASS pioneers will be deeply appreciated. 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/grass-dev/attachments/20110411/63e4cf82/attachment-0001.html


More information about the grass-dev mailing list