📄 tabfeature.cpp
字号:
* In derived classes, this method should be reimplemented to * fill the geometry and representation (color, etc...) part of the * feature from the contents of the .MAP object pointed to by poMAPFile. * * It is assumed that before calling ReadGeometryFromMAPFile(), poMAPFile * currently points to the beginning of a map object. * 调用此方法前,确定poMAPFile指向了一个地图对象的开始位置 * The current implementation does nothing since instances of TABFeature * objects contain no geometry (i.e. TAB_GEOM_NONE). * * Returns 0 on success, -1 on error, in which case CPLError() will have * been called. **********************************************************************/int TABFeature::ReadGeometryFromMAPFile(TABMAPFile * /*poMapFile*/, TABMAPObjHdr * /*poObjHdr*/){ /*----------------------------------------------------------------- * Nothing to do... instances of TABFeature objects contain no geometry. *----------------------------------------------------------------*/ return 0;}/********************************************************************** * TABFeature::ValidateCoordType() * 检查边界,确定是否使用压缩坐标 * Checks the feature envelope to establish if the feature should be * written using Compressed coordinates or not and adjust m_nMapInfoType * accordingly. * * This function should be used only by the ValidateMapInfoType() * implementations. * * Returns TRUE if coord. should be compressed, FALSE otherwise **********************************************************************/UGKBool TABFeature::ValidateCoordType(TABMAPFile * poMapFile){ UGKBool bCompr = FALSE; UGKGeometry *poGeom; poGeom = GetGeometryRef(); /*------------------------------------------------------------- * Decide if coordinates should be compressed or not. *------------------------------------------------------------*/ if (poGeom && poMapFile) { UGKEnvelope oEnv; poGeom->getEnvelope(&oEnv); poMapFile->Coordsys2Int(oEnv.MinX, oEnv.MinY, m_nXMin, m_nYMin); poMapFile->Coordsys2Int(oEnv.MaxX, oEnv.MaxY, m_nXMax, m_nYMax); if ((m_nXMax - m_nXMin) < 65536 && (m_nYMax-m_nYMin) < 65536) { bCompr = TRUE; } m_nComprOrgX = (m_nXMin + m_nXMax) / 2; m_nComprOrgY = (m_nYMin + m_nYMax) / 2; } /*------------------------------------------------------------- * Adjust native type *------------------------------------------------------------*/ if (bCompr && ((m_nMapInfoType%3) == 2)) m_nMapInfoType--; // compr = 1, 4, 7, ... else if (!bCompr && ((m_nMapInfoType%3) == 1)) m_nMapInfoType++; // non-compr = 2, 5, 8, ... return bCompr;}/********************************************************************** * TABFeature::WriteGeometryToMAPFile() * * * In derived classes, this method should be reimplemented to * write the geometry and representation (color, etc...) part of the * feature to the .MAP object pointed to by poMAPFile. * * It is assumed that before calling WriteGeometryToMAPFile(), poMAPFile * currently points to a valid map object. * * The current implementation does nothing since instances of TABFeature * objects contain no geometry (i.e. TAB_GEOM_NONE). * * Returns 0 on success, -1 on error, in which case CPLError() will have * been called. **********************************************************************/int TABFeature::WriteGeometryToMAPFile(TABMAPFile * /* poMapFile*/, TABMAPObjHdr * /*poObjHdr*/){ /*----------------------------------------------------------------- * Nothing to do... instances of TABFeature objects contain no geometry. *----------------------------------------------------------------*/ return 0;}/********************************************************************** * TABFeature::DumpMID() * * Dump feature attributes in a format similar to .MID data records. **********************************************************************/void TABFeature::DumpMID(FILE *fpOut /*=NULL*/){ UGKFeatureDefn *poDefn = GetDefnRef(); if (fpOut == NULL) fpOut = stdout; for( int iField = 0; iField < GetFieldCount(); iField++ ) { UGKFieldDefn *poFDefn = poDefn->GetFieldDefn(iField); fprintf( fpOut, " %s (%s) = %s\n", poFDefn->GetNameRef(), UGKFieldDefn::GetFieldTypeName(poFDefn->GetType()), GetFieldAsString( iField ) ); } fflush(fpOut);}/********************************************************************** * TABFeature::DumpMIF() * * Dump feature geometry in a format similar to .MIF files. **********************************************************************/void TABFeature::DumpMIF(FILE *fpOut /*=NULL*/){ if (fpOut == NULL) fpOut = stdout; /*----------------------------------------------------------------- * Generate output... not much to do, feature contains no geometry. *----------------------------------------------------------------*/ fprintf(fpOut, "NONE\n" ); fflush(fpOut);}/********************************************************************** * TABFeature::WriteGeometryToMIFFile() * * * In derived classes, this method should be reimplemented to * write the geometry and representation (color, etc...) part of the * feature to the .MAP object pointed to by poMAPFile. * * It is assumed that before calling WriteGeometryToMAPFile(), poMAPFile * currently points to a valid map object. * * The current implementation does nothing since instances of TABFeature * objects contain no geometry. * * Returns 0 on success, -1 on error, in which case CPLError() will have * been called. **********************************************************************/int TABFeature::WriteGeometryToMIFFile(MIDDATAFile *fp){ fp->WriteLine("NONE\n"); return 0;}/********************************************************************** * TABFeature::ReadGeometryFromMIFFile() * * In derived classes, this method should be reimplemented to * fill the geometry and representation (color, etc...) part of the * feature from the contents of the .MAP object pointed to by poMAPFile. * * It is assumed that before calling ReadGeometryFromMAPFile(), poMAPFile * currently points to the beginning of a map object. * * The current implementation does nothing since instances of TABFeature * objects contain no geometry (i.e. TAB_GEOM_NONE). * * Returns 0 on success, -1 on error, in which case CPLError() will have * been called. **********************************************************************/int TABFeature::ReadGeometryFromMIFFile(MIDDATAFile *fp){ const char *pszLine; /* Go to the first line of the next feature */ while (((pszLine = fp->GetLine()) != NULL) && fp->IsValidFeature(pszLine) == FALSE) ; return 0;}/********************************************************************** * TABFeature::ReadRecordFromMIDFile() * * This method is used to read the Record (Attributs) for all type of * feature included in a mid/mif file. * * Returns 0 on success, -1 on error, in which case CPLError() will have * been called. **********************************************************************/int TABFeature::ReadRecordFromMIDFile(MIDDATAFile *fp){ const char *pszLine; char **papszToken; int nFields,i; nFields = GetFieldCount(); pszLine = fp->GetLastLine(); papszToken = TokenizeStringComplex(pszLine, fp->GetDelimiter(),TRUE,TRUE); // Ensure that a blank line in a mid file is treated as one field // containing an empty string. if( nFields == 1 && CountOfList(papszToken) == 0 && pszLine[0] == '\0' ) papszToken = AddStringToList(papszToken,""); // Make sure we found at least the expected number of field values. // Note that it is possible to have a stray delimiter at the end of // the line (mif/mid files from Geomedia), so don't produce an error // if we find more tokens than expected. if (CountOfList(papszToken) < nFields) { FreeStrList(papszToken); return -1; } for (i=0;i<nFields;i++) { SetField(i,papszToken[i]); } fp->GetLine(); FreeStrList(papszToken); return 0;}/********************************************************************** * TABFeature::WriteRecordToMIDFile() * * This methode is used to write the Record (Attributs) for all type * of feature included in a mid file. * * Return 0 on success, -1 on error **********************************************************************/int TABFeature::WriteRecordToMIDFile(MIDDATAFile *fp){ int iField, numFields; UGKFieldDefn *poFDefn = NULL; assert(fp); numFields = GetFieldCount(); for(iField=0; iField<numFields; iField++) { if (iField != 0) fp->WriteLine(","); poFDefn = GetFieldDefnRef( iField ); switch(poFDefn->GetType()) { case OFTString: fp->WriteLine("\"%s\"",GetFieldAsString(iField)); break; default: fp->WriteLine("%s",GetFieldAsString(iField)); } } fp->WriteLine("\n"); return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -