Changeset 395
- Timestamp:
- Mar 18, 2013, 2:23:12 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/zoo-project/zoo-services/ogr/ogr2ogr/service.c
r348 r395 39 39 CPL_CVSID("$Id: ogr2ogr.cpp 15473 2008-10-07 20:59:24Z warmerdam $"); 40 40 41 #ifdef WIN32 42 #define strcasecmp _stricmp 43 #define strncasecmp _strnicmp 44 #endif 45 41 46 #ifdef ZOO_SERVICE 42 47 extern "C" { … … 60 65 static int bSkipFailures = FALSE; 61 66 static int nGroupTransactions = 200; 62 static int bPreserveFID = FALSE;67 static int bPreserveFID = TRUE; 63 68 static int nFIDToFetch = OGRNullFID; 64 69 … … 97 102 double dfMaxSegmentLength = 0; 98 103 104 #ifdef ZOO_SERVICE 105 dumpMaps(inputs); 106 #endif 99 107 /* Check strict compilation and runtime library version as we use C++ API */ 100 108 if (! GDAL_CHECK_VERSION("ogr2ogr")) … … 142 150 tmpMap=NULL; 143 151 tmpMap=getMapFromMaps(inputs,"F","value"); 144 if(tmpMap!=NULL ){152 if(tmpMap!=NULL && strncasecmp(tmpMap->value,"NULL",4)!=0){ 145 153 pszFormat=tmpMap->value; 146 154 } … … 148 156 tmpMap=NULL; 149 157 tmpMap=getMapFromMaps(inputs,"DSCO","value"); 150 if(tmpMap!=NULL ){158 if(tmpMap!=NULL && strncasecmp(tmpMap->value,"NULL",4)!=0){ 151 159 papszDSCO = CSLAddString(papszDSCO, tmpMap->value ); 152 160 } … … 154 162 tmpMap=NULL; 155 163 tmpMap=getMapFromMaps(inputs,"LCO","value"); 156 if(tmpMap!=NULL ){164 if(tmpMap!=NULL && strncasecmp(tmpMap->value,"NULL",4)!=0){ 157 165 papszLCO = CSLAddString(papszLCO, tmpMap->value ); 158 166 } … … 160 168 tmpMap=NULL; 161 169 tmpMap=getMapFromMaps(inputs,"preserve_fid","value"); 162 if(tmpMap!=NULL ){170 if(tmpMap!=NULL && strncasecmp(tmpMap->value,"NULL",4)!=0){ 163 171 bPreserveFID = TRUE; 164 172 } … … 166 174 tmpMap=NULL; 167 175 tmpMap=getMapFromMaps(inputs,"skipfailure","value"); 168 if(tmpMap!=NULL){ 169 bPreserveFID = TRUE; 170 bSkipFailures = TRUE; 171 nGroupTransactions = 1; /* #2409 */ 176 if(tmpMap!=NULL && strncasecmp(tmpMap->value,"NULL",4)!=0){ 177 bSkipFailures = TRUE; 178 nGroupTransactions = 1; /* #2409 */ 179 } 180 181 /* if exist, overwrite the data with the same name */ 182 tmpMap=NULL; 183 tmpMap=getMapFromMaps(inputs,"overwrite","value"); 184 if(tmpMap!=NULL && strncasecmp(tmpMap->value,"NULL",4)!=0){ 185 bOverwrite = TRUE; 172 186 } 173 187 174 188 tmpMap=NULL; 175 189 tmpMap=getMapFromMaps(inputs,"append","value"); 176 if(tmpMap!=NULL){ 177 bAppend = TRUE; 178 } 179 180 /* if exist, overwrite the data with the same name */ 181 bOverwrite = TRUE; 182 190 if(tmpMap!=NULL && strncasecmp(tmpMap->value,"TRUE",4)==0){ 191 bAppend = TRUE; 192 } 193 183 194 tmpMap=NULL; 184 195 tmpMap=getMapFromMaps(inputs,"update","value"); 185 if(tmpMap!=NULL ){186 196 if(tmpMap!=NULL && strncasecmp(tmpMap->value,"TRUE",4)==0){ 197 bUpdate = TRUE; 187 198 } 188 199 189 200 tmpMap=NULL; 190 201 tmpMap=getMapFromMaps(inputs,"fid","value"); 191 if(tmpMap!=NULL ){192 202 if(tmpMap!=NULL && strncasecmp(tmpMap->value,"NULL",4)!=0){ 203 nFIDToFetch = atoi(tmpMap->value); 193 204 } 194 205 195 206 tmpMap=NULL; 196 207 tmpMap=getMapFromMaps(inputs,"sql","value"); 197 if(tmpMap!=NULL ){198 208 if(tmpMap!=NULL && strncasecmp(tmpMap->value,"NULL",4)!=0){ 209 pszSQLStatement = tmpMap->value; 199 210 } 200 211 201 212 tmpMap=NULL; 202 213 tmpMap=getMapFromMaps(inputs,"nln","value"); 203 if(tmpMap!=NULL ){214 if(tmpMap!=NULL && strncasecmp(tmpMap->value,"NULL",4)!=0){ 204 215 pszNewLayerName = tmpMap->value; 205 216 } … … 207 218 tmpMap=NULL; 208 219 tmpMap=getMapFromMaps(inputs,"nlt","value"); 209 if(tmpMap!=NULL ){220 if(tmpMap!=NULL && strncasecmp(tmpMap->value,"NULL",4)!=0){ 210 221 pszNewLayerName = tmpMap->value; 211 222 if( EQUAL(tmpMap->value,"NONE") ) … … 253 264 tmpMap=NULL; 254 265 tmpMap=getMapFromMaps(inputs,"tg","value"); 255 if(tmpMap!=NULL ){266 if(tmpMap!=NULL && strncasecmp(tmpMap->value,"NULL",4)!=0){ 256 267 nGroupTransactions = atoi(tmpMap->value); 257 268 } … … 259 270 tmpMap=NULL; 260 271 tmpMap=getMapFromMaps(inputs,"s_srs","value"); 261 if(tmpMap!=NULL ){262 pszSourceSRSDef = tmpMap->value;272 if(tmpMap!=NULL && strncasecmp(tmpMap->value,"NULL",4)!=0){ 273 pszSourceSRSDef = strdup(tmpMap->value); 263 274 } 264 275 265 276 tmpMap=NULL; 266 277 tmpMap=getMapFromMaps(inputs,"a_srs","value"); 267 if(tmpMap!=NULL ){268 pszOutputSRSDef = tmpMap->value;278 if(tmpMap!=NULL && strncasecmp(tmpMap->value,"NULL",4)!=0){ 279 pszOutputSRSDef = strdup(tmpMap->value); 269 280 } 270 281 271 282 tmpMap=NULL; 272 283 tmpMap=getMapFromMaps(inputs,"t_srs","value"); 273 if(tmpMap!=NULL ){274 pszOutputSRSDef = tmpMap->value;275 284 if(tmpMap!=NULL && strncasecmp(tmpMap->value,"NULL",4)!=0){ 285 pszOutputSRSDef = strdup(tmpMap->value); 286 bTransform = TRUE; 276 287 } 277 288 278 289 tmpMap=NULL; 279 290 tmpMap=getMapFromMaps(inputs,"SPAT","value"); 280 if(tmpMap!=NULL ){291 if(tmpMap!=NULL && strncasecmp(tmpMap->value,"NULL",4)!=0){ 281 292 char *tmp=tmpMap->value; 282 293 char *t=strtok(tmp,","); … … 317 328 tmpMap=NULL; 318 329 tmpMap=getMapFromMaps(inputs,"where","value"); 319 if(tmpMap!=NULL ){330 if(tmpMap!=NULL && strncasecmp(tmpMap->value,"NULL",4)!=0){ 320 331 pszWHERE = tmpMap->value; 321 332 } … … 323 334 tmpMap=NULL; 324 335 tmpMap=getMapFromMaps(inputs,"select","value"); 325 if(tmpMap!=NULL ){336 if(tmpMap!=NULL && strncasecmp(tmpMap->value,"NULL",4)!=0){ 326 337 pszSelect = tmpMap->value; 327 338 papszSelFields = CSLTokenizeStringComplex(pszSelect, " ,", … … 331 342 tmpMap=NULL; 332 343 tmpMap=getMapFromMaps(inputs,"segmentize","value"); 333 if(tmpMap!=NULL ){344 if(tmpMap!=NULL && strncasecmp(tmpMap->value,"NULL",4)!=0){ 334 345 dfMaxSegmentLength = atof(tmpMap->value); 335 346 } 336 347 337 tmpMap=NULL;348 /*tmpMap=NULL; 338 349 tmpMap=getMapFromMaps(inputs,"segmentize","value"); 339 350 if(tmpMap!=NULL){ 340 351 dfMaxSegmentLength = atof(tmpMap->value); 341 } 352 }*/ 342 353 343 354 tmpMap=NULL; 344 355 tmpMap=getMapFromMaps(inputs,"InputDSN","value"); 345 if(tmpMap!=NULL){ 346 pszDataSource=(char*)malloc(sizeof(char)*(strlen(dataPath)+strlen(tmpMap->value)+1)); 347 sprintf((char*)pszDataSource,"%s/%s",dataPath,tmpMap->value); 356 if(tmpMap!=NULL && strncasecmp(tmpMap->value,"NULL",4)!=0){ 357 if(strncasecmp(tmpMap->value,"PG",2)!=0 && 358 strncasecmp(tmpMap->value,"My",2)!=0 && 359 strncasecmp(tmpMap->value,"OCI",3)!=0 ){ 360 if(strncasecmp(dataPath,tmpMap->value,strlen(dataPath))==0 || 361 strncasecmp(tempPath,tmpMap->value,strlen(tempPath))==0){ 362 pszDataSource=strdup(tmpMap->value); 363 }else{ 364 pszDataSource=(char*)malloc(sizeof(char)*(strlen(dataPath)+strlen(tmpMap->value)+2)); 365 sprintf((char*)pszDataSource,"%s/%s",dataPath,tmpMap->value); 366 } 367 }else{ 368 pszDataSource=(char*)malloc(sizeof(char)*(strlen(tmpMap->value)+1)); 369 sprintf((char*)pszDataSource,"%s",tmpMap->value); 370 } 348 371 } 349 372 … … 351 374 tmpMap=getMapFromMaps(inputs,"OutputDSN","value"); 352 375 if(tmpMap!=NULL){ 353 pszDestDataSource=(char*)malloc(sizeof(char)*(strlen(tempPath)+strlen(tmpMap->value)+4)); 354 sprintf((char*)pszDestDataSource,"%s/%s",tempPath,tmpMap->value/*,ext*/); 355 pszwebDestData=(char*)malloc(sizeof(char)*(strlen(serverAddress)+strlen(tmpurl)+strlen(tmpMap->value)+4)); 356 sprintf((char*)pszwebDestData,"%s%s/%s",serverAddress,tmpurl,tmpMap->value/*,ext*/); 357 } 358 376 if(strncasecmp(tmpMap->value,"PG",2)!=0 && 377 strncasecmp(tmpMap->value,"MY",2)!=0 && 378 strncasecmp(tmpMap->value,"OCI",3)!=0){ 379 pszDestDataSource=(char*)malloc(sizeof(char)*(strlen(tempPath)+strlen(tmpMap->value)+4)); 380 sprintf((char*)pszDestDataSource,"%s/%s",tempPath,tmpMap->value/*,ext*/); 381 pszwebDestData=(char*)malloc(sizeof(char)*(strlen(serverAddress)+strlen(tmpurl)+strlen(tmpMap->value)+4)); 382 sprintf((char*)pszwebDestData,"%s%s/%s",serverAddress,tmpurl,tmpMap->value/*,ext*/); 383 } 384 else{ 385 pszDestDataSource=(char*)malloc(sizeof(char)*(strlen(tmpMap->value)+1)); 386 sprintf((char*)pszDestDataSource,"%s",tmpMap->value/*,ext*/); 387 pszwebDestData=(char*)malloc(sizeof(char)*(strlen(serverAddress)+strlen(tmpurl)+strlen(tmpMap->value)+4)); 388 sprintf((char*)pszwebDestData,"%s%s/%s",serverAddress,tmpurl,tmpMap->value/*,ext*/); 389 } 390 } 391 392 fprintf(stderr,"Message %s\n",pszDestDataSource); 359 393 #else 360 394 /* -------------------------------------------------------------------- */ … … 529 563 #ifdef ZOO_SERVICE 530 564 { 531 #e ndif565 #else 532 566 Usage(); 567 #endif 533 568 #ifdef ZOO_SERVICE 534 569 setMapInMaps(conf,"lenv","message","Wrong parameter"); … … 722 757 fprintf( stderr, "-where clause ignored in combination with -sql.\n" ); 723 758 if( CSLCount(papszLayers) > 0 ) 724 fprintf( stderr, "layer names ignored in combination with -sql.\n");759 fprintf( stderr, "layer names ignored in combination with -sql. (%s)\n", pszSQLStatement); 725 760 726 761 poResultSet = poDS->ExecuteSQL( pszSQLStatement, poSpatialFilter, … … 783 818 && !bSkipFailures ) 784 819 { 820 #ifdef ZOO_SERVICE 821 char tmp[1024]; 822 sprintf(tmp,"Terminating translation prematurely after failed of layer %s",poLayer->GetLayerDefn()->GetName() ); 823 setMapInMaps(conf,"lenv","message",tmp); 824 return SERVICE_FAILED; 825 #else 785 826 CPLError( CE_Failure, CPLE_AppDefined, 786 827 "Terminating translation prematurely after failed\n" … … 788 829 poLayer->GetLayerDefn()->GetName() ); 789 830 790 #ifdef ZOO_SERVICE791 char tmp[1024];792 sprintf(tmp,"Terminating translation prematurely after failed of layer %s",poLayer->GetLayerDefn()->GetName() );793 setMapInMaps(conf,"lenv","message",tmp);794 return SERVICE_FAILED;795 #else796 831 exit( 1 ); 797 832 #endif … … 800 835 } 801 836 837 #ifdef ZOO_SERVICE 838 outputs->content=createMap("value",(char*)pszwebDestData); 839 #endif 840 802 841 /* -------------------------------------------------------------------- */ 803 842 /* Close down. */ 804 843 /* -------------------------------------------------------------------- */ 844 fprintf(stderr,"%s %d\n",__FILE__,__LINE__); 805 845 delete poOutputSRS; 846 fprintf(stderr,"%s %d\n",__FILE__,__LINE__); 806 847 delete poSourceSRS; 848 fprintf(stderr,"%s %d\n",__FILE__,__LINE__); 807 849 delete poODS; 850 fprintf(stderr,"%s %d\n",__FILE__,__LINE__); 808 851 delete poDS; 809 852 fprintf(stderr,"%s %d\n",__FILE__,__LINE__); 853 854 #ifndef ZOO_SERVICE 810 855 CSLDestroy(papszSelFields); 856 CSLDestroy( papszArgv ); 857 #endif 858 fprintf(stderr,"%s %d\n",__FILE__,__LINE__); 859 CSLDestroy( papszLayers ); 860 fprintf(stderr,"%s %d\n",__FILE__,__LINE__); 811 861 #ifndef ZOO_SERVICE 812 CSLDestroy( papszArgv );813 #endif814 CSLDestroy( papszLayers );815 862 CSLDestroy( papszDSCO ); 816 863 CSLDestroy( papszLCO ); 864 #endif 865 fprintf(stderr,"%s %d\n",__FILE__,__LINE__); 817 866 818 867 OGRCleanupAll(); 868 fprintf(stderr,"%s %d\n",__FILE__,__LINE__); 819 869 820 870 #ifdef DBMALLOC 821 871 malloc_dump(1); 822 872 #endif 873 fprintf(stderr,"%s %d\n",__FILE__,__LINE__); 823 874 824 875 #ifdef ZOO_SERVICE 825 outputs->content=createMap("value",(char*)pszwebDestData);826 876 return SERVICE_SUCCEEDED; 827 877 #else 828 878 return 0; 829 879 #endif 830 880 } … … 1082 1132 /* -------------------------------------------------------------------- */ 1083 1133 int iField; 1134 int hasMmField=-1; 1084 1135 1085 1136 if (papszSelFields && !bAppend ) … … 1088 1139 { 1089 1140 int iSrcField = poFDefn->GetFieldIndex(papszSelFields[iField]); 1141 OGRFieldDefn *tmp=poFDefn->GetFieldDefn(iSrcField); 1142 fprintf(stderr,"NAME: %s\n",tmp->GetNameRef()); 1143 fflush(stderr); 1144 if(tmp!=NULL && strncasecmp(tmp->GetNameRef(),"MMID",4)==0) 1145 hasMmField=1; 1090 1146 if (iSrcField >= 0) 1091 1147 poDstLayer->CreateField( poFDefn->GetFieldDefn(iSrcField) ); … … 1098 1154 } 1099 1155 } 1156 1100 1157 } 1101 1158 else if( !bAppend ) 1102 1159 { 1103 for( iField = 0; iField < poFDefn->GetFieldCount(); iField++ )1160 for( iField = 0; iField < poFDefn->GetFieldCount(); iField++ ){ 1104 1161 poDstLayer->CreateField( poFDefn->GetFieldDefn(iField) ); 1105 } 1162 OGRFieldDefn *tmp=poFDefn->GetFieldDefn(iField); 1163 if(tmp!=NULL && strncasecmp(tmp->GetNameRef(),"MMID",4)==0) 1164 hasMmField=1; 1165 fprintf(stderr,"NAME: %s\n",tmp->GetNameRef()); 1166 } 1167 } 1168 /*if(hasMmField<0){ 1169 OGRFieldDefn oField( "MMID", OFTInteger ); 1170 poDstLayer->CreateField( &oField ); 1171 }*/ 1106 1172 1107 1173 /* -------------------------------------------------------------------- */ … … 1110 1176 OGRFeature *poFeature; 1111 1177 int nFeaturesInTransaction = 0; 1112 1178 int fCount=0; 1113 1179 poSrcLayer->ResetReading(); 1114 1180 … … 1130 1196 else 1131 1197 poFeature = poSrcLayer->GetNextFeature(); 1132 1198 1133 1199 if( poFeature == NULL ) 1134 1200 break; 1201 1202 //poFeature->SetField((poFeature->GetFieldCount()-1),fCount); 1135 1203 1136 1204 if( ++nFeaturesInTransaction == nGroupTransactions ) … … 1161 1229 poDstFeature->SetFID( poFeature->GetFID() ); 1162 1230 1231 /*if(hasMmField<0){ 1232 poDstFeature->SetField((poDstFeature->GetFieldCount()-1),fCount); 1233 fCount++; 1234 }*/ 1235 1163 1236 #ifndef GDAL_1_5_0 1164 1237 if (poDstFeature->GetGeometryRef() != NULL && dfMaxSegmentLength > 0)
Note: See TracChangeset
for help on using the changeset viewer.