LCOV - code coverage report
Current view: directory - ogr/ogrsf_frmts/geoconcept - ogrgeoconceptlayer.cpp (source / functions) Found Hit Coverage
Test: gdal_filtered.info Lines: 236 122 51.7 %
Date: 2010-01-09 Functions: 15 12 80.0 %

       1                 : /******************************************************************************
       2                 :  * $Id: ogrgeoconceptlayer.cpp 
       3                 :  *
       4                 :  * Project:  OpenGIS Simple Features Reference Implementation
       5                 :  * Purpose:  Implements OGRGeoconceptLayer class.
       6                 :  * Author:   Didier Richard, didier.richard@ign.fr
       7                 :  * Language: C++
       8                 :  *
       9                 :  ******************************************************************************
      10                 :  * Copyright (c) 2007,  Geoconcept and IGN
      11                 :  *
      12                 :  * Permission is hereby granted, free of charge, to any person obtaining a
      13                 :  * copy of this software and associated documentation files (the "Software"),
      14                 :  * to deal in the Software without restriction, including without limitation
      15                 :  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
      16                 :  * and/or sell copies of the Software, and to permit persons to whom the
      17                 :  * Software is furnished to do so, subject to the following conditions:
      18                 :  *
      19                 :  * The above copyright notice and this permission notice shall be included
      20                 :  * in all copies or substantial portions of the Software.
      21                 :  *
      22                 :  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
      23                 :  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      24                 :  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
      25                 :  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      26                 :  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
      27                 :  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
      28                 :  * DEALINGS IN THE SOFTWARE.
      29                 :  ****************************************************************************/
      30                 : 
      31                 : #include "ogrgeoconceptlayer.h"
      32                 : #include "cpl_conv.h"
      33                 : #include "cpl_string.h"
      34                 : 
      35                 : CPL_CVSID("$Id: ogrgeoconceptlayer.cpp 00000 2007-11-03 16:08:14Z drichard $");
      36                 : 
      37                 : /************************************************************************/
      38                 : /*                         OGRGeoconceptLayer()                         */
      39                 : /************************************************************************/
      40                 : 
      41               5 : OGRGeoconceptLayer::OGRGeoconceptLayer()
      42                 : {
      43               5 :     _poFeatureDefn = NULL;
      44               5 :     _gcFeature = NULL;
      45               5 : }
      46                 : 
      47                 : /************************************************************************/
      48                 : /*                          ~OGRGeoconceptLayer()                      */
      49                 : /************************************************************************/
      50                 : 
      51              10 : OGRGeoconceptLayer::~OGRGeoconceptLayer()
      52                 : 
      53                 : {
      54                 :   CPLDebug( "GEOCONCEPT",
      55                 :             "%ld features on layer %s.",
      56                 :             GetSubTypeNbFeatures_GCIO(_gcFeature),
      57               5 :             _poFeatureDefn->GetName());
      58                 : 
      59               5 :   if( _poFeatureDefn )
      60                 :   {
      61               5 :     _poFeatureDefn->Release();
      62                 :   }
      63                 : 
      64               5 :   _gcFeature= NULL; /* deleted when OGCGeoconceptDatasource destroyed */
      65              10 : }
      66                 : 
      67                 : /************************************************************************/
      68                 : /*                              Open()                                  */
      69                 : /************************************************************************/
      70                 : 
      71               5 : OGRErr OGRGeoconceptLayer::Open( GCSubType* Subclass )
      72                 : 
      73                 : {
      74               5 :     _gcFeature= Subclass;
      75               5 :     if( GetSubTypeFeatureDefn_GCIO(_gcFeature) )
      76                 :     {
      77               4 :       _poFeatureDefn = (OGRFeatureDefn *)GetSubTypeFeatureDefn_GCIO(_gcFeature);
      78               4 :       _poFeatureDefn->Reference();
      79                 :     }
      80                 :     else
      81                 :     {
      82                 :       char pszln[512];
      83                 :       int n, i;
      84                 : 
      85                 :       snprintf(pszln, 511, "%s.%s", GetSubTypeName_GCIO(_gcFeature),
      86               1 :                                     GetTypeName_GCIO(GetSubTypeType_GCIO(_gcFeature)));
      87               1 :       pszln[511]='\0';
      88                 : 
      89               1 :       _poFeatureDefn = new OGRFeatureDefn(pszln);
      90               1 :       _poFeatureDefn->Reference();
      91               1 :       _poFeatureDefn->SetGeomType(wkbUnknown);
      92                 : 
      93               1 :       if( (n= CountSubTypeFields_GCIO(_gcFeature))>0 )
      94                 :       {
      95               1 :         GCField* aField= NULL;
      96                 :         OGRFieldType oft;
      97               8 :         for( i= 0; i<n; i++ )
      98                 :         {
      99               7 :           if( (aField= GetSubTypeField_GCIO(_gcFeature,i)) )
     100                 :           {
     101               7 :             if( IsPrivateField_GCIO(aField) ) continue;
     102               0 :             switch(GetFieldKind_GCIO(aField)) {
     103                 :             case vIntFld_GCIO      :
     104                 :             case vPositionFld_GCIO :
     105               0 :               oft= OFTInteger;
     106               0 :               break;
     107                 :             case vRealFld_GCIO     :
     108                 :             case vLengthFld_GCIO   :
     109                 :             case vAreaFld_GCIO     :
     110               0 :               oft= OFTReal;
     111               0 :               break;
     112                 :             case vDateFld_GCIO     :
     113               0 :               oft= OFTDate;
     114               0 :               break;
     115                 :             case vTimeFld_GCIO     :
     116               0 :               oft= OFTTime;
     117               0 :               break;
     118                 :             case vMemoFld_GCIO     :
     119                 :             case vChoiceFld_GCIO   :
     120                 :             case vInterFld_GCIO    :
     121                 :             default                :
     122               0 :               oft= OFTString;
     123                 :               break;
     124                 :             }
     125               0 :             OGRFieldDefn ofd(GetFieldName_GCIO(aField), oft);
     126               0 :             _poFeatureDefn->AddFieldDefn(&ofd);
     127                 :           }
     128                 :         }
     129                 :       }
     130               1 :       SetSubTypeFeatureDefn_GCIO(_gcFeature, (OGRFeatureDefnH) _poFeatureDefn);
     131               1 :       _poFeatureDefn->Reference();
     132                 :     }
     133                 : 
     134               5 :     return OGRERR_NONE;
     135                 : }
     136                 : 
     137                 : /************************************************************************/
     138                 : /*                            ResetReading()                            */
     139                 : /************************************************************************/
     140                 : 
     141               6 : void OGRGeoconceptLayer::ResetReading()
     142                 : 
     143                 : {
     144               6 :     Rewind_GCIO(GetSubTypeGCHandle_GCIO(_gcFeature),_gcFeature);
     145               6 : }
     146                 : 
     147                 : /************************************************************************/
     148                 : /*                           GetNextFeature()                           */
     149                 : /************************************************************************/
     150                 : 
     151              33 : OGRFeature *OGRGeoconceptLayer::GetNextFeature()
     152                 : 
     153                 : {
     154              33 :     OGRFeature* poFeature = NULL;
     155                 : 
     156               0 :     for( ;; )
     157                 :     {
     158              33 :       if( !(poFeature= (OGRFeature*)ReadNextFeature_GCIO(_gcFeature)) )
     159                 :       {
     160                 :         /*
     161                 :          * As several features are embed in the Geoconcept file,
     162                 :          * when reaching the end of the feature type, resetting
     163                 :          * the reader would allow reading other features :
     164                 :          * ogrinfo -ro export.gxt FT1 FT2 ...
     165                 :          * will be all features for all features types !
     166                 :          */ 
     167               6 :         Rewind_GCIO(GetSubTypeGCHandle_GCIO(_gcFeature),NULL);
     168               6 :         break;
     169                 :       }
     170              27 :       if( (m_poFilterGeom == NULL || FilterGeometry( poFeature->GetGeometryRef() ) )
     171                 :           &&
     172                 :           (m_poAttrQuery == NULL  || m_poAttrQuery->Evaluate( poFeature )) )
     173                 :       {
     174              27 :         break;
     175                 :       }
     176               0 :       delete poFeature;
     177                 :     }
     178                 : 
     179                 :     CPLDebug( "GEOCONCEPT",
     180                 :               "FID : %ld\n"
     181                 :               "%s  : %s",
     182                 :               poFeature? poFeature->GetFID():-1L,
     183                 :               poFeature && poFeature->GetFieldCount()>0? poFeature->GetFieldDefnRef(0)->GetNameRef():"-",
     184              33 :               poFeature && poFeature->GetFieldCount()>0? poFeature->GetFieldAsString(0):"");
     185                 : 
     186              33 :     return poFeature;
     187                 : }
     188                 : 
     189                 : /************************************************************************/
     190                 : /*            OGRGeoconceptLayer_GetCompatibleFieldName()               */
     191                 : /************************************************************************/
     192                 : 
     193              15 : static char* OGRGeoconceptLayer_GetCompatibleFieldName(const char* pszName)
     194                 : {
     195              15 :     char* pszCompatibleName = CPLStrdup(pszName);
     196                 :     int i;
     197             169 :     for(i=0;pszCompatibleName[i] != 0;i++)
     198                 :     {
     199             154 :         if (pszCompatibleName[i] == ' ')
     200               0 :             pszCompatibleName[i] = '_';
     201                 :     }
     202              15 :     return pszCompatibleName;
     203                 : }
     204                 : 
     205                 : /************************************************************************/
     206                 : /*                           CreateFeature()                            */
     207                 : /************************************************************************/
     208                 : 
     209               2 : OGRErr OGRGeoconceptLayer::CreateFeature( OGRFeature* poFeature )
     210                 : 
     211                 : {
     212                 :     OGRwkbGeometryType eGt;
     213                 :     OGRGeometry* poGeom;
     214                 :     int nextField, iGeom, nbGeom, isSingle;
     215                 : 
     216               2 :     poGeom= poFeature->GetGeometryRef();
     217                 : 
     218               2 :     if (poGeom == NULL)
     219                 :     {
     220                 :         CPLError( CE_Warning, CPLE_NotSupported,
     221               0 :                   "NULL geometry not supported in Geoconcept, feature skipped.\n");
     222               0 :         return OGRERR_NONE;
     223                 :     }
     224                 : 
     225               2 :     eGt= poGeom->getGeometryType();
     226               2 :     switch( eGt ) {
     227                 :     case wkbPoint                 :
     228                 :     case wkbPoint25D              :
     229                 :     case wkbMultiPoint            :
     230                 :     case wkbMultiPoint25D         :
     231               2 :       if( GetSubTypeKind_GCIO(_gcFeature)==vUnknownItemType_GCIO )
     232                 :       {
     233               0 :         SetSubTypeKind_GCIO(_gcFeature,vPoint_GCIO);
     234                 :       }
     235               2 :       else if( GetSubTypeKind_GCIO(_gcFeature)!=vPoint_GCIO )
     236                 :       {
     237                 :         CPLError( CE_Failure, CPLE_NotSupported,
     238                 :                   "Can't write non ponctual feature in a ponctual Geoconcept layer %s.\n",
     239               0 :                   _poFeatureDefn->GetName());
     240               0 :         return OGRERR_FAILURE;
     241                 :       }
     242               2 :       break;
     243                 :     case wkbLineString            :
     244                 :     case wkbLineString25D         :
     245                 :     case wkbMultiLineString       :
     246                 :     case wkbMultiLineString25D    :
     247               0 :       if( GetSubTypeKind_GCIO(_gcFeature)==vUnknownItemType_GCIO )
     248                 :       {
     249               0 :         SetSubTypeKind_GCIO(_gcFeature,vLine_GCIO);
     250                 :       }
     251               0 :       else if( GetSubTypeKind_GCIO(_gcFeature)!=vLine_GCIO )
     252                 :       {
     253                 :         CPLError( CE_Failure, CPLE_NotSupported,
     254                 :                   "Can't write non linear feature in a linear Geoconcept layer %s.\n",
     255               0 :                   _poFeatureDefn->GetName());
     256               0 :         return OGRERR_FAILURE;
     257                 :       }
     258               0 :       break;
     259                 :     case wkbPolygon               :
     260                 :     case wkbPolygon25D            :
     261                 :     case wkbMultiPolygon          :
     262                 :     case wkbMultiPolygon25D       :
     263               0 :       if( GetSubTypeKind_GCIO(_gcFeature)==vUnknownItemType_GCIO )
     264                 :       {
     265               0 :         SetSubTypeKind_GCIO(_gcFeature,vPoly_GCIO);
     266                 :       }
     267               0 :       else if( GetSubTypeKind_GCIO(_gcFeature)!=vPoly_GCIO )
     268                 :       {
     269                 :         CPLError( CE_Failure, CPLE_NotSupported,
     270                 :                   "Can't write non polygonal feature in a polygonal Geoconcept layer %s.\n",
     271               0 :                   _poFeatureDefn->GetName());
     272               0 :         return OGRERR_FAILURE;
     273                 :       }
     274               0 :       break;
     275                 :     case wkbUnknown               :
     276                 :     case wkbGeometryCollection    :
     277                 :     case wkbGeometryCollection25D :
     278                 :     case wkbNone                  :
     279                 :     case wkbLinearRing            :
     280                 :     default                       :
     281                 :       CPLError( CE_Warning, CPLE_AppDefined,
     282                 :                 "Geometry type %s not supported in Geoconcept, feature skipped.\n",
     283               0 :                 OGRGeometryTypeToName(eGt) );
     284               0 :       return OGRERR_NONE;
     285                 :     }
     286               2 :     if( GetSubTypeDim_GCIO(_gcFeature)==vUnknown3D_GCIO )
     287                 :     {
     288               0 :       if( poGeom->getCoordinateDimension()==3 )
     289                 :       {
     290               0 :         SetSubTypeDim_GCIO(_gcFeature,v3D_GCIO);
     291                 :       }
     292                 :       else
     293                 :       {
     294               0 :         SetSubTypeDim_GCIO(_gcFeature,v2D_GCIO);
     295                 :       }
     296                 :     }
     297                 : 
     298               2 :     switch( eGt ) {
     299                 :     case wkbPoint                 :
     300                 :     case wkbPoint25D              :
     301               2 :       nbGeom= 1;
     302               2 :       isSingle= TRUE;
     303               2 :       break;
     304                 :     case wkbMultiPoint            :
     305                 :     case wkbMultiPoint25D         :
     306               0 :       nbGeom= ((OGRGeometryCollection*)poGeom)->getNumGeometries();
     307               0 :       isSingle= FALSE;
     308               0 :       break;
     309                 :     case wkbLineString            :
     310                 :     case wkbLineString25D         :
     311               0 :       nbGeom= 1;
     312               0 :       isSingle= TRUE;
     313               0 :       break;
     314                 :     case wkbMultiLineString       :
     315                 :     case wkbMultiLineString25D    :
     316               0 :       nbGeom= ((OGRGeometryCollection*)poGeom)->getNumGeometries();
     317               0 :       isSingle= FALSE;
     318               0 :       break;
     319                 :     case wkbPolygon               :
     320                 :     case wkbPolygon25D            :
     321               0 :       nbGeom= 1;
     322               0 :       isSingle= TRUE;
     323               0 :       break;
     324                 :     case wkbMultiPolygon          :
     325                 :     case wkbMultiPolygon25D       :
     326               0 :       nbGeom= ((OGRGeometryCollection*)poGeom)->getNumGeometries();
     327               0 :       isSingle= FALSE;
     328               0 :       break;
     329                 :     case wkbUnknown               :
     330                 :     case wkbGeometryCollection    :
     331                 :     case wkbGeometryCollection25D :
     332                 :     case wkbNone                  :
     333                 :     case wkbLinearRing            :
     334                 :     default                       :
     335               0 :       nbGeom= 0;
     336               0 :       isSingle= FALSE;
     337                 :       break;
     338                 :     }
     339                 : 
     340                 :     /* 1st feature, let's write header : */
     341               4 :     if( GetGCMode_GCIO(GetSubTypeGCHandle_GCIO(_gcFeature)) == vWriteAccess_GCIO &&
     342               2 :         GetFeatureCount(TRUE) == 0 )
     343               1 :       if( WriteHeader_GCIO(GetSubTypeGCHandle_GCIO(_gcFeature))==NULL )
     344                 :       {
     345               0 :         return OGRERR_FAILURE;
     346                 :       }
     347                 : 
     348               2 :     if( nbGeom>0 )
     349                 :     {
     350               4 :       for( iGeom= 0; iGeom<nbGeom; iGeom++ )
     351                 :       {
     352                 :         nextField= StartWritingFeature_GCIO(_gcFeature,
     353               2 :                                             isSingle? poFeature->GetFID():OGRNullFID);
     354              12 :         while (nextField!=WRITECOMPLETED_GCIO)
     355                 :         {
     356               8 :           if( nextField==WRITEERROR_GCIO )
     357                 :           {
     358               0 :             return OGRERR_FAILURE;
     359                 :           }
     360               8 :           if( nextField==GEOMETRYEXPECTED_GCIO )
     361                 :           {
     362                 :             OGRGeometry* poGeomPart=
     363               2 :                 isSingle? poGeom:((OGRGeometryCollection*)poGeom)->getGeometryRef(iGeom);
     364                 :             nextField= WriteFeatureGeometry_GCIO(_gcFeature,
     365               2 :                                                  (OGRGeometryH)poGeomPart);
     366                 :           }
     367                 :           else
     368                 :           {
     369                 :             int iF, nF;
     370                 :             OGRFieldDefn *poField;
     371               6 :             GCField* theField= GetSubTypeField_GCIO(_gcFeature,nextField);
     372                 :             /* for each field, find out its mapping ... */
     373               6 :             if( (nF= poFeature->GetFieldCount())>0 )
     374                 :             {
     375              12 :               for( iF= 0; iF<nF; iF++ )
     376                 :               {
     377              12 :                 poField= poFeature->GetFieldDefnRef(iF);
     378              12 :                 char* pszName = OGRGeoconceptLayer_GetCompatibleFieldName(poField->GetNameRef());
     379              12 :                 if( EQUAL(pszName, GetFieldName_GCIO(theField)) )
     380                 :                 {
     381               6 :                   CPLFree(pszName);
     382                 :                   nextField= WriteFeatureFieldAsString_GCIO(_gcFeature,
     383                 :                                                             nextField,
     384                 :                                                             poFeature->IsFieldSet(iF)?
     385                 :                                                               poFeature->GetFieldAsString(iF)
     386                 :                                                             :
     387               6 :                                                               NULL);
     388               6 :                   break;
     389                 :                 }
     390               6 :                 CPLFree(pszName);
     391                 :               }
     392               6 :               if( iF==nF )
     393                 :               {
     394                 :                 CPLError( CE_Failure, CPLE_AppDefined,
     395                 :                           "Can't find a field attached to %s on Geoconcept layer %s.\n",
     396               0 :                           GetFieldName_GCIO(theField), _poFeatureDefn->GetName());
     397               0 :                 return OGRERR_FAILURE;
     398                 :               }
     399                 :             }
     400                 :             else
     401                 :             {
     402               0 :               nextField= WRITECOMPLETED_GCIO;
     403                 :             }
     404                 :           }
     405                 :         }
     406               2 :         StopWritingFeature_GCIO(_gcFeature);
     407                 :       }
     408                 :     }
     409                 : 
     410               2 :     return OGRERR_NONE;
     411                 : }
     412                 : 
     413                 : /************************************************************************/
     414                 : /*                           GetSpatialRef()                            */
     415                 : /************************************************************************/
     416                 : 
     417               3 : OGRSpatialReference *OGRGeoconceptLayer::GetSpatialRef()
     418                 : 
     419                 : {
     420               3 :     GCExportFileH* hGXT= GetSubTypeGCHandle_GCIO(_gcFeature);
     421               3 :     if( !hGXT ) return NULL;
     422               3 :     GCExportFileMetadata* Meta= GetGCMeta_GCIO(hGXT);
     423               3 :     if( !Meta ) return NULL;
     424               3 :     return (OGRSpatialReference*)GetMetaSRS_GCIO(Meta);
     425                 : }
     426                 : 
     427                 : /************************************************************************/
     428                 : /*                          GetFeatureCount()                           */
     429                 : /*                                                                      */
     430                 : /*      If a spatial filter is in effect, we turn control over to       */
     431                 : /*      the generic counter.  Otherwise we return the total count.      */
     432                 : /************************************************************************/
     433                 : 
     434               7 : int OGRGeoconceptLayer::GetFeatureCount( int bForce )
     435                 : 
     436                 : {
     437               7 :     if( m_poFilterGeom != NULL || m_poAttrQuery != NULL )
     438               0 :         return OGRLayer::GetFeatureCount( bForce );
     439                 :     else
     440               7 :         return GetSubTypeNbFeatures_GCIO(_gcFeature);
     441                 : }
     442                 : 
     443                 : /************************************************************************/
     444                 : /*                             GetExtent()                              */
     445                 : /************************************************************************/
     446                 : 
     447               0 : OGRErr OGRGeoconceptLayer::GetExtent( OGREnvelope* psExtent, int bForce )
     448                 : 
     449                 : {
     450                 :     GCExtent* theExtent;
     451                 : 
     452               0 :     theExtent= GetSubTypeExtent_GCIO( _gcFeature );
     453               0 :     psExtent->MinX= GetExtentULAbscissa_GCIO(theExtent);
     454               0 :     psExtent->MinY= GetExtentLROrdinate_GCIO(theExtent);
     455               0 :     psExtent->MaxX= GetExtentLRAbscissa_GCIO(theExtent);
     456               0 :     psExtent->MaxY= GetExtentULOrdinate_GCIO(theExtent);
     457                 : 
     458               0 :     return OGRERR_NONE;
     459                 : }
     460                 : 
     461                 : /************************************************************************/
     462                 : /*                           TestCapability()                           */
     463                 : /************************************************************************/
     464                 : 
     465               0 : int OGRGeoconceptLayer::TestCapability( const char* pszCap )
     466                 : 
     467                 : {
     468               0 :     if( EQUAL(pszCap,OLCRandomRead) )
     469               0 :         return FALSE; // the GetFeature() method does not work for this layer. TODO
     470                 : 
     471               0 :     else if( EQUAL(pszCap,OLCSequentialWrite) )
     472               0 :         return TRUE; // the CreateFeature() method works for this layer.
     473                 : 
     474               0 :     else if( EQUAL(pszCap,OLCRandomWrite) )
     475               0 :         return FALSE; // the SetFeature() method is not operational on this layer.
     476                 : 
     477               0 :     else if( EQUAL(pszCap,OLCFastSpatialFilter) )
     478               0 :         return FALSE; // this layer does not implement spatial filtering efficiently.
     479                 : 
     480               0 :     else if( EQUAL(pszCap,OLCFastFeatureCount) )
     481               0 :         return FALSE; // this layer can not return a feature count efficiently. FIXME
     482                 : 
     483               0 :     else if( EQUAL(pszCap,OLCFastGetExtent) )
     484               0 :         return FALSE; // this layer can not return its data extent efficiently. FIXME
     485                 : 
     486               0 :     else if( EQUAL(pszCap,OLCFastSetNextByIndex) )
     487               0 :         return FALSE; // this layer can not perform the SetNextByIndex() call efficiently.
     488                 : 
     489               0 :     else if( EQUAL(pszCap,OLCDeleteFeature) )
     490               0 :         return FALSE;
     491                 : 
     492               0 :     else if( EQUAL(pszCap,OLCCreateField) )
     493               0 :         return TRUE;
     494                 : 
     495                 :     else
     496               0 :         return FALSE;
     497                 : }
     498                 : 
     499                 : /************************************************************************/
     500                 : /*                            CreateField()                             */
     501                 : /************************************************************************/
     502                 : 
     503               3 : OGRErr OGRGeoconceptLayer::CreateField( OGRFieldDefn *poField, int bApproxOK )
     504                 : 
     505                 : {
     506               3 :     if( GetGCMode_GCIO(GetSubTypeGCHandle_GCIO(_gcFeature))==vReadAccess_GCIO )
     507                 :     {
     508                 :         CPLError( CE_Failure, CPLE_NotSupported,
     509               0 :                   "Can't create fields on a read-only Geoconcept layer.\n");
     510               0 :         return OGRERR_FAILURE;
     511                 : 
     512                 :     }
     513                 : 
     514                 : /* -------------------------------------------------------------------- */
     515                 : /*      Add field to layer                                              */
     516                 : /* -------------------------------------------------------------------- */
     517                 : 
     518                 :     {
     519                 :       /* check whether field exists ... */
     520                 :       GCField* theField;
     521               3 :       char* pszName = OGRGeoconceptLayer_GetCompatibleFieldName(poField->GetNameRef());
     522                 : 
     523               3 :       if( !(theField= FindFeatureField_GCIO(_gcFeature,pszName)) )
     524                 :       {
     525               3 :         if( GetFeatureCount(TRUE) > 0 )
     526                 :         {
     527                 :           CPLError( CE_Failure, CPLE_NotSupported,
     528                 :                     "Can't create field '%s' on existing Geoconcept layer '%s.%s'.\n",
     529                 :                     pszName,
     530                 :                     GetSubTypeName_GCIO(_gcFeature),
     531               0 :                     GetTypeName_GCIO(GetSubTypeType_GCIO(_gcFeature)) );
     532               0 :           CPLFree(pszName);
     533               0 :           return OGRERR_FAILURE;
     534                 :         }
     535               3 :         if( GetSubTypeNbFields_GCIO(_gcFeature)==-1)
     536               1 :           SetSubTypeNbFields_GCIO(_gcFeature, 0L);
     537               3 :         if( !(theField= AddSubTypeField_GCIO(GetSubTypeGCHandle_GCIO(_gcFeature),
     538                 :                                              GetTypeName_GCIO(GetSubTypeType_GCIO(_gcFeature)),
     539                 :                                              GetSubTypeName_GCIO(_gcFeature),
     540                 :                                              FindFeatureFieldIndex_GCIO(_gcFeature,kNbFields_GCIO)
     541                 :                                             +GetSubTypeNbFields_GCIO(_gcFeature)+1L,
     542                 :                                              pszName,
     543                 :                                              GetSubTypeNbFields_GCIO(_gcFeature)-999L,
     544                 :                                              vUnknownItemType_GCIO, NULL, NULL)) )
     545                 :         {
     546                 :           CPLError( CE_Failure, CPLE_AppDefined,
     547                 :                     "Field '%s' could not be created for Feature %s.%s.\n",
     548                 :                     pszName,
     549                 :                     GetSubTypeName_GCIO(_gcFeature),
     550                 :                     GetTypeName_GCIO(GetSubTypeType_GCIO(_gcFeature))
     551               0 :                   );
     552               0 :           CPLFree(pszName);
     553               0 :           return OGRERR_FAILURE;
     554                 :         }
     555               3 :         SetSubTypeNbFields_GCIO(_gcFeature, GetSubTypeNbFields_GCIO(_gcFeature)+1L);
     556               3 :         _poFeatureDefn->AddFieldDefn(poField);
     557                 :       }
     558                 :       else
     559                 :       {
     560               0 :         if( _poFeatureDefn->GetFieldIndex(GetFieldName_GCIO(theField))==-1 )
     561                 :         {
     562                 :           CPLError( CE_Failure, CPLE_AppDefined,
     563                 :                     "Field %s not found for Feature %s.%s.\n",
     564                 :                     GetFieldName_GCIO(theField),
     565                 :                     GetSubTypeName_GCIO(_gcFeature),
     566                 :                     GetTypeName_GCIO(GetSubTypeType_GCIO(_gcFeature))
     567               0 :                   );
     568               0 :           CPLFree(pszName);
     569               0 :           return OGRERR_FAILURE;
     570                 :         }
     571                 :       }
     572                 : 
     573               3 :       CPLFree(pszName);
     574               3 :       pszName = NULL;
     575                 : 
     576                 :       /* check/update type ? */
     577               3 :       if( GetFieldKind_GCIO(theField)==vUnknownItemType_GCIO )
     578                 :       {
     579               3 :         switch(poField->GetType()) {
     580                 :         case OFTInteger        :
     581               0 :           SetFieldKind_GCIO(theField,vIntFld_GCIO);
     582               0 :           break;
     583                 :         case OFTReal           :
     584               0 :           SetFieldKind_GCIO(theField,vRealFld_GCIO);
     585               0 :           break;
     586                 :         case OFTDate           :
     587               0 :           SetFieldKind_GCIO(theField,vDateFld_GCIO);
     588               0 :           break;
     589                 :         case OFTTime           :
     590                 :         case OFTDateTime       :
     591               0 :           SetFieldKind_GCIO(theField,vTimeFld_GCIO);
     592               0 :           break;
     593                 :         case OFTString         :
     594               3 :           SetFieldKind_GCIO(theField,vMemoFld_GCIO);
     595               3 :           break;
     596                 :         case OFTIntegerList    :
     597                 :         case OFTRealList       :
     598                 :         case OFTStringList     :
     599                 :         case OFTBinary         :
     600                 :         default                :
     601                 :           CPLError( CE_Failure, CPLE_NotSupported,
     602                 :                     "Can't create fields of type %s on Geoconcept feature %s.\n",
     603                 :                     OGRFieldDefn::GetFieldTypeName(poField->GetType()),
     604               0 :                     _poFeatureDefn->GetName() );
     605               0 :           return OGRERR_FAILURE;
     606                 :         }
     607                 :       }
     608                 :     }
     609                 : 
     610               3 :     return OGRERR_NONE;
     611                 : }
     612                 : 
     613                 : /************************************************************************/
     614                 : /*                             SyncToDisk()                             */
     615                 : /************************************************************************/
     616                 : 
     617               0 : OGRErr OGRGeoconceptLayer::SyncToDisk()
     618                 : 
     619                 : {
     620               0 :     FFlush_GCIO(GetSubTypeGCHandle_GCIO(_gcFeature));
     621               0 :     return OGRERR_NONE;
     622                 : }
     623                 : 
     624                 : /************************************************************************/
     625                 : /*                             SetSpatialRef()                          */
     626                 : /************************************************************************/
     627                 : 
     628               1 : void OGRGeoconceptLayer::SetSpatialRef( OGRSpatialReference *poSpatialRef )
     629                 : 
     630                 : {
     631                 :     GCSysCoord* os, *ns;
     632               1 :     OGRSpatialReference* poSRS= GetSpatialRef();
     633                 :     GCExportFileH* hGXT;
     634                 :     GCExportFileMetadata* Meta;
     635                 :     /*-----------------------------------------------------------------
     636                 :      * Keep a copy of the OGRSpatialReference...
     637                 :      * Note: we have to take the reference count into account...
     638                 :      *----------------------------------------------------------------*/
     639               1 :     if( poSRS && poSRS->Dereference() == 0) delete poSRS;
     640                 : 
     641               1 :     if( !poSpatialRef ) return;
     642                 : 
     643               1 :     poSRS= poSpatialRef->Clone();
     644               1 :     if( !(hGXT= GetSubTypeGCHandle_GCIO(_gcFeature)) ) return;
     645               1 :     if( !(Meta= GetGCMeta_GCIO(hGXT)) ) return;
     646               1 :     os= GetMetaSysCoord_GCIO(Meta);
     647               1 :     ns= OGRSpatialReference2SysCoord_GCSRS((OGRSpatialReferenceH)poSRS);
     648                 : 
     649               1 :     if( os && ns &&
     650                 :         GetSysCoordSystemID_GCSRS(os)!=-1 &&
     651                 :         (
     652                 :           GetSysCoordSystemID_GCSRS(os)!=GetSysCoordSystemID_GCSRS(ns) ||
     653                 :           GetSysCoordTimeZone_GCSRS(os)!=GetSysCoordTimeZone_GCSRS(ns)
     654                 :         )
     655                 :       )
     656                 :     {
     657                 :       CPLError( CE_Warning, CPLE_AppDefined,
     658               0 :                 "Can't change SRS on Geoconcept layers.\n" );
     659               0 :       return;
     660                 :     }
     661                 : 
     662               1 :     if( os ) DestroySysCoord_GCSRS(&os);
     663               1 :     SetMetaSysCoord_GCIO(Meta, ns);
     664               1 :     SetMetaSRS_GCIO(Meta, (OGRSpatialReferenceH)poSRS);
     665               1 :     return;
     666                 : }

Generated by: LCOV version 1.7