[gdal-dev] Patch for s57reader.cpp

mrxonx at hotmail.com mrxonx at hotmail.com
Fri Nov 4 14:27:57 EDT 2011


Dear all,

Included is a patch for s57reader.cpp that properly applies updates for
certain types of charts.

The essence of this patch is that SG2D field may not be present in
original record, and must be added if update is trying to insert SG2D
fields.

The patch was made against our modified version of OGR, so line numbers
likely do not match and certain function signatures may need to be
updated. If you'd like to apply it - make sure it goes in the
S57Reader::ApplyRecordUpdate.

Best,
--
Mike


-------------- next part --------------
Index: s57reader.cpp
===================================================================
--- s57reader.cpp	(revision 0000)
+++ s57reader.cpp	(working copy)
@@ -2635,16 +2635,30 @@
         /* If we don't have SG2D, check for SG3D */
         if( poDstSG2D == NULL )
         {
-            poSrcSG2D = poUpdate->FindField("SG3D");
             poDstSG2D = poTarget->FindField("SG3D");
+            if (poDstSG2D != NULL) {
+               poSrcSG2D = poUpdate->FindField("SG3D");
+            }
         }
 
-        if( (poSrcSG2D == NULL && nCCUI != 2) || poDstSG2D == NULL )
+        if( (poSrcSG2D == NULL && nCCUI != 2) || (poDstSG2D == NULL && nCCUI != 1) )
         {
             CPLAssert( FALSE );
             return FALSE;
         }
 
+        if (poDstSG2D == NULL) {
+          poTarget->AddField(poTarget->GetModule()->FindFieldDefn("SG2D"));
+          poDstSG2D = poTarget->FindField("SG2D");
+          if (poDstSG2D == NULL) {
+            CPLAssert( FALSE );
+            return FALSE;
+          }
+
+          // Delete null default data that was created
+          poTarget->SetFieldRaw( poDstSG2D, 0, NULL, 0 );
+        }
+
         nCoordSize = poDstSG2D->GetFieldDefn()->GetFixedWidth();
 
         if( nCCUI == 1 ) /* INSERT */


More information about the gdal-dev mailing list