[1] | 1 | /****************************************************************************** |
---|
| 2 | * $Id: ogr2ogr.cpp 15473 2008-10-07 20:59:24Z warmerdam $ |
---|
| 3 | * |
---|
| 4 | * Project: OpenGIS Simple Features Reference Implementation |
---|
| 5 | * Purpose: Simple client for translating between formats. |
---|
| 6 | * Author: Frank Warmerdam, warmerdam@pobox.com |
---|
| 7 | * |
---|
| 8 | ****************************************************************************** |
---|
| 9 | * Copyright (c) 1999, Frank Warmerdam |
---|
| 10 | * |
---|
| 11 | * Permission is hereby granted, free of charge, to any person obtaining a |
---|
| 12 | * copy of this software and associated documentation files (the "Software"), |
---|
| 13 | * to deal in the Software without restriction, including without limitation |
---|
| 14 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
---|
| 15 | * and/or sell copies of the Software, and to permit persons to whom the |
---|
| 16 | * Software is furnished to do so, subject to the following conditions: |
---|
| 17 | * |
---|
| 18 | * The above copyright notice and this permission notice shall be included |
---|
| 19 | * in all copies or substantial portions of the Software. |
---|
| 20 | * |
---|
| 21 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
---|
| 22 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
---|
| 23 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
---|
| 24 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
---|
| 25 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
---|
| 26 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
---|
| 27 | * DEALINGS IN THE SOFTWARE. |
---|
| 28 | ****************************************************************************/ |
---|
| 29 | |
---|
| 30 | #include "ogrsf_frmts.h" |
---|
| 31 | #include "ogr_p.h" |
---|
| 32 | #include "cpl_conv.h" |
---|
| 33 | #include "cpl_string.h" |
---|
| 34 | #include "ogr_api.h" |
---|
[766] | 35 | #if GDAL_VERSION_MAJOR >= 2 |
---|
| 36 | #include <gdal_priv.h> |
---|
| 37 | #endif |
---|
[1] | 38 | #ifdef ZOO_SERVICE |
---|
| 39 | #include "service.h" |
---|
| 40 | #endif |
---|
| 41 | |
---|
| 42 | CPL_CVSID("$Id: ogr2ogr.cpp 15473 2008-10-07 20:59:24Z warmerdam $"); |
---|
| 43 | |
---|
[395] | 44 | #ifdef WIN32 |
---|
| 45 | #define strcasecmp _stricmp |
---|
| 46 | #define strncasecmp _strnicmp |
---|
| 47 | #endif |
---|
| 48 | |
---|
[1] | 49 | #ifdef ZOO_SERVICE |
---|
| 50 | extern "C" { |
---|
| 51 | #endif |
---|
| 52 | |
---|
| 53 | static void Usage(); |
---|
| 54 | |
---|
[766] | 55 | static int TranslateLayer( |
---|
| 56 | #if GDAL_VERSION_MAJOR >= 2 |
---|
| 57 | GDALDataset |
---|
| 58 | #else |
---|
| 59 | OGRDataSource |
---|
| 60 | #endif |
---|
| 61 | *poSrcDS, |
---|
| 62 | OGRLayer * poSrcLayer, |
---|
| 63 | #if GDAL_VERSION_MAJOR >= 2 |
---|
| 64 | GDALDataset |
---|
| 65 | #else |
---|
| 66 | OGRDataSource |
---|
| 67 | #endif |
---|
| 68 | *poDstDS, |
---|
| 69 | char ** papszLSCO, |
---|
| 70 | const char *pszNewLayerName, |
---|
| 71 | int bTransform, |
---|
| 72 | OGRSpatialReference *poOutputSRS, |
---|
| 73 | OGRSpatialReference *poSourceSRS, |
---|
| 74 | char **papszSelFields, |
---|
| 75 | int bAppend, int eGType, |
---|
| 76 | int bOverwrite, |
---|
| 77 | double dfMaxSegmentLength |
---|
| 78 | ); |
---|
| 79 | |
---|
[1] | 80 | static int bSkipFailures = FALSE; |
---|
| 81 | static int nGroupTransactions = 200; |
---|
[395] | 82 | static int bPreserveFID = TRUE; |
---|
[1] | 83 | static int nFIDToFetch = OGRNullFID; |
---|
| 84 | |
---|
| 85 | /************************************************************************/ |
---|
| 86 | /* main() */ |
---|
| 87 | /************************************************************************/ |
---|
| 88 | |
---|
| 89 | #ifdef ZOO_SERVICE |
---|
| 90 | #ifdef WIN32 |
---|
| 91 | __declspec(dllexport) |
---|
| 92 | #endif |
---|
| 93 | int Ogr2Ogr(maps*& conf,maps*& inputs,maps*& outputs) |
---|
| 94 | #else |
---|
| 95 | int main( int nArgc, char ** papszArgv ) |
---|
| 96 | #endif |
---|
| 97 | { |
---|
| 98 | const char *pszFormat = "ESRI Shapefile"; |
---|
| 99 | const char *pszDataSource = NULL; |
---|
| 100 | const char *pszDestDataSource = NULL; |
---|
[49] | 101 | const char *pszwebDestData = NULL; |
---|
[1] | 102 | char **papszLayers = NULL; |
---|
| 103 | char **papszDSCO = NULL, **papszLCO = NULL; |
---|
| 104 | int bTransform = FALSE; |
---|
| 105 | int bAppend = FALSE, bUpdate = FALSE, bOverwrite = FALSE; |
---|
| 106 | const char *pszOutputSRSDef = NULL; |
---|
| 107 | const char *pszSourceSRSDef = NULL; |
---|
| 108 | OGRSpatialReference *poOutputSRS = NULL; |
---|
| 109 | OGRSpatialReference *poSourceSRS = NULL; |
---|
| 110 | const char *pszNewLayerName = NULL; |
---|
| 111 | const char *pszWHERE = NULL; |
---|
| 112 | OGRGeometry *poSpatialFilter = NULL; |
---|
| 113 | const char *pszSelect; |
---|
| 114 | char **papszSelFields = NULL; |
---|
| 115 | const char *pszSQLStatement = NULL; |
---|
| 116 | int eGType = -2; |
---|
[252] | 117 | double dfMaxSegmentLength = 0; |
---|
[1] | 118 | |
---|
[395] | 119 | #ifdef ZOO_SERVICE |
---|
| 120 | dumpMaps(inputs); |
---|
| 121 | #endif |
---|
[1] | 122 | /* Check strict compilation and runtime library version as we use C++ API */ |
---|
| 123 | if (! GDAL_CHECK_VERSION("ogr2ogr")) |
---|
| 124 | #ifdef ZOO_SERVICE |
---|
| 125 | { |
---|
| 126 | fprintf(stderr,"Not correct version of the gdal library\n"); |
---|
[38] | 127 | setMapInMaps(conf,"lenv","message","Unable to check gdal version for ogr2ogr_service.zo"); |
---|
[1] | 128 | return SERVICE_FAILED; |
---|
| 129 | } |
---|
| 130 | #else |
---|
| 131 | exit(1); |
---|
| 132 | #endif |
---|
| 133 | /* -------------------------------------------------------------------- */ |
---|
| 134 | /* Register format(s). */ |
---|
| 135 | /* -------------------------------------------------------------------- */ |
---|
| 136 | OGRRegisterAll(); |
---|
| 137 | |
---|
| 138 | #ifdef ZOO_SERVICE |
---|
[40] | 139 | map *tmpMap=NULL; |
---|
[1] | 140 | char dataPath[1024]; |
---|
| 141 | tmpMap=getMapFromMaps(conf,"main","dataPath"); |
---|
| 142 | if(tmpMap!=NULL) |
---|
| 143 | sprintf(dataPath,"%s",tmpMap->value); |
---|
| 144 | tmpMap=NULL; |
---|
| 145 | char tempPath[1024]; |
---|
| 146 | tmpMap=getMapFromMaps(conf,"main","tmpPath"); |
---|
| 147 | if(tmpMap!=NULL){ |
---|
| 148 | sprintf(tempPath,"%s",tmpMap->value); |
---|
| 149 | } |
---|
[49] | 150 | |
---|
| 151 | tmpMap=NULL; |
---|
| 152 | char serverAddress[1024]; |
---|
| 153 | tmpMap=getMapFromMaps(conf,"main","serverAddress"); |
---|
| 154 | if(tmpMap!=NULL){ |
---|
| 155 | sprintf(serverAddress,"%s",tmpMap->value); |
---|
| 156 | } |
---|
| 157 | |
---|
| 158 | tmpMap=NULL; |
---|
| 159 | char tmpurl[1024]; |
---|
| 160 | tmpMap=getMapFromMaps(conf,"main","tmpurl"); |
---|
| 161 | if(tmpMap!=NULL){ |
---|
| 162 | sprintf(tmpurl,"%s",tmpMap->value); |
---|
| 163 | } |
---|
[1] | 164 | |
---|
[40] | 165 | tmpMap=NULL; |
---|
[1] | 166 | tmpMap=getMapFromMaps(inputs,"F","value"); |
---|
[395] | 167 | if(tmpMap!=NULL && strncasecmp(tmpMap->value,"NULL",4)!=0){ |
---|
[1] | 168 | pszFormat=tmpMap->value; |
---|
| 169 | } |
---|
| 170 | |
---|
[40] | 171 | tmpMap=NULL; |
---|
[1] | 172 | tmpMap=getMapFromMaps(inputs,"DSCO","value"); |
---|
[395] | 173 | if(tmpMap!=NULL && strncasecmp(tmpMap->value,"NULL",4)!=0){ |
---|
[1] | 174 | papszDSCO = CSLAddString(papszDSCO, tmpMap->value ); |
---|
| 175 | } |
---|
| 176 | |
---|
[40] | 177 | tmpMap=NULL; |
---|
[1] | 178 | tmpMap=getMapFromMaps(inputs,"LCO","value"); |
---|
[395] | 179 | if(tmpMap!=NULL && strncasecmp(tmpMap->value,"NULL",4)!=0){ |
---|
[1] | 180 | papszLCO = CSLAddString(papszLCO, tmpMap->value ); |
---|
| 181 | } |
---|
| 182 | |
---|
[40] | 183 | tmpMap=NULL; |
---|
[1] | 184 | tmpMap=getMapFromMaps(inputs,"preserve_fid","value"); |
---|
[395] | 185 | if(tmpMap!=NULL && strncasecmp(tmpMap->value,"NULL",4)!=0){ |
---|
[1] | 186 | bPreserveFID = TRUE; |
---|
| 187 | } |
---|
| 188 | |
---|
[40] | 189 | tmpMap=NULL; |
---|
[1] | 190 | tmpMap=getMapFromMaps(inputs,"skipfailure","value"); |
---|
[395] | 191 | if(tmpMap!=NULL && strncasecmp(tmpMap->value,"NULL",4)!=0){ |
---|
| 192 | bSkipFailures = TRUE; |
---|
| 193 | nGroupTransactions = 1; /* #2409 */ |
---|
[40] | 194 | } |
---|
[1] | 195 | |
---|
[395] | 196 | /* if exist, overwrite the data with the same name */ |
---|
[40] | 197 | tmpMap=NULL; |
---|
[395] | 198 | tmpMap=getMapFromMaps(inputs,"overwrite","value"); |
---|
| 199 | if(tmpMap!=NULL && strncasecmp(tmpMap->value,"NULL",4)!=0){ |
---|
| 200 | bOverwrite = TRUE; |
---|
| 201 | } |
---|
| 202 | |
---|
| 203 | tmpMap=NULL; |
---|
[1] | 204 | tmpMap=getMapFromMaps(inputs,"append","value"); |
---|
[395] | 205 | if(tmpMap!=NULL && strncasecmp(tmpMap->value,"TRUE",4)==0){ |
---|
| 206 | bAppend = TRUE; |
---|
[40] | 207 | } |
---|
[1] | 208 | |
---|
[40] | 209 | tmpMap=NULL; |
---|
[1] | 210 | tmpMap=getMapFromMaps(inputs,"update","value"); |
---|
[395] | 211 | if(tmpMap!=NULL && strncasecmp(tmpMap->value,"TRUE",4)==0){ |
---|
| 212 | bUpdate = TRUE; |
---|
[40] | 213 | } |
---|
[1] | 214 | |
---|
[40] | 215 | tmpMap=NULL; |
---|
[1] | 216 | tmpMap=getMapFromMaps(inputs,"fid","value"); |
---|
[395] | 217 | if(tmpMap!=NULL && strncasecmp(tmpMap->value,"NULL",4)!=0){ |
---|
| 218 | nFIDToFetch = atoi(tmpMap->value); |
---|
[40] | 219 | } |
---|
[1] | 220 | |
---|
[40] | 221 | tmpMap=NULL; |
---|
[1] | 222 | tmpMap=getMapFromMaps(inputs,"sql","value"); |
---|
[395] | 223 | if(tmpMap!=NULL && strncasecmp(tmpMap->value,"NULL",4)!=0){ |
---|
| 224 | pszSQLStatement = tmpMap->value; |
---|
[40] | 225 | } |
---|
[1] | 226 | |
---|
[40] | 227 | tmpMap=NULL; |
---|
[1] | 228 | tmpMap=getMapFromMaps(inputs,"nln","value"); |
---|
[395] | 229 | if(tmpMap!=NULL && strncasecmp(tmpMap->value,"NULL",4)!=0){ |
---|
[1] | 230 | pszNewLayerName = tmpMap->value; |
---|
[40] | 231 | } |
---|
[1] | 232 | |
---|
[40] | 233 | tmpMap=NULL; |
---|
[1] | 234 | tmpMap=getMapFromMaps(inputs,"nlt","value"); |
---|
[395] | 235 | if(tmpMap!=NULL && strncasecmp(tmpMap->value,"NULL",4)!=0){ |
---|
[1] | 236 | pszNewLayerName = tmpMap->value; |
---|
| 237 | if( EQUAL(tmpMap->value,"NONE") ) |
---|
| 238 | eGType = wkbNone; |
---|
| 239 | else if( EQUAL(tmpMap->value,"GEOMETRY") ) |
---|
| 240 | eGType = wkbUnknown; |
---|
| 241 | else if( EQUAL(tmpMap->value,"POINT") ) |
---|
| 242 | eGType = wkbPoint; |
---|
| 243 | else if( EQUAL(tmpMap->value,"LINESTRING") ) |
---|
| 244 | eGType = wkbLineString; |
---|
| 245 | else if( EQUAL(tmpMap->value,"POLYGON") ) |
---|
| 246 | eGType = wkbPolygon; |
---|
| 247 | else if( EQUAL(tmpMap->value,"GEOMETRYCOLLECTION") ) |
---|
| 248 | eGType = wkbGeometryCollection; |
---|
| 249 | else if( EQUAL(tmpMap->value,"MULTIPOINT") ) |
---|
| 250 | eGType = wkbMultiPoint; |
---|
| 251 | else if( EQUAL(tmpMap->value,"MULTILINESTRING") ) |
---|
| 252 | eGType = wkbMultiLineString; |
---|
| 253 | else if( EQUAL(tmpMap->value,"MULTIPOLYGON") ) |
---|
| 254 | eGType = wkbMultiPolygon; |
---|
| 255 | else if( EQUAL(tmpMap->value,"GEOMETRY25D") ) |
---|
| 256 | eGType = wkbUnknown | wkb25DBit; |
---|
| 257 | else if( EQUAL(tmpMap->value,"POINT25D") ) |
---|
| 258 | eGType = wkbPoint25D; |
---|
| 259 | else if( EQUAL(tmpMap->value,"LINESTRING25D") ) |
---|
| 260 | eGType = wkbLineString25D; |
---|
| 261 | else if( EQUAL(tmpMap->value,"POLYGON25D") ) |
---|
| 262 | eGType = wkbPolygon25D; |
---|
| 263 | else if( EQUAL(tmpMap->value,"GEOMETRYCOLLECTION25D") ) |
---|
| 264 | eGType = wkbGeometryCollection25D; |
---|
| 265 | else if( EQUAL(tmpMap->value,"MULTIPOINT25D") ) |
---|
| 266 | eGType = wkbMultiPoint25D; |
---|
| 267 | else if( EQUAL(tmpMap->value,"MULTILINESTRING25D") ) |
---|
| 268 | eGType = wkbMultiLineString25D; |
---|
| 269 | else if( EQUAL(tmpMap->value,"MULTIPOLYGON25D") ) |
---|
| 270 | eGType = wkbMultiPolygon25D; |
---|
| 271 | else |
---|
| 272 | { |
---|
| 273 | fprintf( stderr, "-nlt %s: type not recognised.\n", |
---|
| 274 | tmpMap->value ); |
---|
| 275 | exit( 1 ); |
---|
| 276 | } |
---|
[40] | 277 | } |
---|
[1] | 278 | |
---|
[40] | 279 | tmpMap=NULL; |
---|
[1] | 280 | tmpMap=getMapFromMaps(inputs,"tg","value"); |
---|
[395] | 281 | if(tmpMap!=NULL && strncasecmp(tmpMap->value,"NULL",4)!=0){ |
---|
[1] | 282 | nGroupTransactions = atoi(tmpMap->value); |
---|
[40] | 283 | } |
---|
[1] | 284 | |
---|
[40] | 285 | tmpMap=NULL; |
---|
[1] | 286 | tmpMap=getMapFromMaps(inputs,"s_srs","value"); |
---|
[395] | 287 | if(tmpMap!=NULL && strncasecmp(tmpMap->value,"NULL",4)!=0){ |
---|
| 288 | pszSourceSRSDef = strdup(tmpMap->value); |
---|
[40] | 289 | } |
---|
[1] | 290 | |
---|
[40] | 291 | tmpMap=NULL; |
---|
[1] | 292 | tmpMap=getMapFromMaps(inputs,"a_srs","value"); |
---|
[395] | 293 | if(tmpMap!=NULL && strncasecmp(tmpMap->value,"NULL",4)!=0){ |
---|
| 294 | pszOutputSRSDef = strdup(tmpMap->value); |
---|
[40] | 295 | } |
---|
[1] | 296 | |
---|
[40] | 297 | tmpMap=NULL; |
---|
[1] | 298 | tmpMap=getMapFromMaps(inputs,"t_srs","value"); |
---|
[395] | 299 | if(tmpMap!=NULL && strncasecmp(tmpMap->value,"NULL",4)!=0){ |
---|
| 300 | pszOutputSRSDef = strdup(tmpMap->value); |
---|
| 301 | bTransform = TRUE; |
---|
[40] | 302 | } |
---|
[1] | 303 | |
---|
[40] | 304 | tmpMap=NULL; |
---|
[1] | 305 | tmpMap=getMapFromMaps(inputs,"SPAT","value"); |
---|
[395] | 306 | if(tmpMap!=NULL && strncasecmp(tmpMap->value,"NULL",4)!=0){ |
---|
[1] | 307 | char *tmp=tmpMap->value; |
---|
| 308 | char *t=strtok(tmp,","); |
---|
| 309 | int cnt=0; |
---|
| 310 | double dfULX, dfULY, dfLRX, dfLRY; |
---|
| 311 | while(t!=NULL){ |
---|
| 312 | switch(cnt){ |
---|
| 313 | case 0: |
---|
| 314 | dfULX = atof(t); |
---|
| 315 | break; |
---|
| 316 | case 1: |
---|
| 317 | dfULY = atof(t); |
---|
| 318 | break; |
---|
| 319 | case 2: |
---|
| 320 | dfLRX = atof(t); |
---|
| 321 | break; |
---|
| 322 | case 3: |
---|
| 323 | dfLRY = atof(t); |
---|
| 324 | break; |
---|
| 325 | } |
---|
| 326 | fprintf(stderr,"%s\n\n",t); |
---|
| 327 | fprintf(stderr,"%f - %f - %f - %f\n\n",dfULX,dfULY,dfLRX,dfLRY); |
---|
| 328 | t=strtok(NULL,","); |
---|
| 329 | cnt++; |
---|
| 330 | } |
---|
| 331 | |
---|
[40] | 332 | OGRLinearRing oRing; |
---|
| 333 | |
---|
| 334 | oRing.addPoint( dfULX, dfULY ); |
---|
| 335 | oRing.addPoint( dfULX, dfLRY ); |
---|
| 336 | oRing.addPoint( dfLRX, dfLRY ); |
---|
| 337 | oRing.addPoint( dfLRX, dfULY ); |
---|
| 338 | oRing.addPoint( dfULX, dfULY ); |
---|
| 339 | poSpatialFilter = new OGRPolygon(); |
---|
| 340 | ((OGRPolygon *) poSpatialFilter)->addRing( &oRing ); |
---|
| 341 | } |
---|
[1] | 342 | |
---|
[40] | 343 | tmpMap=NULL; |
---|
[1] | 344 | tmpMap=getMapFromMaps(inputs,"where","value"); |
---|
[395] | 345 | if(tmpMap!=NULL && strncasecmp(tmpMap->value,"NULL",4)!=0){ |
---|
[1] | 346 | pszWHERE = tmpMap->value; |
---|
[40] | 347 | } |
---|
[1] | 348 | |
---|
[40] | 349 | tmpMap=NULL; |
---|
[1] | 350 | tmpMap=getMapFromMaps(inputs,"select","value"); |
---|
[395] | 351 | if(tmpMap!=NULL && strncasecmp(tmpMap->value,"NULL",4)!=0){ |
---|
[1] | 352 | pszSelect = tmpMap->value; |
---|
| 353 | papszSelFields = CSLTokenizeStringComplex(pszSelect, " ,", |
---|
| 354 | FALSE, FALSE ); |
---|
[40] | 355 | } |
---|
[1] | 356 | |
---|
[40] | 357 | tmpMap=NULL; |
---|
[1] | 358 | tmpMap=getMapFromMaps(inputs,"segmentize","value"); |
---|
[395] | 359 | if(tmpMap!=NULL && strncasecmp(tmpMap->value,"NULL",4)!=0){ |
---|
[1] | 360 | dfMaxSegmentLength = atof(tmpMap->value); |
---|
[40] | 361 | } |
---|
[1] | 362 | |
---|
[395] | 363 | /*tmpMap=NULL; |
---|
[1] | 364 | tmpMap=getMapFromMaps(inputs,"segmentize","value"); |
---|
| 365 | if(tmpMap!=NULL){ |
---|
| 366 | dfMaxSegmentLength = atof(tmpMap->value); |
---|
[395] | 367 | }*/ |
---|
[1] | 368 | |
---|
| 369 | tmpMap=NULL; |
---|
| 370 | tmpMap=getMapFromMaps(inputs,"InputDSN","value"); |
---|
[395] | 371 | if(tmpMap!=NULL && strncasecmp(tmpMap->value,"NULL",4)!=0){ |
---|
| 372 | if(strncasecmp(tmpMap->value,"PG",2)!=0 && |
---|
| 373 | strncasecmp(tmpMap->value,"My",2)!=0 && |
---|
| 374 | strncasecmp(tmpMap->value,"OCI",3)!=0 ){ |
---|
| 375 | if(strncasecmp(dataPath,tmpMap->value,strlen(dataPath))==0 || |
---|
| 376 | strncasecmp(tempPath,tmpMap->value,strlen(tempPath))==0){ |
---|
| 377 | pszDataSource=strdup(tmpMap->value); |
---|
| 378 | }else{ |
---|
| 379 | pszDataSource=(char*)malloc(sizeof(char)*(strlen(dataPath)+strlen(tmpMap->value)+2)); |
---|
| 380 | sprintf((char*)pszDataSource,"%s/%s",dataPath,tmpMap->value); |
---|
| 381 | } |
---|
| 382 | }else{ |
---|
| 383 | pszDataSource=(char*)malloc(sizeof(char)*(strlen(tmpMap->value)+1)); |
---|
| 384 | sprintf((char*)pszDataSource,"%s",tmpMap->value); |
---|
| 385 | } |
---|
[1] | 386 | } |
---|
| 387 | |
---|
| 388 | tmpMap=NULL; |
---|
| 389 | tmpMap=getMapFromMaps(inputs,"OutputDSN","value"); |
---|
| 390 | if(tmpMap!=NULL){ |
---|
[395] | 391 | if(strncasecmp(tmpMap->value,"PG",2)!=0 && |
---|
| 392 | strncasecmp(tmpMap->value,"MY",2)!=0 && |
---|
| 393 | strncasecmp(tmpMap->value,"OCI",3)!=0){ |
---|
| 394 | pszDestDataSource=(char*)malloc(sizeof(char)*(strlen(tempPath)+strlen(tmpMap->value)+4)); |
---|
| 395 | sprintf((char*)pszDestDataSource,"%s/%s",tempPath,tmpMap->value/*,ext*/); |
---|
| 396 | pszwebDestData=(char*)malloc(sizeof(char)*(strlen(serverAddress)+strlen(tmpurl)+strlen(tmpMap->value)+4)); |
---|
| 397 | sprintf((char*)pszwebDestData,"%s%s/%s",serverAddress,tmpurl,tmpMap->value/*,ext*/); |
---|
| 398 | } |
---|
| 399 | else{ |
---|
| 400 | pszDestDataSource=(char*)malloc(sizeof(char)*(strlen(tmpMap->value)+1)); |
---|
| 401 | sprintf((char*)pszDestDataSource,"%s",tmpMap->value/*,ext*/); |
---|
| 402 | pszwebDestData=(char*)malloc(sizeof(char)*(strlen(serverAddress)+strlen(tmpurl)+strlen(tmpMap->value)+4)); |
---|
| 403 | sprintf((char*)pszwebDestData,"%s%s/%s",serverAddress,tmpurl,tmpMap->value/*,ext*/); |
---|
| 404 | } |
---|
[1] | 405 | } |
---|
| 406 | |
---|
[395] | 407 | fprintf(stderr,"Message %s\n",pszDestDataSource); |
---|
[1] | 408 | #else |
---|
| 409 | /* -------------------------------------------------------------------- */ |
---|
| 410 | /* Processing command line arguments. */ |
---|
| 411 | /* -------------------------------------------------------------------- */ |
---|
| 412 | nArgc = OGRGeneralCmdLineProcessor( nArgc, &papszArgv, 0 ); |
---|
| 413 | |
---|
| 414 | if( nArgc < 1 ) |
---|
| 415 | exit( -nArgc ); |
---|
| 416 | |
---|
| 417 | for( int iArg = 1; iArg < nArgc; iArg++ ) |
---|
| 418 | { |
---|
| 419 | if( EQUAL(papszArgv[iArg], "--utility_version") ) |
---|
| 420 | { |
---|
| 421 | printf("%s was compiled against GDAL %s and is running against GDAL %s\n", |
---|
| 422 | papszArgv[0], GDAL_RELEASE_NAME, GDALVersionInfo("RELEASE_NAME")); |
---|
| 423 | return 0; |
---|
| 424 | } |
---|
| 425 | else if( EQUAL(papszArgv[iArg],"-f") && iArg < nArgc-1 ) |
---|
| 426 | { |
---|
| 427 | pszFormat = papszArgv[++iArg]; |
---|
| 428 | } |
---|
| 429 | else if( EQUAL(papszArgv[iArg],"-dsco") && iArg < nArgc-1 ) |
---|
| 430 | { |
---|
| 431 | papszDSCO = CSLAddString(papszDSCO, papszArgv[++iArg] ); |
---|
| 432 | } |
---|
| 433 | else if( EQUAL(papszArgv[iArg],"-lco") && iArg < nArgc-1 ) |
---|
| 434 | { |
---|
| 435 | papszLCO = CSLAddString(papszLCO, papszArgv[++iArg] ); |
---|
| 436 | } |
---|
| 437 | else if( EQUAL(papszArgv[iArg],"-preserve_fid") ) |
---|
| 438 | { |
---|
| 439 | bPreserveFID = TRUE; |
---|
| 440 | } |
---|
| 441 | else if( EQUALN(papszArgv[iArg],"-skip",5) ) |
---|
| 442 | { |
---|
| 443 | bSkipFailures = TRUE; |
---|
| 444 | nGroupTransactions = 1; /* #2409 */ |
---|
| 445 | } |
---|
| 446 | else if( EQUAL(papszArgv[iArg],"-append") ) |
---|
| 447 | { |
---|
| 448 | bAppend = TRUE; |
---|
| 449 | } |
---|
| 450 | else if( EQUAL(papszArgv[iArg],"-overwrite") ) |
---|
| 451 | { |
---|
| 452 | bOverwrite = TRUE; |
---|
| 453 | } |
---|
| 454 | else if( EQUAL(papszArgv[iArg],"-update") ) |
---|
| 455 | { |
---|
| 456 | bUpdate = TRUE; |
---|
| 457 | } |
---|
| 458 | else if( EQUAL(papszArgv[iArg],"-fid") && papszArgv[iArg+1] != NULL ) |
---|
| 459 | { |
---|
| 460 | nFIDToFetch = atoi(papszArgv[++iArg]); |
---|
| 461 | } |
---|
| 462 | else if( EQUAL(papszArgv[iArg],"-sql") && papszArgv[iArg+1] != NULL ) |
---|
| 463 | { |
---|
| 464 | pszSQLStatement = papszArgv[++iArg]; |
---|
| 465 | } |
---|
| 466 | else if( EQUAL(papszArgv[iArg],"-nln") && iArg < nArgc-1 ) |
---|
| 467 | { |
---|
| 468 | pszNewLayerName = papszArgv[++iArg]; |
---|
| 469 | } |
---|
| 470 | else if( EQUAL(papszArgv[iArg],"-nlt") && iArg < nArgc-1 ) |
---|
| 471 | { |
---|
| 472 | if( EQUAL(papszArgv[iArg+1],"NONE") ) |
---|
| 473 | eGType = wkbNone; |
---|
| 474 | else if( EQUAL(papszArgv[iArg+1],"GEOMETRY") ) |
---|
| 475 | eGType = wkbUnknown; |
---|
| 476 | else if( EQUAL(papszArgv[iArg+1],"POINT") ) |
---|
| 477 | eGType = wkbPoint; |
---|
| 478 | else if( EQUAL(papszArgv[iArg+1],"LINESTRING") ) |
---|
| 479 | eGType = wkbLineString; |
---|
| 480 | else if( EQUAL(papszArgv[iArg+1],"POLYGON") ) |
---|
| 481 | eGType = wkbPolygon; |
---|
| 482 | else if( EQUAL(papszArgv[iArg+1],"GEOMETRYCOLLECTION") ) |
---|
| 483 | eGType = wkbGeometryCollection; |
---|
| 484 | else if( EQUAL(papszArgv[iArg+1],"MULTIPOINT") ) |
---|
| 485 | eGType = wkbMultiPoint; |
---|
| 486 | else if( EQUAL(papszArgv[iArg+1],"MULTILINESTRING") ) |
---|
| 487 | eGType = wkbMultiLineString; |
---|
| 488 | else if( EQUAL(papszArgv[iArg+1],"MULTIPOLYGON") ) |
---|
| 489 | eGType = wkbMultiPolygon; |
---|
| 490 | else if( EQUAL(papszArgv[iArg+1],"GEOMETRY25D") ) |
---|
| 491 | eGType = wkbUnknown | wkb25DBit; |
---|
| 492 | else if( EQUAL(papszArgv[iArg+1],"POINT25D") ) |
---|
| 493 | eGType = wkbPoint25D; |
---|
| 494 | else if( EQUAL(papszArgv[iArg+1],"LINESTRING25D") ) |
---|
| 495 | eGType = wkbLineString25D; |
---|
| 496 | else if( EQUAL(papszArgv[iArg+1],"POLYGON25D") ) |
---|
| 497 | eGType = wkbPolygon25D; |
---|
| 498 | else if( EQUAL(papszArgv[iArg+1],"GEOMETRYCOLLECTION25D") ) |
---|
| 499 | eGType = wkbGeometryCollection25D; |
---|
| 500 | else if( EQUAL(papszArgv[iArg+1],"MULTIPOINT25D") ) |
---|
| 501 | eGType = wkbMultiPoint25D; |
---|
| 502 | else if( EQUAL(papszArgv[iArg+1],"MULTILINESTRING25D") ) |
---|
| 503 | eGType = wkbMultiLineString25D; |
---|
| 504 | else if( EQUAL(papszArgv[iArg+1],"MULTIPOLYGON25D") ) |
---|
| 505 | eGType = wkbMultiPolygon25D; |
---|
| 506 | else |
---|
| 507 | { |
---|
| 508 | fprintf( stderr, "-nlt %s: type not recognised.\n", |
---|
| 509 | papszArgv[iArg+1] ); |
---|
| 510 | exit( 1 ); |
---|
| 511 | } |
---|
| 512 | iArg++; |
---|
| 513 | } |
---|
| 514 | else if( (EQUAL(papszArgv[iArg],"-tg") || |
---|
| 515 | EQUAL(papszArgv[iArg],"-gt")) && iArg < nArgc-1 ) |
---|
| 516 | { |
---|
| 517 | nGroupTransactions = atoi(papszArgv[++iArg]); |
---|
| 518 | } |
---|
| 519 | else if( EQUAL(papszArgv[iArg],"-s_srs") && iArg < nArgc-1 ) |
---|
| 520 | { |
---|
| 521 | pszSourceSRSDef = papszArgv[++iArg]; |
---|
| 522 | } |
---|
| 523 | else if( EQUAL(papszArgv[iArg],"-a_srs") && iArg < nArgc-1 ) |
---|
| 524 | { |
---|
| 525 | pszOutputSRSDef = papszArgv[++iArg]; |
---|
| 526 | } |
---|
| 527 | else if( EQUAL(papszArgv[iArg],"-t_srs") && iArg < nArgc-1 ) |
---|
| 528 | { |
---|
| 529 | pszOutputSRSDef = papszArgv[++iArg]; |
---|
| 530 | bTransform = TRUE; |
---|
| 531 | } |
---|
| 532 | else if( EQUAL(papszArgv[iArg],"-spat") |
---|
| 533 | && papszArgv[iArg+1] != NULL |
---|
| 534 | && papszArgv[iArg+2] != NULL |
---|
| 535 | && papszArgv[iArg+3] != NULL |
---|
| 536 | && papszArgv[iArg+4] != NULL ) |
---|
| 537 | { |
---|
| 538 | OGRLinearRing oRing; |
---|
| 539 | |
---|
| 540 | oRing.addPoint( atof(papszArgv[iArg+1]), atof(papszArgv[iArg+2]) ); |
---|
| 541 | oRing.addPoint( atof(papszArgv[iArg+1]), atof(papszArgv[iArg+4]) ); |
---|
| 542 | oRing.addPoint( atof(papszArgv[iArg+3]), atof(papszArgv[iArg+4]) ); |
---|
| 543 | oRing.addPoint( atof(papszArgv[iArg+3]), atof(papszArgv[iArg+2]) ); |
---|
| 544 | oRing.addPoint( atof(papszArgv[iArg+1]), atof(papszArgv[iArg+2]) ); |
---|
| 545 | |
---|
| 546 | poSpatialFilter = new OGRPolygon(); |
---|
| 547 | ((OGRPolygon *) poSpatialFilter)->addRing( &oRing ); |
---|
| 548 | iArg += 4; |
---|
| 549 | } |
---|
| 550 | else if( EQUAL(papszArgv[iArg],"-where") && papszArgv[iArg+1] != NULL ) |
---|
| 551 | { |
---|
| 552 | pszWHERE = papszArgv[++iArg]; |
---|
| 553 | } |
---|
| 554 | else if( EQUAL(papszArgv[iArg],"-select") && papszArgv[iArg+1] != NULL) |
---|
| 555 | { |
---|
| 556 | pszSelect = papszArgv[++iArg]; |
---|
| 557 | papszSelFields = CSLTokenizeStringComplex(pszSelect, " ,", |
---|
| 558 | FALSE, FALSE ); |
---|
| 559 | } |
---|
| 560 | else if( EQUAL(papszArgv[iArg],"-segmentize") && iArg < nArgc-1 ) |
---|
| 561 | { |
---|
| 562 | dfMaxSegmentLength = atof(papszArgv[++iArg]); |
---|
| 563 | } |
---|
| 564 | else if( papszArgv[iArg][0] == '-' ) |
---|
| 565 | { |
---|
| 566 | Usage(); |
---|
| 567 | } |
---|
| 568 | else if( pszDestDataSource == NULL ) |
---|
| 569 | pszDestDataSource = papszArgv[iArg]; |
---|
| 570 | else if( pszDataSource == NULL ) |
---|
| 571 | pszDataSource = papszArgv[iArg]; |
---|
| 572 | else |
---|
| 573 | papszLayers = CSLAddString( papszLayers, papszArgv[iArg] ); |
---|
| 574 | } |
---|
| 575 | #endif |
---|
| 576 | |
---|
| 577 | if( pszDataSource == NULL ) |
---|
| 578 | #ifdef ZOO_SERVICE |
---|
| 579 | { |
---|
[395] | 580 | #else |
---|
| 581 | Usage(); |
---|
[1] | 582 | #endif |
---|
| 583 | #ifdef ZOO_SERVICE |
---|
[39] | 584 | setMapInMaps(conf,"lenv","message","Wrong parameter"); |
---|
| 585 | return SERVICE_FAILED; |
---|
[1] | 586 | } |
---|
| 587 | #endif |
---|
| 588 | |
---|
| 589 | /* -------------------------------------------------------------------- */ |
---|
| 590 | /* Open data source. */ |
---|
| 591 | /* -------------------------------------------------------------------- */ |
---|
[766] | 592 | #if GDAL_VERSION_MAJOR >= 2 |
---|
| 593 | GDALDataset *poDS; |
---|
| 594 | GDALDataset *poODS; |
---|
| 595 | GDALDriverManager* poR=GetGDALDriverManager(); |
---|
| 596 | GDALDriver *poDriver = NULL; |
---|
| 597 | #else |
---|
| 598 | OGRDataSource* poDS; |
---|
| 599 | OGRDataSource *poODS; |
---|
| 600 | OGRSFDriverRegistrar *poR = OGRSFDriverRegistrar::GetRegistrar(); |
---|
| 601 | OGRSFDriver *poDriver = NULL; |
---|
| 602 | #endif |
---|
[1] | 603 | |
---|
| 604 | /* -------------------------------------------------------------------- */ |
---|
| 605 | /* Report failure */ |
---|
| 606 | /* -------------------------------------------------------------------- */ |
---|
| 607 | if( poDS == NULL ) |
---|
| 608 | { |
---|
| 609 | fprintf( stderr, "FAILURE:\n" |
---|
| 610 | "Unable to open datasource `%s' with the following drivers.\n", |
---|
| 611 | pszDataSource ); |
---|
| 612 | |
---|
| 613 | for( int iDriver = 0; iDriver < poR->GetDriverCount(); iDriver++ ) |
---|
| 614 | { |
---|
[766] | 615 | #if GDAL_VERSION_MAJOR >= 2 |
---|
| 616 | fprintf( stderr, " -> %s\n", poR->GetDriver(iDriver)->GetDescription() ); |
---|
| 617 | #else |
---|
| 618 | fprintf( stderr, " -> %s\n", poR->GetDriver(iDriver)->GetName() ); |
---|
| 619 | #endif |
---|
[1] | 620 | } |
---|
| 621 | #ifdef ZOO_SERVICE |
---|
[39] | 622 | char tmp[1024]; |
---|
| 623 | sprintf(tmp,"Unable to open datasource `%s' with the following drivers.",pszDataSource); |
---|
| 624 | setMapInMaps(conf,"lenv","message",tmp); |
---|
| 625 | return SERVICE_FAILED; |
---|
[1] | 626 | #else |
---|
| 627 | exit( 1 ); |
---|
| 628 | #endif |
---|
| 629 | } |
---|
| 630 | |
---|
| 631 | /* -------------------------------------------------------------------- */ |
---|
| 632 | /* Try opening the output datasource as an existing, writable */ |
---|
| 633 | /* -------------------------------------------------------------------- */ |
---|
| 634 | if( bUpdate ) |
---|
| 635 | { |
---|
[766] | 636 | poODS = |
---|
| 637 | #if GDAL_VERSION_MAJOR >= 2 |
---|
| 638 | (GDALDataset*) GDALOpenEx( pszDestDataSource, |
---|
| 639 | GDAL_OF_UPDATE | GDAL_OF_VECTOR, |
---|
| 640 | NULL, NULL, NULL ) |
---|
| 641 | #else |
---|
| 642 | OGRSFDriverRegistrar::Open( pszDestDataSource, TRUE ) |
---|
| 643 | #endif |
---|
| 644 | ; |
---|
[1] | 645 | if( poODS == NULL ) |
---|
| 646 | { |
---|
| 647 | fprintf( stderr, "FAILURE:\n" |
---|
| 648 | "Unable to open existing output datasource `%s'.\n", |
---|
| 649 | pszDestDataSource ); |
---|
| 650 | #ifdef ZOO_SERVICE |
---|
[39] | 651 | char tmp[1024]; |
---|
| 652 | sprintf(tmp,"Unable to open existing output datasource `%s'.",pszDestDataSource); |
---|
| 653 | setMapInMaps(conf,"lenv","message",tmp); |
---|
| 654 | return SERVICE_FAILED; |
---|
[1] | 655 | #else |
---|
| 656 | exit( 1 ); |
---|
| 657 | #endif |
---|
| 658 | } |
---|
| 659 | |
---|
| 660 | if( CSLCount(papszDSCO) > 0 ) |
---|
| 661 | { |
---|
| 662 | fprintf( stderr, "WARNING: Datasource creation options ignored since an existing datasource\n" |
---|
| 663 | " being updated.\n" ); |
---|
| 664 | } |
---|
| 665 | } |
---|
| 666 | |
---|
| 667 | /* -------------------------------------------------------------------- */ |
---|
| 668 | /* Find the output driver. */ |
---|
| 669 | /* -------------------------------------------------------------------- */ |
---|
| 670 | else |
---|
| 671 | { |
---|
| 672 | int iDriver; |
---|
| 673 | |
---|
| 674 | for( iDriver = 0; |
---|
| 675 | iDriver < poR->GetDriverCount() && poDriver == NULL; |
---|
| 676 | iDriver++ ) |
---|
| 677 | { |
---|
[766] | 678 | #if GDAL_VERSION_MAJOR >=2 |
---|
| 679 | if( EQUAL(poR->GetDriver(iDriver)->GetDescription(),pszFormat) ) |
---|
| 680 | #else |
---|
| 681 | if( EQUAL(poR->GetDriver(iDriver)->GetName(),pszFormat) ) |
---|
| 682 | #endif |
---|
[1] | 683 | { |
---|
| 684 | poDriver = poR->GetDriver(iDriver); |
---|
| 685 | } |
---|
| 686 | } |
---|
| 687 | |
---|
| 688 | if( poDriver == NULL ) |
---|
| 689 | { |
---|
| 690 | fprintf( stderr, "Unable to find driver `%s'.\n", pszFormat ); |
---|
| 691 | fprintf( stderr, "The following drivers are available:\n" ); |
---|
| 692 | |
---|
| 693 | for( iDriver = 0; iDriver < poR->GetDriverCount(); iDriver++ ) |
---|
| 694 | { |
---|
[766] | 695 | #if GDAL_VERSION_MAJOR >= 2 |
---|
| 696 | fprintf( stderr, " -> %s\n", poR->GetDriver(iDriver)->GetDescription() ); |
---|
| 697 | #else |
---|
| 698 | fprintf( stderr, " -> %s\n", poR->GetDriver(iDriver)->GetName() ); |
---|
| 699 | #endif |
---|
[1] | 700 | } |
---|
| 701 | #ifdef ZOO_SERVICE |
---|
[39] | 702 | char tmp[1024]; |
---|
| 703 | sprintf(tmp,"Unable to find driver `%s'.",pszFormat); |
---|
| 704 | setMapInMaps(conf,"lenv","message",tmp); |
---|
| 705 | return SERVICE_FAILED; |
---|
[1] | 706 | #else |
---|
| 707 | exit( 1 ); |
---|
| 708 | #endif |
---|
| 709 | } |
---|
| 710 | |
---|
[766] | 711 | #if GDAL_VERSION_MAJOR >=2 |
---|
| 712 | if( !CPLTestBool( CSLFetchNameValueDef(poDriver->GetMetadata(), GDAL_DCAP_CREATE, "FALSE") ) ) |
---|
| 713 | #else |
---|
| 714 | if( !poDriver->TestCapability( ODrCCreateDataSource ) ) |
---|
| 715 | #endif |
---|
[1] | 716 | { |
---|
| 717 | fprintf( stderr, "%s driver does not support data source creation.\n", |
---|
| 718 | pszFormat ); |
---|
| 719 | #ifdef ZOO_SERVICE |
---|
[39] | 720 | char tmp[1024]; |
---|
| 721 | sprintf(tmp,"%s driver does not support data source creation.",pszFormat); |
---|
| 722 | setMapInMaps(conf,"lenv","message",tmp); |
---|
| 723 | return SERVICE_FAILED; |
---|
[1] | 724 | #else |
---|
| 725 | exit( 1 ); |
---|
| 726 | #endif |
---|
| 727 | } |
---|
| 728 | |
---|
| 729 | /* -------------------------------------------------------------------- */ |
---|
| 730 | /* Create the output data source. */ |
---|
| 731 | /* -------------------------------------------------------------------- */ |
---|
[766] | 732 | #if GDAL_VERSION_MAJOR >=2 |
---|
| 733 | poODS = poDriver->Create( pszDestDataSource, 0, 0, 0, GDT_Unknown, papszDSCO ); |
---|
| 734 | #else |
---|
| 735 | poODS = poDriver->CreateDataSource( pszDestDataSource, papszDSCO ); |
---|
| 736 | #endif |
---|
[1] | 737 | if( poODS == NULL ) |
---|
| 738 | { |
---|
| 739 | fprintf( stderr, "%s driver failed to create %s\n", |
---|
| 740 | pszFormat, pszDestDataSource ); |
---|
| 741 | #ifdef ZOO_SERVICE |
---|
[39] | 742 | char tmp[1024]; |
---|
| 743 | sprintf(tmp,"%s driver failed to create %s",pszFormat, pszDestDataSource); |
---|
| 744 | setMapInMaps(conf,"lenv","message",tmp); |
---|
| 745 | return SERVICE_FAILED; |
---|
[1] | 746 | #else |
---|
| 747 | exit( 1 ); |
---|
| 748 | #endif |
---|
| 749 | } |
---|
| 750 | } |
---|
| 751 | |
---|
| 752 | /* -------------------------------------------------------------------- */ |
---|
| 753 | /* Parse the output SRS definition if possible. */ |
---|
| 754 | /* -------------------------------------------------------------------- */ |
---|
| 755 | if( pszOutputSRSDef != NULL ) |
---|
| 756 | { |
---|
| 757 | poOutputSRS = new OGRSpatialReference(); |
---|
| 758 | if( poOutputSRS->SetFromUserInput( pszOutputSRSDef ) != OGRERR_NONE ) |
---|
| 759 | { |
---|
| 760 | fprintf( stderr, "Failed to process SRS definition: %s\n", |
---|
| 761 | pszOutputSRSDef ); |
---|
| 762 | #ifdef ZOO_SERVICE |
---|
[39] | 763 | char tmp[1024]; |
---|
| 764 | sprintf(tmp,"Failed to process SRS definition: %s",pszOutputSRSDef); |
---|
| 765 | setMapInMaps(conf,"lenv","message",tmp); |
---|
| 766 | return SERVICE_FAILED; |
---|
[1] | 767 | #else |
---|
| 768 | exit( 1 ); |
---|
| 769 | #endif |
---|
| 770 | } |
---|
| 771 | } |
---|
| 772 | |
---|
| 773 | /* -------------------------------------------------------------------- */ |
---|
| 774 | /* Parse the source SRS definition if possible. */ |
---|
| 775 | /* -------------------------------------------------------------------- */ |
---|
| 776 | if( pszSourceSRSDef != NULL ) |
---|
| 777 | { |
---|
| 778 | poSourceSRS = new OGRSpatialReference(); |
---|
| 779 | if( poSourceSRS->SetFromUserInput( pszSourceSRSDef ) != OGRERR_NONE ) |
---|
| 780 | { |
---|
| 781 | fprintf( stderr, "Failed to process SRS definition: %s\n", |
---|
| 782 | pszSourceSRSDef ); |
---|
| 783 | #ifdef ZOO_SERVICE |
---|
[39] | 784 | char tmp[1024]; |
---|
| 785 | sprintf(tmp,"Failed to process SRS definition: %s",pszOutputSRSDef); |
---|
| 786 | setMapInMaps(conf,"lenv","message",tmp); |
---|
| 787 | return SERVICE_FAILED; |
---|
[1] | 788 | #else |
---|
| 789 | exit( 1 ); |
---|
| 790 | #endif |
---|
| 791 | } |
---|
| 792 | } |
---|
| 793 | |
---|
| 794 | /* -------------------------------------------------------------------- */ |
---|
| 795 | /* Special case for -sql clause. No source layers required. */ |
---|
| 796 | /* -------------------------------------------------------------------- */ |
---|
| 797 | if( pszSQLStatement != NULL ) |
---|
| 798 | { |
---|
| 799 | OGRLayer *poResultSet; |
---|
| 800 | |
---|
| 801 | if( pszWHERE != NULL ) |
---|
| 802 | fprintf( stderr, "-where clause ignored in combination with -sql.\n" ); |
---|
| 803 | if( CSLCount(papszLayers) > 0 ) |
---|
[395] | 804 | fprintf( stderr, "layer names ignored in combination with -sql. (%s)\n", pszSQLStatement); |
---|
[1] | 805 | |
---|
| 806 | poResultSet = poDS->ExecuteSQL( pszSQLStatement, poSpatialFilter, |
---|
| 807 | NULL ); |
---|
| 808 | |
---|
| 809 | if( poResultSet != NULL ) |
---|
| 810 | { |
---|
| 811 | if( !TranslateLayer( poDS, poResultSet, poODS, papszLCO, |
---|
| 812 | pszNewLayerName, bTransform, poOutputSRS, |
---|
| 813 | poSourceSRS, papszSelFields, bAppend, eGType, |
---|
| 814 | bOverwrite, dfMaxSegmentLength )) |
---|
| 815 | { |
---|
| 816 | CPLError( CE_Failure, CPLE_AppDefined, |
---|
| 817 | "Terminating translation prematurely after failed\n" |
---|
| 818 | "translation from sql statement." ); |
---|
| 819 | |
---|
| 820 | exit( 1 ); |
---|
| 821 | } |
---|
| 822 | poDS->ReleaseResultSet( poResultSet ); |
---|
| 823 | } |
---|
| 824 | } |
---|
| 825 | |
---|
| 826 | /* -------------------------------------------------------------------- */ |
---|
| 827 | /* Process each data source layer. */ |
---|
| 828 | /* -------------------------------------------------------------------- */ |
---|
| 829 | for( int iLayer = 0; |
---|
| 830 | pszSQLStatement == NULL && iLayer < poDS->GetLayerCount(); |
---|
| 831 | iLayer++ ) |
---|
| 832 | { |
---|
| 833 | OGRLayer *poLayer = poDS->GetLayer(iLayer); |
---|
| 834 | |
---|
| 835 | if( poLayer == NULL ) |
---|
| 836 | { |
---|
| 837 | fprintf( stderr, "FAILURE: Couldn't fetch advertised layer %d!\n", |
---|
| 838 | iLayer ); |
---|
| 839 | #ifdef ZOO_SERVICE |
---|
[39] | 840 | char tmp[1024]; |
---|
| 841 | sprintf(tmp,"Couldn't fetch advertised layer %d!",iLayer); |
---|
| 842 | setMapInMaps(conf,"lenv","message",tmp); |
---|
| 843 | return SERVICE_FAILED; |
---|
[1] | 844 | #else |
---|
[39] | 845 | exit( 1 ); |
---|
[1] | 846 | #endif |
---|
| 847 | } |
---|
| 848 | |
---|
| 849 | if( CSLCount(papszLayers) == 0 |
---|
| 850 | || CSLFindString( papszLayers, |
---|
| 851 | poLayer->GetLayerDefn()->GetName() ) != -1 ) |
---|
| 852 | { |
---|
| 853 | if( pszWHERE != NULL ) |
---|
| 854 | poLayer->SetAttributeFilter( pszWHERE ); |
---|
| 855 | |
---|
| 856 | if( poSpatialFilter != NULL ) |
---|
| 857 | poLayer->SetSpatialFilter( poSpatialFilter ); |
---|
| 858 | |
---|
| 859 | if( !TranslateLayer( poDS, poLayer, poODS, papszLCO, |
---|
| 860 | pszNewLayerName, bTransform, poOutputSRS, |
---|
| 861 | poSourceSRS, papszSelFields, bAppend, eGType, |
---|
| 862 | bOverwrite, dfMaxSegmentLength ) |
---|
| 863 | && !bSkipFailures ) |
---|
| 864 | { |
---|
| 865 | #ifdef ZOO_SERVICE |
---|
[39] | 866 | char tmp[1024]; |
---|
| 867 | sprintf(tmp,"Terminating translation prematurely after failed of layer %s",poLayer->GetLayerDefn()->GetName() ); |
---|
| 868 | setMapInMaps(conf,"lenv","message",tmp); |
---|
| 869 | return SERVICE_FAILED; |
---|
[1] | 870 | #else |
---|
[395] | 871 | CPLError( CE_Failure, CPLE_AppDefined, |
---|
| 872 | "Terminating translation prematurely after failed\n" |
---|
| 873 | "translation of layer %s (use -skipfailures to skip errors)\n", |
---|
| 874 | poLayer->GetLayerDefn()->GetName() ); |
---|
| 875 | |
---|
[1] | 876 | exit( 1 ); |
---|
| 877 | #endif |
---|
| 878 | } |
---|
| 879 | } |
---|
| 880 | } |
---|
| 881 | |
---|
[395] | 882 | #ifdef ZOO_SERVICE |
---|
| 883 | outputs->content=createMap("value",(char*)pszwebDestData); |
---|
| 884 | #endif |
---|
| 885 | |
---|
[1] | 886 | /* -------------------------------------------------------------------- */ |
---|
| 887 | /* Close down. */ |
---|
| 888 | /* -------------------------------------------------------------------- */ |
---|
[395] | 889 | fprintf(stderr,"%s %d\n",__FILE__,__LINE__); |
---|
[1] | 890 | delete poOutputSRS; |
---|
[395] | 891 | fprintf(stderr,"%s %d\n",__FILE__,__LINE__); |
---|
[1] | 892 | delete poSourceSRS; |
---|
[395] | 893 | fprintf(stderr,"%s %d\n",__FILE__,__LINE__); |
---|
[1] | 894 | delete poODS; |
---|
[395] | 895 | fprintf(stderr,"%s %d\n",__FILE__,__LINE__); |
---|
[1] | 896 | delete poDS; |
---|
[395] | 897 | fprintf(stderr,"%s %d\n",__FILE__,__LINE__); |
---|
[1] | 898 | |
---|
[395] | 899 | #ifndef ZOO_SERVICE |
---|
[1] | 900 | CSLDestroy(papszSelFields); |
---|
[395] | 901 | CSLDestroy( papszArgv ); |
---|
[1] | 902 | #endif |
---|
[395] | 903 | fprintf(stderr,"%s %d\n",__FILE__,__LINE__); |
---|
[1] | 904 | CSLDestroy( papszLayers ); |
---|
[395] | 905 | fprintf(stderr,"%s %d\n",__FILE__,__LINE__); |
---|
| 906 | #ifndef ZOO_SERVICE |
---|
[1] | 907 | CSLDestroy( papszDSCO ); |
---|
| 908 | CSLDestroy( papszLCO ); |
---|
[395] | 909 | #endif |
---|
| 910 | fprintf(stderr,"%s %d\n",__FILE__,__LINE__); |
---|
[1] | 911 | |
---|
| 912 | OGRCleanupAll(); |
---|
[395] | 913 | fprintf(stderr,"%s %d\n",__FILE__,__LINE__); |
---|
[1] | 914 | |
---|
| 915 | #ifdef DBMALLOC |
---|
| 916 | malloc_dump(1); |
---|
| 917 | #endif |
---|
[395] | 918 | fprintf(stderr,"%s %d\n",__FILE__,__LINE__); |
---|
[1] | 919 | |
---|
| 920 | #ifdef ZOO_SERVICE |
---|
| 921 | return SERVICE_SUCCEEDED; |
---|
| 922 | #else |
---|
[395] | 923 | return 0; |
---|
[1] | 924 | #endif |
---|
| 925 | } |
---|
| 926 | |
---|
| 927 | /************************************************************************/ |
---|
| 928 | /* Usage() */ |
---|
| 929 | /************************************************************************/ |
---|
| 930 | |
---|
| 931 | static void Usage() |
---|
| 932 | |
---|
| 933 | { |
---|
[766] | 934 | #if GDAL_VERSION_MAJOR >= 2 |
---|
| 935 | GDALDataset *poDS; |
---|
| 936 | GDALDataset *poODS; |
---|
| 937 | GDALDriverManager* poR=GetGDALDriverManager(); |
---|
| 938 | GDALDriver *poDriver = NULL; |
---|
| 939 | #else |
---|
| 940 | OGRDataSource* poDS; |
---|
| 941 | OGRDataSource *poODS; |
---|
| 942 | OGRSFDriverRegistrar *poR = OGRSFDriverRegistrar::GetRegistrar(); |
---|
| 943 | OGRSFDriver *poDriver = NULL; |
---|
| 944 | #endif |
---|
[1] | 945 | |
---|
| 946 | #ifdef ZOO_SERVICE |
---|
| 947 | fprintf(stderr, |
---|
| 948 | #else |
---|
| 949 | printf( |
---|
| 950 | #endif |
---|
| 951 | "Usage: ogr2ogr [--help-general] [-skipfailures] [-append] [-update] [-gt n]\n" |
---|
| 952 | " [-select field_list] [-where restricted_where] \n" |
---|
| 953 | " [-sql <sql statement>] \n" |
---|
| 954 | " [-spat xmin ymin xmax ymax] [-preserve_fid] [-fid FID]\n" |
---|
| 955 | " [-a_srs srs_def] [-t_srs srs_def] [-s_srs srs_def]\n" |
---|
| 956 | " [-f format_name] [-overwrite] [[-dsco NAME=VALUE] ...]\n" |
---|
| 957 | " [-segmentize max_dist]\n" |
---|
| 958 | " dst_datasource_name src_datasource_name\n" |
---|
| 959 | " [-lco NAME=VALUE] [-nln name] [-nlt type] [layer [layer ...]]\n" |
---|
| 960 | "\n" |
---|
| 961 | " -f format_name: output file format name, possible values are:\n"); |
---|
| 962 | |
---|
| 963 | for( int iDriver = 0; iDriver < poR->GetDriverCount(); iDriver++ ) |
---|
| 964 | { |
---|
[766] | 965 | poDriver = poR->GetDriver(iDriver); |
---|
[1] | 966 | |
---|
[766] | 967 | #if GDAL_VERSION_MAJOR >=2 |
---|
| 968 | if( !CPLTestBool( CSLFetchNameValueDef(poDriver->GetMetadata(), GDAL_DCAP_CREATE, "FALSE") ) ) |
---|
| 969 | #else |
---|
| 970 | if( !poDriver->TestCapability( ODrCCreateDataSource ) ) |
---|
| 971 | #endif |
---|
| 972 | #if GDAL_VERSION_MAJOR >= 2 |
---|
| 973 | fprintf( stderr, " -> %s\n", poDriver->GetDescription() ); |
---|
| 974 | #else |
---|
| 975 | fprintf( stderr, " -> %s\n", poDriver->GetName() ); |
---|
| 976 | #endif |
---|
[1] | 977 | } |
---|
| 978 | |
---|
| 979 | #ifdef ZOO_SERVICE |
---|
| 980 | fprintf(stderr, |
---|
| 981 | #else |
---|
| 982 | printf( |
---|
| 983 | #endif |
---|
| 984 | " -append: Append to existing layer instead of creating new if it exists\n" |
---|
| 985 | " -overwrite: delete the output layer and recreate it empty\n" |
---|
| 986 | " -update: Open existing output datasource in update mode\n" |
---|
| 987 | " -select field_list: Comma-delimited list of fields from input layer to\n" |
---|
| 988 | " copy to the new layer (defaults to all)\n" |
---|
| 989 | " -where restricted_where: Attribute query (like SQL WHERE)\n" |
---|
| 990 | " -sql statement: Execute given SQL statement and save result.\n" |
---|
| 991 | " -skipfailures: skip features or layers that fail to convert\n" |
---|
| 992 | " -gt n: group n features per transaction (default 200)\n" |
---|
| 993 | " -spat xmin ymin xmax ymax: spatial query extents\n" |
---|
| 994 | " -segmentize max_dist: maximum distance between 2 nodes.\n" |
---|
| 995 | " Used to create intermediate points\n" |
---|
| 996 | " -dsco NAME=VALUE: Dataset creation option (format specific)\n" |
---|
| 997 | " -lco NAME=VALUE: Layer creation option (format specific)\n" |
---|
| 998 | " -nln name: Assign an alternate name to the new layer\n" |
---|
| 999 | " -nlt type: Force a geometry type for new layer. One of NONE, GEOMETRY,\n" |
---|
| 1000 | " POINT, LINESTRING, POLYGON, GEOMETRYCOLLECTION, MULTIPOINT,\n" |
---|
| 1001 | " MULTIPOLYGON, or MULTILINESTRING. Add \"25D\" for 3D layers.\n" |
---|
| 1002 | " Default is type of source layer.\n" ); |
---|
| 1003 | |
---|
| 1004 | #ifdef ZOO_SERVICE |
---|
| 1005 | fprintf(stderr, |
---|
| 1006 | #else |
---|
| 1007 | printf( |
---|
| 1008 | #endif |
---|
| 1009 | " -a_srs srs_def: Assign an output SRS\n" |
---|
| 1010 | " -t_srs srs_def: Reproject/transform to this SRS on output\n" |
---|
| 1011 | " -s_srs srs_def: Override source SRS\n" |
---|
| 1012 | "\n" |
---|
| 1013 | " Srs_def can be a full WKT definition (hard to escape properly),\n" |
---|
| 1014 | " or a well known definition (ie. EPSG:4326) or a file with a WKT\n" |
---|
| 1015 | " definition.\n" ); |
---|
| 1016 | |
---|
| 1017 | |
---|
| 1018 | #ifndef ZOO_SERVICE |
---|
| 1019 | exit( 1 ); |
---|
| 1020 | #endif |
---|
| 1021 | } |
---|
| 1022 | |
---|
| 1023 | /************************************************************************/ |
---|
| 1024 | /* TranslateLayer() */ |
---|
| 1025 | /************************************************************************/ |
---|
| 1026 | |
---|
[766] | 1027 | static int TranslateLayer( |
---|
| 1028 | #if GDAL_VERSION_MAJOR >= 2 |
---|
| 1029 | GDALDataset |
---|
| 1030 | #else |
---|
| 1031 | OGRDataSource |
---|
| 1032 | #endif |
---|
| 1033 | *poSrcDS, |
---|
| 1034 | OGRLayer * poSrcLayer, |
---|
| 1035 | #if GDAL_VERSION_MAJOR >= 2 |
---|
| 1036 | GDALDataset |
---|
| 1037 | #else |
---|
| 1038 | OGRDataSource |
---|
| 1039 | #endif |
---|
| 1040 | *poDstDS, |
---|
| 1041 | char **papszLCO, |
---|
| 1042 | const char *pszNewLayerName, |
---|
| 1043 | int bTransform, |
---|
| 1044 | OGRSpatialReference *poOutputSRS, |
---|
| 1045 | OGRSpatialReference *poSourceSRS, |
---|
| 1046 | char **papszSelFields, |
---|
| 1047 | int bAppend, int eGType, int bOverwrite, |
---|
| 1048 | double dfMaxSegmentLength) |
---|
[40] | 1049 | |
---|
[1] | 1050 | { |
---|
| 1051 | OGRLayer *poDstLayer; |
---|
| 1052 | OGRFeatureDefn *poFDefn; |
---|
| 1053 | OGRErr eErr; |
---|
| 1054 | int bForceToPolygon = FALSE; |
---|
| 1055 | int bForceToMultiPolygon = FALSE; |
---|
| 1056 | |
---|
| 1057 | if( pszNewLayerName == NULL ) |
---|
| 1058 | pszNewLayerName = poSrcLayer->GetLayerDefn()->GetName(); |
---|
| 1059 | |
---|
| 1060 | if( wkbFlatten(eGType) == wkbPolygon ) |
---|
| 1061 | bForceToPolygon = TRUE; |
---|
| 1062 | else if( wkbFlatten(eGType) == wkbMultiPolygon ) |
---|
| 1063 | bForceToMultiPolygon = TRUE; |
---|
| 1064 | |
---|
| 1065 | /* -------------------------------------------------------------------- */ |
---|
| 1066 | /* Setup coordinate transformation if we need it. */ |
---|
| 1067 | /* -------------------------------------------------------------------- */ |
---|
| 1068 | OGRCoordinateTransformation *poCT = NULL; |
---|
| 1069 | |
---|
| 1070 | if( bTransform ) |
---|
| 1071 | { |
---|
| 1072 | if( poSourceSRS == NULL ) |
---|
| 1073 | poSourceSRS = poSrcLayer->GetSpatialRef(); |
---|
| 1074 | |
---|
| 1075 | if( poSourceSRS == NULL ) |
---|
| 1076 | { |
---|
| 1077 | fprintf( stderr, "Can't transform coordinates, source layer has no\n" |
---|
| 1078 | "coordinate system. Use -s_srs to set one.\n" ); |
---|
| 1079 | #ifdef ZOO_SERVICE |
---|
| 1080 | return SERVICE_FAILED; |
---|
| 1081 | #else |
---|
| 1082 | exit( 1 ); |
---|
| 1083 | #endif |
---|
| 1084 | } |
---|
| 1085 | |
---|
| 1086 | CPLAssert( NULL != poSourceSRS ); |
---|
| 1087 | CPLAssert( NULL != poOutputSRS ); |
---|
| 1088 | |
---|
| 1089 | poCT = OGRCreateCoordinateTransformation( poSourceSRS, poOutputSRS ); |
---|
| 1090 | if( poCT == NULL ) |
---|
| 1091 | { |
---|
| 1092 | char *pszWKT = NULL; |
---|
| 1093 | |
---|
| 1094 | fprintf( stderr, "Failed to create coordinate transformation between the\n" |
---|
| 1095 | "following coordinate systems. This may be because they\n" |
---|
| 1096 | "are not transformable, or because projection services\n" |
---|
| 1097 | "(PROJ.4 DLL/.so) could not be loaded.\n" ); |
---|
| 1098 | |
---|
| 1099 | poSourceSRS->exportToPrettyWkt( &pszWKT, FALSE ); |
---|
| 1100 | fprintf( stderr, "Source:\n%s\n", pszWKT ); |
---|
| 1101 | |
---|
| 1102 | poOutputSRS->exportToPrettyWkt( &pszWKT, FALSE ); |
---|
| 1103 | fprintf( stderr, "Target:\n%s\n", pszWKT ); |
---|
| 1104 | #ifdef ZOO_SERVICE |
---|
| 1105 | return SERVICE_FAILED; |
---|
| 1106 | #else |
---|
| 1107 | exit( 1 ); |
---|
| 1108 | #endif |
---|
| 1109 | } |
---|
| 1110 | } |
---|
| 1111 | |
---|
| 1112 | /* -------------------------------------------------------------------- */ |
---|
| 1113 | /* Get other info. */ |
---|
| 1114 | /* -------------------------------------------------------------------- */ |
---|
| 1115 | poFDefn = poSrcLayer->GetLayerDefn(); |
---|
| 1116 | |
---|
| 1117 | if( poOutputSRS == NULL ) |
---|
| 1118 | poOutputSRS = poSrcLayer->GetSpatialRef(); |
---|
| 1119 | |
---|
| 1120 | /* -------------------------------------------------------------------- */ |
---|
| 1121 | /* Find the layer. */ |
---|
| 1122 | /* -------------------------------------------------------------------- */ |
---|
| 1123 | int iLayer = -1; |
---|
| 1124 | poDstLayer = NULL; |
---|
| 1125 | |
---|
| 1126 | for( iLayer = 0; iLayer < poDstDS->GetLayerCount(); iLayer++ ) |
---|
| 1127 | { |
---|
| 1128 | OGRLayer *poLayer = poDstDS->GetLayer(iLayer); |
---|
| 1129 | |
---|
| 1130 | if( poLayer != NULL |
---|
| 1131 | && EQUAL(poLayer->GetLayerDefn()->GetName(),pszNewLayerName) ) |
---|
| 1132 | { |
---|
| 1133 | poDstLayer = poLayer; |
---|
| 1134 | break; |
---|
| 1135 | } |
---|
| 1136 | } |
---|
| 1137 | |
---|
| 1138 | /* -------------------------------------------------------------------- */ |
---|
| 1139 | /* If the user requested overwrite, and we have the layer in */ |
---|
| 1140 | /* question we need to delete it now so it will get recreated */ |
---|
| 1141 | /* (overwritten). */ |
---|
| 1142 | /* -------------------------------------------------------------------- */ |
---|
| 1143 | if( poDstLayer != NULL && bOverwrite ) |
---|
| 1144 | { |
---|
| 1145 | if( poDstDS->DeleteLayer( iLayer ) != OGRERR_NONE ) |
---|
| 1146 | { |
---|
| 1147 | fprintf( stderr, |
---|
| 1148 | "DeleteLayer() failed when overwrite requested.\n" ); |
---|
| 1149 | return FALSE; |
---|
| 1150 | } |
---|
| 1151 | poDstLayer = NULL; |
---|
| 1152 | } |
---|
| 1153 | |
---|
| 1154 | /* -------------------------------------------------------------------- */ |
---|
| 1155 | /* If the layer does not exist, then create it. */ |
---|
| 1156 | /* -------------------------------------------------------------------- */ |
---|
| 1157 | if( poDstLayer == NULL ) |
---|
| 1158 | { |
---|
| 1159 | if( eGType == -2 ) |
---|
| 1160 | eGType = poFDefn->GetGeomType(); |
---|
| 1161 | |
---|
| 1162 | if( !poDstDS->TestCapability( ODsCCreateLayer ) ) |
---|
| 1163 | { |
---|
| 1164 | fprintf( stderr, |
---|
| 1165 | "Layer %s not found, and CreateLayer not supported by driver.", |
---|
| 1166 | pszNewLayerName ); |
---|
| 1167 | return FALSE; |
---|
| 1168 | } |
---|
| 1169 | |
---|
| 1170 | CPLErrorReset(); |
---|
| 1171 | |
---|
| 1172 | poDstLayer = poDstDS->CreateLayer( pszNewLayerName, poOutputSRS, |
---|
| 1173 | (OGRwkbGeometryType) eGType, |
---|
| 1174 | papszLCO ); |
---|
| 1175 | |
---|
| 1176 | if( poDstLayer == NULL ) |
---|
| 1177 | return FALSE; |
---|
| 1178 | |
---|
| 1179 | bAppend = FALSE; |
---|
| 1180 | } |
---|
| 1181 | |
---|
| 1182 | /* -------------------------------------------------------------------- */ |
---|
| 1183 | /* Otherwise we will append to it, if append was requested. */ |
---|
| 1184 | /* -------------------------------------------------------------------- */ |
---|
| 1185 | else if( !bAppend ) |
---|
| 1186 | { |
---|
| 1187 | fprintf( stderr, "FAILED: Layer %s already exists, and -append not specified.\n" |
---|
| 1188 | " Consider using -append, or -overwrite.\n", |
---|
| 1189 | pszNewLayerName ); |
---|
| 1190 | return FALSE; |
---|
| 1191 | } |
---|
| 1192 | else |
---|
| 1193 | { |
---|
| 1194 | if( CSLCount(papszLCO) > 0 ) |
---|
| 1195 | { |
---|
| 1196 | fprintf( stderr, "WARNING: Layer creation options ignored since an existing layer is\n" |
---|
| 1197 | " being appended to.\n" ); |
---|
| 1198 | } |
---|
| 1199 | } |
---|
| 1200 | |
---|
| 1201 | /* -------------------------------------------------------------------- */ |
---|
| 1202 | /* Add fields. Default to copy all field. */ |
---|
| 1203 | /* If only a subset of all fields requested, then output only */ |
---|
| 1204 | /* the selected fields, and in the order that they were */ |
---|
| 1205 | /* selected. */ |
---|
| 1206 | /* -------------------------------------------------------------------- */ |
---|
| 1207 | int iField; |
---|
[395] | 1208 | int hasMmField=-1; |
---|
[1] | 1209 | |
---|
| 1210 | if (papszSelFields && !bAppend ) |
---|
| 1211 | { |
---|
| 1212 | for( iField=0; papszSelFields[iField] != NULL; iField++) |
---|
| 1213 | { |
---|
| 1214 | int iSrcField = poFDefn->GetFieldIndex(papszSelFields[iField]); |
---|
[395] | 1215 | OGRFieldDefn *tmp=poFDefn->GetFieldDefn(iSrcField); |
---|
| 1216 | fprintf(stderr,"NAME: %s\n",tmp->GetNameRef()); |
---|
| 1217 | fflush(stderr); |
---|
| 1218 | if(tmp!=NULL && strncasecmp(tmp->GetNameRef(),"MMID",4)==0) |
---|
| 1219 | hasMmField=1; |
---|
[1] | 1220 | if (iSrcField >= 0) |
---|
| 1221 | poDstLayer->CreateField( poFDefn->GetFieldDefn(iSrcField) ); |
---|
| 1222 | else |
---|
| 1223 | { |
---|
| 1224 | fprintf( stderr, "Field '%s' not found in source layer.\n", |
---|
| 1225 | papszSelFields[iField] ); |
---|
| 1226 | if( !bSkipFailures ) |
---|
| 1227 | return FALSE; |
---|
| 1228 | } |
---|
| 1229 | } |
---|
[395] | 1230 | |
---|
[1] | 1231 | } |
---|
| 1232 | else if( !bAppend ) |
---|
| 1233 | { |
---|
[395] | 1234 | for( iField = 0; iField < poFDefn->GetFieldCount(); iField++ ){ |
---|
[1] | 1235 | poDstLayer->CreateField( poFDefn->GetFieldDefn(iField) ); |
---|
[395] | 1236 | OGRFieldDefn *tmp=poFDefn->GetFieldDefn(iField); |
---|
| 1237 | if(tmp!=NULL && strncasecmp(tmp->GetNameRef(),"MMID",4)==0) |
---|
| 1238 | hasMmField=1; |
---|
| 1239 | fprintf(stderr,"NAME: %s\n",tmp->GetNameRef()); |
---|
| 1240 | } |
---|
[1] | 1241 | } |
---|
[395] | 1242 | /*if(hasMmField<0){ |
---|
| 1243 | OGRFieldDefn oField( "MMID", OFTInteger ); |
---|
| 1244 | poDstLayer->CreateField( &oField ); |
---|
| 1245 | }*/ |
---|
[1] | 1246 | |
---|
| 1247 | /* -------------------------------------------------------------------- */ |
---|
| 1248 | /* Transfer features. */ |
---|
| 1249 | /* -------------------------------------------------------------------- */ |
---|
| 1250 | OGRFeature *poFeature; |
---|
| 1251 | int nFeaturesInTransaction = 0; |
---|
[395] | 1252 | int fCount=0; |
---|
[1] | 1253 | poSrcLayer->ResetReading(); |
---|
| 1254 | |
---|
| 1255 | if( nGroupTransactions ) |
---|
| 1256 | poDstLayer->StartTransaction(); |
---|
| 1257 | |
---|
| 1258 | while( TRUE ) |
---|
| 1259 | { |
---|
| 1260 | OGRFeature *poDstFeature = NULL; |
---|
| 1261 | |
---|
| 1262 | if( nFIDToFetch != OGRNullFID ) |
---|
| 1263 | { |
---|
| 1264 | // Only fetch feature on first pass. |
---|
| 1265 | if( nFeaturesInTransaction == 0 ) |
---|
| 1266 | poFeature = poSrcLayer->GetFeature(nFIDToFetch); |
---|
| 1267 | else |
---|
| 1268 | poFeature = NULL; |
---|
| 1269 | } |
---|
| 1270 | else |
---|
| 1271 | poFeature = poSrcLayer->GetNextFeature(); |
---|
[395] | 1272 | |
---|
[1] | 1273 | if( poFeature == NULL ) |
---|
| 1274 | break; |
---|
| 1275 | |
---|
[395] | 1276 | //poFeature->SetField((poFeature->GetFieldCount()-1),fCount); |
---|
| 1277 | |
---|
[1] | 1278 | if( ++nFeaturesInTransaction == nGroupTransactions ) |
---|
| 1279 | { |
---|
| 1280 | poDstLayer->CommitTransaction(); |
---|
| 1281 | poDstLayer->StartTransaction(); |
---|
| 1282 | nFeaturesInTransaction = 0; |
---|
| 1283 | } |
---|
| 1284 | |
---|
| 1285 | CPLErrorReset(); |
---|
| 1286 | poDstFeature = OGRFeature::CreateFeature( poDstLayer->GetLayerDefn() ); |
---|
| 1287 | |
---|
| 1288 | if( poDstFeature->SetFrom( poFeature, TRUE ) != OGRERR_NONE ) |
---|
| 1289 | { |
---|
| 1290 | if( nGroupTransactions ) |
---|
| 1291 | poDstLayer->CommitTransaction(); |
---|
| 1292 | |
---|
| 1293 | CPLError( CE_Failure, CPLE_AppDefined, |
---|
| 1294 | "Unable to translate feature %ld from layer %s.\n", |
---|
| 1295 | poFeature->GetFID(), poFDefn->GetName() ); |
---|
| 1296 | |
---|
| 1297 | OGRFeature::DestroyFeature( poFeature ); |
---|
| 1298 | OGRFeature::DestroyFeature( poDstFeature ); |
---|
| 1299 | return FALSE; |
---|
| 1300 | } |
---|
| 1301 | |
---|
| 1302 | if( bPreserveFID ) |
---|
| 1303 | poDstFeature->SetFID( poFeature->GetFID() ); |
---|
| 1304 | |
---|
[395] | 1305 | /*if(hasMmField<0){ |
---|
| 1306 | poDstFeature->SetField((poDstFeature->GetFieldCount()-1),fCount); |
---|
| 1307 | fCount++; |
---|
| 1308 | }*/ |
---|
| 1309 | |
---|
[1] | 1310 | #ifndef GDAL_1_5_0 |
---|
| 1311 | if (poDstFeature->GetGeometryRef() != NULL && dfMaxSegmentLength > 0) |
---|
| 1312 | poDstFeature->GetGeometryRef()->segmentize(dfMaxSegmentLength); |
---|
| 1313 | #endif |
---|
| 1314 | |
---|
| 1315 | if( poCT && poDstFeature->GetGeometryRef() != NULL ) |
---|
| 1316 | { |
---|
| 1317 | eErr = poDstFeature->GetGeometryRef()->transform( poCT ); |
---|
| 1318 | if( eErr != OGRERR_NONE ) |
---|
| 1319 | { |
---|
| 1320 | if( nGroupTransactions ) |
---|
| 1321 | poDstLayer->CommitTransaction(); |
---|
| 1322 | |
---|
| 1323 | fprintf( stderr, "Failed to reproject feature %d (geometry probably out of source or destination SRS).\n", |
---|
| 1324 | (int) poFeature->GetFID() ); |
---|
| 1325 | if( !bSkipFailures ) |
---|
| 1326 | { |
---|
| 1327 | OGRFeature::DestroyFeature( poFeature ); |
---|
| 1328 | OGRFeature::DestroyFeature( poDstFeature ); |
---|
| 1329 | return FALSE; |
---|
| 1330 | } |
---|
| 1331 | } |
---|
| 1332 | } |
---|
| 1333 | |
---|
| 1334 | if( poDstFeature->GetGeometryRef() != NULL && bForceToPolygon ) |
---|
| 1335 | { |
---|
| 1336 | poDstFeature->SetGeometryDirectly( |
---|
| 1337 | OGRGeometryFactory::forceToPolygon( |
---|
| 1338 | poDstFeature->StealGeometry() ) ); |
---|
| 1339 | } |
---|
| 1340 | |
---|
| 1341 | if( poDstFeature->GetGeometryRef() != NULL && bForceToMultiPolygon ) |
---|
| 1342 | { |
---|
| 1343 | poDstFeature->SetGeometryDirectly( |
---|
| 1344 | OGRGeometryFactory::forceToMultiPolygon( |
---|
| 1345 | poDstFeature->StealGeometry() ) ); |
---|
| 1346 | } |
---|
| 1347 | |
---|
| 1348 | OGRFeature::DestroyFeature( poFeature ); |
---|
| 1349 | |
---|
| 1350 | CPLErrorReset(); |
---|
| 1351 | if( poDstLayer->CreateFeature( poDstFeature ) != OGRERR_NONE |
---|
| 1352 | && !bSkipFailures ) |
---|
| 1353 | { |
---|
| 1354 | if( nGroupTransactions ) |
---|
| 1355 | poDstLayer->RollbackTransaction(); |
---|
| 1356 | |
---|
| 1357 | OGRFeature::DestroyFeature( poDstFeature ); |
---|
| 1358 | return FALSE; |
---|
| 1359 | } |
---|
| 1360 | |
---|
| 1361 | OGRFeature::DestroyFeature( poDstFeature ); |
---|
| 1362 | } |
---|
| 1363 | |
---|
| 1364 | if( nGroupTransactions ) |
---|
| 1365 | poDstLayer->CommitTransaction(); |
---|
| 1366 | |
---|
| 1367 | /* -------------------------------------------------------------------- */ |
---|
| 1368 | /* Cleaning */ |
---|
| 1369 | /* -------------------------------------------------------------------- */ |
---|
| 1370 | delete poCT; |
---|
| 1371 | |
---|
| 1372 | return TRUE; |
---|
| 1373 | } |
---|
| 1374 | |
---|
| 1375 | #ifdef ZOO_SERVICE |
---|
| 1376 | } |
---|
| 1377 | #endif |
---|