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

📄 mitab_feature.cpp

📁 支持各种栅格图像和矢量图像读取的库
💻 CPP
📖 第 1 页 / 共 5 页
字号:
     *----------------------------------------------------------------*/    if (m_nMapInfoType == TAB_GEOM_CUSTOMSYMBOL ||        m_nMapInfoType == TAB_GEOM_CUSTOMSYMBOL_C )    {        m_nUnknown_    = poObjBlock->ReadByte();  // ???         m_nCustomStyle = poObjBlock->ReadByte();  // 0x01=Show BG,                                                  // 0x02=Apply Color        poObjBlock->ReadIntCoord(bComprCoord, nX, nY);        m_nSymbolDefIndex = poObjBlock->ReadByte();   // Symbol index        poMapFile->ReadSymbolDef(m_nSymbolDefIndex, &m_sSymbolDef);        m_nFontDefIndex = poObjBlock->ReadByte();    // Font index        poMapFile->ReadFontDef(m_nFontDefIndex, &m_sFontDef);    }    else    {        CPLError(CE_Failure, CPLE_AssertionFailed,           "ReadGeometryFromMAPFile(): unsupported geometry type %d (0x%2.2x)",                 m_nMapInfoType, m_nMapInfoType);        return -1;    }    /*-----------------------------------------------------------------     * Create and fill geometry object     *----------------------------------------------------------------*/    poMapFile->Int2Coordsys(nX, nY, dX, dY);    poGeometry = new OGRPoint(dX, dY);        SetGeometryDirectly(poGeometry);    SetMBR(dX, dY, dX, dY);    return 0;}/********************************************************************** *                   TABCustomPoint::WriteGeometryToMAPFile() * * Write the geometry and representation (color, etc...) part of the * feature to the .MAP object pointed to by poMAPFile. * * It is assumed that poMAPFile currently points to a valid map object. * * Returns 0 on success, -1 on error, in which case CPLError() will have * been called. **********************************************************************/int TABCustomPoint::WriteGeometryToMAPFile(TABMAPFile *poMapFile,                                       TABMAPObjHdr *poObjHdr){    GInt32              nX, nY;    OGRGeometry         *poGeom;    OGRPoint            *poPoint;    /*-----------------------------------------------------------------     * We assume that ValidateMapInfoType() was called already and that     * the type in poObjHdr->m_nType is valid.     *----------------------------------------------------------------*/    CPLAssert(m_nMapInfoType == poObjHdr->m_nType);    /*-----------------------------------------------------------------     * Fetch and validate geometry     *----------------------------------------------------------------*/    poGeom = GetGeometryRef();    if (poGeom && wkbFlatten(poGeom->getGeometryType()) == wkbPoint)        poPoint = (OGRPoint*)poGeom;    else    {        CPLError(CE_Failure, CPLE_AssertionFailed,                 "TABCustomPoint: Missing or Invalid Geometry!");        return -1;    }    poMapFile->Coordsys2Int(poPoint->getX(), poPoint->getY(), nX, nY);    /*-----------------------------------------------------------------     * Copy object information     *----------------------------------------------------------------*/    TABMAPObjCustomPoint *poPointHdr = (TABMAPObjCustomPoint *)poObjHdr;    poPointHdr->m_nX = nX;    poPointHdr->m_nY = nY;    poPointHdr->SetMBR(nX, nY, nX, nY);    poPointHdr->m_nUnknown_ = m_nUnknown_;    poPointHdr->m_nCustomStyle = m_nCustomStyle;// 0x01=Show BG,                                               // 0x02=Apply Color    m_nSymbolDefIndex = poMapFile->WriteSymbolDef(&m_sSymbolDef);    poPointHdr->m_nSymbolId = m_nSymbolDefIndex;      // Symbol index    m_nFontDefIndex = poMapFile->WriteFontDef(&m_sFontDef);    poPointHdr->m_nFontId = m_nFontDefIndex;      // Font index    if (CPLGetLastErrorNo() != 0)        return -1;    return 0;}/********************************************************************** *                   TABCustomPoint::GetStyleString() * * Return style string for this feature. * * Style String is built only once during the first call to GetStyleString(). **********************************************************************/const char *TABCustomPoint::GetStyleString(){    if (m_pszStyleString == NULL)    {        m_pszStyleString = CPLStrdup(GetSymbolStyleString());    }    return m_pszStyleString;}/*===================================================================== *                      class TABPolyline *====================================================================*//********************************************************************** *                   TABPolyline::TABPolyline() * * Constructor. **********************************************************************/TABPolyline::TABPolyline(OGRFeatureDefn *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(OGRFeatureDefn *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(){    OGRGeometry         *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         *------------------------------------------------------------*/        OGRMultiLineString *poMultiLine = (OGRMultiLineString*)poGeom;        numParts = poMultiLine->getNumGeometries();    }    return numParts;}/********************************************************************** *                   TABPolyline::GetPartRef() * * Returns a reference to the specified OGRLineString number, hiding the * complexity of dealing with OGRMultiLineString vs OGRLineString cases. * * Returns NULL if the geometry contained in the object is invalid or  * missing or if the specified part index is invalid. **********************************************************************/OGRLineString *TABPolyline::GetPartRef(int nPartIndex){    OGRGeometry         *poGeom;    poGeom = GetGeometryRef();    if (poGeom && wkbFlatten(poGeom->getGeometryType()) == wkbLineString && nPartIndex==0)    {        /*-------------------------------------------------------------         * Simple polyline         *------------------------------------------------------------*/        return (OGRLineString *)poGeom;    }    else if (poGeom && wkbFlatten(poGeom->getGeometryType()) == wkbMultiLineString)    {        /*-------------------------------------------------------------         * Multiple polyline         *------------------------------------------------------------*/        OGRMultiLineString *poMultiLine = (OGRMultiLineString*)poGeom;        if (nPartIndex >= 0 &&            nPartIndex < poMultiLine->getNumGeometries())        {            return (OGRLineString*)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*/){    OGRGeometry   *poGeom;    OGRMultiLineString *poMultiLine = NULL;    /*-----------------------------------------------------------------     * Fetch and validate geometry     *----------------------------------------------------------------*/    poGeom = GetGeometryRef();    if (poGeom && wkbFlatten(poGeom->getGeometryType()) == wkbLineString)    {        /*-------------------------------------------------------------         * Simple polyline         *------------------------------------------------------------*/        OGRLineString *poLine = (OGRLineString*)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        {            CPLError(CE_Failure, CPLE_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;        GInt32 numPointsTotal = 0;        poMultiLine = (OGRMultiLineString*)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)            {                CPLError(CE_Failure, CPLE_AssertionFailed,                         "TABPolyline: Object contains an invalid Geometry!");                m_nMapInfoType = TAB_GEOM_NONE;                numPointsTotal = 0;                break;            }            OGRLineString *poLine = (OGRLineString*)poGeom;            numPointsTotal += poLine->getNumPoints();        }        if (numPointsTotal > TAB_300_MAX_VERTICES)            m_nMapInfoType = TAB_GEOM_V450_MULTIPLINE;    }    else    {        CPLError(CE_Failure, CPLE_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 

⌨️ 快捷键说明

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