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

📄 tabregion.cpp

📁 linux下一款GIS程序源码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
{    if (m_pszStyleString == NULL)    {        // Since GetPen/BrushStyleString() use CPLSPrintf(), we need         // to use temporary buffers        char *pszPen = UGKStrdup(GetPenStyleString());        char *pszBrush = UGKStrdup(GetBrushStyleString());        m_pszStyleString = UGKStrdup(UGKSPrintf("%s;%s", pszBrush, pszPen));        UGK_Free(pszPen);        UGK_Free(pszBrush);    }    return m_pszStyleString;}/********************************************************************** *                   TABRegion::DumpMIF() * * Dump feature geometry in a format similar to .MIF REGIONs. **********************************************************************/void TABRegion::DumpMIF(FILE *fpOut /*=NULL*/){    UGKGeometry   *poGeom;    int i, numPoints;    if (fpOut == NULL)        fpOut = stdout;    /*-----------------------------------------------------------------     * Fetch and validate geometry     *----------------------------------------------------------------*/    poGeom = GetGeometryRef();    if (poGeom && (wkbFlatten(poGeom->getGeometryType()) == wkbPolygon ||                   wkbFlatten(poGeom->getGeometryType()) == wkbMultiPolygon))    {        /*-------------------------------------------------------------         * Generate output for region         *         * Note that we want to handle both UGKPolygons and UGKMultiPolygons         * that's why we use the GetNumRings()/GetRingRef() interface.         *------------------------------------------------------------*/        int iRing, numRingsTotal = GetNumRings();        fprintf(fpOut, "REGION %d\n", numRingsTotal);        for(iRing=0; iRing < numRingsTotal; iRing++)        {            UGKLinearRing       *poRing;            poRing = GetRingRef(iRing);            if (poRing == NULL)            {                UGKError(ET_Failure, UGKErr_AssertionFailed,                          "TABRegion: Object Geometry contains NULL rings!");                return;            }            numPoints = poRing->getNumPoints();            fprintf(fpOut, " %d\n", numPoints);            for(i=0; i<numPoints; i++)                fprintf(fpOut, "%g %g\n",poRing->getX(i),poRing->getY(i));        }    }    else    {        UGKError(ET_Failure, UGKErr_AssertionFailed,                  "TABRegion: Missing or Invalid Geometry!");        return;    }    if (m_bCenterIsSet)        fprintf(fpOut, "Center %g %g\n", m_dCenterX, m_dCenterY);    // Finish with PEN/BRUSH/etc. clauses    DumpPenDef();    DumpBrushDef();    fflush(fpOut);}/********************************************************************** *                   TABRegion::GetCenter() * * Returns the center/label point of the region.   * Compute one using UGKPolygonLabelPoint() if it was not explicitly set  * before. * * Returns 0 on success, -1 on error. **********************************************************************/int TABRegion::GetCenter(double &dX, double &dY){    if (!m_bCenterIsSet)    {        /*-------------------------------------------------------------         * Calculate label point.  If we have a multipolygon then we use          * the first UGKPolygon in the feature to calculate the point.         *------------------------------------------------------------*/        UGKPoint        oLabelPoint;        UGKPolygon      *poPolygon=NULL;        UGKGeometry     *poGeom;        poGeom = GetGeometryRef();        if (poGeom == NULL)            return -1;        if (wkbFlatten(poGeom->getGeometryType()) == wkbMultiPolygon)        {            UGKMultiPolygon *poMultiPolygon = (UGKMultiPolygon *)poGeom;            if (poMultiPolygon->getNumGeometries() > 0)                poPolygon = (UGKPolygon*)poMultiPolygon->getGeometryRef(0);        }        else if (wkbFlatten(poGeom->getGeometryType()) == wkbPolygon)        {            poPolygon = (UGKPolygon*)poGeom;        }        if (poPolygon != NULL &&            UGKPolygonLabelPoint(poPolygon, &oLabelPoint) == UGKERR_NONE)        {            m_dCenterX = oLabelPoint.getX();            m_dCenterY = oLabelPoint.getY();        }        else        {            UGKEnvelope oEnv;            poGeom->getEnvelope(&oEnv);            m_dCenterX = (oEnv.MaxX + oEnv.MinX)/2.0;            m_dCenterY = (oEnv.MaxY + oEnv.MinY)/2.0;        }        m_bCenterIsSet = TRUE;    }    if (!m_bCenterIsSet)        return -1;    dX = m_dCenterX;    dY = m_dCenterY;    return 0;}/********************************************************************** *                   TABRegion::SetCenter() * * Set the X,Y coordinates to use as center/label point for the region. **********************************************************************/void TABRegion::SetCenter(double dX, double dY){    m_dCenterX = dX;    m_dCenterY = dY;    m_bCenterIsSet = TRUE;}/********************************************************************** *                   TABRegion::ReadGeometryFromMIFFile() * * Fill the geometry and representation (color, etc...) part of the * feature from the contents of the .MIF file * * Returns 0 on success, -1 on error, in which case CPLError() will have * been called. **********************************************************************/int TABRegion::ReadGeometryFromMIFFile(MIDDATAFile *fp){    double               dX, dY;    UGKLinearRing       *poRing;    UGKGeometry         *poGeometry = NULL;    UGKPolygon          *poPolygon = NULL;    UGKMultiPolygon     *poMultiPolygon = NULL;    int                  i,iSection, numLineSections=0;    char               **papszToken;    const char          *pszLine;    UGKEnvelope          sEnvelope;    m_bSmooth = FALSE;    /*=============================================================     * REGION (Similar to PLINE MULTIPLE)     *============================================================*/    papszToken = TokenizeString2(fp->GetLastLine(),                                     " \t", 0x0001);        if (CountOfList(papszToken) ==2)      numLineSections = atoi(papszToken[1]);    FreeStrList(papszToken);    papszToken = NULL;    /*-------------------------------------------------------------     * For 1-ring regions, we return an UGKPolygon with one single     * UGKLinearRing geometry.      *     * REGIONs with multiple rings are returned as UGKMultiPolygon     * instead of as UGKPolygons since UGKPolygons require that the     * first ring be the outer ring, and the other all be inner      * rings, but this is not guaranteed inside MapInfo files.       *------------------------------------------------------------*/    if (numLineSections > 1)        poGeometry = poMultiPolygon = new UGKMultiPolygon;    else        poGeometry = NULL;  // Will be set later    for(iSection=0; iSection<numLineSections; iSection++)    {        int     numSectionVertices = 0;        poPolygon = new UGKPolygon();        if ((pszLine = fp->GetLine()) != NULL)        {            numSectionVertices = atoi(pszLine);        }        poRing = new UGKLinearRing();        poRing->setNumPoints(numSectionVertices);        for(i=0; i<numSectionVertices; i++)        {            pszLine = fp->GetLine();            if (pszLine)            {                papszToken = TokenizeStringComplex(pszLine," ,\t",                                                      TRUE,FALSE);                if (CountOfList(papszToken) == 2)                {                                  dX = fp->GetXTrans(atof(papszToken[0]));                    dY = fp->GetYTrans(atof(papszToken[1]));                    poRing->setPoint(i, dX, dY);                }                FreeStrList(papszToken);                papszToken = NULL;            }           }        poPolygon->addRingDirectly(poRing);        poRing = NULL;        if (numLineSections > 1)            poMultiPolygon->addGeometryDirectly(poPolygon);        else            poGeometry = poPolygon;        poPolygon = NULL;    }        SetGeometryDirectly(poGeometry);    poGeometry->getEnvelope(&sEnvelope);        SetMBR(sEnvelope.MinX, sEnvelope.MinY, sEnvelope.MaxX, sEnvelope.MaxY);    while (((pszLine = fp->GetLine()) != NULL) &&            fp->IsValidFeature(pszLine) == FALSE)    {        papszToken = TokenizeStringComplex(pszLine,"() ,",                                              TRUE,FALSE);                if (CountOfList(papszToken) > 1)        {            if (EQUALN(papszToken[0],"PEN",3))            {                                if (CountOfList(papszToken) == 4)                {                               SetPenWidthMIF(atoi(papszToken[1]));                    SetPenPattern(atoi(papszToken[2]));                    SetPenColor(atoi(papszToken[3]));                }                            }            else if (EQUALN(papszToken[0],"BRUSH", 5))            {                if (CountOfList(papszToken) >= 3)                {                    SetBrushFGColor(atoi(papszToken[2]));                    SetBrushPattern(atoi(papszToken[1]));                                        if (CountOfList(papszToken) == 4)                       SetBrushBGColor(atoi(papszToken[3]));                    else                      SetBrushTransparent(TRUE);                }                            }            else if (EQUALN(papszToken[0],"CENTER",6))            {                if (CountOfList(papszToken) == 3)                {                    SetCenter(fp->GetXTrans(atof(papszToken[1])),                              fp->GetYTrans(atof(papszToken[2])) );                }            }        }        FreeStrList(papszToken);        papszToken = NULL;    }            return 0; }    /********************************************************************** *                   TABRegion::WriteGeometryToMIFFile() * * Write the geometry and representation (color, etc...) part of the * feature to the .MIF file * * Returns 0 on success, -1 on error, in which case CPLError() will have * been called. **********************************************************************/int TABRegion::WriteGeometryToMIFFile(MIDDATAFile *fp){     UGKGeometry         *poGeom;    poGeom = GetGeometryRef();    if (poGeom && (wkbFlatten(poGeom->getGeometryType()) == wkbPolygon ||                   wkbFlatten(poGeom->getGeometryType()) == wkbMultiPolygon ) )    {        /*=============================================================         * REGIONs are similar to PLINE MULTIPLE         *         * We accept both UGKPolygons (with one or multiple rings) and          * UGKMultiPolygons as input.         *============================================================*/        int     i, iRing, numRingsTotal, numPoints;        numRingsTotal = GetNumRings();                fp->WriteLine("Region %d\n",numRingsTotal);                for(iRing=0; iRing < numRingsTotal; iRing++)        {            UGKLinearRing       *poRing;            poRing = GetRingRef(iRing);            if (poRing == NULL)            {                UGKError(ET_Failure, UGKErr_AssertionFailed,                          "TABRegion: Object Geometry contains NULL rings!");                return -1;            }            numPoints = poRing->getNumPoints();            fp->WriteLine("  %d\n",numPoints);            for(i=0; i<numPoints; i++)            {                fp->WriteLine("%.16g %.16g\n",poRing->getX(i), poRing->getY(i));            }        }                if (GetPenPattern())          fp->WriteLine("    Pen (%d,%d,%d)\n",                          GetPenWidthMIF(),GetPenPattern(),                          GetPenColor());                if (GetBrushPattern())        {            if (GetBrushTransparent() == 0)              fp->WriteLine("    Brush (%d,%d,%d)\n",GetBrushPattern(),                            GetBrushFGColor(),GetBrushBGColor());            else              fp->WriteLine("    Brush (%d,%d)\n",GetBrushPattern(),                            GetBrushFGColor());        }        if (m_bCenterIsSet)        {            fp->WriteLine("    Center %.16g %.16g\n", m_dCenterX, m_dCenterY);        }    }    else    {        UGKError(ET_Failure, UGKErr_AssertionFailed,                  "TABRegion: Object contains an invalid Geometry!");        return -1;    }    return 0; }

⌨️ 快捷键说明

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