Changeset 369 for trunk/zoo-project/zoo-services/gdal
- Timestamp:
- Oct 8, 2012, 11:49:08 PM (12 years ago)
- 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 4 4 CC=gcc 5 5 6 cgi-env/ service.zo: service.c7 g++ ${CFLAGS} -shared -fpic -o cgi-env/ service.zo ./service.c ${GDAL_LIBS} ${MACOS_LD_FLAGS}6 cgi-env/translate_service.zo: service.c 7 g++ ${CFLAGS} -shared -fpic -o cgi-env/translate_service.zo ./service.c ${GDAL_LIBS} ${MACOS_LD_FLAGS} 8 8 9 9 clean: -
trunk/zoo-project/zoo-services/gdal/translate/cgi-env/Gdal_Translate.zcfg
r290 r369 6 6 statusSupported = true 7 7 serviceType = C 8 serviceProvider = gdal_service.zo8 serviceProvider = translate_service.zo 9 9 <MetaData> 10 10 title = My Demo … … 13 13 [Format] 14 14 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). 16 16 minOccurs = 0 17 17 maxOccurs = 1 … … 19 19 DataType = string 20 20 <Default> 21 value = demo.tif21 value = GTiff 22 22 </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 /> 23 32 </LiteralData> 24 33 [InputDSN] … … 29 38 <LiteralData> 30 39 DataType = string 31 <Default> 32 </Default> 40 <Default /> 33 41 </LiteralData> 34 [OutputD ataSourceName]42 [OutputDSN] 35 43 Title = The output data source name 36 44 Abstract = The output data source name to use as source for convertion. … … 39 47 <LiteralData> 40 48 DataType = string 41 <Default> 42 </Default> 49 <Default /> 43 50 </LiteralData> 44 51 </DataInputs> 45 52 <DataOutputs> 46 [ OutputedDataSourceName]53 [Result] 47 54 Title = The resulting converted file 48 55 Abstract = The file name resulting of the convertion -
trunk/zoo-project/zoo-services/gdal/translate/makefile.vc
r367 r369 16 16 !ENDIF 17 17 18 cgi-env/ gdal_service.zo: service.c19 $(CPP) -DWIN32 -DZOO_SERVICE -DNEED_STRCASESTR-I$(GDAL_DIR)/frmts/ $(CFLAGS) /c service.c20 link /dll /out:cgi-env/gdal_service.zo $(FILES) ./service.obj $(LDFLAGS) 18 cgi-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 21 21 22 22 clean: -
trunk/zoo-project/zoo-services/gdal/translate/service.c
r348 r369 33 33 #include "gdal_priv.h" 34 34 #include "ogr_spatialref.h" 35 #include "vrt dataset.h"35 #include "vrt/vrtdataset.h" 36 36 37 37 #include "service.h" 38 38 39 40 39 CPL_CVSID("$Id$"); 41 40 42 41 extern "C" { 43 44 42 45 43 static void AttachMetadata( GDALDatasetH, char ** ); … … 50 48 /************************************************************************/ 51 49 50 #ifdef WIN32 51 __declspec(dllexport) 52 #endif 52 53 int Gdal_Translate(maps*& conf,maps*& inputs,maps*& outputs) 53 54 { 54 55 fprintf(stderr,"STARTING GDAL TRANSLATE\n"); 56 fflush(stderr); 55 57 56 58 57 GDALDatasetH hDataset, hOutDS; … … 97 96 /* ----------------------------------------------------------------- */ 98 97 GDALAllRegister(); 99 100 98 /* ----------------------------------------------------------------- */ 101 99 /* Extract Format, InputDSN, OutputDSN parameters */ … … 124 122 tmpMap=getMapFromMaps(inputs,"InputDSN","value"); 125 123 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); 128 126 } 129 127 tmpMap=NULL; 130 128 tmpMap=getMapFromMaps(inputs,"OutputDSN","value"); 131 129 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)); 133 131 char *ext=new char[4]; 134 132 ext="tif"; … … 168 166 break; 169 167 } 170 fprintf(stderr,"%s\n\n",t);171 fprintf(stderr,"%f - %f - %f - %f\n\n",dfULX,dfULY,dfLRX,dfLRY);172 168 t=strtok(NULL,","); 173 169 cnt++; 174 170 } 175 171 } 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 176 258 tmpMap=NULL; 177 259 tmpMap=getMapFromMaps(inputs,"SRS","value"); … … 180 262 if( oOutputSRS.SetFromUserInput( tmpMap->value ) != OGRERR_NONE ) 181 263 { 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", 183 266 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; 188 272 } 189 273 oOutputSRS.exportToWkt( &pszOutputSRS ); … … 213 297 } 214 298 } 215 fprintf(stderr,"==%s %s %s %==\n",pszFormat,pszSource,pszDest);216 fflush(stderr);217 299 218 300 if( pszDest == NULL ){ … … 242 324 243 325 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 } 253 333 254 334 /* ----------------------------------------------------------------- */ … … 259 339 && GDALGetRasterCount(hDataset) == 0 ) 260 340 { 261 fprintf( stderr, 341 char *msg=(char*) CPLMalloc(1024*sizeof(char)); 342 sprintf( msg, 262 343 "Input file contains subdatasets. Please, select one of them for reading.\n" ); 263 fflush(stderr);344 setMapInMaps(conf,"lenv","message",msg); 264 345 GDALClose( hDataset ); 265 346 /** … … 288 369 289 370 bSubCall = bOldSubCall; 290 CPLFree( pszSubDest );371 free( pszSubDest ); 291 372 292 373 GDALClose( hDataset ); … … 310 391 311 392 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 ); 313 394 314 395 if( anSrcWin[2] == 0 && anSrcWin[3] == 0 ){ … … 375 456 "rotated. This configuration is not supported.\n" ); 376 457 GDALClose( hDataset ); 377 CPLFree( panBandList );458 free( panBandList ); 378 459 fflush(stderr); 379 460 /** … … 439 520 int iDr; 440 521 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); 443 524 for( iDr = 0; iDr < GDALGetDriverCount(); iDr++ ) 444 525 { … … 449 530 NULL ) != NULL ) 450 531 { 451 printf( " %s: %s\n", 532 fprintf(stderr,msg); 533 char *tmp=strdup(msg); 534 sprintf( msg,"%s %s: %s\n",tmp, 452 535 GDALGetDriverShortName( hDriver ), 453 536 GDALGetDriverLongName( hDriver ) ); 537 free(tmp); 454 538 } 455 539 } 456 printf( "\n" ); 457 540 setMapInMaps(conf,"lenv","message",msg); 458 541 GDALClose( hDataset ); 459 CPLFree( panBandList );542 free( panBandList ); 460 543 fflush(stderr); 461 544 /** … … 463 546 */ 464 547 CSLDestroy( papszCreateOptions ); 465 exit( 1 );548 return 4; 466 549 } 467 550 … … 472 555 /* virtual input source to copy from. */ 473 556 /* ----------------------------------------------------------------- */ 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 474 563 if( eOutputType == GDT_Unknown 475 564 && !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 480 566 && nGCPCount == 0 && !bGotBounds 481 567 && pszOutputSRS == NULL && !bSetNoData … … 484 570 485 571 hOutDS = GDALCreateCopy( hDriver, pszDest, hDataset, 486 bStrict, papszCreateOptions,572 FALSE, (char**)0, 487 573 pfnProgress, NULL ); 488 574 … … 492 578 GDALClose( hDataset ); 493 579 494 CPLFree( panBandList );580 free( panBandList ); 495 581 496 582 if( !bSubCall ) … … 501 587 */ 502 588 } 589 fprintf(stderr,"==%s %s %s %d==\n",pszFormat,pszSource,pszDest,__LINE__); 590 fflush(stderr); 503 591 504 592 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); 510 601 return SERVICE_SUCCEEDED; 511 602 } 512 fprintf(stderr,"==%s %s %s %==\n",pszFormat,pszSource,pszDest);513 fflush(stderr);514 603 515 604 /* ----------------------------------------------------------------- */ … … 528 617 ? atof(pszOYSize)/100*anSrcWin[3] : atoi(pszOYSize))); 529 618 } 530 fprintf(stderr,"==%s %s %s %==\n",pszFormat,pszSource,pszDest);531 fflush(stderr);532 619 533 620 /* ================================================================= */ … … 595 682 596 683 GDALDeinitGCPs( nGCPCount, pasGCPs ); 597 CPLFree( pasGCPs );684 free( pasGCPs ); 598 685 } 599 686 … … 617 704 618 705 GDALDeinitGCPs( nGCPs, pasGCPs ); 619 CPLFree( pasGCPs );706 free( pasGCPs ); 620 707 } 621 708 … … 625 712 poVDS->SetMetadata( ((GDALDataset*)hDataset)->GetMetadata() ); 626 713 AttachMetadata( (GDALDatasetH) poVDS, papszMetadataOptions ); 627 fprintf(stderr,"Transfer generally applicable metadata.\n");628 fflush(stderr);629 714 630 715 /* ----------------------------------------------------------------- */ … … 664 749 fprintf(stderr, "Error : band %d has no color table\n", panBandList[0]); 665 750 GDALClose( hDataset ); 666 CPLFree( panBandList );751 free( panBandList ); 667 752 fflush(stderr); 668 753 /** … … 760 845 /* Write to the output file using CopyCreate(). */ 761 846 /* ----------------------------------------------------------------- */ 762 fprintf(stderr,"DEBUG pszDest %s\n",pszDest);763 847 hOutDS = GDALCreateCopy( hDriver, pszDest, (GDALDatasetH) poVDS, 764 848 bStrict, papszCreateOptions, 765 849 pfnProgress, NULL ); 766 fprintf(stderr,"DEBUG pszDest %s\n",pszDest);767 fflush(stderr);768 850 769 851 if( hOutDS != NULL ) … … 773 855 774 856 GDALClose( (GDALDatasetH) poVDS ); 775 857 776 858 GDALClose( hDataset ); 777 778 CPLFree( panBandList );859 860 free( panBandList ); 779 861 780 CPLFree( pszOutputSRS );862 free( pszOutputSRS ); 781 863 782 864 if( !bSubCall ) … … 791 873 CSLDestroy( papszCreateOptions ); 792 874 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); 797 876 798 877 return SERVICE_SUCCEEDED; … … 817 896 pszValue = CPLParseNameValue( papszMetadataOptions[i], &pszKey ); 818 897 GDALSetMetadataItem(hDS,pszKey,pszValue,NULL); 819 CPLFree( pszKey );898 free( pszKey ); 820 899 } 821 900
Note: See TracChangeset
for help on using the changeset viewer.