Changeset 369


Ignore:
Timestamp:
Oct 8, 2012, 11:49:08 PM (12 years ago)
Author:
djay
Message:

Add GCP option to gdal_translate service. Add warp service based on gdal_warp.

Location:
trunk/zoo-project/zoo-services/gdal
Files:
6 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/zoo-project/zoo-services/gdal/translate/Makefile

    r284 r369  
    44CC=gcc
    55
    6 cgi-env/service.zo: service.c
    7         g++ ${CFLAGS} -shared -fpic -o cgi-env/service.zo ./service.c ${GDAL_LIBS} ${MACOS_LD_FLAGS}
     6cgi-env/translate_service.zo: service.c
     7        g++ ${CFLAGS} -shared -fpic -o cgi-env/translate_service.zo ./service.c ${GDAL_LIBS} ${MACOS_LD_FLAGS}
    88
    99clean:
  • trunk/zoo-project/zoo-services/gdal/translate/cgi-env/Gdal_Translate.zcfg

    r290 r369  
    66 statusSupported = true
    77 serviceType = C
    8  serviceProvider = gdal_service.zo
     8 serviceProvider = translate_service.zo
    99 <MetaData>
    1010   title = My Demo
     
    1313  [Format]
    1414   Title = Format of the output data
    15    Abstract = Select the output format.
     15   Abstract = Select the output format by usig short name of the format (use gda-config --formats for list of available formats on your platform).
    1616   minOccurs = 0
    1717   maxOccurs = 1
     
    1919    DataType = string
    2020    <Default>
    21      value = demo.tif
     21     value = GTiff
    2222    </Default>
     23   </LiteralData>
     24  [GCP]
     25   Title = Ground Point Control
     26   Abstract = Ground Point Control in the form : pixel,line,eating,northing(,elev).
     27   minOccurs = 0
     28   maxOccurs = unbounded
     29   <LiteralData>
     30    DataType = string
     31    <Default />
    2332   </LiteralData>
    2433  [InputDSN]
     
    2938   <LiteralData>
    3039    DataType = string
    31     <Default>
    32     </Default> 
     40    <Default />
    3341   </LiteralData>
    34   [OutputDataSourceName]
     42  [OutputDSN]
    3543   Title = The output data source name
    3644   Abstract = The output data source name to use as source for convertion.
     
    3947   <LiteralData>
    4048    DataType = string
    41     <Default>
    42     </Default> 
     49    <Default />
    4350   </LiteralData>
    4451 </DataInputs>
    4552 <DataOutputs>
    46   [OutputedDataSourceName]
     53  [Result]
    4754   Title = The resulting converted file
    4855   Abstract = The file name resulting of the convertion
  • trunk/zoo-project/zoo-services/gdal/translate/makefile.vc

    r367 r369  
    1616!ENDIF
    1717
    18 cgi-env/gdal_service.zo: service.c
    19         $(CPP) -DWIN32 -DZOO_SERVICE -DNEED_STRCASESTR -I$(GDAL_DIR)/frmts/ $(CFLAGS) /c service.c
    20         link /dll /out:cgi-env/gdal_service.zo  $(FILES) ./service.obj $(LDFLAGS)
     18cgi-env/translate_service.zo: service.c
     19        $(CPP)  /D_CRT_NONSTDC_NO_DEPRECATE -DWIN32 -DZOO_SERVICE -I$(GDAL_DIR)/frmts/ $(CFLAGS) /c service.c
     20        link /dll /out:cgi-env/gdal_service.zo  $(FILES) ./service.obj $(LDFLAGS) /FORCE:MULTIPLE
    2121
    2222clean:
  • trunk/zoo-project/zoo-services/gdal/translate/service.c

    r348 r369  
    3333#include "gdal_priv.h"
    3434#include "ogr_spatialref.h"
    35 #include "vrtdataset.h"
     35#include "vrt/vrtdataset.h"
    3636
    3737#include "service.h"
    3838
    39 
    4039CPL_CVSID("$Id$");
    4140
    4241extern "C" {
    43 
    4442
    4543  static void AttachMetadata( GDALDatasetH, char ** );
     
    5048  /************************************************************************/
    5149
     50#ifdef WIN32
     51__declspec(dllexport)
     52#endif
    5253  int Gdal_Translate(maps*& conf,maps*& inputs,maps*& outputs)
    5354  {
    54    
    55     fprintf(stderr,"STARTING GDAL TRANSLATE\n");
    56     fflush(stderr);
     55
    5756
    5857    GDALDatasetH        hDataset, hOutDS;
     
    9796    /* ----------------------------------------------------------------- */
    9897    GDALAllRegister();
    99 
    10098    /* ----------------------------------------------------------------- */
    10199    /* Extract Format, InputDSN, OutputDSN parameters                    */
     
    124122    tmpMap=getMapFromMaps(inputs,"InputDSN","value");
    125123    if(tmpMap!=NULL){
    126       pszSource=(char*)malloc(sizeof(char)*(strlen(dataPath)+strlen(tmpMap->value)+4));
    127       sprintf((char*)pszSource,"%s/%s.tif",dataPath,tmpMap->value);
     124      pszSource=(char*)CPLMalloc(sizeof(char)*(strlen(dataPath)+strlen(tmpMap->value)+4));
     125      sprintf((char*)pszSource,"%s/%s",dataPath,tmpMap->value);
    128126    }
    129127    tmpMap=NULL;
    130128    tmpMap=getMapFromMaps(inputs,"OutputDSN","value");
    131129    if(tmpMap!=NULL){
    132       pszDest=(char*)malloc(sizeof(char)*(strlen(tempPath)+strlen(tmpMap->value)+4));
     130      pszDest=(char*)CPLMalloc(sizeof(char)*(strlen(tempPath)+strlen(tmpMap->value)+4));
    133131      char *ext=new char[4];
    134132      ext="tif";
     
    168166          break;
    169167        }
    170         fprintf(stderr,"%s\n\n",t);
    171         fprintf(stderr,"%f - %f - %f - %f\n\n",dfULX,dfULY,dfLRX,dfLRY);
    172168        t=strtok(NULL,",");
    173169        cnt++;
    174170      }
    175171    }
     172
     173    tmpMap=NULL;
     174    tmpMap=getMapFromMaps(inputs,"GCP","value");
     175    if(tmpMap!=NULL){
     176      map* length=getMapFromMaps(inputs,"GCP","length");
     177      int len=0;
     178      if(length){
     179        len=atoi(length->value);
     180        int i;
     181        maps* currentMaps=getMaps(inputs,"GCP");
     182        for(i=0;i<len;i++){
     183          char* endptr = NULL;
     184          /* -gcp pixel line easting northing [elev] */
     185         
     186          nGCPCount++;
     187          pasGCPs = (GDAL_GCP *)
     188            realloc( pasGCPs, sizeof(GDAL_GCP) * nGCPCount );
     189          GDALInitGCPs( 1, pasGCPs + nGCPCount - 1 );
     190
     191          map* currentMap=getMapArray(currentMaps->content,"value",i);
     192
     193          char* tmpV=strdup(currentMap->value);
     194          char *res=strtok(tmpV,",");
     195          int j=0;
     196          while(res!=NULL){
     197            switch(j){
     198            case 0:
     199              pasGCPs[nGCPCount-1].dfGCPPixel = CPLAtofM(res);
     200              break;
     201            case 1:
     202              pasGCPs[nGCPCount-1].dfGCPLine = CPLAtofM(res);
     203              break;
     204            case 2:
     205              pasGCPs[nGCPCount-1].dfGCPX = CPLAtofM(res);
     206              break;
     207            case 3:
     208              pasGCPs[nGCPCount-1].dfGCPY = CPLAtofM(res);
     209              break;
     210            case 4:
     211              if(res!=NULL && (strtod(res, &endptr) != 0.0 || res[0] == '0'))
     212                if (endptr && *endptr == 0)
     213                  pasGCPs[nGCPCount-1].dfGCPZ = CPLAtofM(res);
     214              break;
     215            }
     216            res=strtok(NULL,",");
     217            j++;
     218          }
     219        }
     220      }else{
     221        char* endptr = NULL;
     222        /* -gcp pixel line easting northing [elev] */
     223       
     224        nGCPCount++;
     225        pasGCPs = (GDAL_GCP *)
     226          realloc( pasGCPs, sizeof(GDAL_GCP) * nGCPCount );
     227        GDALInitGCPs( 1, pasGCPs + nGCPCount - 1 );
     228       
     229        char* tmpV=strdup(tmpMap->value);
     230        char *res=strtok(tmpV,",");
     231        int j=0;
     232        while(res!=NULL){
     233          switch(j){
     234          case 0:
     235            pasGCPs[nGCPCount-1].dfGCPPixel = CPLAtofM(res);
     236            break;
     237          case 1:
     238            pasGCPs[nGCPCount-1].dfGCPLine = CPLAtofM(res);
     239            break;
     240          case 2:
     241            pasGCPs[nGCPCount-1].dfGCPX = CPLAtofM(res);
     242            break;
     243          case 3:
     244            pasGCPs[nGCPCount-1].dfGCPY = CPLAtofM(res);
     245            break;
     246          case 4:
     247            if(res!=NULL && (CPLStrtod(res, &endptr) != 0.0 || res[0] == '0'))
     248              if (endptr && *endptr == 0)
     249                pasGCPs[nGCPCount-1].dfGCPZ = CPLAtofM(res);
     250            break;
     251          }         
     252          res=strtok(NULL,",");
     253          j++;
     254        }
     255      }
     256    }
     257
    176258    tmpMap=NULL;
    177259    tmpMap=getMapFromMaps(inputs,"SRS","value");
     
    180262      if( oOutputSRS.SetFromUserInput( tmpMap->value ) != OGRERR_NONE )
    181263        {
    182           fprintf( stderr, "Failed to process SRS definition: %s\n",
     264          char *msg=(char*)CPLMalloc(100*sizeof(char));
     265          sprintf( msg, "Failed to process SRS definition: %s\n",
    183266                   tmpMap->value );
    184             /**
    185              * Avoiding GDALDestroyDriverManager() call
    186              */
    187           exit( 1 );
     267          setMapInMaps(conf,"lenv","message",msg);
     268          /**
     269           * Avoiding GDALDestroyDriverManager() call
     270           */
     271          return SERVICE_FAILED;
    188272        }
    189273      oOutputSRS.exportToWkt( &pszOutputSRS );
     
    213297        }
    214298    }
    215     fprintf(stderr,"==%s %s %s %==\n",pszFormat,pszSource,pszDest);
    216     fflush(stderr);
    217299
    218300    if( pszDest == NULL ){
     
    242324   
    243325    if( hDataset == NULL ){
    244         fprintf( stderr,
    245                  "GDALOpen failed - %d\n%s\n",
    246                  CPLGetLastErrorNo(), CPLGetLastErrorMsg() );
    247         fflush(stderr);
    248         /**
    249          * Avoiding GDALDestroyDriverManager() call
    250          */
    251         exit( 1 );
    252       }
     326      char *msg=(char*) CPLMalloc(1024*sizeof(char));
     327      sprintf( msg,
     328               "GDALOpen failed - %d\n%s\n",
     329               CPLGetLastErrorNo(), CPLGetLastErrorMsg() );
     330      setMapInMaps(conf,"lenv","message",msg);
     331      return SERVICE_FAILED;
     332    }
    253333
    254334    /* ----------------------------------------------------------------- */
     
    259339        && GDALGetRasterCount(hDataset) == 0 )
    260340      {
    261         fprintf( stderr,
     341        char *msg=(char*) CPLMalloc(1024*sizeof(char));
     342        sprintf( msg,
    262343                 "Input file contains subdatasets. Please, select one of them for reading.\n" );
    263         fflush(stderr);
     344        setMapInMaps(conf,"lenv","message",msg);
    264345        GDALClose( hDataset );
    265346        /**
     
    288369       
    289370        bSubCall = bOldSubCall;
    290         CPLFree( pszSubDest );
     371        free( pszSubDest );
    291372
    292373        GDALClose( hDataset );
     
    310391
    311392    if( !bQuiet )
    312       printf( "Input file size is %d, %d\n", nRasterXSize, nRasterYSize );
     393      fprintf( stderr, "Input file size is %d, %d\n", nRasterXSize, nRasterYSize );
    313394
    314395    if( anSrcWin[2] == 0 && anSrcWin[3] == 0 ){
     
    375456                     "rotated.  This configuration is not supported.\n" );
    376457            GDALClose( hDataset );
    377             CPLFree( panBandList );
     458            free( panBandList );
    378459            fflush(stderr);
    379460            /**
     
    439520        int     iDr;
    440521       
    441         printf( "Output driver `%s' not recognised.\n", pszFormat );
    442         printf( "The following format drivers are configured and support output:\n" );
     522        char* msg=(char*) CPLMalloc(4096*sizeof(char));
     523        sprintf(msg,"Output driver `%s' not recognised.\nThe following format drivers are configured and support output:\n",pszFormat);
    443524        for( iDr = 0; iDr < GDALGetDriverCount(); iDr++ )
    444525          {
     
    449530                                        NULL ) != NULL )
    450531              {
    451                 printf( "  %s: %s\n",
     532                fprintf(stderr,msg);
     533                char *tmp=strdup(msg);
     534                sprintf( msg,"%s  %s: %s\n",tmp,
    452535                        GDALGetDriverShortName( hDriver  ),
    453536                        GDALGetDriverLongName( hDriver ) );
     537                free(tmp);
    454538              }
    455539          }
    456         printf( "\n" );
    457        
     540        setMapInMaps(conf,"lenv","message",msg);
    458541        GDALClose( hDataset );
    459         CPLFree( panBandList );
     542        free( panBandList );
    460543        fflush(stderr);
    461544        /**
     
    463546         */
    464547        CSLDestroy( papszCreateOptions );
    465         exit( 1 );
     548        return 4;
    466549      }
    467550
     
    472555    /*   virtual input source to copy from.                              */
    473556    /* ----------------------------------------------------------------- */
     557    int bSpatialArrangementPreserved = (
     558           anSrcWin[0] == 0 && anSrcWin[1] == 0
     559        && anSrcWin[2] == GDALGetRasterXSize(hDataset)
     560        && anSrcWin[3] == GDALGetRasterYSize(hDataset)
     561        && pszOXSize == NULL && pszOYSize == NULL );
     562
    474563    if( eOutputType == GDT_Unknown
    475564        && !bScale && CSLCount(papszMetadataOptions) == 0 && bDefBands
    476         && anSrcWin[0] == 0 && anSrcWin[1] == 0
    477         && anSrcWin[2] == GDALGetRasterXSize(hDataset)
    478         && anSrcWin[3] == GDALGetRasterYSize(hDataset)
    479         && pszOXSize == NULL && pszOYSize == NULL
     565        && bSpatialArrangementPreserved
    480566        && nGCPCount == 0 && !bGotBounds
    481567        && pszOutputSRS == NULL && !bSetNoData
     
    484570       
    485571        hOutDS = GDALCreateCopy( hDriver, pszDest, hDataset,
    486                                  bStrict, papszCreateOptions,
     572                                 FALSE, (char**)0,
    487573                                 pfnProgress, NULL );
    488574
     
    492578        GDALClose( hDataset );
    493579
    494         CPLFree( panBandList );
     580        free( panBandList );
    495581
    496582        if( !bSubCall )
     
    501587             */
    502588          }
     589        fprintf(stderr,"==%s %s %s %d==\n",pszFormat,pszSource,pszDest,__LINE__);
     590        fflush(stderr);
    503591
    504592        CSLDestroy( papszCreateOptions );
    505         outputs=(maps*)malloc(sizeof(maps*));
    506         outputs->name="OutputedPolygon";
    507         outputs->content=createMap("value",(char*)pszDest);
    508         outputs->next=NULL;
    509        
     593        fprintf(stderr,"==%s %s %s %d==\n",pszFormat,pszSource,pszDest,__LINE__);
     594        fflush(stderr);
     595        //outputs=(maps*)CPLMalloc(sizeof(maps*));
     596        //outputs->name="OutputedPolygon";
     597        //outputs->content=createMap("value",(char*)pszDest);
     598        //outputs->next=NULL;
     599        dumpMaps(outputs);
     600        setMapInMaps(outputs,"Result","value",(char*)pszDest);
    510601        return SERVICE_SUCCEEDED;
    511602      }
    512     fprintf(stderr,"==%s %s %s %==\n",pszFormat,pszSource,pszDest);
    513     fflush(stderr);
    514603
    515604    /* ----------------------------------------------------------------- */
     
    528617                          ? atof(pszOYSize)/100*anSrcWin[3] : atoi(pszOYSize)));
    529618      }
    530     fprintf(stderr,"==%s %s %s %==\n",pszFormat,pszSource,pszDest);
    531     fflush(stderr);
    532619
    533620    /* ================================================================= */
     
    595682
    596683        GDALDeinitGCPs( nGCPCount, pasGCPs );
    597         CPLFree( pasGCPs );
     684        free( pasGCPs );
    598685      }
    599686
     
    617704
    618705        GDALDeinitGCPs( nGCPs, pasGCPs );
    619         CPLFree( pasGCPs );
     706        free( pasGCPs );
    620707      }
    621708
     
    625712    poVDS->SetMetadata( ((GDALDataset*)hDataset)->GetMetadata() );
    626713    AttachMetadata( (GDALDatasetH) poVDS, papszMetadataOptions );
    627     fprintf(stderr,"Transfer generally applicable metadata.\n");
    628     fflush(stderr);
    629714
    630715    /* ----------------------------------------------------------------- */
     
    664749                fprintf(stderr, "Error : band %d has no color table\n", panBandList[0]);
    665750                GDALClose( hDataset );
    666                 CPLFree( panBandList );
     751                free( panBandList );
    667752                fflush(stderr);
    668753                /**
     
    760845    /*      Write to the output file using CopyCreate().                 */
    761846    /* ----------------------------------------------------------------- */
    762     fprintf(stderr,"DEBUG pszDest %s\n",pszDest);
    763847    hOutDS = GDALCreateCopy( hDriver, pszDest, (GDALDatasetH) poVDS,
    764848                             bStrict, papszCreateOptions,
    765849                             pfnProgress, NULL );
    766     fprintf(stderr,"DEBUG pszDest %s\n",pszDest);
    767     fflush(stderr);
    768850
    769851    if( hOutDS != NULL )
     
    773855   
    774856    GDALClose( (GDALDatasetH) poVDS );
    775        
     857         
    776858    GDALClose( hDataset );
    777 
    778     CPLFree( panBandList );
     859   
     860    free( panBandList );
    779861   
    780     CPLFree( pszOutputSRS );
     862    free( pszOutputSRS );
    781863
    782864    if( !bSubCall )
     
    791873    CSLDestroy( papszCreateOptions );
    792874   
    793     outputs=(maps*)malloc(sizeof(maps*));
    794     outputs->name="OutputedPolygon";
    795     outputs->content=createMap("value",(char*)pszDest);
    796     outputs->next=NULL;
     875    setMapInMaps(outputs,"Result","value",(char*)pszDest);
    797876
    798877    return SERVICE_SUCCEEDED;
     
    817896        pszValue = CPLParseNameValue( papszMetadataOptions[i], &pszKey );
    818897        GDALSetMetadataItem(hDS,pszKey,pszValue,NULL);
    819         CPLFree( pszKey );
     898        free( pszKey );
    820899      }
    821900
Note: See TracChangeset for help on using the changeset viewer.

Search

Context Navigation

ZOO Sponsors

http://www.zoo-project.org/trac/chrome/site/img/geolabs-logo.pnghttp://www.zoo-project.org/trac/chrome/site/img/neogeo-logo.png http://www.zoo-project.org/trac/chrome/site/img/apptech-logo.png http://www.zoo-project.org/trac/chrome/site/img/3liz-logo.png http://www.zoo-project.org/trac/chrome/site/img/gateway-logo.png

Become a sponsor !

Knowledge partners

http://www.zoo-project.org/trac/chrome/site/img/ocu-logo.png http://www.zoo-project.org/trac/chrome/site/img/gucas-logo.png http://www.zoo-project.org/trac/chrome/site/img/polimi-logo.png http://www.zoo-project.org/trac/chrome/site/img/fem-logo.png http://www.zoo-project.org/trac/chrome/site/img/supsi-logo.png http://www.zoo-project.org/trac/chrome/site/img/cumtb-logo.png

Become a knowledge partner

Related links

http://zoo-project.org/img/ogclogo.png http://zoo-project.org/img/osgeologo.png