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

📄 tabregion.cpp

📁 linux下一款GIS程序源码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
            return nStatus;  // Error has already been reported.        /*-------------------------------------------------------------         * Go through all the rings in our UGKMultiPolygon or UGKPolygon         * to write the coordinates themselves...         *------------------------------------------------------------*/        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;            }            int numPoints = poRing->getNumPoints();                        for(i=0; nStatus == 0 && i<numPoints; i++)            {                poMapFile->Coordsys2Int(poRing->getX(i), poRing->getY(i),                                        nX, nY);                if ((nStatus=poCoordBlock->WriteIntCoord(nX, nY,                                                         bCompressed)) != 0)                {                    // Failed ... error message has already been produced                    return nStatus;                }               }        }/* for iRing*/        nCoordDataSize = poCoordBlock->GetFeatureDataSize();        /*-------------------------------------------------------------         * ... and finally copy info to poObjHdr         *------------------------------------------------------------*/        TABMAPObjPLine *poPLineHdr = (TABMAPObjPLine *)poObjHdr;        poPLineHdr->m_nCoordBlockPtr = nCoordBlockPtr;        poPLineHdr->m_nCoordDataSize = nCoordDataSize;        poPLineHdr->m_numLineSections = numRingsTotal;        poPLineHdr->m_bSmooth = m_bSmooth;        // MBR (Minimum Bounding Rectangle).        poPLineHdr->SetMBR(m_nXMin, m_nYMin, m_nXMax, m_nYMax);        // Region center/label point        double dX, dY;        if (GetCenter(dX, dY) != -1)        {            poMapFile->Coordsys2Int(dX, dY, poPLineHdr->m_nLabelX,                                     poPLineHdr->m_nLabelY);        }        else        {            poPLineHdr->m_nLabelX = m_nComprOrgX;            poPLineHdr->m_nLabelY = m_nComprOrgY;        }                // Compressed coordinate origin (useful only in compressed case!)        poPLineHdr->m_nComprOrgX = m_nComprOrgX;        poPLineHdr->m_nComprOrgY = m_nComprOrgY;        m_nPenDefIndex = poMapFile->WritePenDef(&m_sPenDef);        poPLineHdr->m_nPenId = m_nPenDefIndex;      // Pen index        m_nBrushDefIndex = poMapFile->WriteBrushDef(&m_sBrushDef);        poPLineHdr->m_nBrushId = m_nBrushDefIndex;  // Brush index    }    else    {        UGKError(ET_Failure, UGKErr_AssertionFailed,                  "TABRegion: Object contains an invalid Geometry!");        return -1;    }    if (UGKGetLastErrorNo() != 0)        return -1;    return 0;}/********************************************************************** *                   TABRegion::GetNumRings() * * Return the total number of rings in this object making it look like * all parts of the UGKMultiPolygon (or UGKPolygon) are a single collection * of rings... hides the complexity of handling UGKMultiPolygons vs  * UGKPolygons, etc. * * Returns 0 if the geometry contained in the object is invalid or missing. **********************************************************************/int TABRegion::GetNumRings(){    return ComputeNumRings(NULL, NULL);}int TABRegion::ComputeNumRings(TABMAPCoordSecHdr **ppasSecHdrs,                               TABMAPFile *poMapFile){    UGKGeometry         *poGeom;    int                 numRingsTotal = 0, iLastSect = 0;    if (ppasSecHdrs)        *ppasSecHdrs = NULL;    poGeom = GetGeometryRef();    if (poGeom && (wkbFlatten(poGeom->getGeometryType()) == wkbPolygon ||                   wkbFlatten(poGeom->getGeometryType()) == wkbMultiPolygon))    {        /*-------------------------------------------------------------         * Calculate total number of rings...         *------------------------------------------------------------*/        UGKPolygon      *poPolygon=NULL;        UGKMultiPolygon *poMultiPolygon = NULL;        if (wkbFlatten(poGeom->getGeometryType()) == wkbMultiPolygon)        {            poMultiPolygon = (UGKMultiPolygon *)poGeom;            for(int iPoly=0; iPoly<poMultiPolygon->getNumGeometries(); iPoly++)            {                // We are guaranteed that all parts are UGKPolygons                poPolygon = (UGKPolygon*)poMultiPolygon->getGeometryRef(iPoly);                if (poPolygon  == NULL)                    continue;                numRingsTotal += poPolygon->getNumInteriorRings()+1;                if (ppasSecHdrs)                {                    if (AppendSecHdrs(poPolygon, *ppasSecHdrs,                                       poMapFile, iLastSect) != 0)                        return 0; // An error happened, return count=0                }            }/*for*/        }        else        {            poPolygon = (UGKPolygon*)poGeom;            numRingsTotal = poPolygon->getNumInteriorRings()+1;            if (ppasSecHdrs)            {                if (AppendSecHdrs(poPolygon, *ppasSecHdrs,                                   poMapFile, iLastSect) != 0)                    return 0;  // An error happened, return count=0            }        }    }    /*-----------------------------------------------------------------     * If we're generating section header blocks, then init the      * coordinate offset values.     *     * In calculation of nDataOffset, we have to take into account that     * V450 header section uses int32 instead of int16 for numVertices     * and we add another 2 bytes to align with a 4 bytes boundary.     *------------------------------------------------------------*/    int nTotalHdrSizeUncompressed;    if (m_nMapInfoType == TAB_GEOM_V450_REGION ||        m_nMapInfoType == TAB_GEOM_V450_REGION_C)        nTotalHdrSizeUncompressed = 28 * numRingsTotal;    else        nTotalHdrSizeUncompressed = 24 * numRingsTotal;    if (ppasSecHdrs)    {        int numPointsTotal = 0;        assert(iLastSect == numRingsTotal);        for (int iRing=0; iRing<numRingsTotal; iRing++)        {            (*ppasSecHdrs)[iRing].nDataOffset = nTotalHdrSizeUncompressed +                                                   numPointsTotal*4*2;            (*ppasSecHdrs)[iRing].nVertexOffset = numPointsTotal;            numPointsTotal += (*ppasSecHdrs)[iRing].numVertices;        }    }    return numRingsTotal;}/********************************************************************** *                   TABRegion::AppendSecHdrs() * * (Private method) * * Add a TABMAPCoordSecHdr for each ring in the specified polygon. **********************************************************************/int TABRegion::AppendSecHdrs(UGKPolygon *poPolygon,                             TABMAPCoordSecHdr * &pasSecHdrs,                             TABMAPFile *poMapFile,                             int &iLastRing){    int iRing, numRingsInPolygon;    /*-------------------------------------------------------------     * Add a pasSecHdrs[] entry for each ring in this polygon.     * Note that the structs won't be fully initialized.     *------------------------------------------------------------*/    numRingsInPolygon = poPolygon->getNumInteriorRings()+1;    pasSecHdrs = (TABMAPCoordSecHdr*)UGK_Realloc(pasSecHdrs,                                                (iLastRing+numRingsInPolygon)*                                                sizeof(TABMAPCoordSecHdr));    for(iRing=0; iRing < numRingsInPolygon; iRing++)    {        UGKLinearRing   *poRing;        UGKEnvelope     sEnvelope;        if (iRing == 0)            poRing = poPolygon->getExteriorRing();        else             poRing = poPolygon->getInteriorRing(iRing-1);        if (poRing == NULL)        {            UGKError(ET_Failure, UGKErr_AssertionFailed,                       "Assertion Failed: Encountered NULL ring in UGKPolygon");            return -1;        }        poRing->getEnvelope(&sEnvelope);                    pasSecHdrs[iLastRing].numVertices = poRing->getNumPoints();        if (iRing == 0)            pasSecHdrs[iLastRing].numHoles = numRingsInPolygon-1;        else             pasSecHdrs[iLastRing].numHoles = 0;        poMapFile->Coordsys2Int(sEnvelope.MinX, sEnvelope.MinY,                                pasSecHdrs[iLastRing].nXMin,                                pasSecHdrs[iLastRing].nYMin);        poMapFile->Coordsys2Int(sEnvelope.MaxX, sEnvelope.MaxY,                                pasSecHdrs[iLastRing].nXMax,                                pasSecHdrs[iLastRing].nYMax);        iLastRing++;    }/* for iRing*/    return 0;}/********************************************************************** *                   TABRegion::GetRingRef() * * Returns a reference to the specified ring number making it look like * all parts of the UGKMultiPolygon (or UGKPolygon) are a single collection * of rings... hides the complexity of handling UGKMultiPolygons vs  * UGKPolygons, etc. * * Returns NULL if the geometry contained in the object is invalid or  * missing or if the specified ring index is invalid. **********************************************************************/UGKLinearRing *TABRegion::GetRingRef(int nRequestedRingIndex){    UGKGeometry     *poGeom;    UGKLinearRing   *poRing = NULL;    poGeom = GetGeometryRef();    if (poGeom && (wkbFlatten(poGeom->getGeometryType()) == wkbPolygon ||                   wkbFlatten(poGeom->getGeometryType()) == wkbMultiPolygon))    {        /*-------------------------------------------------------------         * Establish number of polygons based on geometry type         *------------------------------------------------------------*/        UGKPolygon      *poPolygon=NULL;        UGKMultiPolygon *poMultiPolygon = NULL;        int             iCurRing = 0;        int             numUGKPolygons = 0;        if (wkbFlatten(poGeom->getGeometryType()) == wkbMultiPolygon)        {            poMultiPolygon = (UGKMultiPolygon *)poGeom;            numUGKPolygons = poMultiPolygon->getNumGeometries();        }        else        {            poPolygon = (UGKPolygon*)poGeom;            numUGKPolygons = 1;        }        /*-------------------------------------------------------------         * Loop through polygons until we find the requested ring.         *------------------------------------------------------------*/        iCurRing = 0;        for(int iPoly=0; poRing == NULL && iPoly < numUGKPolygons; iPoly++)        {            if (poMultiPolygon)                poPolygon = (UGKPolygon*)poMultiPolygon->getGeometryRef(iPoly);            else                poPolygon = (UGKPolygon*)poGeom;            int numIntRings = poPolygon->getNumInteriorRings();            if (iCurRing == nRequestedRingIndex)            {                poRing = poPolygon->getExteriorRing();            }            else if (nRequestedRingIndex > iCurRing &&                     nRequestedRingIndex-(iCurRing+1) < numIntRings)           {                poRing = poPolygon->getInteriorRing(nRequestedRingIndex-                                                                (iCurRing+1) );            }            iCurRing += numIntRings+1;        }    }    return poRing;}/********************************************************************** *                   TABRegion::RingIsHole() * * Return false if the requested ring index is the first of a polygon **********************************************************************/UGKBool TABRegion::IsInteriorRing(int nRequestedRingIndex){    UGKGeometry     *poGeom;    UGKLinearRing   *poRing = NULL;    poGeom = GetGeometryRef();    if (poGeom && (wkbFlatten(poGeom->getGeometryType()) == wkbPolygon ||                   wkbFlatten(poGeom->getGeometryType()) == wkbMultiPolygon))    {        /*-------------------------------------------------------------         * Establish number of polygons based on geometry type         *------------------------------------------------------------*/        UGKPolygon      *poPolygon=NULL;        UGKMultiPolygon *poMultiPolygon = NULL;        int             iCurRing = 0;        int             numUGKPolygons = 0;        if (wkbFlatten(poGeom->getGeometryType()) == wkbMultiPolygon)        {            poMultiPolygon = (UGKMultiPolygon *)poGeom;            numUGKPolygons = poMultiPolygon->getNumGeometries();        }        else        {            poPolygon = (UGKPolygon*)poGeom;            numUGKPolygons = 1;        }        /*-------------------------------------------------------------         * Loop through polygons until we find the requested ring.         *------------------------------------------------------------*/        iCurRing = 0;        for(int iPoly=0; poRing == NULL && iPoly < numUGKPolygons; iPoly++)        {            if (poMultiPolygon)                poPolygon = (UGKPolygon*)poMultiPolygon->getGeometryRef(iPoly);            else                poPolygon = (UGKPolygon*)poGeom;            int numIntRings = poPolygon->getNumInteriorRings();            if (iCurRing == nRequestedRingIndex)            {                return FALSE;            }            else if (nRequestedRingIndex > iCurRing &&                     nRequestedRingIndex-(iCurRing+1) < numIntRings)           {                return TRUE;            }            iCurRing += numIntRings+1;        }    }    return FALSE;}/********************************************************************** *                   TABRegion::GetStyleString() * * Return style string for this feature. * * Style String is built only once during the first call to GetStyleString(). **********************************************************************/const char *TABRegion::GetStyleString()

⌨️ 快捷键说明

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