Ticket #2671: rfc35_v2.patch

File rfc35_v2.patch, 63.8 KB (added by rouault, 5 years ago)

v2 of implementation of rfc35

  • ogr/ogr_api.h

     
    254254OGRFieldDefnH CPL_DLL OGR_FD_GetFieldDefn( OGRFeatureDefnH, int );
    255255int    CPL_DLL OGR_FD_GetFieldIndex( OGRFeatureDefnH, const char * );
    256256void   CPL_DLL OGR_FD_AddFieldDefn( OGRFeatureDefnH, OGRFieldDefnH );
     257OGRErr CPL_DLL OGR_FD_DeleteFieldDefn( OGRFeatureDefnH hDefn, int iField );
     258OGRErr CPL_DLL OGR_FD_ReorderFieldDefns( OGRFeatureDefnH hDefn, int* panMap );
    257259OGRwkbGeometryType CPL_DLL OGR_FD_GetGeomType( OGRFeatureDefnH );
    258260void   CPL_DLL OGR_FD_SetGeomType( OGRFeatureDefnH, OGRwkbGeometryType );
    259261int    CPL_DLL OGR_FD_IsGeometryIgnored( OGRFeatureDefnH );
     
    355357OGRErr CPL_DLL OGR_L_GetExtent( OGRLayerH, OGREnvelope *, int );
    356358int    CPL_DLL OGR_L_TestCapability( OGRLayerH, const char * );
    357359OGRErr CPL_DLL OGR_L_CreateField( OGRLayerH, OGRFieldDefnH, int );
     360OGRErr CPL_DLL OGR_L_DeleteField( OGRLayerH, int iField );
     361OGRErr CPL_DLL OGR_L_ReorderFields( OGRLayerH, int* panMap );
     362OGRErr CPL_DLL OGR_L_ReorderField( OGRLayerH, int iOldFieldPos, int iNewFieldPos );
     363OGRErr CPL_DLL OGR_L_AlterFieldDefn( OGRLayerH, int iField, OGRFieldDefnH hNewFieldDefn, int nFlags );
    358364OGRErr CPL_DLL OGR_L_StartTransaction( OGRLayerH );
    359365OGRErr CPL_DLL OGR_L_CommitTransaction( OGRLayerH );
    360366OGRErr CPL_DLL OGR_L_RollbackTransaction( OGRLayerH );
  • ogr/ogr_core.h

     
    220220#  define DB2_V72_UNFIX_BYTE_ORDER(x) (x)
    221221#endif
    222222
     223#define ALTER_NAME_FLAG            0x1
     224#define ALTER_TYPE_FLAG            0x2
     225#define ALTER_WIDTH_PRECISION_FLAG 0x4
     226#define ALTER_ALL_FLAG             (ALTER_NAME_FLAG | ALTER_TYPE_FLAG | ALTER_WIDTH_PRECISION_FLAG)
     227
    223228/************************************************************************/
    224229/*                  ogr_feature.h related definitions.                  */
    225230/************************************************************************/
     
    324329#define OLCFastFeatureCount    "FastFeatureCount"
    325330#define OLCFastGetExtent       "FastGetExtent"
    326331#define OLCCreateField         "CreateField"
     332#define OLCDeleteField         "DeleteField"
     333#define OLCReorderFields       "ReorderFields"
     334#define OLCAlterFieldDefn      "AlterFieldDefn"
    327335#define OLCTransactions        "Transactions"
    328336#define OLCDeleteFeature       "DeleteFeature"
    329337#define OLCFastSetNextByIndex  "FastSetNextByIndex"
  • ogr/ogr_feature.h

     
    141141    int         GetFieldIndex( const char * );
    142142
    143143    void        AddFieldDefn( OGRFieldDefn * );
     144    OGRErr      DeleteFieldDefn( int iField );
     145    OGRErr      ReorderFieldDefns( int* panMap );
    144146
    145147    OGRwkbGeometryType GetGeomType() { return eGeomType; }
    146148    void        SetGeomType( OGRwkbGeometryType );
  • ogr/ogrfeaturedefn.cpp

     
    374374}
    375375
    376376/************************************************************************/
     377/*                           DeleteFieldDefn()                          */
     378/************************************************************************/
     379
     380/**
     381 * \brief Delete an existing field definition.
     382 *
     383 * To delete an existing field definition from a layer definition, do not use this
     384 * function directly, but use OGRLayer::DeleteField() instead.
     385 *
     386 * This method should only be called while there are no OGRFeature
     387 * objects in existance based on this OGRFeatureDefn.
     388 *
     389 * This method is the same as the C function OGR_FD_DeleteFieldDefn().
     390 *
     391 * @param iField the index of the field defintion.
     392 * @return OGRERR_NONE in case of success.
     393 * @since OGR 1.9.0
     394 */
     395
     396OGRErr OGRFeatureDefn::DeleteFieldDefn( int iField )
     397
     398{
     399    if (iField < 0 || iField >= nFieldCount)
     400        return OGRERR_FAILURE;
     401
     402    if (iField < nFieldCount - 1)
     403    {
     404        memmove(papoFieldDefn + iField,
     405                papoFieldDefn + iField + 1,
     406                (nFieldCount - 1 - iField) * sizeof(void*));
     407    }
     408
     409    nFieldCount--;
     410
     411    return OGRERR_NONE;
     412}
     413
     414/************************************************************************/
     415/*                       OGR_FD_DeleteFieldDefn()                       */
     416/************************************************************************/
     417
     418/**
     419 * \brief Delete an existing field definition.
     420 *
     421 * To delete an existing field definition from a layer definition, do not use this
     422 * function directly, but use OGR_L_DeleteField() instead.
     423 *
     424 * This method should only be called while there are no OGRFeature
     425 * objects in existance based on this OGRFeatureDefn.
     426 *
     427 * This method is the same as the C++ method OGRFeatureDefn::DeleteFieldDefn().
     428 *
     429 * @param hDefn handle to the feature definition.
     430 * @param iField the index of the field defintion.
     431 * @return OGRERR_NONE in case of success.
     432 * @since OGR 1.9.0
     433 */
     434
     435OGRErr OGR_FD_DeleteFieldDefn( OGRFeatureDefnH hDefn, int iField )
     436
     437{
     438    return ((OGRFeatureDefn *) hDefn)->DeleteFieldDefn( iField );
     439}
     440
     441/************************************************************************/
     442/*                         ReorderFieldDefns()                          */
     443/************************************************************************/
     444
     445/**
     446 * \brief Reorder the field definitions in the array of the feature definition
     447 *
     448 * To reorder the field definitions in a layer definition, do not use this
     449 * function directly, but use OGR_L_ReorderFields() instead.
     450 *
     451 * This method should only be called while there are no OGRFeature
     452 * objects in existance based on this OGRFeatureDefn.
     453 *
     454 * This method is the same as the C function OGR_FD_ReorderFieldDefns().
     455 *
     456 * @param panMap an array of GetFieldCount() elements which
     457 * is a permutation of [0, GetFieldCount()-1]. panMap is such that,
     458 * for each field definition at position i after reordering,
     459 * its position before reordering was panMap[i].
     460 * @return OGRERR_NONE in case of success.
     461 * @since OGR 1.9.0
     462 */
     463
     464OGRErr OGRFeatureDefn::ReorderFieldDefns( int* panMap )
     465
     466{
     467    if (nFieldCount == 0)
     468        return OGRERR_NONE;
     469
     470    OGRErr eErr = OGRCheckPermutation(panMap, nFieldCount);
     471    if (eErr != OGRERR_NONE)
     472        return eErr;
     473
     474    OGRFieldDefn** papoFieldDefnNew = (OGRFieldDefn**)
     475        CPLMalloc(sizeof(OGRFieldDefn*) * nFieldCount);
     476
     477    for(int i=0;i<nFieldCount;i++)
     478    {
     479        papoFieldDefnNew[i] = papoFieldDefn[panMap[i]];
     480    }
     481
     482    CPLFree(papoFieldDefn);
     483    papoFieldDefn = papoFieldDefnNew;
     484
     485    return OGRERR_NONE;
     486}
     487
     488/************************************************************************/
     489/*                     OGR_FD_ReorderFieldDefns()                       */
     490/************************************************************************/
     491
     492/**
     493 * \brief Reorder the field definitions in the array of the feature definition
     494 *
     495 * To reorder the field definitions in a layer definition, do not use this
     496 * function directly, but use OGR_L_ReorderFields() instead.
     497 *
     498 * This method should only be called while there are no OGRFeature
     499 * objects in existance based on this OGRFeatureDefn.
     500 *
     501 * This method is the same as the C++ method OGRFeatureDefn::ReorderFieldDefns().
     502 *
     503 * @param hDefn handle to the feature definition.
     504 * @param panMap an array of GetFieldCount() elements which
     505 * is a permutation of [0, GetFieldCount()-1]. panMap is such that,
     506 * for each field definition at position i after reordering,
     507 * its position before reordering was panMap[i].
     508 * @return OGRERR_NONE in case of success.
     509 * @since OGR 1.9.0
     510 */
     511
     512OGRErr OGR_FD_ReorderFieldDefn( OGRFeatureDefnH hDefn, int* panMap )
     513
     514{
     515    return ((OGRFeatureDefn *) hDefn)->ReorderFieldDefns( panMap );
     516}
     517
     518/************************************************************************/
    377519/*                            GetGeomType()                             */
    378520/************************************************************************/
    379521
  • ogr/ogrsf_frmts/ogrsf_frmts.dox

     
    21042104 <li> <b>OLCCreateField</b> / "CreateField": TRUE if this layer can create
    21052105new fields on the current layer using CreateField(), otherwise FALSE.<p>
    21062106
     2107 <li> <b>OLCDeleteField</b> / "DeleteField": TRUE if this layer can delete
     2108existing fields on the current layer using DeleteField(), otherwise FALSE.<p>
     2109
     2110 <li> <b>OLCReorderFields</b> / "ReorderFields": TRUE if this layer can reorder
     2111existing fields on the current layer using ReorderField() or ReorderFields(), otherwise FALSE.<p>
     2112
     2113 <li> <b>OLCAlterFieldDefn</b> / "AlterFieldDefn": TRUE if this layer can alter
     2114the definition of an existing field on the current layer using AlterFieldDefn(), otherwise FALSE.<p>
     2115
    21072116 <li> <b>OLCDeleteFeature</b> / "DeleteFeature": TRUE if the DeleteFeature()
    21082117method is supported on this layer, otherwise FALSE.<p>
    21092118
     
    21862195 <li> <b>OLCCreateField</b> / "CreateField": TRUE if this layer can create
    21872196new fields on the current layer using CreateField(), otherwise FALSE.<p>
    21882197
     2198 <li> <b>OLCDeleteField</b> / "DeleteField": TRUE if this layer can delete
     2199existing fields on the current layer using DeleteField(), otherwise FALSE.<p>
     2200
     2201 <li> <b>OLCReorderFields</b> / "ReorderFields": TRUE if this layer can reorder
     2202existing fields on the current layer using ReorderField() or ReorderFields(), otherwise FALSE.<p>
     2203
     2204 <li> <b>OLCAlterFieldDefn</b> / "AlterFieldDefn": TRUE if this layer can alter
     2205the definition of an existing field on the current layer using AlterFieldDefn(), otherwise FALSE.<p>
     2206
    21892207 <li> <b>OLCDeleteFeature</b> / "DeleteFeature": TRUE if the DeleteFeature()
    21902208method is supported on this layer, otherwise FALSE.<p>
    21912209
     
    23772395to reflect the new field.  Applications should never modify the OGRFeatureDefn
    23782396used by a layer directly.
    23792397
     2398This method should not be called while there are feature objects in existance that
     2399were obtained or created with the previous layer definition.
     2400
     2401Not all drivers support this method. You can query a layer to check if it supports it
     2402with the OLCCreateField capability. Some drivers may only support this method while
     2403there are still no features in the layer. When it is supported, the existings features of the
     2404backing file/database should be updated accordingly.
     2405
    23802406This function is the same as the C function OGR_L_CreateField().
    23812407
    23822408@param poField field definition to write to disk.
     
    23982424to reflect the new field.  Applications should never modify the OGRFeatureDefn
    23992425used by a layer directly.
    24002426
     2427This function should not be called while there are feature objects in existance that
     2428were obtained or created with the previous layer definition.
     2429
     2430Not all drivers support this function. You can query a layer to check if it supports it
     2431with the OLCCreateField capability. Some drivers may only support this method while
     2432there are still no features in the layer. When it is supported, the existings features of the
     2433backing file/database should be updated accordingly.
     2434
    24012435 This function is the same as the C++ method OGRLayer::CreateField().
    24022436
    24032437 @param hLayer handle to the layer to write the field definition.
     
    24102444*/
    24112445
    24122446/**
     2447\fn OGRErr OGRLayer::DeleteField( int iField );
     2448
     2449\brief Delete an existing field on a layer.
     2450
     2451You must use this to delete existing fields
     2452on a real layer. Internally the OGRFeatureDefn for the layer will be updated
     2453to reflect the deleted field.  Applications should never modify the OGRFeatureDefn
     2454used by a layer directly.
     2455
     2456This method should not be called while there are feature objects in existance that
     2457were obtained or created with the previous layer definition.
     2458
     2459Not all drivers support this method. You can query a layer to check if it supports it
     2460with the OLCDeleteField capability. Some drivers may only support this method while
     2461there are still no features in the layer. When it is supported, the existings features of the
     2462backing file/database should be updated accordingly.
     2463
     2464This function is the same as the C function OGR_L_DeleteField().
     2465
     2466@param iField index of the field to delete.
     2467
     2468@return OGRERR_NONE on success.
     2469
     2470@since OGR 1.9.0
     2471*/
     2472
     2473/**
     2474
     2475\fn OGRErr OGR_L_DeleteField( OGRLayerH hLayer, int iField);
     2476
     2477\brief Create a new field on a layer.
     2478
     2479You must use this to delete existing fields
     2480on a real layer. Internally the OGRFeatureDefn for the layer will be updated
     2481to reflect the deleted field.  Applications should never modify the OGRFeatureDefn
     2482used by a layer directly.
     2483
     2484This function should not be called while there are feature objects in existance that
     2485were obtained or created with the previous layer definition.
     2486
     2487Not all drivers support this function. You can query a layer to check if it supports it
     2488with the OLCDeleteField capability. Some drivers may only support this method while
     2489there are still no features in the layer. When it is supported, the existings features of the
     2490backing file/database should be updated accordingly.
     2491
     2492This function is the same as the C++ method OGRLayer::DeleteField().
     2493
     2494@param hLayer handle to the layer.
     2495@param iField index of the field to delete.
     2496
     2497@return OGRERR_NONE on success.
     2498
     2499@since OGR 1.9.0
     2500*/
     2501
     2502/**
     2503\fn OGRErr OGRLayer::ReorderFields( int* panMap );
     2504
     2505\brief Reorder all the fields of a layer.
     2506
     2507You must use this to reorder existing fields
     2508on a real layer. Internally the OGRFeatureDefn for the layer will be updated
     2509to reflect the reordering of the fields.  Applications should never modify the OGRFeatureDefn
     2510used by a layer directly.
     2511
     2512This method should not be called while there are feature objects in existance that
     2513were obtained or created with the previous layer definition.
     2514
     2515panMap is such that,for each field definition at position i after reordering,
     2516its position before reordering was panMap[i].
     2517
     2518For example, let suppose the fields were "0","1","2","3","4" initially.
     2519ReorderFields([0,2,3,1,4]) will reorder them as "0","2","3","1","4".
     2520
     2521Not all drivers support this method. You can query a layer to check if it supports it
     2522with the OLCReorderFields capability. Some drivers may only support this method while
     2523there are still no features in the layer. When it is supported, the existings features of the
     2524backing file/database should be updated accordingly.
     2525
     2526This function is the same as the C function OGR_L_ReorderFields().
     2527
     2528@param panMap an array of GetLayerDefn()->GetFieldCount() elements which
     2529is a permutation of [0, GetLayerDefn()->GetFieldCount()-1].
     2530
     2531@return OGRERR_NONE on success.
     2532
     2533@since OGR 1.9.0
     2534*/
     2535
     2536/**
     2537
     2538\fn OGRErr OGR_L_ReorderFields( OGRLayerH hLayer, int* panMap );
     2539
     2540\brief Reorder all the fields of a layer.
     2541
     2542You must use this to reorder existing fields
     2543on a real layer. Internally the OGRFeatureDefn for the layer will be updated
     2544to reflect the reordering of the fields.  Applications should never modify the OGRFeatureDefn
     2545used by a layer directly.
     2546
     2547This function should not be called while there are feature objects in existance that
     2548were obtained or created with the previous layer definition.
     2549
     2550panMap is such that,for each field definition at position i after reordering,
     2551its position before reordering was panMap[i].
     2552
     2553For example, let suppose the fields were "0","1","2","3","4" initially.
     2554ReorderFields([0,2,3,1,4]) will reorder them as "0","2","3","1","4".
     2555
     2556Not all drivers support this function. You can query a layer to check if it supports it
     2557with the OLCReorderFields capability. Some drivers may only support this method while
     2558there are still no features in the layer. When it is supported, the existings features of the
     2559backing file/database should be updated accordingly.
     2560
     2561This function is the same as the C++ method OGRLayer::ReorderFields().
     2562
     2563@param hLayer handle to the layer.
     2564@param panMap an array of GetLayerDefn()->GetFieldCount() elements which
     2565is a permutation of [0, GetLayerDefn()->GetFieldCount()-1].
     2566
     2567@return OGRERR_NONE on success.
     2568
     2569@since OGR 1.9.0
     2570*/
     2571
     2572/**
     2573\fn OGRErr OGRLayer::ReorderField( int iOldFieldPos, int iNewFieldPos );
     2574
     2575\brief Reorder an existing field on a layer.
     2576
     2577This method is a conveniency wrapper of ReorderFields() dedicated to move a single field.
     2578It is a non-virtual method, so drivers should implement ReorderFields() instead.
     2579
     2580You must use this to reorder existing fields
     2581on a real layer. Internally the OGRFeatureDefn for the layer will be updated
     2582to reflect the reordering of the fields.  Applications should never modify the OGRFeatureDefn
     2583used by a layer directly.
     2584
     2585This method should not be called while there are feature objects in existance that
     2586were obtained or created with the previous layer definition.
     2587
     2588The field definition that was at initial position iOldFieldPos will be moved at
     2589position iNewFieldPos, and elements between will be shuffled accordingly.
     2590
     2591For example, let suppose the fields were "0","1","2","3","4" initially.
     2592ReorderField(1, 3) will reorder them as "0","2","3","1","4".
     2593
     2594Not all drivers support this method. You can query a layer to check if it supports it
     2595with the OLCReorderFields capability. Some drivers may only support this method while
     2596there are still no features in the layer. When it is supported, the existings features of the
     2597backing file/database should be updated accordingly.
     2598
     2599This function is the same as the C function OGR_L_ReorderField().
     2600
     2601@param iOldFieldPos previous position of the field to move. Must be in the range [0,GetFieldCount()-1].
     2602@param iNewFieldPos new position of the field to move. Must be in the range [0,GetFieldCount()-1].
     2603
     2604@return OGRERR_NONE on success.
     2605
     2606@since OGR 1.9.0
     2607*/
     2608
     2609/**
     2610
     2611\fn OGRErr OGR_L_ReorderField( OGRLayerH hLayer, int iOldFieldPos, int iNewFieldPos );
     2612
     2613\brief Reorder an existing field on a layer.
     2614
     2615This function is a conveniency wrapper of OGR_L_ReorderFields() dedicated to move a single field.
     2616
     2617You must use this to reorder existing fields
     2618on a real layer. Internally the OGRFeatureDefn for the layer will be updated
     2619to reflect the reordering of the fields.  Applications should never modify the OGRFeatureDefn
     2620used by a layer directly.
     2621
     2622This function should not be called while there are feature objects in existance that
     2623were obtained or created with the previous layer definition.
     2624
     2625The field definition that was at initial position iOldFieldPos will be moved at
     2626position iNewFieldPos, and elements between will be shuffled accordingly.
     2627
     2628For example, let suppose the fields were "0","1","2","3","4" initially.
     2629ReorderField(1, 3) will reorder them as "0","2","3","1","4".
     2630
     2631Not all drivers support this function. You can query a layer to check if it supports it
     2632with the OLCReorderFields capability. Some drivers may only support this method while
     2633there are still no features in the layer. When it is supported, the existings features of the
     2634backing file/database should be updated accordingly.
     2635
     2636This function is the same as the C++ method OGRLayer::ReorderField().
     2637
     2638@param hLayer handle to the layer.
     2639@param iOldFieldPos previous position of the field to move. Must be in the range [0,GetFieldCount()-1].
     2640@param iNewFieldPos new position of the field to move. Must be in the range [0,GetFieldCount()-1].
     2641
     2642@return OGRERR_NONE on success.
     2643
     2644@since OGR 1.9.0
     2645*/
     2646
     2647/**
     2648\fn OGRErr OGRLayer::AlterFieldDefn( int iField, OGRFieldDefn* poNewFieldDefn, int nFlags );
     2649
     2650\brief Alter the definition of an existing field on a layer.
     2651
     2652You must use this to alter the definition of an existing field of a real layer.
     2653Internally the OGRFeatureDefn for the layer will be updated
     2654to reflect the altered field.  Applications should never modify the OGRFeatureDefn
     2655used by a layer directly.
     2656
     2657This method should not be called while there are feature objects in existance that
     2658were obtained or created with the previous layer definition.
     2659
     2660Not all drivers support this method. You can query a layer to check if it supports it
     2661with the OLCAlterFieldDefn capability. Some drivers may only support this method while
     2662there are still no features in the layer. When it is supported, the existings features of the
     2663backing file/database should be updated accordingly. Some drivers might also not support
     2664all update flags.
     2665
     2666This function is the same as the C function OGR_L_AlterFieldDefn().
     2667
     2668@param iField index of the field whose definition must be altered.
     2669@param poNewFieldDefn new field definition
     2670@param nFlags combination of ALTER_NAME_FLAG, ALTER_TYPE_FLAG and ALTER_WIDTH_PRECISION_FLAG
     2671to indicate which of the name and/or type and/or width and precision fields from the new field
     2672definition must be taken into account.
     2673
     2674@return OGRERR_NONE on success.
     2675
     2676@since OGR 1.9.0
     2677*/
     2678
     2679/**
     2680\fn OGRErr OGR_L_AlterFieldDefn( OGRLayerH hLayer, int iField, OGRFieldDefnH hNewFieldDefn, int nFlags )
     2681
     2682\brief Alter the definition of an existing field on a layer.
     2683
     2684You must use this to alter the definition of an existing field of a real layer.
     2685Internally the OGRFeatureDefn for the layer will be updated
     2686to reflect the altered field.  Applications should never modify the OGRFeatureDefn
     2687used by a layer directly.
     2688
     2689This function should not be called while there are feature objects in existance that
     2690were obtained or created with the previous layer definition.
     2691
     2692Not all drivers support this function. You can query a layer to check if it supports it
     2693with the OLCAlterFieldDefn capability. Some drivers may only support this method while
     2694there are still no features in the layer. When it is supported, the existings features of the
     2695backing file/database should be updated accordingly. Some drivers might also not support
     2696all update flags.
     2697
     2698This function is the same as the C++ method OGRLayer::AlterFieldDefn().
     2699
     2700@param hLayer handle to the layer.
     2701@param iField index of the field whose definition must be altered.
     2702@param hNewFieldDefn new field definition
     2703@param nFlags combination of ALTER_NAME_FLAG, ALTER_TYPE_FLAG and ALTER_WIDTH_PRECISION_FLAG
     2704to indicate which of the name and/or type and/or width and precision fields from the new field
     2705definition must be taken into account.
     2706
     2707@return OGRERR_NONE on success.
     2708
     2709@since OGR 1.9.0
     2710*/
     2711
     2712/**
    24132713 \fn  void OGRLayer::GetStyleTable();
    24142714
    24152715 \brief Returns layer style table.
  • ogr/ogrsf_frmts/ogrsf_frmts.h

     
    9595
    9696    virtual OGRErr      CreateField( OGRFieldDefn *poField,
    9797                                     int bApproxOK = TRUE );
     98    virtual OGRErr      DeleteField( int iField );
     99    virtual OGRErr      ReorderFields( int* panMap );
     100    virtual OGRErr      AlterFieldDefn( int iField, OGRFieldDefn* poNewFieldDefn, int nFlags );
    98101
    99102    virtual OGRErr      SyncToDisk();
    100103
     
    117120    int                 GetRefCount() const;
    118121
    119122    GIntBig             GetFeaturesRead();
    120    
     123
     124    /* non virtual : conveniency wrapper for ReorderFields() */
     125    OGRErr              ReorderField( int iOldFieldPos, int iNewFieldPos );
     126
    121127    /* consider these private */
    122128    OGRErr               InitializeIndexSupport( const char * );
    123129    OGRLayerAttrIndex   *GetIndex() { return m_poAttrIndex; }
  • ogr/ogrsf_frmts/generic/ogrlayer.cpp

     
    485485}
    486486
    487487/************************************************************************/
     488/*                            DeleteField()                             */
     489/************************************************************************/
     490
     491OGRErr OGRLayer::DeleteField( int iField )
     492
     493{
     494    (void) iField;
     495
     496    CPLError( CE_Failure, CPLE_NotSupported,
     497              "DeleteField() not supported by this layer.\n" );
     498
     499    return OGRERR_UNSUPPORTED_OPERATION;
     500}
     501
     502/************************************************************************/
     503/*                         OGR_L_DeleteField()                          */
     504/************************************************************************/
     505
     506OGRErr OGR_L_DeleteField( OGRLayerH hLayer, int iField )
     507
     508{
     509    VALIDATE_POINTER1( hLayer, "OGR_L_DeleteField", OGRERR_INVALID_HANDLE );
     510
     511    return ((OGRLayer *) hLayer)->DeleteField( iField );
     512}
     513
     514/************************************************************************/
     515/*                           ReorderFields()                            */
     516/************************************************************************/
     517
     518OGRErr OGRLayer::ReorderFields( int* panMap )
     519
     520{
     521    (void) panMap;
     522
     523    CPLError( CE_Failure, CPLE_NotSupported,
     524              "ReorderFields() not supported by this layer.\n" );
     525
     526    return OGRERR_UNSUPPORTED_OPERATION;
     527}
     528
     529/************************************************************************/
     530/*                       OGR_L_ReorderFields()                          */
     531/************************************************************************/
     532
     533OGRErr OGR_L_ReorderFields( OGRLayerH hLayer, int* panMap )
     534
     535{
     536    VALIDATE_POINTER1( hLayer, "OGR_L_ReorderFields", OGRERR_INVALID_HANDLE );
     537
     538    return ((OGRLayer *) hLayer)->ReorderFields( panMap );
     539}
     540
     541/************************************************************************/
     542/*                            ReorderField()                            */
     543/************************************************************************/
     544
     545OGRErr OGRLayer::ReorderField( int iOldFieldPos, int iNewFieldPos )
     546
     547{
     548    OGRErr eErr;
     549
     550    int nFieldCount = GetLayerDefn()->GetFieldCount();
     551
     552    if (iOldFieldPos < 0 || iOldFieldPos >= nFieldCount)
     553    {
     554        CPLError( CE_Failure, CPLE_NotSupported,
     555                  "Invalid field index");
     556        return OGRERR_FAILURE;
     557    }
     558    if (iNewFieldPos < 0 || iNewFieldPos >= nFieldCount)
     559    {
     560        CPLError( CE_Failure, CPLE_NotSupported,
     561                  "Invalid field index");
     562        return OGRERR_FAILURE;
     563    }
     564    if (iNewFieldPos == iOldFieldPos)
     565        return OGRERR_NONE;
     566
     567    int* panMap = (int*) CPLMalloc(sizeof(int) * nFieldCount);
     568    int i;
     569    if (iOldFieldPos < iNewFieldPos)
     570    {
     571        /* "0","1","2","3","4" (1,3) -> "0","2","3","1","4" */
     572        for(i=0;i<iOldFieldPos;i++)
     573            panMap[i] = i;
     574        for(;i<iNewFieldPos;i++)
     575            panMap[i] = i + 1;
     576        panMap[iNewFieldPos] = iOldFieldPos;
     577        for(i=iNewFieldPos+1;i<nFieldCount;i++)
     578            panMap[i] = i;
     579    }
     580    else
     581    {
     582        /* "0","1","2","3","4" (3,1) -> "0","3","1","2","4" */
     583        for(i=0;i<iNewFieldPos;i++)
     584            panMap[i] = i;
     585        panMap[iNewFieldPos] = iOldFieldPos;
     586        for(i=iNewFieldPos+1;i<=iOldFieldPos;i++)
     587            panMap[i] = i - 1;
     588        for(;i<nFieldCount;i++)
     589            panMap[i] = i;
     590    }
     591
     592    eErr = ReorderFields(panMap);
     593
     594    CPLFree(panMap);
     595
     596    return eErr;
     597}
     598
     599/************************************************************************/
     600/*                        OGR_L_ReorderField()                          */
     601/************************************************************************/
     602
     603OGRErr OGR_L_ReorderField( OGRLayerH hLayer, int iOldFieldPos, int iNewFieldPos )
     604
     605{
     606    VALIDATE_POINTER1( hLayer, "OGR_L_ReorderField", OGRERR_INVALID_HANDLE );
     607
     608    return ((OGRLayer *) hLayer)->ReorderField( iOldFieldPos, iNewFieldPos );
     609}
     610
     611/************************************************************************/
     612/*                           AlterFieldDefn()                           */
     613/************************************************************************/
     614
     615OGRErr OGRLayer::AlterFieldDefn( int iField, OGRFieldDefn* poNewFieldDefn,
     616                                 int nFlags )
     617
     618{
     619    (void) iField;
     620    (void) poNewFieldDefn;
     621    (void) nFlags;
     622
     623    CPLError( CE_Failure, CPLE_NotSupported,
     624              "AlterFieldDefn() not supported by this layer.\n" );
     625
     626    return OGRERR_UNSUPPORTED_OPERATION;
     627}
     628
     629/************************************************************************/
     630/*                        OGR_L_AlterFieldDefn()                        */
     631/************************************************************************/
     632
     633OGRErr OGR_L_AlterFieldDefn( OGRLayerH hLayer, int iField, OGRFieldDefnH hNewFieldDefn,
     634                             int nFlags )
     635
     636{
     637    VALIDATE_POINTER1( hLayer, "OGR_L_AlterFieldDefn", OGRERR_INVALID_HANDLE );
     638    VALIDATE_POINTER1( hNewFieldDefn, "OGR_L_AlterFieldDefn", OGRERR_INVALID_HANDLE );
     639
     640    return ((OGRLayer *) hLayer)->AlterFieldDefn( iField, (OGRFieldDefn*) hNewFieldDefn, nFlags );
     641}
     642
     643/************************************************************************/
    488644/*                          StartTransaction()                          */
    489645/************************************************************************/
    490646
  • ogr/ogrsf_frmts/shape/shapefil.h

     
    555555int     SHPAPI_CALL
    556556      DBFDeleteField( DBFHandle hDBF, int iField );
    557557
     558int SHPAPI_CALL
     559      DBFReorderFields( DBFHandle psDBF, int* panMap );
     560
     561int SHPAPI_CALL
     562      DBFAlterFieldDefn( DBFHandle psDBF, int iField, const char * pszFieldName,
     563                         char chType, int nWidth, int nDecimals );
     564
    558565DBFFieldType SHPAPI_CALL
    559566      DBFGetFieldInfo( DBFHandle psDBF, int iField,
    560567                       char * pszFieldName, int * pnWidth, int * pnDecimals );
  • ogr/ogrsf_frmts/shape/ogrshapelayer.cpp

     
    3030#include "ogrshape.h"
    3131#include "cpl_conv.h"
    3232#include "cpl_string.h"
     33#include "ogr_p.h"
    3334
    3435#if defined(_WIN32_WCE)
    3536#  include <wce_errno.h>
     
    809810
    810811    else if( EQUAL(pszCap,OLCCreateField) )
    811812        return bUpdateAccess;
    812    
     813
     814    else if( EQUAL(pszCap,OLCDeleteField) )
     815        return bUpdateAccess;
     816
     817    else if( EQUAL(pszCap,OLCReorderFields) )
     818        return bUpdateAccess;
     819
     820    else if( EQUAL(pszCap,OLCAlterFieldDefn) )
     821        return bUpdateAccess;
     822
    813823    else if( EQUAL(pszCap,OLCIgnoreFields) )
    814824        return TRUE;
    815825
     
    10041014}
    10051015
    10061016/************************************************************************/
     1017/*                            DeleteField()                             */
     1018/************************************************************************/
     1019
     1020OGRErr OGRShapeLayer::DeleteField( int iField )
     1021{
     1022    if( !bUpdateAccess )
     1023    {
     1024        CPLError( CE_Failure, CPLE_NotSupported,
     1025                  "Can't delete fields on a read-only shapefile layer.");
     1026        return OGRERR_FAILURE;
     1027    }
     1028
     1029    if (iField < 0 || iField >= poFeatureDefn->GetFieldCount())
     1030    {
     1031        CPLError( CE_Failure, CPLE_NotSupported,
     1032                  "Invalid field index");
     1033        return OGRERR_FAILURE;
     1034    }
     1035
     1036    if ( DBFDeleteField( hDBF, iField ) )
     1037    {
     1038        return poFeatureDefn->DeleteFieldDefn( iField );
     1039    }
     1040    else
     1041        return OGRERR_FAILURE;
     1042}
     1043
     1044/************************************************************************/
     1045/*                           ReorderFields()                            */
     1046/************************************************************************/
     1047
     1048OGRErr OGRShapeLayer::ReorderFields( int* panMap )
     1049{
     1050    if( !bUpdateAccess )
     1051    {
     1052        CPLError( CE_Failure, CPLE_NotSupported,
     1053                  "Can't reorder fields on a read-only shapefile layer.");
     1054        return OGRERR_FAILURE;
     1055    }
     1056
     1057    if (poFeatureDefn->GetFieldCount() == 0)
     1058        return OGRERR_NONE;
     1059
     1060    OGRErr eErr = OGRCheckPermutation(panMap, poFeatureDefn->GetFieldCount());
     1061    if (eErr != OGRERR_NONE)
     1062        return eErr;
     1063
     1064    if ( DBFReorderFields( hDBF, panMap ) )
     1065    {
     1066        return poFeatureDefn->ReorderFieldDefns( panMap );
     1067    }
     1068    else
     1069        return OGRERR_FAILURE;
     1070}
     1071
     1072/************************************************************************/
     1073/*                           AlterFieldDefn()                           */
     1074/************************************************************************/
     1075
     1076OGRErr OGRShapeLayer::AlterFieldDefn( int iField, OGRFieldDefn* poNewFieldDefn, int nFlags )
     1077{
     1078    if( !bUpdateAccess )
     1079    {
     1080        CPLError( CE_Failure, CPLE_NotSupported,
     1081                  "Can't alter field definition on a read-only shapefile layer.");
     1082        return OGRERR_FAILURE;
     1083    }
     1084
     1085    if (iField < 0 || iField >= poFeatureDefn->GetFieldCount())
     1086    {
     1087        CPLError( CE_Failure, CPLE_NotSupported,
     1088                  "Invalid field index");
     1089        return OGRERR_FAILURE;
     1090    }
     1091
     1092    OGRFieldDefn* poFieldDefn = poFeatureDefn->GetFieldDefn(iField);
     1093
     1094    if ((nFlags & ALTER_TYPE_FLAG) &&
     1095        poNewFieldDefn->GetType() != poFieldDefn->GetType())
     1096    {
     1097        CPLError( CE_Failure, CPLE_NotSupported, "Cannot alter field type");
     1098        return OGRERR_FAILURE;
     1099    }
     1100
     1101    char chNativeType;
     1102    char            szFieldName[20];
     1103    int             nWidth, nPrecision;
     1104    DBFFieldType    eDBFType;
     1105
     1106    chNativeType = DBFGetNativeFieldType( hDBF, iField );
     1107    eDBFType = DBFGetFieldInfo( hDBF, iField, szFieldName,
     1108                                &nWidth, &nPrecision );
     1109
     1110    if (nFlags & ALTER_NAME_FLAG)
     1111        strncpy(szFieldName, poNewFieldDefn->GetNameRef(), 10);
     1112    if (nFlags & ALTER_WIDTH_PRECISION_FLAG)
     1113    {
     1114        nWidth = poNewFieldDefn->GetWidth();
     1115        nPrecision = poNewFieldDefn->GetPrecision();
     1116    }
     1117
     1118    if ( DBFAlterFieldDefn( hDBF, iField, szFieldName,
     1119                            chNativeType, nWidth, nPrecision) )
     1120    {
     1121        if (nFlags & ALTER_NAME_FLAG)
     1122            poFieldDefn->SetName(szFieldName);
     1123        if (nFlags & ALTER_WIDTH_PRECISION_FLAG)
     1124        {
     1125            poFieldDefn->SetWidth(nWidth);
     1126            poFieldDefn->SetPrecision(nPrecision);
     1127        }
     1128        return OGRERR_NONE;
     1129    }
     1130    else
     1131        return OGRERR_FAILURE;
     1132}
     1133
     1134/************************************************************************/
    10071135/*                           GetSpatialRef()                            */
    10081136/************************************************************************/
    10091137
  • ogr/ogrsf_frmts/shape/dbfopen.c

     
    18431843    psDBF->nRecordLength -= nDeletedFieldSize;
    18441844
    18451845    /* overwrite field information in header */
    1846     memcpy(psDBF->pszHeader + iField*32,
     1846    memmove(psDBF->pszHeader + iField*32,
    18471847           psDBF->pszHeader + (iField+1)*32,
    18481848           sizeof(char) * (psDBF->nFields - iField)*32);
    18491849
     
    18931893
    18941894    return TRUE;
    18951895}
     1896
     1897/************************************************************************/
     1898/*                          DBFReorderFields()                          */
     1899/*                                                                      */
     1900/*      Reorder the fields of a .dbf file                               */
     1901/*                                                                      */
     1902/* panMap must be exactly psDBF->nFields long and be a permutation      */
     1903/* of [0, psDBF->nFields-1]. This assumption will not be asserted in the*/
     1904/* code of DBFReorderFields.                                            */
     1905/************************************************************************/
     1906
     1907int SHPAPI_CALL
     1908DBFReorderFields( DBFHandle psDBF, int* panMap )
     1909{
     1910    SAOffset nRecordOffset;
     1911    int      i, iRecord;
     1912    int     *panFieldOffsetNew;
     1913    int     *panFieldSizeNew;
     1914    int     *panFieldDecimalsNew;
     1915    char    *pachFieldTypeNew;
     1916    char    *pszHeaderNew;
     1917    char    *pszRecord;
     1918    char    *pszRecordNew;
     1919
     1920    if ( psDBF->nFields == 0 )
     1921        return TRUE;
     1922
     1923    /* make sure that everything is written in .dbf */
     1924    if( !DBFFlushRecord( psDBF ) )
     1925        return FALSE;
     1926
     1927    panFieldOffsetNew = (int *) malloc(sizeof(int) * psDBF->nFields);
     1928    panFieldSizeNew = (int *) malloc(sizeof(int) *  psDBF->nFields);
     1929    panFieldDecimalsNew = (int *) malloc(sizeof(int) *  psDBF->nFields);
     1930    pachFieldTypeNew = (char *) malloc(sizeof(char) *  psDBF->nFields);
     1931    pszHeaderNew = (char*) malloc(sizeof(char) * 32 *  psDBF->nFields);
     1932
     1933    /* shuffle fields definitions */
     1934    for(i=0; i < psDBF->nFields; i++)
     1935    {
     1936        panFieldSizeNew[i] = psDBF->panFieldSize[panMap[i]];
     1937        panFieldDecimalsNew[i] = psDBF->panFieldDecimals[panMap[i]];
     1938        pachFieldTypeNew[i] = psDBF->pachFieldType[panMap[i]];
     1939        memcpy(pszHeaderNew + i * 32,
     1940               psDBF->pszHeader + panMap[i] * 32, 32);
     1941    }
     1942    panFieldOffsetNew[0] = 1;
     1943    for(i=1; i < psDBF->nFields; i++)
     1944    {
     1945        panFieldOffsetNew[i] = panFieldOffsetNew[i - 1] + panFieldSizeNew[i - 1];
     1946    }
     1947
     1948    /* we're done if we're dealing with not yet created .dbf */
     1949    if ( !(psDBF->bNoHeader && psDBF->nRecords == 0) )
     1950    {
     1951        /* force update of header with new header and record length */
     1952        psDBF->bNoHeader = TRUE;
     1953        DBFUpdateHeader( psDBF );
     1954
     1955        /* alloc record */
     1956        pszRecord = (char *) malloc(sizeof(char) * psDBF->nRecordLength);
     1957        pszRecordNew = (char *) malloc(sizeof(char) * psDBF->nRecordLength);
     1958
     1959        /* shuffle fields in records */
     1960        for (iRecord = 0; iRecord < psDBF->nRecords; iRecord++)
     1961        {
     1962            nRecordOffset =
     1963                psDBF->nRecordLength * (SAOffset) iRecord + psDBF->nHeaderLength;
     1964
     1965            /* load record */
     1966            psDBF->sHooks.FSeek( psDBF->fp, nRecordOffset, 0 );
     1967            psDBF->sHooks.FRead( pszRecord, psDBF->nRecordLength, 1, psDBF->fp );
     1968
     1969            pszRecordNew[0] = pszRecord[0];
     1970
     1971            for(i=0; i < psDBF->nFields; i++)
     1972            {
     1973                memcpy(pszRecordNew + panFieldOffsetNew[i],
     1974                       pszRecord + psDBF->panFieldOffset[panMap[i]],
     1975                       psDBF->panFieldSize[panMap[i]]);
     1976            }
     1977
     1978            /* write record */
     1979            psDBF->sHooks.FSeek( psDBF->fp, nRecordOffset, 0 );
     1980            psDBF->sHooks.FWrite( pszRecordNew, psDBF->nRecordLength, 1, psDBF->fp );
     1981        }
     1982
     1983        /* free record */
     1984        free(pszRecord);
     1985        free(pszRecordNew);
     1986    }
     1987
     1988    free(psDBF->panFieldOffset);
     1989    free(psDBF->panFieldSize);
     1990    free(psDBF->panFieldDecimals);
     1991    free(psDBF->pachFieldType);
     1992    free(psDBF->pszHeader);
     1993
     1994    psDBF->panFieldOffset = panFieldOffsetNew;
     1995    psDBF->panFieldSize = panFieldSizeNew;
     1996    psDBF->panFieldDecimals =panFieldDecimalsNew;
     1997    psDBF->pachFieldType = pachFieldTypeNew;
     1998    psDBF->pszHeader = pszHeaderNew;
     1999
     2000    return TRUE;
     2001}
     2002
     2003
     2004/************************************************************************/
     2005/*                          DBFAlterFieldDefn()                         */
     2006/*                                                                      */
     2007/*      Alter a field definition in a .dbf file                         */
     2008/************************************************************************/
     2009
     2010int SHPAPI_CALL
     2011DBFAlterFieldDefn( DBFHandle psDBF, int iField, const char * pszFieldName,
     2012                    char chType, int nWidth, int nDecimals )
     2013{
     2014    int   i;
     2015    int   iRecord;
     2016    int   nOffset;
     2017    int   nOldWidth;
     2018    int   nOldRecordLength;
     2019    int   nRecordOffset;
     2020    char* pszFInfo;
     2021
     2022    if (iField < 0 || iField >= psDBF->nFields)
     2023        return FALSE;
     2024
     2025    /* make sure that everything is written in .dbf */
     2026    if( !DBFFlushRecord( psDBF ) )
     2027        return FALSE;
     2028
     2029    nOffset = psDBF->panFieldOffset[iField];
     2030    nOldWidth = psDBF->panFieldSize[iField];
     2031    nOldRecordLength = psDBF->nRecordLength;
     2032
     2033/* -------------------------------------------------------------------- */
     2034/*      Do some checking to ensure we can add records to this file.     */
     2035/* -------------------------------------------------------------------- */
     2036    if( nWidth < 1 )
     2037        return -1;
     2038
     2039    if( nWidth > 255 )
     2040        nWidth = 255;
     2041
     2042/* -------------------------------------------------------------------- */
     2043/*      Assign the new field information fields.                        */
     2044/* -------------------------------------------------------------------- */
     2045    psDBF->panFieldSize[iField] = nWidth;
     2046    psDBF->panFieldDecimals[iField] = nDecimals;
     2047    psDBF->pachFieldType[iField] = chType;
     2048
     2049/* -------------------------------------------------------------------- */
     2050/*      Update the header information.                                  */
     2051/* -------------------------------------------------------------------- */
     2052    pszFInfo = psDBF->pszHeader + 32 * iField;
     2053
     2054    for( i = 0; i < 32; i++ )
     2055        pszFInfo[i] = '\0';
     2056
     2057    if( (int) strlen(pszFieldName) < 10 )
     2058        strncpy( pszFInfo, pszFieldName, strlen(pszFieldName));
     2059    else
     2060        strncpy( pszFInfo, pszFieldName, 10);
     2061
     2062    pszFInfo[11] = psDBF->pachFieldType[iField];
     2063
     2064    if( chType == 'C' )
     2065    {
     2066        pszFInfo[16] = (unsigned char) (nWidth % 256);
     2067        pszFInfo[17] = (unsigned char) (nWidth / 256);
     2068    }
     2069    else
     2070    {
     2071        pszFInfo[16] = (unsigned char) nWidth;
     2072        pszFInfo[17] = (unsigned char) nDecimals;
     2073    }
     2074
     2075/* -------------------------------------------------------------------- */
     2076/*      Update offsets                                                  */
     2077/* -------------------------------------------------------------------- */
     2078    if (nWidth != nOldWidth)
     2079    {
     2080        for (i = iField + 1; i < psDBF->nFields; i++)
     2081             psDBF->panFieldOffset[i] += nWidth - nOldWidth;
     2082        psDBF->nRecordLength += nWidth - nOldWidth;
     2083
     2084        psDBF->pszCurrentRecord = (char *) SfRealloc(psDBF->pszCurrentRecord,
     2085                                                     psDBF->nRecordLength);
     2086    }
     2087
     2088    /* we're done if we're dealing with not yet created .dbf */
     2089    if ( psDBF->bNoHeader && psDBF->nRecords == 0 )
     2090        return TRUE;
     2091
     2092    /* force update of header with new header and record length */
     2093    psDBF->bNoHeader = TRUE;
     2094    DBFUpdateHeader( psDBF );
     2095
     2096    if (nWidth < nOldWidth)
     2097    {
     2098        char* pszRecord = (char *) malloc(sizeof(char) * nOldRecordLength);
     2099
     2100        /* move records to their new positions */
     2101        for (iRecord = 0; iRecord < psDBF->nRecords; iRecord++)
     2102        {
     2103            nRecordOffset =
     2104                nOldRecordLength * (SAOffset) iRecord + psDBF->nHeaderLength;
     2105
     2106            /* load record */
     2107            psDBF->sHooks.FSeek( psDBF->fp, nRecordOffset, 0 );
     2108            psDBF->sHooks.FRead( pszRecord, nOldRecordLength, 1, psDBF->fp );
     2109
     2110            if (nOffset + nOldWidth < nOldRecordLength)
     2111            {
     2112                memmove( pszRecord + nOffset + nWidth,
     2113                         pszRecord + nOffset + nOldWidth,
     2114                         nOldRecordLength - (nOffset + nOldWidth));
     2115            }
     2116
     2117            nRecordOffset =
     2118                psDBF->nRecordLength * (SAOffset) iRecord + psDBF->nHeaderLength;
     2119
     2120            /* write record */
     2121            psDBF->sHooks.FSeek( psDBF->fp, nRecordOffset, 0 );
     2122            psDBF->sHooks.FWrite( pszRecord, psDBF->nRecordLength, 1, psDBF->fp );
     2123        }
     2124
     2125        free(pszRecord);
     2126    }
     2127    else if (nWidth > nOldWidth)
     2128    {
     2129        char* pszRecord = (char *) malloc(sizeof(char) * psDBF->nRecordLength);
     2130
     2131        /* move records to their new positions */
     2132        for (iRecord = psDBF->nRecords - 1; iRecord >= 0; iRecord--)
     2133        {
     2134            nRecordOffset =
     2135                nOldRecordLength * (SAOffset) iRecord + psDBF->nHeaderLength;
     2136
     2137            /* load record */
     2138            psDBF->sHooks.FSeek( psDBF->fp, nRecordOffset, 0 );
     2139            psDBF->sHooks.FRead( pszRecord, nOldRecordLength, 1, psDBF->fp );
     2140
     2141            if (nOffset + nOldWidth < nOldRecordLength)
     2142            {
     2143                memmove( pszRecord + nOffset + nWidth,
     2144                         pszRecord + nOffset + nOldWidth,
     2145                         nOldRecordLength - (nOffset + nOldWidth));
     2146            }
     2147            memset(pszRecord + nOffset + nOldWidth, ' ', nWidth - nOldWidth);
     2148
     2149            nRecordOffset =
     2150                psDBF->nRecordLength * (SAOffset) iRecord + psDBF->nHeaderLength;
     2151
     2152            /* write record */
     2153            psDBF->sHooks.FSeek( psDBF->fp, nRecordOffset, 0 );
     2154            psDBF->sHooks.FWrite( pszRecord, psDBF->nRecordLength, 1, psDBF->fp );
     2155        }
     2156
     2157        free(pszRecord);
     2158    }
     2159
     2160    return TRUE;
     2161}
  • ogr/ogrsf_frmts/shape/ogrshape.h

     
    121121
    122122    virtual OGRErr      CreateField( OGRFieldDefn *poField,
    123123                                     int bApproxOK = TRUE );
     124    virtual OGRErr      DeleteField( int iField );
     125    virtual OGRErr      ReorderFields( int* panMap );
     126    virtual OGRErr      AlterFieldDefn( int iField, OGRFieldDefn* poNewFieldDefn, int nFlags );
    124127
    125128    virtual OGRSpatialReference *GetSpatialRef();
    126129   
  • swig/include/ogr.i

     
    208208
    209209%constant NullFID = -1;
    210210
     211%constant ALTER_NAME_FLAG = 1;
     212%constant ALTER_TYPE_FLAG = 2;
     213%constant ALTER_WIDTH_PRECISION_FLAG = 4;
     214%constant ALTER_ALL_FLAG = 1 + 2 + 4;
     215
    211216%constant char *OLCRandomRead          = "RandomRead";
    212217%constant char *OLCSequentialWrite     = "SequentialWrite";
    213218%constant char *OLCRandomWrite         = "RandomWrite";
     
    215220%constant char *OLCFastFeatureCount    = "FastFeatureCount";
    216221%constant char *OLCFastGetExtent       = "FastGetExtent";
    217222%constant char *OLCCreateField         = "CreateField";
     223%constant char *OLCDeleteField         = "DeleteField";
     224%constant char *OLCReorderFields       = "ReorderFields";
     225%constant char *OLCAlterFieldDefn      = "AlterFieldDefn";
    218226%constant char *OLCTransactions        = "Transactions";
    219227%constant char *OLCDeleteFeature       = "DeleteFeature";
    220228%constant char *OLCFastSetNextByIndex  = "FastSetNextByIndex";
     
    242250#define OLCFastFeatureCount    "FastFeatureCount"
    243251#define OLCFastGetExtent       "FastGetExtent"
    244252#define OLCCreateField         "CreateField"
     253#define OLCDeleteField         "DeleteField"
     254#define OLCReorderFields       "ReorderFields"
     255#define OLCAlterFieldDefn      "AlterFieldDefn"
    245256#define OLCTransactions        "Transactions"
    246257#define OLCDeleteFeature       "DeleteFeature"
    247258#define OLCFastSetNextByIndex  "FastSetNextByIndex"
     
    633644    return OGR_L_CreateField(self, field_def, approx_ok);
    634645  }
    635646%clear OGRFieldDefnShadow *field_def;
    636  
     647
     648  OGRErr DeleteField(int iField)
     649  {
     650    return OGR_L_DeleteField(self, iField);
     651  }
     652
     653  OGRErr ReorderField(int iOldFieldPos, int iNewFieldPos)
     654  {
     655    return OGR_L_ReorderField(self, iOldFieldPos, iNewFieldPos);
     656  }
     657
     658  OGRErr ReorderFields(int nList, int *pList)
     659  {
     660    if (nList != OGR_FD_GetFieldCount(OGR_L_GetLayerDefn(self)))
     661    {
     662      CPLError(CE_Failure, CPLE_IllegalArg,
     663               "List should have %d elements",
     664               OGR_FD_GetFieldCount(OGR_L_GetLayerDefn(self)));
     665      return OGRERR_FAILURE;
     666    }
     667    return OGR_L_ReorderFields(self, pList);
     668  }
     669
     670%apply Pointer NONNULL {OGRFieldDefnShadow *field_def};
     671  OGRErr AlterFieldDefn(int iField, OGRFieldDefnShadow* field_def, int nFlags)
     672  {
     673    return OGR_L_AlterFieldDefn(self, iField, field_def, nFlags);
     674  }
     675%clear OGRFieldDefnShadow *field_def;
     676
    637677  OGRErr StartTransaction() {
    638678    return OGR_L_StartTransaction(self);
    639679  }
  • swig/python/extensions/ogr_wrap.cpp

     
    34693469SWIGINTERN OGRErr OGRLayerShadow_CreateField(OGRLayerShadow *self,OGRFieldDefnShadow *field_def,int approx_ok=1){
    34703470    return OGR_L_CreateField(self, field_def, approx_ok);
    34713471  }
     3472SWIGINTERN OGRErr OGRLayerShadow_DeleteField(OGRLayerShadow *self,int iField){
     3473    return OGR_L_DeleteField(self, iField);
     3474  }
     3475SWIGINTERN OGRErr OGRLayerShadow_ReorderField(OGRLayerShadow *self,int iOldFieldPos,int iNewFieldPos){
     3476    return OGR_L_ReorderField(self, iOldFieldPos, iNewFieldPos);
     3477  }
     3478SWIGINTERN OGRErr OGRLayerShadow_ReorderFields(OGRLayerShadow *self,int nList,int *pList){
     3479    if (nList != OGR_FD_GetFieldCount(OGR_L_GetLayerDefn(self)))
     3480    {
     3481      CPLError(CE_Failure, CPLE_IllegalArg,
     3482               "List should have %d elements",
     3483               OGR_FD_GetFieldCount(OGR_L_GetLayerDefn(self)));
     3484      return OGRERR_FAILURE;
     3485    }
     3486    return OGR_L_ReorderFields(self, pList);
     3487  }
     3488SWIGINTERN OGRErr OGRLayerShadow_AlterFieldDefn(OGRLayerShadow *self,int iField,OGRFieldDefnShadow *field_def,int nFlags){
     3489    return OGR_L_AlterFieldDefn(self, iField, field_def, nFlags);
     3490  }
    34723491SWIGINTERN OGRErr OGRLayerShadow_StartTransaction(OGRLayerShadow *self){
    34733492    return OGR_L_StartTransaction(self);
    34743493  }
     
    67046723}
    67056724
    67066725
     6726SWIGINTERN PyObject *_wrap_Layer_DeleteField(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
     6727  PyObject *resultobj = 0;
     6728  OGRLayerShadow *arg1 = (OGRLayerShadow *) 0 ;
     6729  int arg2 ;
     6730  void *argp1 = 0 ;
     6731  int res1 = 0 ;
     6732  int val2 ;
     6733  int ecode2 = 0 ;
     6734  PyObject * obj0 = 0 ;
     6735  PyObject * obj1 = 0 ;
     6736  OGRErr result;
     6737 
     6738  if (!PyArg_ParseTuple(args,(char *)"OO:Layer_DeleteField",&obj0,&obj1)) SWIG_fail;
     6739  res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_OGRLayerShadow, 0 |  0 );
     6740  if (!SWIG_IsOK(res1)) {
     6741    SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Layer_DeleteField" "', argument " "1"" of type '" "OGRLayerShadow *""'");
     6742  }
     6743  arg1 = reinterpret_cast< OGRLayerShadow * >(argp1);
     6744  ecode2 = SWIG_AsVal_int(obj1, &val2);
     6745  if (!SWIG_IsOK(ecode2)) {
     6746    SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "Layer_DeleteField" "', argument " "2"" of type '" "int""'");
     6747  }
     6748  arg2 = static_cast< int >(val2);
     6749  {
     6750    if ( bUseExceptions ) {
     6751      CPLErrorReset();
     6752    }
     6753    result = (OGRErr)OGRLayerShadow_DeleteField(arg1,arg2);
     6754    if ( bUseExceptions ) {
     6755      CPLErr eclass = CPLGetLastErrorType();
     6756      if ( eclass == CE_Failure || eclass == CE_Fatal ) {
     6757        SWIG_exception( SWIG_RuntimeError, CPLGetLastErrorMsg() );
     6758      }
     6759    }
     6760  }
     6761  {
     6762    /* %typemap(out) OGRErr */
     6763    if ( result != 0 && bUseExceptions) {
     6764      PyErr_SetString( PyExc_RuntimeError, OGRErrMessages(result) );
     6765      SWIG_fail;
     6766    }
     6767  }
     6768  {
     6769    /* %typemap(ret) OGRErr */
     6770    if (resultobj == Py_None ) {
     6771      Py_DECREF(resultobj);
     6772      resultobj = 0;
     6773    }
     6774    if (resultobj == 0) {
     6775      resultobj = PyInt_FromLong( result );
     6776    }
     6777  }
     6778  return resultobj;
     6779fail:
     6780  return NULL;
     6781}
     6782
     6783
     6784SWIGINTERN PyObject *_wrap_Layer_ReorderField(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
     6785  PyObject *resultobj = 0;
     6786  OGRLayerShadow *arg1 = (OGRLayerShadow *) 0 ;
     6787  int arg2 ;
     6788  int arg3 ;
     6789  void *argp1 = 0 ;
     6790  int res1 = 0 ;
     6791  int val2 ;
     6792  int ecode2 = 0 ;
     6793  int val3 ;
     6794  int ecode3 = 0 ;
     6795  PyObject * obj0 = 0 ;
     6796  PyObject * obj1 = 0 ;
     6797  PyObject * obj2 = 0 ;
     6798  OGRErr result;
     6799 
     6800  if (!PyArg_ParseTuple(args,(char *)"OOO:Layer_ReorderField",&obj0,&obj1,&obj2)) SWIG_fail;
     6801  res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_OGRLayerShadow, 0 |  0 );
     6802  if (!SWIG_IsOK(res1)) {
     6803    SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Layer_ReorderField" "', argument " "1"" of type '" "OGRLayerShadow *""'");
     6804  }
     6805  arg1 = reinterpret_cast< OGRLayerShadow * >(argp1);
     6806  ecode2 = SWIG_AsVal_int(obj1, &val2);
     6807  if (!SWIG_IsOK(ecode2)) {
     6808    SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "Layer_ReorderField" "', argument " "2"" of type '" "int""'");
     6809  }
     6810  arg2 = static_cast< int >(val2);
     6811  ecode3 = SWIG_AsVal_int(obj2, &val3);
     6812  if (!SWIG_IsOK(ecode3)) {
     6813    SWIG_exception_fail(SWIG_ArgError(ecode3), "in method '" "Layer_ReorderField" "', argument " "3"" of type '" "int""'");
     6814  }
     6815  arg3 = static_cast< int >(val3);
     6816  {
     6817    if ( bUseExceptions ) {
     6818      CPLErrorReset();
     6819    }
     6820    result = (OGRErr)OGRLayerShadow_ReorderField(arg1,arg2,arg3);
     6821    if ( bUseExceptions ) {
     6822      CPLErr eclass = CPLGetLastErrorType();
     6823      if ( eclass == CE_Failure || eclass == CE_Fatal ) {
     6824        SWIG_exception( SWIG_RuntimeError, CPLGetLastErrorMsg() );
     6825      }
     6826    }
     6827  }
     6828  {
     6829    /* %typemap(out) OGRErr */
     6830    if ( result != 0 && bUseExceptions) {
     6831      PyErr_SetString( PyExc_RuntimeError, OGRErrMessages(result) );
     6832      SWIG_fail;
     6833    }
     6834  }
     6835  {
     6836    /* %typemap(ret) OGRErr */
     6837    if (resultobj == Py_None ) {
     6838      Py_DECREF(resultobj);
     6839      resultobj = 0;
     6840    }
     6841    if (resultobj == 0) {
     6842      resultobj = PyInt_FromLong( result );
     6843    }
     6844  }
     6845  return resultobj;
     6846fail:
     6847  return NULL;
     6848}
     6849
     6850
     6851SWIGINTERN PyObject *_wrap_Layer_ReorderFields(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
     6852  PyObject *resultobj = 0;
     6853  OGRLayerShadow *arg1 = (OGRLayerShadow *) 0 ;
     6854  int arg2 ;
     6855  int *arg3 = (int *) 0 ;
     6856  void *argp1 = 0 ;
     6857  int res1 = 0 ;
     6858  PyObject * obj0 = 0 ;
     6859  PyObject * obj1 = 0 ;
     6860  OGRErr result;
     6861 
     6862  if (!PyArg_ParseTuple(args,(char *)"OO:Layer_ReorderFields",&obj0,&obj1)) SWIG_fail;
     6863  res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_OGRLayerShadow, 0 |  0 );
     6864  if (!SWIG_IsOK(res1)) {
     6865    SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Layer_ReorderFields" "', argument " "1"" of type '" "OGRLayerShadow *""'");
     6866  }
     6867  arg1 = reinterpret_cast< OGRLayerShadow * >(argp1);
     6868  {
     6869    /* %typemap(in,numinputs=1) (int nList, int* pList)*/
     6870    /* check if is List */
     6871    if ( !PySequence_Check(obj1) ) {
     6872      PyErr_SetString(PyExc_TypeError, "not a sequence");
     6873      SWIG_fail;
     6874    }
     6875    arg2 = PySequence_Size(obj1);
     6876    arg3 = (int*) malloc(arg2*sizeof(int));
     6877    for( int i = 0; i<arg2; i++ ) {
     6878      PyObject *o = PySequence_GetItem(obj1,i);
     6879      if ( !PyArg_Parse(o,"i",&arg3[i]) ) {
     6880        PyErr_SetString(PyExc_TypeError, "not an integer");
     6881        Py_DECREF(o);
     6882        SWIG_fail;
     6883      }
     6884      Py_DECREF(o);
     6885    }
     6886  }
     6887  {
     6888    if ( bUseExceptions ) {
     6889      CPLErrorReset();
     6890    }
     6891    result = (OGRErr)OGRLayerShadow_ReorderFields(arg1,arg2,arg3);
     6892    if ( bUseExceptions ) {
     6893      CPLErr eclass = CPLGetLastErrorType();
     6894      if ( eclass == CE_Failure || eclass == CE_Fatal ) {
     6895        SWIG_exception( SWIG_RuntimeError, CPLGetLastErrorMsg() );
     6896      }
     6897    }
     6898  }
     6899  {
     6900    /* %typemap(out) OGRErr */
     6901    if ( result != 0 && bUseExceptions) {
     6902      PyErr_SetString( PyExc_RuntimeError, OGRErrMessages(result) );
     6903      SWIG_fail;
     6904    }
     6905  }
     6906  {
     6907    /* %typemap(freearg) (int nList, int* pList) */
     6908    if (arg3) {
     6909      free((void*) arg3);
     6910    }
     6911  }
     6912  {
     6913    /* %typemap(ret) OGRErr */
     6914    if (resultobj == Py_None ) {
     6915      Py_DECREF(resultobj);
     6916      resultobj = 0;
     6917    }
     6918    if (resultobj == 0) {
     6919      resultobj = PyInt_FromLong( result );
     6920    }
     6921  }
     6922  return resultobj;
     6923fail:
     6924  {
     6925    /* %typemap(freearg) (int nList, int* pList) */
     6926    if (arg3) {
     6927      free((void*) arg3);
     6928    }
     6929  }
     6930  return NULL;
     6931}
     6932
     6933
     6934SWIGINTERN PyObject *_wrap_Layer_AlterFieldDefn(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
     6935  PyObject *resultobj = 0;
     6936  OGRLayerShadow *arg1 = (OGRLayerShadow *) 0 ;
     6937  int arg2 ;
     6938  OGRFieldDefnShadow *arg3 = (OGRFieldDefnShadow *) 0 ;
     6939  int arg4 ;
     6940  void *argp1 = 0 ;
     6941  int res1 = 0 ;
     6942  int val2 ;
     6943  int ecode2 = 0 ;
     6944  void *argp3 = 0 ;
     6945  int res3 = 0 ;
     6946  int val4 ;
     6947  int ecode4 = 0 ;
     6948  PyObject * obj0 = 0 ;
     6949  PyObject * obj1 = 0 ;
     6950  PyObject * obj2 = 0 ;
     6951  PyObject * obj3 = 0 ;
     6952  OGRErr result;
     6953 
     6954  if (!PyArg_ParseTuple(args,(char *)"OOOO:Layer_AlterFieldDefn",&obj0,&obj1,&obj2,&obj3)) SWIG_fail;
     6955  res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_OGRLayerShadow, 0 |  0 );
     6956  if (!SWIG_IsOK(res1)) {
     6957    SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Layer_AlterFieldDefn" "', argument " "1"" of type '" "OGRLayerShadow *""'");
     6958  }
     6959  arg1 = reinterpret_cast< OGRLayerShadow * >(argp1);
     6960  ecode2 = SWIG_AsVal_int(obj1, &val2);
     6961  if (!SWIG_IsOK(ecode2)) {
     6962    SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "Layer_AlterFieldDefn" "', argument " "2"" of type '" "int""'");
     6963  }
     6964  arg2 = static_cast< int >(val2);
     6965  res3 = SWIG_ConvertPtr(obj2, &argp3,SWIGTYPE_p_OGRFieldDefnShadow, 0 |  0 );
     6966  if (!SWIG_IsOK(res3)) {
     6967    SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "Layer_AlterFieldDefn" "', argument " "3"" of type '" "OGRFieldDefnShadow *""'");
     6968  }
     6969  arg3 = reinterpret_cast< OGRFieldDefnShadow * >(argp3);
     6970  ecode4 = SWIG_AsVal_int(obj3, &val4);
     6971  if (!SWIG_IsOK(ecode4)) {
     6972    SWIG_exception_fail(SWIG_ArgError(ecode4), "in method '" "Layer_AlterFieldDefn" "', argument " "4"" of type '" "int""'");
     6973  }
     6974  arg4 = static_cast< int >(val4);
     6975  {
     6976    if (!arg3) {
     6977      SWIG_exception(SWIG_ValueError,"Received a NULL pointer.");
     6978    }
     6979  }
     6980  {
     6981    if ( bUseExceptions ) {
     6982      CPLErrorReset();
     6983    }
     6984    result = (OGRErr)OGRLayerShadow_AlterFieldDefn(arg1,arg2,arg3,arg4);
     6985    if ( bUseExceptions ) {
     6986      CPLErr eclass = CPLGetLastErrorType();
     6987      if ( eclass == CE_Failure || eclass == CE_Fatal ) {
     6988        SWIG_exception( SWIG_RuntimeError, CPLGetLastErrorMsg() );
     6989      }
     6990    }
     6991  }
     6992  {
     6993    /* %typemap(out) OGRErr */
     6994    if ( result != 0 && bUseExceptions) {
     6995      PyErr_SetString( PyExc_RuntimeError, OGRErrMessages(result) );
     6996      SWIG_fail;
     6997    }
     6998  }
     6999  {
     7000    /* %typemap(ret) OGRErr */
     7001    if (resultobj == Py_None ) {
     7002      Py_DECREF(resultobj);
     7003      resultobj = 0;
     7004    }
     7005    if (resultobj == 0) {
     7006      resultobj = PyInt_FromLong( result );
     7007    }
     7008  }
     7009  return resultobj;
     7010fail:
     7011  return NULL;
     7012}
     7013
     7014
    67077015SWIGINTERN PyObject *_wrap_Layer_StartTransaction(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
    67087016  PyObject *resultobj = 0;
    67097017  OGRLayerShadow *arg1 = (OGRLayerShadow *) 0 ;
     
    1675317061                "\n"
    1675417062                "OGRERR_NONE on success. \n"
    1675517063                ""},
     17064         { (char *)"Layer_DeleteField", _wrap_Layer_DeleteField, METH_VARARGS, (char *)"Layer_DeleteField(Layer self, int iField) -> OGRErr"},
     17065         { (char *)"Layer_ReorderField", _wrap_Layer_ReorderField, METH_VARARGS, (char *)"Layer_ReorderField(Layer self, int iOldFieldPos, int iNewFieldPos) -> OGRErr"},
     17066         { (char *)"Layer_ReorderFields", _wrap_Layer_ReorderFields, METH_VARARGS, (char *)"Layer_ReorderFields(Layer self, int nList) -> OGRErr"},
     17067         { (char *)"Layer_AlterFieldDefn", _wrap_Layer_AlterFieldDefn, METH_VARARGS, (char *)"Layer_AlterFieldDefn(Layer self, int iField, FieldDefn field_def, int nFlags) -> OGRErr"},
    1675617068         { (char *)"Layer_StartTransaction", _wrap_Layer_StartTransaction, METH_VARARGS, (char *)"\n"
    1675717069                "Layer_StartTransaction(Layer self) -> OGRErr\n"
    1675817070                "\n"
     
    1983820150  SWIG_Python_SetConstant(d, "wkbXDR",SWIG_From_int(static_cast< int >(0)));
    1983920151  SWIG_Python_SetConstant(d, "wkbNDR",SWIG_From_int(static_cast< int >(1)));
    1984020152  SWIG_Python_SetConstant(d, "NullFID",SWIG_From_int(static_cast< int >(-1)));
     20153  SWIG_Python_SetConstant(d, "ALTER_NAME_FLAG",SWIG_From_int(static_cast< int >(1)));
     20154  SWIG_Python_SetConstant(d, "ALTER_TYPE_FLAG",SWIG_From_int(static_cast< int >(2)));
     20155  SWIG_Python_SetConstant(d, "ALTER_WIDTH_PRECISION_FLAG",SWIG_From_int(static_cast< int >(4)));
     20156  SWIG_Python_SetConstant(d, "ALTER_ALL_FLAG",SWIG_From_int(static_cast< int >(1+2+4)));
    1984120157  SWIG_Python_SetConstant(d, "OLCRandomRead",SWIG_FromCharPtr("RandomRead"));
    1984220158  SWIG_Python_SetConstant(d, "OLCSequentialWrite",SWIG_FromCharPtr("SequentialWrite"));
    1984320159  SWIG_Python_SetConstant(d, "OLCRandomWrite",SWIG_FromCharPtr("RandomWrite"));
     
    1984520161  SWIG_Python_SetConstant(d, "OLCFastFeatureCount",SWIG_FromCharPtr("FastFeatureCount"));
    1984620162  SWIG_Python_SetConstant(d, "OLCFastGetExtent",SWIG_FromCharPtr("FastGetExtent"));
    1984720163  SWIG_Python_SetConstant(d, "OLCCreateField",SWIG_FromCharPtr("CreateField"));
     20164  SWIG_Python_SetConstant(d, "OLCDeleteField",SWIG_FromCharPtr("DeleteField"));
     20165  SWIG_Python_SetConstant(d, "OLCReorderFields",SWIG_FromCharPtr("ReorderFields"));
     20166  SWIG_Python_SetConstant(d, "OLCAlterFieldDefn",SWIG_FromCharPtr("AlterFieldDefn"));
    1984820167  SWIG_Python_SetConstant(d, "OLCTransactions",SWIG_FromCharPtr("Transactions"));
    1984920168  SWIG_Python_SetConstant(d, "OLCDeleteFeature",SWIG_FromCharPtr("DeleteFeature"));
    1985020169  SWIG_Python_SetConstant(d, "OLCFastSetNextByIndex",SWIG_FromCharPtr("FastSetNextByIndex"));
  • swig/python/osgeo/ogr.py

     
    103103wkbXDR = _ogr.wkbXDR
    104104wkbNDR = _ogr.wkbNDR
    105105NullFID = _ogr.NullFID
     106ALTER_NAME_FLAG = _ogr.ALTER_NAME_FLAG
     107ALTER_TYPE_FLAG = _ogr.ALTER_TYPE_FLAG
     108ALTER_WIDTH_PRECISION_FLAG = _ogr.ALTER_WIDTH_PRECISION_FLAG
     109ALTER_ALL_FLAG = _ogr.ALTER_ALL_FLAG
    106110OLCRandomRead = _ogr.OLCRandomRead
    107111OLCSequentialWrite = _ogr.OLCSequentialWrite
    108112OLCRandomWrite = _ogr.OLCRandomWrite
     
    110114OLCFastFeatureCount = _ogr.OLCFastFeatureCount
    111115OLCFastGetExtent = _ogr.OLCFastGetExtent
    112116OLCCreateField = _ogr.OLCCreateField
     117OLCDeleteField = _ogr.OLCDeleteField
     118OLCReorderFields = _ogr.OLCReorderFields
     119OLCAlterFieldDefn = _ogr.OLCAlterFieldDefn
    113120OLCTransactions = _ogr.OLCTransactions
    114121OLCDeleteFeature = _ogr.OLCDeleteFeature
    115122OLCFastSetNextByIndex = _ogr.OLCFastSetNextByIndex
     
    15101517        """
    15111518        return _ogr.Layer_CreateField(self, *args, **kwargs)
    15121519
     1520    def DeleteField(self, *args):
     1521        """DeleteField(self, int iField) -> OGRErr"""
     1522        return _ogr.Layer_DeleteField(self, *args)
     1523
     1524    def ReorderField(self, *args):
     1525        """ReorderField(self, int iOldFieldPos, int iNewFieldPos) -> OGRErr"""
     1526        return _ogr.Layer_ReorderField(self, *args)
     1527
     1528    def ReorderFields(self, *args):
     1529        """ReorderFields(self, int nList) -> OGRErr"""
     1530        return _ogr.Layer_ReorderFields(self, *args)
     1531
     1532    def AlterFieldDefn(self, *args):
     1533        """AlterFieldDefn(self, int iField, FieldDefn field_def, int nFlags) -> OGRErr"""
     1534        return _ogr.Layer_AlterFieldDefn(self, *args)
     1535
    15131536    def StartTransaction(self, *args):
    15141537        """
    15151538        StartTransaction(self) -> OGRErr
  • ogr/ogr_p.h

     
    117117/* Fast atof function */
    118118double OGRFastAtof(const char* pszStr);
    119119
     120OGRErr CPL_DLL OGRCheckPermutation(int* panPermutation, int nSize);
     121
    120122#endif /* ndef OGR_P_H_INCLUDED */
  • ogr/ogrutils.cpp

     
    13501350        }
    13511351    }
    13521352}
     1353
     1354/**
     1355 * Check that panPermutation is a permutation of [0,nSize-1].
     1356 * @param panPermutation an array of nSize elements.
     1357 * @param nSize size of the array.
     1358 * @return OGRERR_NONE if panPermutation is a permutation of [0,nSize-1].
     1359 * @since OGR 1.9.0
     1360 */
     1361OGRErr OGRCheckPermutation(int* panPermutation, int nSize)
     1362{
     1363    OGRErr eErr = OGRERR_NONE;
     1364    int* panCheck = (int*)CPLCalloc(nSize, sizeof(int));
     1365    int i;
     1366    for(i=0;i<nSize;i++)
     1367    {
     1368        if (panPermutation[i] < 0 || panPermutation[i] >= nSize)
     1369        {
     1370            CPLError(CE_Failure, CPLE_IllegalArg,
     1371                     "Bad value for element %d", i);
     1372            eErr = OGRERR_FAILURE;
     1373            break;
     1374        }
     1375        if (panCheck[panPermutation[i]] != 0)
     1376        {
     1377            CPLError(CE_Failure, CPLE_IllegalArg,
     1378                     "Array is not a permutation of [0,%d]",
     1379                     nSize - 1);
     1380            eErr = OGRERR_FAILURE;
     1381            break;
     1382        }
     1383        panCheck[panPermutation[i]] = 1;
     1384    }
     1385    CPLFree(panCheck);
     1386    return eErr;
     1387}