⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mitab_feature_mif.cpp

📁 GIS系统支持库Geospatial Data Abstraction Library代码.GDAL is a translator library for raster geospatial dat
💻 CPP
📖 第 1 页 / 共 5 页
字号:
        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;    /*-------------------------------------------------------------     * Note: The text string may contain "\n" chars or "\\" chars     * and we expect to receive them in an escaped form.     *------------------------------------------------------------*/    fp->WriteLine("Text \"%s\"\n", GetTextString() );    //    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            *poPoint;    OGRMultiPoint       *poMultiPoint;    char                **papszToken;    const char          *pszLine;    int                 nNumPoint, i;    double              dfX,dfY;    OGREnvelope         sEnvelope;    papszToken = CSLTokenizeString2(fp->GetLastLine(),                                     " \t", CSLT_HONOURSTRINGS);         if (CSLCount(papszToken) !=2)    {        CSLDestroy(papszToken);        return -1;    }        nNumPoint = atoi(papszToken[1]);    poMultiPoint = new OGRMultiPoint;    CSLDestroy(papszToken);    papszToken = NULL;    // Get each point and add them to the multipoint feature    for(i=0; i<nNumPoint; i++)    {        pszLine = fp->GetLine();        papszToken = CSLTokenizeString2(fp->GetLastLine(),                                         " \t", CSLT_HONOURSTRINGS);        if (CSLCount(papszToken) !=2)        {            CSLDestroy(papszToken);            return -1;        }        dfX = fp->GetXTrans(atof(papszToken[0]));        dfY = fp->GetXTrans(atof(papszToken[1]));        poPoint = new OGRPoint(dfX, dfY);        if ( poMultiPoint->addGeometryDirectly( poPoint ) != OGRERR_NONE)        {            CPLAssert(FALSE); // Just in case OGR is modified        }        // Set center        if(i == 0)        {            SetCenter( dfX, dfY );        }    }    if( SetGeometryDirectly( poMultiPoint ) != OGRERR_NONE)    {        CPLAssert(FALSE); // Just in case OGR is modified    }    poMultiPoint->getEnvelope(&sEnvelope);    SetMBR(sEnvelope.MinX, sEnvelope.MinY,           sEnvelope.MaxX,sEnvelope.MaxY);    // Read optional SYMBOL line...    while (((pszLine = fp->GetLine()) != NULL) &&            fp->IsValidFeature(pszLine) == FALSE)    {        papszToken = CSLTokenizeStringComplex(pszLine," ,()\t",                                              TRUE,FALSE);        if (CSLCount(papszToken) == 4 && EQUAL(papszToken[0], "SYMBOL") )        {            SetSymbolNo(atoi(papszToken[1]));            SetSymbolColor(atoi(papszToken[2]));            SetSymbolSize(atoi(papszToken[3]));        }    }    return 0; }/********************************************************************** * **********************************************************************/int TABMultiPoint::WriteGeometryToMIFFile(MIDDATAFile *fp){     OGRGeometry         *poGeom;    OGRPoint            *poPoint;    OGRMultiPoint       *poMultiPoint;    int                 nNumPoints, iPoint;     /*-----------------------------------------------------------------     * Fetch and validate geometry     *----------------------------------------------------------------*/    poGeom = GetGeometryRef();    if (poGeom && wkbFlatten(poGeom->getGeometryType()) == wkbMultiPoint)    {        poMultiPoint = (OGRMultiPoint*)poGeom;        nNumPoints = poMultiPoint->getNumGeometries();        fp->WriteLine("MultiPoint %d\n", nNumPoints);        for(iPoint=0; iPoint < nNumPoints; iPoint++)        {            /*------------------------------------------------------------             * Validate each point             *-----------------------------------------------------------*/            poGeom = poMultiPoint->getGeometryRef(iPoint);            if (poGeom && wkbFlatten(poGeom->getGeometryType()) == wkbPoint)            {                 poPoint = (OGRPoint*)poGeom;                fp->WriteLine("%.16g %.16g\n",poPoint->getX(),poPoint->getY());            }            else            {                CPLError(CE_Failure, CPLE_AssertionFailed,                         "TABMultiPoint: Missing or Invalid Geometry!");                return -1;            }        }        // Write symbol        fp->WriteLine("    Symbol (%d,%d,%d)\n",GetSymbolNo(),GetSymbolColor(),                      GetSymbolSize());    }    return 0; }/********************************************************************** * **********************************************************************/int TABDebugFeature::ReadGeometryFromMIFFile(MIDDATAFile *fp){    const char *pszLine;       /* Go to the first line of the next feature */   printf("%s\n", fp->GetLastLine());   while (((pszLine = fp->GetLine()) != NULL) &&           fp->IsValidFeature(pszLine) == FALSE)     ;     ret

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -