[FWTools] Images corrupted using gdal_translate with ecwp: URL

catria massimo.piccinetti at gmail.com
Sat Jan 12 11:28:52 EST 2008



Frank Warmerdam-2 wrote:
> 
> catria wrote:
>> I'm trying to download a little portion (1km x 1km) of a big ECW from an
>> Image Server, in GEOTiff format.
>> The downloaded Images are often corrupted, but gdal_translate does NOT
>> display any error.
>> I'm quite sure the problem is the slow Internet Connection.
>> 
>> This is an example of corrupted Image
>> http://www.nabble.com/file/p14617888/730_4840.jpeg 
>> 
>> There is any workaround to this problem?
> 
> Catria,
> 
> I have not had good luck with ecwp protocol, and I'm not sure why.  I
> imagine this is a bug in the GDAL ECW driver or perhaps something about
> the way I build the ECW SDK.  In any event, I have no useful suggestions
> to
> make this work.
> 
> Best regards,
> -- 
> ---------------------------------------+--------------------------------------
> I set the clouds in motion - turn up   | Frank Warmerdam,
> warmerdam at pobox.com
> light and sound - activate the windows | http://pobox.com/~warmerdam
> and watch the world go round - Rush    | President OSGeo, http://osgeo.org
> 
> _______________________________________________
> FWTools mailing list
> FWTools at lists.maptools.org
> http://lists.maptools.org/mailman/listinfo/fwtools
> http://fwtools.maptools.org/
> 
> 

I have downloaded the ECW SDK to try to understand the problem. I see that
the SDK works in Blocking mode and Callback mode. The Blocking mode in not
suitable for slow Internet Connections, because the DLL use a preset time,
and can deliver incomplete data to the caller.

I have written a little tool (for my needs) using the Callback mode, and it
work fine using a very slow connection.

char* crea_parte(PARAMETRI parametri)
{
   [...]

   err = NCScbmOpenFileView(parametri->ecw_url, &file_view_ptr,
ShowViewCallback);
   if (err != NCS_SUCCESS)
      return ERRORE("NCScbmOpenFileView", NULL, err);

   err = NCScbmGetViewFileInfo(file_view_ptr, &file_info_ptr);
   if (err != NCS_SUCCESS)
   {
      NCScbmCloseFileView(file_view_ptr);
      return ERRORE("NCScbmGetViewFileInfo", NULL, err);
   }

   [...]

   err = NCScbmSetFileView(file_view_ptr, num_bande, bande, tlx,tly,
brx,bry, sizex,sizey);
   if (err != NCS_SUCCESS)
   {
      NCScbmCloseFileView(file_view_ptr);
      return ERRORE("NCScbmSetFileViewEx", NULL, err);
   }

   for (k=1; k<=parametri->num_retry; ++k)
   {
      for (i=0;i<parametri->secs_timeout;++i)
      {
         Sleep(1000);
         if (stato_globale != NCSECW_READ_OK)
         {
            NCScbmCloseFileView(file_view_ptr);
            return ERRORE("timeout", NULL, (NCSError)0);
         }
         if (terminato)
            break;
      }
      if (i < parametri->secs_timeout)
         break;

      NCScbmSetFileView(file_view_ptr, num_bande, bande, tlx,tly, brx,bry,
sizex,sizey);
   }
   
   NCScbmCloseFileView(file_view_ptr);

   if (k > parametri->num_retry)
      return ERRORE("timeout", NULL, (NCSError)0);

   if (stato_globale != NCSECW_READ_OK)
      return ERRORE("NCScbmReadViewLineRGB", NULL, (NCSError)0);

   if (write_tiff(parametri->out_file, buffer, sizex, sizey,
atoi(&file_info_ptr->szProjection[4]),
parametri->TLX,parametri->TLY,file_info_ptr->fCellIncrementX ))
      return ERRORE("write_tiff", NULL, (NCSError)0);

   free(rgb);
   free_buffer(buffer);
   rgb = NULL;
   buffer = NULL;

   return NULL;
}

/*
 *
 */
static NCSEcwReadStatus ShowViewCallback(NCSFileView* file_view_ptr)
{
   NCSFileViewSetInfo* file_view_info_ptr;
   NCSEcwReadStatus stato;
   UINT32 sizex;
   UINT32 sizey;
   int line;
   int cella;
   int num_bande;

   if (rgb == NULL || buffer == NULL)
      return NCSECW_READ_OK;

   NCScbmGetViewInfo(file_view_ptr, &file_view_info_ptr);

   sizex = file_view_info_ptr->nSizeX;
   sizey = file_view_info_ptr->nSizeY;
   num_bande = file_view_info_ptr->nBands;

   for (line=0; line<(int)sizey; ++line)
   {
      stato = NCScbmReadViewLineRGB(file_view_ptr, rgb);
      if(stato != NCSECW_READ_OK)
      {
         stato_globale = stato;
         return stato;
      }

      for(cella=0; cella<(int)sizex; ++cella)
      {
         buffer->r [line * sizex + cella] = rgb [cella * 3];
         buffer->g [line * sizex + cella] = rgb [cella * 3 + 1];
         buffer->b [line * sizex + cella] = rgb [cella * 3 + 2];

         buffer->rgb [ (line * sizex * num_bande) + (cella * num_bande) + 0
] = rgb [cella * 3];
         buffer->rgb [ (line * sizex * num_bande) + (cella * num_bande) + 1
] = rgb [cella * 3 + 1];
         buffer->rgb [ (line * sizex * num_bande) + (cella * num_bande) + 2
] = rgb [cella * 3 + 2];
      }
   }

   if (file_view_info_ptr->nBlocksAvailable ==
file_view_info_ptr->nBlocksInView)
      terminato = 1;

   return stato;
}

I use 2 loops 

   for (k=1; k<=parametri->num_retry; ++k)
   {
      for (i=0;i<parametri->secs_timeout;++i)
      {

because in some circumstances after the first NCScbmSetFileView() the ECW
Thread stops delivering data blocks to the Callback Routine
If you call NCScbmSetFileView() again with the same parameters, the DLL use
the Cache for older data, and deliver the remaining blocks.

Im not an expert, and think this code is not thread safe, but works quite
fine.


-- 
View this message in context: http://www.nabble.com/Images-corrupted-using-gdal_translate-with-ecwp%3A-URL-tp14617888p14775376.html
Sent from the FWTools mailing list archive at Nabble.com.



More information about the FWTools mailing list