📄 mitab_feature.cpp
字号:
* 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 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){ GInt32 nX, nY; double dX, dY, dXMin, dYMin, dXMax, dYMax; OGRGeometry *poGeometry; OGRLineString *poLine; GBool 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 OGRLineString(); 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; GUInt32 nCoordDataSize; GInt32 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) { CPLError(CE_Failure, CPLE_FileIO, "Can't access coordinate block at offset %d", nCoordBlockPtr); return -1; } poCoordBlock->SetComprCoordOrigin(nCenterX, nCenterY); poGeometry = po
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -