void GMLReader::SetFeatureProperty( const char *pszElement, const 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("GML","Encountered property missing from class schema."); return; } GMLPropertyDefn *poPDefn = new GMLPropertyDefn(pszElement,pszElement); if( EQUAL(CPLGetConfigOption( "GML_FIELDTYPES", ""), "ALWAYS_STRING") ) poPDefn->SetType( GMLPT_String ); poClass->AddProperty( poPDefn ); } /* -------------------------------------------------------------------- */ /* Set the property */ /* -------------------------------------------------------------------- */ poFeature->SetProperty( iProperty, pszValue ); /* -------------------------------------------------------------------- */ /* Do we need to update the property type? */ /* -------------------------------------------------------------------- */ if( !poClass->IsSchemaLocked() ) poClass->GetProperty( iProperty )->AnalysePropertyValue(pszValue); }
int NASReader::IsAttributeElement( const char *pszElement ) { if( m_poState->m_poFeature == NULL ) return FALSE; GMLFeatureClass *poClass = m_poState->m_poFeature->GetClass(); // If the schema is not yet locked, then any simple element // is potentially an attribute. if( !poClass->IsSchemaLocked() ) return TRUE; // Otherwise build the path to this element into a single string // and compare against known attributes. CPLString osElemPath; if( m_poState->m_nPathLength == 0 ) osElemPath = pszElement; else { osElemPath = m_poState->m_pszPath; osElemPath += "|"; osElemPath += pszElement; } for( int i = 0; i < poClass->GetPropertyCount(); i++ ) if( EQUAL(poClass->GetProperty(i)->GetSrcElement(),osElemPath) ) return TRUE; return FALSE; }
int GMLReader::IsAttributeElement( const char *pszElement ) { if( m_poState->m_poFeature == NULL ) return FALSE; if( m_poState->m_nPathLength > 0 ) return FALSE; GMLFeatureClass *poClass = m_poState->m_poFeature->GetClass(); if( !poClass->IsSchemaLocked() ) return TRUE; for( int i = 0; i < poClass->GetPropertyCount(); i++ ) if( EQUAL(poClass->GetProperty(i)->GetSrcElement(),pszElement) ) return TRUE; return FALSE; }
void NASReader::SetFeatureProperty( const char *pszElement, const 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("GML","Encountered property missing from class schema."); 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 ); } /* -------------------------------------------------------------------- */ /* Set the property */ /* -------------------------------------------------------------------- */ poFeature->SetProperty( iProperty, pszValue ); /* -------------------------------------------------------------------- */ /* Do we need to update the property type? */ /* -------------------------------------------------------------------- */ if( !poClass->IsSchemaLocked() ) { poClass->GetProperty(iProperty)->AnalysePropertyValue( poFeature->GetProperty(iProperty)); } }
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 ); } /* -------------------------------------------------------------------- */ /* 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; } /* -------------------------------------------------------------------- */ /* 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)); } }