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

📄 tabpolyline.cpp

📁 linux下一款GIS程序源码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
// tabpolyline.cpp: implementation of the TABPolyline class.////////////////////////////////////////////////////////////////////////#include "tabpolyline.h"#include "ugk_errhandle.h"#include "ugk_memopr.h"#include "ugk_string.h"#include "ugkmultilinestring.h"#include "tabmapobjline.h"#include "tabmapobjpline.h"/********************************************************************** *                   TABPolyline::TABPolyline() * * Constructor. **********************************************************************/TABPolyline::TABPolyline(UGKFeatureDefn *poDefnIn):                 TABFeature(poDefnIn){    m_bCenterIsSet = FALSE;    m_bSmooth = FALSE;}/********************************************************************** *                   TABPolyline::~TABPolyline() * * Destructor. **********************************************************************/TABPolyline::~TABPolyline(){}/********************************************************************** *                     TABPolyline::CloneTABFeature() * * Duplicate feature, including stuff specific to each TABFeature type. * * This method calls the generic TABFeature::CloneTABFeature() and  * then copies any members specific to its own type. **********************************************************************/TABFeature *TABPolyline::CloneTABFeature(UGKFeatureDefn *poNewDefn/*=NULL*/){    /*-----------------------------------------------------------------     * Alloc new feature and copy the base stuff     *----------------------------------------------------------------*/    TABPolyline *poNew = new TABPolyline(poNewDefn ? poNewDefn : GetDefnRef());    CopyTABFeatureBase(poNew);    /*-----------------------------------------------------------------     * And members specific to this class     *----------------------------------------------------------------*/    // ITABFeaturePen    *(poNew->GetPenDefRef()) = *GetPenDefRef();    poNew->m_bSmooth = m_bSmooth;    poNew->m_bCenterIsSet = m_bCenterIsSet;    poNew->m_dCenterX = m_dCenterX;    poNew->m_dCenterY = m_dCenterY;    return poNew;}/********************************************************************** *                   TABPolyline::GetNumParts() * * Return the total number of parts in this object. * * Returns 0 if the geometry contained in the object is invalid or missing. **********************************************************************/int TABPolyline::GetNumParts(){    UGKGeometry         *poGeom;    int                 numParts = 0;    poGeom = GetGeometryRef();    if (poGeom && wkbFlatten(poGeom->getGeometryType()) == wkbLineString)    {        /*-------------------------------------------------------------         * Simple polyline         *------------------------------------------------------------*/        numParts = 1;    }    else if (poGeom && wkbFlatten(poGeom->getGeometryType()) == wkbMultiLineString)    {        /*-------------------------------------------------------------         * Multiple polyline         *------------------------------------------------------------*/        UGKMultiLineString *poMultiLine = (UGKMultiLineString*)poGeom;        numParts = poMultiLine->getNumGeometries();    }    return numParts;}/********************************************************************** *                   TABPolyline::GetPartRef() * * Returns a reference to the specified UGKLineString number, hiding the * complexity of dealing with UGKMultiLineString vs UGKLineString cases. * * Returns NULL if the geometry contained in the object is invalid or  * missing or if the specified part index is invalid. **********************************************************************/UGKLineString *TABPolyline::GetPartRef(int nPartIndex){    UGKGeometry         *poGeom;    poGeom = GetGeometryRef();    if (poGeom && wkbFlatten(poGeom->getGeometryType()) == wkbLineString && nPartIndex==0)    {        /*-------------------------------------------------------------         * Simple polyline         *------------------------------------------------------------*/        return (UGKLineString *)poGeom;    }    else if (poGeom && wkbFlatten(poGeom->getGeometryType()) == wkbMultiLineString)    {        /*-------------------------------------------------------------         * Multiple polyline         *------------------------------------------------------------*/        UGKMultiLineString *poMultiLine = (UGKMultiLineString*)poGeom;        if (nPartIndex >= 0 &&            nPartIndex < poMultiLine->getNumGeometries())        {            return (UGKLineString*)poMultiLine->getGeometryRef(nPartIndex);        }        else            return NULL;    }    return NULL;}/********************************************************************** *                   TABPolyline::ValidateMapInfoType() * * Check the feature's geometry part and return the corresponding * mapinfo object type code.  The m_nMapInfoType member will also * be updated for further calls to GetMapInfoType(); * * Returns TAB_GEOM_NONE if the geometry is not compatible with what * is expected for this object class. **********************************************************************/int  TABPolyline::ValidateMapInfoType(TABMAPFile *poMapFile /*=NULL*/){    UGKGeometry   *poGeom;    UGKMultiLineString *poMultiLine = NULL;    /*-----------------------------------------------------------------     * Fetch and validate geometry     *----------------------------------------------------------------*/    poGeom = GetGeometryRef();    if (poGeom && wkbFlatten(poGeom->getGeometryType()) == wkbLineString)    {        /*-------------------------------------------------------------         * Simple polyline         *------------------------------------------------------------*/        UGKLineString *poLine = (UGKLineString*)poGeom;        if ( poLine->getNumPoints() > TAB_300_MAX_VERTICES)        {            m_nMapInfoType = TAB_GEOM_V450_MULTIPLINE;        }        else if ( poLine->getNumPoints() > 2 )        {            m_nMapInfoType = TAB_GEOM_PLINE;        }        else if ( poLine->getNumPoints() == 2 )        {            m_nMapInfoType = TAB_GEOM_LINE;        }        else        {            UGKError(ET_Failure, UGKErr_AssertionFailed,                      "TABPolyline: Geometry must contain at least 2 points.");            m_nMapInfoType = TAB_GEOM_NONE;        }    }    else if (poGeom && wkbFlatten(poGeom->getGeometryType()) == wkbMultiLineString)    {        /*-------------------------------------------------------------         * Multiple polyline... validate all components         *------------------------------------------------------------*/        int iLine, numLines;        UGKInt32 numPointsTotal = 0;        poMultiLine = (UGKMultiLineString*)poGeom;        numLines = poMultiLine->getNumGeometries();        m_nMapInfoType = TAB_GEOM_MULTIPLINE;        for(iLine=0; iLine < numLines; iLine++)        {            poGeom = poMultiLine->getGeometryRef(iLine);            if (poGeom && wkbFlatten(poGeom->getGeometryType()) != wkbLineString)            {                UGKError(ET_Failure, UGKErr_AssertionFailed,                          "TABPolyline: Object contains an invalid Geometry!");                m_nMapInfoType = TAB_GEOM_NONE;                numPointsTotal = 0;                break;            }            UGKLineString *poLine = (UGKLineString*)poGeom;            numPointsTotal += poLine->getNumPoints();        }        if (numPointsTotal > TAB_300_MAX_VERTICES)            m_nMapInfoType = TAB_GEOM_V450_MULTIPLINE;    }    else    {        UGKError(ET_Failure, UGKErr_AssertionFailed,                  "TABPolyline: Missing or Invalid Geometry!");        m_nMapInfoType = TAB_GEOM_NONE;    }    /*-----------------------------------------------------------------     * Decide if coordinates should be compressed or not.     *     * __TODO__ We never write type LINE (2 points line) as compressed     * for the moment.  If we ever do it, then the decision to write     * a 2 point line in compressed coordinates or not should take into     * account the location of the object block MBR, so this would be     * better handled directly by TABMAPObjLine::WriteObject() since the     * object block center is not known until it is written to disk.     *----------------------------------------------------------------*/    if (m_nMapInfoType != TAB_GEOM_LINE)    {        ValidateCoordType(poMapFile);    }    return m_nMapInfoType;}/********************************************************************** *                   TABPolyline::ReadGeometryFromMAPFile() * * 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 poMAPFile currently points to the beginning of * a map object. * * Returns 0 on success, -1 on error, in which case CPLError() will have * been called. **********************************************************************/int TABPolyline::ReadGeometryFromMAPFile(TABMAPFile *poMapFile,                                         TABMAPObjHdr *poObjHdr){    UGKInt32              nX, nY;    double              dX, dY, dXMin, dYMin, dXMax, dYMax;    UGKGeometry         *poGeometry;    UGKLineString       *poLine;    UGKBool               bComprCoord = poObjHdr->IsCompressedType();        /*-----------------------------------------------------------------     * Fetch and validate geometry type     *----------------------------------------------------------------*/    m_nMapInfoType = poObjHdr->m_nType;    if (m_nMapInfoType == TAB_GEOM_LINE ||        m_nMapInfoType == TAB_GEOM_LINE_C )    {        /*=============================================================         * LINE (2 vertices)         *============================================================*/        TABMAPObjLine *poLineHdr = (TABMAPObjLine *)poObjHdr;        m_bSmooth = FALSE;        poGeometry = poLine = new UGKLineString();        poLine->setNumPoints(2);        poMapFile->Int2Coordsys(poLineHdr->m_nX1, poLineHdr->m_nY1,                                 dXMin, dYMin);        poLine->setPoint(0, dXMin, dYMin);        poMapFile->Int2Coordsys(poLineHdr->m_nX2, poLineHdr->m_nY2,                                dXMax, dYMax);        poLine->setPoint(1, dXMax, dYMax);        m_nPenDefIndex = poLineHdr->m_nPenId;      // Pen index        poMapFile->ReadPenDef(m_nPenDefIndex, &m_sPenDef);    }    else if (m_nMapInfoType == TAB_GEOM_PLINE ||             m_nMapInfoType == TAB_GEOM_PLINE_C )    {        /*=============================================================         * PLINE ( > 2 vertices)         *============================================================*/        int     i, numPoints, nStatus;        UGKUInt32 nCoordDataSize;        UGKInt32  nCoordBlockPtr, nCenterX, nCenterY;        TABMAPCoordBlock *poCoordBlock;        /*-------------------------------------------------------------         * Copy data from poObjHdr         *------------------------------------------------------------*/        TABMAPObjPLine *poPLineHdr = (TABMAPObjPLine *)poObjHdr;        nCoordBlockPtr  = poPLineHdr->m_nCoordBlockPtr;        nCoordDataSize  = poPLineHdr->m_nCoordDataSize;        //numLineSections = poPLineHdr->m_numLineSections; // Always 1        m_bSmooth       = poPLineHdr->m_bSmooth;        // Centroid/label point        poMapFile->Int2Coordsys(poPLineHdr->m_nLabelX, poPLineHdr->m_nLabelY,                                 dX, dY);        SetCenter(dX, dY);        // Compressed coordinate origin (useful only in compressed case!)        nCenterX = poPLineHdr->m_nComprOrgX;        nCenterY = poPLineHdr->m_nComprOrgY;        // MBR        poMapFile->Int2Coordsys(poPLineHdr->m_nMinX, poPLineHdr->m_nMinY,                                 dXMin, dYMin);        poMapFile->Int2Coordsys(poPLineHdr->m_nMaxX, poPLineHdr->m_nMaxY,                                 dXMax, dYMax);        m_nPenDefIndex = poPLineHdr->m_nPenId;        // Pen index        poMapFile->ReadPenDef(m_nPenDefIndex, &m_sPenDef);        /*-------------------------------------------------------------         * Create Geometry and read coordinates         *------------------------------------------------------------*/        numPoints = nCoordDataSize/(bComprCoord?4:8);        poCoordBlock = poMapFile->GetCoordBlock(nCoordBlockPtr);        if (poCoordBlock == NULL)        {            UGKError(ET_Failure, UGKErr_FileIO,                     "Can't access coordinate block at offset %d",                       nCoordBlockPtr);            return -1;        }        poCoordBlock->SetComprCoordOrigin(nCenterX, nCenterY);        poGeometry = poLine = new UGKLineString();        poLine->setNumPoints(numPoints);        nStatus = 0;        for(i=0; nStatus == 0 && i<numPoints; i++)        {            nStatus = poCoordBlock->ReadIntCoord(bComprCoord, nX, nY);            if (nStatus != 0)                break;            poMapFile->Int2Coordsys(nX, nY, dX, dY);            poLine->setPoint(i, dX, dY);        }        if (nStatus != 0)        {            // Failed ... error message has already been produced            delete poGeometry;            return nStatus;        }       }    else if (m_nMapInfoType == TAB_GEOM_MULTIPLINE ||             m_nMapInfoType == TAB_GEOM_MULTIPLINE_C ||             m_nMapInfoType == TAB_GEOM_V450_MULTIPLINE ||             m_nMapInfoType == TAB_GEOM_V450_MULTIPLINE_C )    {        /*=============================================================         * PLINE MULTIPLE         *============================================================*/        int     i, iSection;        UGKInt32  nCoordBlockPtr, numLineSections, nCenterX, nCenterY;        UGKInt32  nCoordDataSize, numPointsTotal, *panXY;        TABMAPCoordBlock        *poCoordBlock;        UGKMultiLineString      *poMultiLine;        TABMAPCoordSecHdr       *pasSecHdrs;        UGKBool bV450 = (m_nMapInfoType == TAB_GEOM_V450_MULTIPLINE ||                       m_nMapInfoType == TAB_GEOM_V450_MULTIPLINE_C);        /*-------------------------------------------------------------         * Copy data from poObjHdr         *------------------------------------------------------------*/        TABMAPObjPLine *poPLineHdr = (TABMAPObjPLine *)poObjHdr;        nCoordBlockPtr  = poPLineHdr->m_nCoordBlockPtr;        nCoordDataSize  = poPLineHdr->m_nCoordDataSize;        numLineSections = poPLineHdr->m_numLineSections;        m_bSmooth       = poPLineHdr->m_bSmooth;        // Centroid/label point        poMapFile->Int2Coordsys(poPLineHdr->m_nLabelX, poPLineHdr->m_nLabelY,                                 dX, dY);        SetCenter(dX, dY);        // Compressed coordinate origin (useful only in compressed case!)        nCenterX = poPLineHdr->m_nComprOrgX;        nCenterY = poPLineHdr->m_nComprOrgY;        // MBR        poMapFile->Int2Coordsys(poPLineHdr->m_nMinX, poPLineHdr->m_nMinY,                                 dXMin, dYMin);        poMapFile->Int2Coordsys(poPLineHdr->m_nMaxX, poPLineHdr->m_nMaxY,                                 dXMax, dYMax);        m_nPenDefIndex = poPLineHdr->m_nPenId;        // Pen index        poMapFile->ReadPenDef(m_nPenDefIndex, &m_sPenDef);        /*-------------------------------------------------------------         * Read data from the coord. block

⌨️ 快捷键说明

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