📄 mitab_feature_mif.cpp
字号:
if (EQUALN(papszToken[0],"PEN",3)) { if (CSLCount(papszToken) == 4) { SetPenWidthMIF(atoi(papszToken[1])); SetPenPattern(atoi(papszToken[2])); SetPenColor(atoi(papszToken[3])); } } } CSLDestroy(papszToken); papszToken = NULL; } return 0; }/********************************************************************** * **********************************************************************/int TABArc::WriteGeometryToMIFFile(MIDDATAFile *fp){ /*------------------------------------------------------------- * Start/End angles * Since we ALWAYS produce files in quadrant 1 then we can * ignore the special angle conversion required by flipped axis. *------------------------------------------------------------*/ // Write the Arc's actual MBR fp->WriteLine("Arc %.16g %.16g %.16g %.16g\n", m_dCenterX-m_dXRadius, m_dCenterY-m_dYRadius, m_dCenterX+m_dXRadius, m_dCenterY+m_dYRadius); fp->WriteLine(" %.16g %.16g\n",m_dStartAngle,m_dEndAngle); if (GetPenPattern()) fp->WriteLine(" Pen (%d,%d,%d)\n",GetPenWidthMIF(),GetPenPattern(), GetPenColor()); return 0; }/********************************************************************** * **********************************************************************/int TABText::ReadGeometryFromMIFFile(MIDDATAFile *fp){ double dXMin, dYMin, dXMax, dYMax; OGRGeometry *poGeometry; const char *pszLine; char **papszToken; const char *pszString; char *pszTmpString; papszToken = CSLTokenizeString2(fp->GetLastLine(), " \t", CSLT_HONOURSTRINGS); if (CSLCount(papszToken) == 1) { CSLDestroy(papszToken); papszToken = CSLTokenizeString2(fp->GetLine(), " \t", CSLT_HONOURSTRINGS); if (CSLCount(papszToken) != 1) { CSLDestroy(papszToken); return -1; } else pszString = papszToken[0]; } else if (CSLCount(papszToken) == 2) { pszString = papszToken[1]; } else { CSLDestroy(papszToken); return -1; } /*------------------------------------------------------------- * Note: The text string may contain escaped "\n" chars, and we * sstore them in memory in the UnEscaped form to be OGR * compliant. See Maptools bug 1107 for more details. *------------------------------------------------------------*/ pszTmpString = CPLStrdup(pszString); m_pszString = TABUnEscapeString(pszTmpString, TRUE); if (pszTmpString != m_pszString) CPLFree(pszTmpString); CSLDestroy(papszToken); papszToken = CSLTokenizeString2(fp->GetLine(), " \t", CSLT_HONOURSTRINGS); if (CSLCount(papszToken) != 4) { CSLDestroy(papszToken); return -1; } else { dXMin = fp->GetXTrans(atof(papszToken[0])); dXMax = fp->GetXTrans(atof(papszToken[2])); dYMin = fp->GetYTrans(atof(papszToken[1])); dYMax = fp->GetYTrans(atof(papszToken[3])); m_dHeight = dYMax - dYMin; //SetTextBoxHeight(dYMax - dYMin); m_dWidth = dXMax - dXMin; //SetTextBoxWidth(dXMax - dXMin); if (m_dHeight <0.0) m_dHeight*=-1.0; if (m_dWidth <0.0) m_dWidth*=-1.0; } CSLDestroy(papszToken); papszToken = NULL; /* Set/retrieve the MBR to make sure Mins are smaller than Maxs */ SetMBR(dXMin, dYMin, dXMax, dYMax); GetMBR(dXMin, dYMin, dXMax, dYMax); while (((pszLine = fp->GetLine()) != NULL) && fp->IsValidFeature(pszLine) == FALSE) { papszToken = CSLTokenizeStringComplex(pszLine,"() ,", TRUE,FALSE); if (CSLCount(papszToken) > 1) { if (EQUALN(papszToken[0],"FONT",4)) { if (CSLCount(papszToken) >= 5) { SetFontName(papszToken[1]); SetFontFGColor(atoi(papszToken[4])); if (CSLCount(papszToken) ==6) { SetFontBGColor(atoi(papszToken[5])); SetFontStyleMIFValue(atoi(papszToken[2]),TRUE); } else SetFontStyleMIFValue(atoi(papszToken[2])); // papsztoken[3] = Size ??? } } else if (EQUALN(papszToken[0],"SPACING",7)) { if (CSLCount(papszToken) >= 2) { if (EQUALN(papszToken[1],"2",1)) { SetTextSpacing(TABTSDouble); } else if (EQUALN(papszToken[1],"1.5",3)) { SetTextSpacing(TABTS1_5); } } if (CSLCount(papszToken) == 7) { if (EQUALN(papszToken[2],"LAbel",5)) { if (EQUALN(papszToken[4],"simple",6)) { SetTextLineType(TABTLSimple); SetTextLineEndPoint(fp->GetXTrans(atof(papszToken[5])), fp->GetYTrans(atof(papszToken[6]))); } else if (EQUALN(papszToken[4],"arrow", 5)) { SetTextLineType(TABTLArrow); SetTextLineEndPoint(fp->GetXTrans(atof(papszToken[5])), fp->GetYTrans(atof(papszToken[6]))); } } } } else if (EQUALN(papszToken[0],"Justify",7)) { if (CSLCount(papszToken) == 2) { if (EQUALN( papszToken[1],"Center",6)) { SetTextJustification(TABTJCenter); } else if (EQUALN( papszToken[1],"Right",5)) { SetTextJustification(TABTJRight); } } } else if (EQUALN(papszToken[0],"Angle",5)) { if (CSLCount(papszToken) == 2) { SetTextAngle(atof(papszToken[1])); } } else if (EQUALN(papszToken[0],"LAbel",5)) { if (CSLCount(papszToken) == 5) { if (EQUALN(papszToken[2],"simple",6)) { SetTextLineType(TABTLSimple); SetTextLineEndPoint(fp->GetXTrans(atof(papszToken[3])), fp->GetYTrans(atof(papszToken[4]))); } else if (EQUALN(papszToken[2],"arrow", 5)) { SetTextLineType(TABTLArrow); SetTextLineEndPoint(fp->GetXTrans(atof(papszToken[3])), fp->GetYTrans(atof(papszToken[4]))); } } // What I do with the XY coordonate } } CSLDestroy(papszToken); papszToken = NULL; } /*----------------------------------------------------------------- * Create an OGRPoint Geometry... * The point X,Y values will be the coords of the lower-left corner before * rotation is applied. (Note that the rotation in MapInfo is done around * the upper-left corner) * We need to calculate the true lower left corner of the text based * on the MBR after rotation, the text height and the rotation angle. *---------------------------------------------------------------- */ double dCos, dSin, dX, dY; dSin = sin(m_dAngle*PI/180.0); dCos = cos(m_dAngle*PI/180.0); if (dSin > 0.0 && dCos > 0.0) { dX = dXMin + m_dHeight * dSin; dY = dYMin; } else if (dSin > 0.0 && dCos < 0.0) { dX = dXMax; dY = dYMin - m_dHeight * dCos; } else if (dSin < 0.0 && dCos < 0.0) { dX = dXMax + m_dHeight * dSin; dY = dYMax; } else // dSin < 0 && dCos > 0 { dX = dXMin; dY = dYMax - m_dHeight * dCos; } poGeometry = new OGRPoint(dX, dY); SetGeometryDirectly(poGeometry); /*----------------------------------------------------------------- * Compute Text Width: the width of the Text MBR before rotation * in ground units... unfortunately this value is not stored in the * file, so we have to compute it with the MBR after rotation and * the height of the MBR before rotation: * With W = Width of MBR before rotation * H = Height of MBR before rotation * dX = Width of MBR after rotation * dY = Height of MBR after rotation * teta = rotation angle * * For [-PI/4..teta..+PI/4] or [3*PI/4..teta..5*PI/4], we'll use: * W = H * (dX - H * sin(teta)) / (H * cos(teta)) * * and for other teta values, use: * W = H * (dY - H * cos(teta)) / (H * sin(teta)) *---------------------------------------------------------------- */ dSin = ABS(dSin); dCos = ABS(dCos); if (m_dHeight == 0.0) m_dWidth = 0.0; else if ( dCos > dSin ) m_dWidth = m_dHeight * ((dXMax-dXMin) - m_dHeight*dSin) / (m_dHeight*dCos); else m_dWidth = m_dHeight * ((dYMax-dYMin) - m_dHeight*dCos) / (m_dHeight*dSin); m_dWidth = ABS(m_dWidth); return 0; }/********************************************************************** * **********************************************************************/int TABText::WriteGeometryToMIFFile(MIDDATAFile *fp){ double dXMin,dYMin,dXMax,dYMax; char *pszTmpString; /*------------------------------------------------------------- * Note: The text string may contain unescaped "\n" chars or * "\\" chars and we expect to receive them in an unescaped * form. Those characters are unescaped in memory to be like * other OGR drivers. See MapTools bug 1107 for more details. *------------------------------------------------------------*/ pszTmpString = TABEscapeString(m_pszString); if(pszTmpString == NULL) fp->WriteLine("Text \"\"\n" ); else fp->WriteLine("Text \"%s\"\n", pszTmpString ); if (pszTmpString != m_pszString) CPLFree(pszTmpString); // UpdateTextMBR(); GetMBR(dXMin, dYMin, dXMax, dYMax); fp->WriteLine(" %.16g %.16g %.16g %.16g\n",dXMin, dYMin,dXMax, dYMax); if (IsFontBGColorUsed()) fp->WriteLine(" Font (\"%s\",%d,%d,%d,%d)\n", GetFontNameRef(), GetFontStyleMIFValue(),0,GetFontFGColor(), GetFontBGColor()); else fp->WriteLine(" Font (\"%s\",%d,%d,%d)\n", GetFontNameRef(), GetFontStyleMIFValue(),0,GetFontFGColor()); switch (GetTextSpacing()) { case TABTS1_5: fp->WriteLine(" Spacing 1.5\n"); break; case TABTSDouble: fp->WriteLine(" Spacing 2.0\n"); break; case TABTSSingle: default: break; } switch (GetTextJustification()) { case TABTJCenter: fp->WriteLine(" Justify Center\n"); break; case TABTJRight: fp->WriteLine(" Justify Right\n"); break; case TABTJLeft: default: break; } if (ABS(GetTextAngle()) > 0.000001) fp->WriteLine(" Angle %.16g\n",GetTextAngle()); switch (GetTextLineType()) { case TABTLSimple: if (m_bLineEndSet) fp->WriteLine(" Label Line Simple %.16g %.16g \n", m_dfLineEndX, m_dfLineEndY ); break; case TABTLArrow: if (m_bLineEndSet) fp->WriteLine(" Label Line Arrow %.16g %.16g \n", m_dfLineEndX, m_dfLineEndY ); break; case TABTLNoLine: default: break; } return 0; }/********************************************************************** * **********************************************************************/int TABMultiPoint::ReadGeometryFromMIFFile(MIDDATAFile *fp){ OGRPoint *poPoi
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -