int GMLReader::ReArrangeTemplateClasses ( GFSTemplateList *pCC ) { /* rearranging the final FeatureClass list [SEQUENTIAL] */ int m_nSavedClassCount = GetClassCount(); /* saving the previous FeatureClass list */ GMLFeatureClass **m_papoSavedClass = (GMLFeatureClass **) CPLMalloc( sizeof(void*) * m_nSavedClassCount ); int clIdx; for (clIdx = 0; clIdx < GetClassCount(); clIdx++) { /* tranferring any previous FeatureClass */ m_papoSavedClass[clIdx] = m_papoClass[clIdx]; } /* cleaning the previous FeatureClass list */ SetClassListLocked( FALSE ); CPLFree( m_papoClass ); m_nClassCount = 0; m_papoClass = NULL; GFSTemplateItem *pItem = pCC->GetFirst(); while ( pItem != NULL ) { /* * re-inserting any required FeatureClassup * accordingly to actual SEQUENTIAL layout */ GMLFeatureClass* poClass = NULL; for( int iClass = 0; iClass < m_nSavedClassCount; iClass++ ) { GMLFeatureClass* poItem = m_papoSavedClass[iClass]; if( EQUAL(poItem->GetName(), pItem->GetName() )) { poClass = poItem; break; } } if (poClass != NULL) { if (poClass->GetFeatureCount() > 0) AddClass( poClass ); } pItem = pItem->GetNext(); } SetClassListLocked( TRUE ); /* destroying the saved List and any unused FeatureClass */ for( int iClass = 0; iClass < m_nSavedClassCount; iClass++ ) { int bUnused = TRUE; GMLFeatureClass* poClass = m_papoSavedClass[iClass]; for( int iClass2 = 0; iClass2 < m_nClassCount; iClass2++ ) { if (m_papoClass[iClass2] == poClass) { bUnused = FALSE; break; } } if ( bUnused == TRUE ) delete poClass; } CPLFree( m_papoSavedClass ); return 1; }
void NASReader::SetFeaturePropertyDirectly( const char *pszElement, char *pszValue ) { GMLFeature *poFeature = GetState()->m_poFeature; CPLAssert( poFeature != NULL ); /* -------------------------------------------------------------------- */ /* Does this property exist in the feature class? If not, add */ /* it. */ /* -------------------------------------------------------------------- */ GMLFeatureClass *poClass = poFeature->GetClass(); int iProperty; for( iProperty=0; iProperty < poClass->GetPropertyCount(); iProperty++ ) { if( EQUAL(poClass->GetProperty( iProperty )->GetSrcElement(), pszElement ) ) break; } if( iProperty == poClass->GetPropertyCount() ) { if( poClass->IsSchemaLocked() ) { CPLDebug("NAS", "Encountered property missing from class schema."); CPLFree(pszValue); return; } CPLString osFieldName; if( strchr(pszElement,'|') == NULL ) osFieldName = pszElement; else { osFieldName = strrchr(pszElement,'|') + 1; if( poClass->GetPropertyIndex(osFieldName) != -1 ) osFieldName = pszElement; } // Does this conflict with an existing property name? while( poClass->GetProperty(osFieldName) != NULL ) { osFieldName += "_"; } GMLPropertyDefn *poPDefn = new GMLPropertyDefn(osFieldName,pszElement); if( EQUAL(CPLGetConfigOption( "GML_FIELDTYPES", ""), "ALWAYS_STRING") ) poPDefn->SetType( GMLPT_String ); poClass->AddProperty( poPDefn ); } if ( GMLPropertyDefn::IsSimpleType( poClass->GetProperty( iProperty )->GetType() ) ) { const GMLProperty *poProp = poFeature->GetProperty(iProperty); if ( poProp && poProp->nSubProperties > 0 ) { int iId = poClass->GetPropertyIndex( "gml_id" ); const GMLProperty *poIdProp = poFeature->GetProperty(iId); CPLDebug("NAS", "Overwriting existing property %s.%s of value '%s' with '%s' (gml_id: %s).", poClass->GetName(), pszElement, poProp->papszSubProperties[0], pszValue, poIdProp && poIdProp->nSubProperties>0 && poIdProp->papszSubProperties[0] ? poIdProp->papszSubProperties[0] : "(null)" ); } } /* -------------------------------------------------------------------- */ /* We want to handle <lage> specially to ensure it is zero */ /* filled, and treated as a string depspite the numeric */ /* content. https://trac.wheregroup.com/PostNAS/ticket/9 */ /* -------------------------------------------------------------------- */ if( strcmp(poClass->GetProperty(iProperty)->GetName(),"lage") == 0 ) { if( strlen(pszValue) < 5 ) { CPLString osValue = "00000"; osValue += pszValue; poFeature->SetPropertyDirectly( iProperty, CPLStrdup(osValue + osValue.size() - 5) ); CPLFree(pszValue); } else poFeature->SetPropertyDirectly( iProperty, pszValue ); if( !poClass->IsSchemaLocked() ) { poClass->GetProperty(iProperty)->SetWidth( 5 ); poClass->GetProperty(iProperty)->SetType( GMLPT_String ); } return; } else if( strcmp(poClass->GetProperty(iProperty)->GetName(),"kartendarstellung") == 0 || strcmp(poClass->GetProperty(iProperty)->GetName(),"rechtsbehelfsverfahren") == 0 ) { poFeature->SetPropertyDirectly( iProperty, CPLStrdup( EQUAL( pszValue, "true" ) ? "1" : "0" ) ); CPLFree(pszValue); if( !poClass->IsSchemaLocked() ) { poClass->GetProperty(iProperty)->SetType( GMLPT_Integer ); } return; } /* -------------------------------------------------------------------- */ /* Set the property */ /* -------------------------------------------------------------------- */ poFeature->SetPropertyDirectly( iProperty, pszValue ); /* -------------------------------------------------------------------- */ /* Do we need to update the property type? */ /* -------------------------------------------------------------------- */ if( !poClass->IsSchemaLocked() ) { // Special handling for punktkennung per NAS #12 if( strcmp(poClass->GetProperty(iProperty)->GetName(), "punktkennung") == 0) { poClass->GetProperty(iProperty)->SetWidth( 15 ); poClass->GetProperty(iProperty)->SetType( GMLPT_String ); } // Special handling for artDerFlurstuecksgrenze per http://trac.osgeo.org/gdal/ticket/4255 else if( strcmp(poClass->GetProperty(iProperty)->GetName(), "artDerFlurstuecksgrenze") == 0) { poClass->GetProperty(iProperty)->SetType( GMLPT_IntegerList ); } else poClass->GetProperty(iProperty)->AnalysePropertyValue( poFeature->GetProperty(iProperty)); } }