📄 tabpolyline.cpp
字号:
*------------------------------------------------------------*/ pasSecHdrs = (TABMAPCoordSecHdr*)UGK_Malloc(numLineSections* sizeof(TABMAPCoordSecHdr)); poCoordBlock = poMapFile->GetCoordBlock(nCoordBlockPtr); if (poCoordBlock == NULL || poCoordBlock->ReadCoordSecHdrs(bComprCoord, bV450, numLineSections, pasSecHdrs, numPointsTotal) != 0) { UGKError(ET_Failure, UGKErr_FileIO, "Failed reading coordinate data at offset %d", nCoordBlockPtr); UGK_Free(pasSecHdrs); return -1; } poCoordBlock->SetComprCoordOrigin(nCenterX, nCenterY); panXY = (UGKInt32*)UGK_Malloc(numPointsTotal*2*sizeof(UGKInt32)); if (poCoordBlock->ReadIntCoords(bComprCoord,numPointsTotal,panXY) != 0) { UGKError(ET_Failure, UGKErr_FileIO, "Failed reading coordinate data at offset %d", nCoordBlockPtr); UGK_Free(pasSecHdrs); UGK_Free(panXY); return -1; } /*------------------------------------------------------------- * Create a Geometry collection with one line geometry for * each coordinates section * If object contains only one section, then return a simple LineString *------------------------------------------------------------*/ if (numLineSections > 1) poGeometry = poMultiLine = new UGKMultiLineString(); else poGeometry = poMultiLine = NULL; for(iSection=0; iSection<numLineSections; iSection++) { UGKInt32 *pnXYPtr; int numSectionVertices; numSectionVertices = pasSecHdrs[iSection].numVertices; pnXYPtr = panXY + (pasSecHdrs[iSection].nVertexOffset * 2); poLine = new UGKLineString(); poLine->setNumPoints(numSectionVertices); for(i=0; i<numSectionVertices; i++) { poMapFile->Int2Coordsys(*pnXYPtr, *(pnXYPtr+1), dX, dY); poLine->setPoint(i, dX, dY); pnXYPtr += 2; } if (poGeometry==NULL) poGeometry = poLine; else if (poMultiLine->addGeometryDirectly(poLine) != UGKERR_NONE) { assert(FALSE); // Just in case lower-level lib is modified } poLine = NULL; } UGK_Free(pasSecHdrs); UGK_Free(panXY); } else { UGKError(ET_Failure, UGKErr_AssertionFailed, "ReadGeometryFromMAPFile(): unsupported geometry type %d (0x%2.2x)", m_nMapInfoType, m_nMapInfoType); return -1; } SetGeometryDirectly(poGeometry); SetMBR(dXMin, dYMin, dXMax, dYMax); return 0;}/********************************************************************** * TABPolyline::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 TABPolyline::WriteGeometryToMAPFile(TABMAPFile *poMapFile, TABMAPObjHdr *poObjHdr){ UGKInt32 nX, nY; TABMAPObjectBlock *poObjBlock; UGKGeometry *poGeom; UGKLineString *poLine=NULL; /*----------------------------------------------------------------- * We assume that ValidateMapInfoType() was called already and that * the type in poObjHdr->m_nType is valid. *----------------------------------------------------------------*/ assert(m_nMapInfoType == poObjHdr->m_nType); UGKErrorReset(); poObjBlock = poMapFile->GetCurObjBlock(); /*----------------------------------------------------------------- * Fetch and validate geometry *----------------------------------------------------------------*/ poGeom = GetGeometryRef(); if ((m_nMapInfoType == TAB_GEOM_LINE || m_nMapInfoType == TAB_GEOM_LINE_C ) && poGeom && wkbFlatten(poGeom->getGeometryType()) == wkbLineString && (poLine = (UGKLineString*)poGeom)->getNumPoints() == 2) { /*============================================================= * LINE (2 vertices) *============================================================*/ TABMAPObjLine *poLineHdr = (TABMAPObjLine *)poObjHdr; poMapFile->Coordsys2Int(poLine->getX(0), poLine->getY(0), poLineHdr->m_nX1, poLineHdr->m_nY1); poMapFile->Coordsys2Int(poLine->getX(1), poLine->getY(1), poLineHdr->m_nX2, poLineHdr->m_nY2); poLineHdr->SetMBR(poLineHdr->m_nX1, poLineHdr->m_nY1, poLineHdr->m_nX2, poLineHdr->m_nY2 ); m_nPenDefIndex = poMapFile->WritePenDef(&m_sPenDef); poLineHdr->m_nPenId = m_nPenDefIndex; // Pen index } else if ((m_nMapInfoType == TAB_GEOM_PLINE || m_nMapInfoType == TAB_GEOM_PLINE_C ) && poGeom && wkbFlatten(poGeom->getGeometryType()) == wkbLineString ) { /*============================================================= * PLINE ( > 2 vertices and less than 32767 vertices) *============================================================*/ int i, numPoints, nStatus; UGKUInt32 nCoordDataSize; UGKInt32 nCoordBlockPtr; TABMAPCoordBlock *poCoordBlock; UGKBool bCompressed = poObjHdr->IsCompressedType(); /*------------------------------------------------------------- * Process geometry first... *------------------------------------------------------------*/ poLine = (UGKLineString*)poGeom; numPoints = poLine->getNumPoints(); assert(numPoints <= TAB_300_MAX_VERTICES); poCoordBlock = poMapFile->GetCurCoordBlock(); poCoordBlock->StartNewFeature(); nCoordBlockPtr = poCoordBlock->GetCurAddress(); poCoordBlock->SetComprCoordOrigin(m_nComprOrgX, m_nComprOrgY); nStatus = 0; for(i=0; nStatus == 0 && i<numPoints; i++) { poMapFile->Coordsys2Int(poLine->getX(i), poLine->getY(i), nX, nY); if ((nStatus = poCoordBlock->WriteIntCoord(nX, nY, bCompressed)) != 0) { // Failed ... error message has already been produced return nStatus; } } nCoordDataSize = poCoordBlock->GetFeatureDataSize(); /*------------------------------------------------------------- * Copy info to poObjHdr *------------------------------------------------------------*/ TABMAPObjPLine *poPLineHdr = (TABMAPObjPLine *)poObjHdr; poPLineHdr->m_nCoordBlockPtr = nCoordBlockPtr; poPLineHdr->m_nCoordDataSize = nCoordDataSize; poPLineHdr->m_numLineSections = 1; poPLineHdr->m_bSmooth = m_bSmooth; // MBR poPLineHdr->SetMBR(m_nXMin, m_nYMin, m_nXMax, m_nYMax); // Polyline 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 } else if (poGeom && (wkbFlatten(poGeom->getGeometryType()) == wkbMultiLineString || wkbFlatten(poGeom->getGeometryType()) == wkbLineString) ) { /*============================================================= * PLINE MULTIPLE (or single PLINE with more than 32767 vertices) *============================================================*/ int nStatus=0, i, iLine; UGKInt32 numPointsTotal, numPoints; UGKUInt32 nCoordDataSize; UGKInt32 nCoordBlockPtr, numLines; TABMAPCoordBlock *poCoordBlock; UGKMultiLineString *poMultiLine=NULL; TABMAPCoordSecHdr *pasSecHdrs; UGKEnvelope sEnvelope; UGKBool bCompressed = poObjHdr->IsCompressedType(); assert(m_nMapInfoType == TAB_GEOM_MULTIPLINE || m_nMapInfoType == TAB_GEOM_MULTIPLINE_C || m_nMapInfoType == TAB_GEOM_V450_MULTIPLINE || m_nMapInfoType == TAB_GEOM_V450_MULTIPLINE_C); /*------------------------------------------------------------- * Process geometry first... *------------------------------------------------------------*/ poCoordBlock = poMapFile->GetCurCoordBlock(); poCoordBlock->StartNewFeature(); nCoordBlockPtr = poCoordBlock->GetCurAddress(); poCoordBlock->SetComprCoordOrigin(m_nComprOrgX, m_nComprOrgY); if (wkbFlatten(poGeom->getGeometryType()) == wkbMultiLineString) { poMultiLine = (UGKMultiLineString*)poGeom; numLines = poMultiLine->getNumGeometries(); } else { poMultiLine = NULL; numLines = 1; } /*------------------------------------------------------------- * Build and write array of coord sections headers *------------------------------------------------------------*/ pasSecHdrs = (TABMAPCoordSecHdr*)UGK_Calloc(numLines, sizeof(TABMAPCoordSecHdr)); /*------------------------------------------------------------- * 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. *------------------------------------------------------------*/ UGKBool bV450 = (m_nMapInfoType == TAB_GEOM_V450_MULTIPLINE || m_nMapInfoType == TAB_GEOM_V450_MULTIPLINE_C ); int nTotalHdrSizeUncompressed; if (bV450) nTotalHdrSizeUncompressed = 28 * numLines; else nTotalHdrSizeUncompressed = 24 * numLines; numPointsTotal = 0; for(iLine=0; iLine < numLines; iLine++) { if (poMultiLine) poGeom = poMultiLine->getGeometryRef(iLine); if (poGeom && wkbFlatten(poGeom->getGeometryType()) == wkbLineString) { poLine = (UGKLineString*)poGeom; numPoints = poLine->getNumPoints(); poLine->getEnvelope(&sEnvelope); pasSecHdrs[iLine].numVertices = poLine->getNumPoints(); pasSecHdrs[iLine].numHoles = 0; // It's a line! poMapFile->Coordsys2Int(sEnvelope.MinX, sEnvelope.MinY, pasSecHdrs[iLine].nXMin, pasSecHdrs[iLine].nYMin); poMapFile->Coordsys2Int(sEnvelope.MaxX, sEnvelope.MaxY, pasSecHdrs[iLine].nXMax, pasSecHdrs[iLine].nYMax); pasSecHdrs[iLine].nDataOffset = nTotalHdrSizeUncompressed + numPointsTotal*4*2; pasSecHdrs[iLine].nVertexOffset = numPointsTotal; numPointsTotal += numPoints; } else { UGKError(ET_Failure, UGKErr_AssertionFailed, "TABPolyline: Object contains an invalid Geometry!"); nStatus = -1; } } if (nStatus == 0) nStatus = poCoordBlock->WriteCoordSecHdrs(bV450, numLines, pasSecHdrs, bCompressed); UGK_Free(pasSecHdrs); pasSecHdrs = NULL; if (nStatus != 0) return nStatus; // Error has already been reported. /*------------------------------------------------------------- * Then write the coordinates themselves... *------------------------------------------------------------*/ for(iLine=0; nStatus == 0 && iLine < numLines; iLine++) { if (poMultiLine) poGeom = poMultiLine->getGeometryRef(iLine); if (poGeom && wkbFlatten(poGeom->getGeometryType()) == wkbLineString) { poLine = (UGKLineString*)poGeom; numPoints = poLine->getNumPoints(); for(i=0; nStatus == 0 && i<numPoints; i++) { poMapFile->Coordsys2Int(poLine->getX(i), poLine->getY(i), nX, nY); if ((nStatus=poCoordBlock->WriteIntCoord(nX, nY, bCompressed)) != 0) { // Failed ... error message has already been produced return nStatus; } } } else { UGKError(ET_Failure, UGKErr_AssertionFailed, "TABPolyline: Object contains an invalid Geometry!"); return -1; } } nCoordDataSize = poCoordBlock->GetFeatureDataSize(); /*------------------------------------------------------------- * ... and finally copy info to poObjHdr *------------------------------------------------------------*/ TABMAPObjPLine *poPLineHdr = (TABMAPObjPLine *)poObjHdr; poPLineHdr->m_nCoordBlockPtr = nCoordBlockPtr; poPLineHdr->m_nCoordDataSize = nCoordDataSize; poPLineHdr->m_numLineSections = numLines; poPLineHdr->m_bSmooth = m_bSmooth; // MBR poPLineHdr->SetMBR(m_nXMin, m_nYMin, m_nXMax, m_nYMax); // Polyline 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 } else { UGKError(ET_Failure, UGKErr_AssertionFailed, "TABPolyline: Object contains an invalid Geometry!"); return -1; } if (UGKGetLastErrorType() == ET_Failure ) return -1; return 0;}/********************************************************************** * TABPolyline::GetStyleString() * * Return style string for this feature. * * Style String is built only once during the first call to GetStyleString(). **********************************************************************/const char *TABPolyline::GetStyleString(){ if (m_pszStyleString == NULL) { m_pszStyleString = UGKStrdup(GetPenStyleString()); } return m_pszStyleString;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -