📄 ugkfeature.cpp
字号:
}/************************************************************************//* SetField() *//************************************************************************//** * Set field to list of strings value. * * This method currently on has an effect of OFTStringList fields. * * @param iField the field to set, from 0 to GetFieldCount()-1. * @param papszValues the values to assign. */void UGKFeature::SetField( int iField, char ** papszValues ){ UGKFieldDefn *poFDefn = poDefn->GetFieldDefn( iField ); assert( poFDefn != NULL || iField == -1 ); if( poFDefn == NULL ) return; if( poFDefn->GetType() == OFTStringList ) { UGKField uField; uField.StringList.nCount = CountOfList(papszValues); uField.StringList.paList = papszValues; SetField( iField, &uField ); }}/************************************************************************//* SetField() *//************************************************************************//** * Set field. * * The passed value UGKField must be of exactly the same type as the * target field, or an application crash may occur. The passed value * is copied, and will not be affected. It remains the responsibility of * the caller. * * @param iField the field to fetch, from 0 to GetFieldCount()-1. * @param puValue the value to assign. */void UGKFeature::SetField( int iField, UGKField * puValue ){ UGKFieldDefn *poFDefn = poDefn->GetFieldDefn( iField ); assert( poFDefn != NULL || iField == -1 ); if( poFDefn == NULL ) return; if( poFDefn->GetType() == OFTInteger ) { pauFields[iField] = *puValue; } else if( poFDefn->GetType() == OFTReal ) { pauFields[iField] = *puValue; } else if( poFDefn->GetType() == OFTString ) { if( IsFieldSet( iField ) ) UGK_Free( pauFields[iField].String ); if( puValue->String == NULL ) pauFields[iField].String = NULL; else if( puValue->Set.nMarker1 == UGKUnsetMarker && puValue->Set.nMarker2 == UGKUnsetMarker ) pauFields[iField] = *puValue; else pauFields[iField].String = UGKStrdup( puValue->String ); } else if( poFDefn->GetType() == OFTIntegerList ) { int nCount = puValue->IntegerList.nCount; if( IsFieldSet( iField ) ) UGK_Free( pauFields[iField].IntegerList.paList ); if( puValue->Set.nMarker1 == UGKUnsetMarker && puValue->Set.nMarker2 == UGKUnsetMarker ) { pauFields[iField] = *puValue; } else { pauFields[iField].IntegerList.paList = (int *) UGK_Malloc(sizeof(int) * nCount); memcpy( pauFields[iField].IntegerList.paList, puValue->IntegerList.paList, sizeof(int) * nCount ); pauFields[iField].IntegerList.nCount = nCount; } } else if( poFDefn->GetType() == OFTRealList ) { int nCount = puValue->RealList.nCount; if( IsFieldSet( iField ) ) UGK_Free( pauFields[iField].RealList.paList ); if( puValue->Set.nMarker1 == UGKUnsetMarker && puValue->Set.nMarker2 == UGKUnsetMarker ) { pauFields[iField] = *puValue; } else { pauFields[iField].RealList.paList = (double *) UGK_Malloc(sizeof(double) * nCount); memcpy( pauFields[iField].RealList.paList, puValue->RealList.paList, sizeof(double) * nCount ); pauFields[iField].RealList.nCount = nCount; } } else if( poFDefn->GetType() == OFTStringList ) { if( IsFieldSet( iField ) ) { char **papszPtr=pauFields[iField].StringList.paList; if ( papszPtr ) { while( *papszPtr != NULL ) { UGK_Free( *papszPtr ); papszPtr++; } UGK_Free( pauFields[iField].StringList.paList ); } } if( puValue->Set.nMarker1 == UGKUnsetMarker && puValue->Set.nMarker2 == UGKUnsetMarker ) { pauFields[iField] = *puValue; } else { pauFields[iField].StringList.paList = DuplicateList( puValue->StringList.paList ); pauFields[iField].StringList.nCount = puValue->StringList.nCount; assert( CountOfList(puValue->StringList.paList) == puValue->StringList.nCount ); } } else /* do nothing for other field types */;}/************************************************************************//* SetFID() *//************************************************************************//** 设置feature标识 * Set the feature identifier. * * For specific types of features this operation may fail on illegal * features ids. Generally it always succeeds. Feature ids should be * greater than or equal to zero, with the exception of UGKNullFID (-1) * indicating that the feature id is unknown. * * @param nFID the new feature identifier value to assign. * * @return On success UGKERR_NONE, or on failure some other value. */UGKErr UGKFeature::SetFID( long nFID ){ this->nFID = nFID; return UGKERR_NONE;}/************************************************************************//* Equal() *//************************************************************************//** 判断两个feature是否一样 * Test if two features are the same. * * Two features are considered equal if the share them (pointer equality) * same UGKFeatureDefn, have the same field values, and the same geometry * (as tested by UGKGeometry::Equal()) as well as the same feature id. * * @param poFeature the other feature to test this one against. * * @return TRUE if they are equal, otherwise FALSE. */UGKBool UGKFeature::Equal( UGKFeature * poFeature ){ if( poFeature == this ) return TRUE; if( GetFID() != poFeature->GetFID() ) return FALSE; if( GetDefnRef() != poFeature->GetDefnRef() ) return FALSE; //notdef: add testing of attributes at a later date. if( GetGeometryRef() != NULL && (!GetGeometryRef()->Equals( poFeature->GetGeometryRef() ) ) ) return FALSE; return TRUE;}/************************************************************************//* SetFrom() *//************************************************************************//** * Set one feature from another. * * Overwrite the contents of this feature from the geometry and attributes * of another. The poSrcFeature does not need to have the same * UGKFeatureDefn. Field values are copied by corresponding field names. * Field types do not have to exactly match. SetField() method conversion * rules will be applied as needed. * * @param poSrcFeature the feature from which geometry, and field values will * be copied. * * @param bForgiving TRUE if the operation should continue despite lacking * output fields matching some of the source fields. * * @return UGKERR_NONE if the operation succeeds, even if some values are * not transferred, otherwise an error code. */UGKErr UGKFeature::SetFrom( UGKFeature * poSrcFeature, int bForgiving ){ UGKErr eErr; SetFID( UGKNullFID );/* -------------------------------------------------------------------- *//* Set the geometry. *//* -------------------------------------------------------------------- */ eErr = SetGeometry( poSrcFeature->GetGeometryRef() ); if( eErr != UGKERR_NONE ) return eErr;/* -------------------------------------------------------------------- *//* Copy feature style string. *//* -------------------------------------------------------------------- */ if( poSrcFeature->GetStyleString() != NULL ) SetStyleString( poSrcFeature->GetStyleString() );/* -------------------------------------------------------------------- *//* Set the fields by name. *//* -------------------------------------------------------------------- */ int iField, iDstField; for( iField = 0; iField < poSrcFeature->GetFieldCount(); iField++ ) { iDstField = GetFieldIndex( poSrcFeature->GetFieldDefnRef(iField)->GetNameRef() ); if( iDstField == -1 ) { if( bForgiving ) continue; else return UGKERR_FAILURE; } if( !poSrcFeature->IsFieldSet(iField) ) { UnsetField( iDstField ); continue; } switch( poSrcFeature->GetFieldDefnRef(iField)->GetType() ) { case OFTInteger: SetField( iDstField, poSrcFeature->GetFieldAsInteger( iField ) ); break; case OFTReal: SetField( iDstField, poSrcFeature->GetFieldAsDouble( iField ) ); break; case OFTString: SetField( iDstField, poSrcFeature->GetFieldAsString( iField ) ); break; default: if( poSrcFeature->GetFieldDefnRef(iField)->GetType() == GetFieldDefnRef(iDstField)->GetType() ) { SetField( iDstField, poSrcFeature->GetRawFieldRef(iField) ); } else if( !bForgiving ) return UGKERR_FAILURE; break; } } return UGKERR_NONE;}/************************************************************************//* GetStyleString() *//************************************************************************//** * Fetch style string for this feature. * * Set the UGK Feature Style Specification for details on the format of * this string. * * @return a reference to a representation in string format, or NULL if * there isn't one. */const char *UGKFeature::GetStyleString(){ if (m_pszStyleString) return m_pszStyleString; else return NULL;}/************************************************************************//* SetStyleString() *//************************************************************************//** * Set feature style string. * * @param pszString the style string to apply to this feature, cannot be NULL. */void UGKFeature::SetStyleString(const char *pszString){ if (m_pszStyleString) UGK_Free(m_pszStyleString); m_pszStyleString = UGKStrdup(pszString); }/************************************************************************//* SetStyleTable() *//************************************************************************/void UGKFeature::SetStyleTable(UGKStyleTable *poStyleTable){ m_poStyleTable = poStyleTable;}/************************************************************************//* RemapFields() *//* *//* This is used to transform a feature "in place" from one *//* feature defn to another with minimum work. *//************************************************************************/UGKErr UGKFeature::RemapFields( UGKFeatureDefn *poNewDefn, int *panRemapSource ){ int iDstField; UGKField *pauNewFields; if( poNewDefn == NULL ) poNewDefn = poDefn; pauNewFields = (UGKField *) UGK_Calloc( poNewDefn->GetFieldCount(), sizeof(UGKField) ); for( iDstField = 0; iDstField < poDefn->GetFieldCount(); iDstField++ ) { if( panRemapSource[iDstField] == -1 ) { pauNewFields[iDstField].Set.nMarker1 = UGKUnsetMarker; pauNewFields[iDstField].Set.nMarker2 = UGKUnsetMarker; } else { memcpy( pauNewFields + iDstField, pauFields + panRemapSource[iDstField], sizeof(UGKField) ); } } /* ** We really should be freeing memory for old columns that ** are no longer present. We don't for now because it is a bit messy ** and would take too long to test. *//* -------------------------------------------------------------------- *//* Apply new definition and fields. *//* -------------------------------------------------------------------- */ UGK_Free( pauFields ); pauFields = pauNewFields; poDefn = poNewDefn; return UGKERR_NONE;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -