Ignore:
Timestamp:
Mar 18, 2013, 2:23:12 PM (12 years ago)
Author:
djay
Message:

Upgrade ogr2ogr to follow new ogr2ogr original source code.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/zoo-project/zoo-services/ogr/ogr2ogr/service.c

    r348 r395  
    3939CPL_CVSID("$Id: ogr2ogr.cpp 15473 2008-10-07 20:59:24Z warmerdam $");
    4040
     41#ifdef WIN32
     42#define strcasecmp _stricmp
     43#define strncasecmp _strnicmp
     44#endif
     45
    4146#ifdef ZOO_SERVICE
    4247extern "C" {
     
    6065static int bSkipFailures = FALSE;
    6166static int nGroupTransactions = 200;
    62 static int bPreserveFID = FALSE;
     67static int bPreserveFID = TRUE;
    6368static int nFIDToFetch = OGRNullFID;
    6469
     
    97102    double      dfMaxSegmentLength = 0;
    98103
     104#ifdef ZOO_SERVICE
     105    dumpMaps(inputs);
     106#endif
    99107    /* Check strict compilation and runtime library version as we use C++ API */
    100108    if (! GDAL_CHECK_VERSION("ogr2ogr"))
     
    142150    tmpMap=NULL;
    143151    tmpMap=getMapFromMaps(inputs,"F","value");
    144     if(tmpMap!=NULL){
     152    if(tmpMap!=NULL && strncasecmp(tmpMap->value,"NULL",4)!=0){
    145153      pszFormat=tmpMap->value;
    146154    }
     
    148156    tmpMap=NULL;
    149157    tmpMap=getMapFromMaps(inputs,"DSCO","value");
    150     if(tmpMap!=NULL){
     158    if(tmpMap!=NULL && strncasecmp(tmpMap->value,"NULL",4)!=0){
    151159          papszDSCO = CSLAddString(papszDSCO, tmpMap->value );
    152160    }
     
    154162    tmpMap=NULL;
    155163    tmpMap=getMapFromMaps(inputs,"LCO","value");
    156     if(tmpMap!=NULL){
     164    if(tmpMap!=NULL && strncasecmp(tmpMap->value,"NULL",4)!=0){
    157165          papszLCO = CSLAddString(papszLCO, tmpMap->value );
    158166    }
     
    160168    tmpMap=NULL;
    161169    tmpMap=getMapFromMaps(inputs,"preserve_fid","value");
    162     if(tmpMap!=NULL){
     170    if(tmpMap!=NULL && strncasecmp(tmpMap->value,"NULL",4)!=0){
    163171          bPreserveFID = TRUE;
    164172    }
     
    166174    tmpMap=NULL;
    167175    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;
    172186    }
    173187
    174188    tmpMap=NULL;
    175189    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
    183194    tmpMap=NULL;
    184195    tmpMap=getMapFromMaps(inputs,"update","value");
    185     if(tmpMap!=NULL){
    186           bUpdate = TRUE;
     196    if(tmpMap!=NULL && strncasecmp(tmpMap->value,"TRUE",4)==0){
     197      bUpdate = TRUE;
    187198    }
    188199
    189200    tmpMap=NULL;
    190201    tmpMap=getMapFromMaps(inputs,"fid","value");
    191     if(tmpMap!=NULL){
    192           nFIDToFetch = atoi(tmpMap->value);
     202    if(tmpMap!=NULL && strncasecmp(tmpMap->value,"NULL",4)!=0){
     203      nFIDToFetch = atoi(tmpMap->value);
    193204    }
    194205
    195206    tmpMap=NULL;
    196207    tmpMap=getMapFromMaps(inputs,"sql","value");
    197     if(tmpMap!=NULL){
    198           pszSQLStatement = tmpMap->value;
     208    if(tmpMap!=NULL && strncasecmp(tmpMap->value,"NULL",4)!=0){
     209      pszSQLStatement = tmpMap->value;
    199210    }
    200211
    201212    tmpMap=NULL;
    202213    tmpMap=getMapFromMaps(inputs,"nln","value");
    203     if(tmpMap!=NULL){
     214    if(tmpMap!=NULL && strncasecmp(tmpMap->value,"NULL",4)!=0){
    204215          pszNewLayerName = tmpMap->value;
    205216    }
     
    207218    tmpMap=NULL;
    208219    tmpMap=getMapFromMaps(inputs,"nlt","value");
    209     if(tmpMap!=NULL){
     220    if(tmpMap!=NULL && strncasecmp(tmpMap->value,"NULL",4)!=0){
    210221          pszNewLayerName = tmpMap->value;
    211222          if( EQUAL(tmpMap->value,"NONE") )
     
    253264    tmpMap=NULL;
    254265    tmpMap=getMapFromMaps(inputs,"tg","value");
    255     if(tmpMap!=NULL){
     266    if(tmpMap!=NULL && strncasecmp(tmpMap->value,"NULL",4)!=0){
    256267          nGroupTransactions = atoi(tmpMap->value);
    257268    }
     
    259270    tmpMap=NULL;
    260271    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);
    263274    }
    264275
    265276    tmpMap=NULL;
    266277    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);
    269280    }
    270281
    271282    tmpMap=NULL;
    272283    tmpMap=getMapFromMaps(inputs,"t_srs","value");
    273     if(tmpMap!=NULL){
    274           pszOutputSRSDef = tmpMap->value;
    275           bTransform = TRUE;
     284    if(tmpMap!=NULL && strncasecmp(tmpMap->value,"NULL",4)!=0){
     285      pszOutputSRSDef = strdup(tmpMap->value);
     286      bTransform = TRUE;
    276287    }
    277288
    278289    tmpMap=NULL;
    279290    tmpMap=getMapFromMaps(inputs,"SPAT","value");
    280     if(tmpMap!=NULL){
     291    if(tmpMap!=NULL && strncasecmp(tmpMap->value,"NULL",4)!=0){
    281292      char *tmp=tmpMap->value;
    282293      char *t=strtok(tmp,",");
     
    317328    tmpMap=NULL;
    318329    tmpMap=getMapFromMaps(inputs,"where","value");
    319     if(tmpMap!=NULL){
     330    if(tmpMap!=NULL && strncasecmp(tmpMap->value,"NULL",4)!=0){
    320331          pszWHERE = tmpMap->value;
    321332    }
     
    323334    tmpMap=NULL;
    324335    tmpMap=getMapFromMaps(inputs,"select","value");
    325     if(tmpMap!=NULL){
     336    if(tmpMap!=NULL && strncasecmp(tmpMap->value,"NULL",4)!=0){
    326337          pszSelect = tmpMap->value;
    327338          papszSelFields = CSLTokenizeStringComplex(pszSelect, " ,",
     
    331342    tmpMap=NULL;
    332343    tmpMap=getMapFromMaps(inputs,"segmentize","value");
    333     if(tmpMap!=NULL){
     344    if(tmpMap!=NULL && strncasecmp(tmpMap->value,"NULL",4)!=0){
    334345          dfMaxSegmentLength = atof(tmpMap->value);
    335346    }
    336347
    337     tmpMap=NULL;
     348    /*tmpMap=NULL;
    338349    tmpMap=getMapFromMaps(inputs,"segmentize","value");
    339350    if(tmpMap!=NULL){
    340351          dfMaxSegmentLength = atof(tmpMap->value);
    341     }
     352    }*/
    342353
    343354    tmpMap=NULL;
    344355    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      }
    348371    }
    349372
     
    351374    tmpMap=getMapFromMaps(inputs,"OutputDSN","value");
    352375    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);
    359393#else
    360394/* -------------------------------------------------------------------- */
     
    529563#ifdef ZOO_SERVICE
    530564        {
    531 #endif
     565#else
    532566          Usage();
     567#endif
    533568#ifdef ZOO_SERVICE
    534569          setMapInMaps(conf,"lenv","message","Wrong parameter");
     
    722757            fprintf( stderr,  "-where clause ignored in combination with -sql.\n" );
    723758        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);
    725760       
    726761        poResultSet = poDS->ExecuteSQL( pszSQLStatement, poSpatialFilter,
     
    783818                && !bSkipFailures )
    784819            {
     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
    785826                CPLError( CE_Failure, CPLE_AppDefined,
    786827                          "Terminating translation prematurely after failed\n"
     
    788829                          poLayer->GetLayerDefn()->GetName() );
    789830
    790 #ifdef ZOO_SERVICE
    791                 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 #else
    796831                exit( 1 );
    797832#endif
     
    800835    }
    801836
     837#ifdef ZOO_SERVICE
     838    outputs->content=createMap("value",(char*)pszwebDestData);
     839#endif
     840
    802841/* -------------------------------------------------------------------- */
    803842/*      Close down.                                                     */
    804843/* -------------------------------------------------------------------- */
     844    fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
    805845    delete poOutputSRS;
     846    fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
    806847    delete poSourceSRS;
     848    fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
    807849    delete poODS;
     850    fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
    808851    delete poDS;
    809 
     852    fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
     853
     854#ifndef ZOO_SERVICE
    810855    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__);
    811861#ifndef ZOO_SERVICE
    812         CSLDestroy( papszArgv );
    813 #endif
    814     CSLDestroy( papszLayers );
    815862    CSLDestroy( papszDSCO );
    816863    CSLDestroy( papszLCO );
     864#endif
     865    fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
    817866
    818867    OGRCleanupAll();
     868    fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
    819869
    820870#ifdef DBMALLOC
    821871    malloc_dump(1);
    822872#endif
     873    fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
    823874   
    824875#ifdef ZOO_SERVICE
    825     outputs->content=createMap("value",(char*)pszwebDestData);
    826876    return SERVICE_SUCCEEDED;
    827877#else
    828         return 0;
     878    return 0;
    829879#endif
    830880}
     
    10821132/* -------------------------------------------------------------------- */
    10831133    int         iField;
     1134    int hasMmField=-1;
    10841135
    10851136    if (papszSelFields && !bAppend )
     
    10881139        {
    10891140            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;
    10901146            if (iSrcField >= 0)
    10911147                poDstLayer->CreateField( poFDefn->GetFieldDefn(iSrcField) );
     
    10981154            }
    10991155        }
     1156
    11001157    }
    11011158    else if( !bAppend )
    11021159    {
    1103         for( iField = 0; iField < poFDefn->GetFieldCount(); iField++ )
     1160      for( iField = 0; iField < poFDefn->GetFieldCount(); iField++ ){
    11041161            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      }*/
    11061172
    11071173/* -------------------------------------------------------------------- */
     
    11101176    OGRFeature  *poFeature;
    11111177    int         nFeaturesInTransaction = 0;
    1112    
     1178    int fCount=0;
    11131179    poSrcLayer->ResetReading();
    11141180
     
    11301196        else
    11311197            poFeature = poSrcLayer->GetNextFeature();
    1132        
     1198
    11331199        if( poFeature == NULL )
    11341200            break;
     1201
     1202        //poFeature->SetField((poFeature->GetFieldCount()-1),fCount);
    11351203
    11361204        if( ++nFeaturesInTransaction == nGroupTransactions )
     
    11611229            poDstFeature->SetFID( poFeature->GetFID() );
    11621230
     1231        /*if(hasMmField<0){
     1232          poDstFeature->SetField((poDstFeature->GetFieldCount()-1),fCount);
     1233          fCount++;
     1234        }*/
     1235
    11631236#ifndef GDAL_1_5_0
    11641237        if (poDstFeature->GetGeometryRef() != NULL && dfMaxSegmentLength > 0)
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