Exemple #1
0
/*!
  \brief Load geometry (linestring HP/DPM layer)

  \todo Really needed?

  \return TRUE on success or FALSE on failure
*/
bool VFKFeature::LoadGeometryLineStringHP()
{
    int           id, idxId, idxHp_Id;
    VFKDataBlock *poDataBlockLines;
    VFKFeature   *poLine;
    
    poDataBlockLines = (VFKDataBlock *) m_poDataBlock->GetReader()->GetDataBlock("SBP");
    if (!poDataBlockLines)
        return FALSE;
    
    idxId    = m_poDataBlock->GetPropertyIndex("ID");
    idxHp_Id = poDataBlockLines->GetPropertyIndex("HP_ID");
    if (idxId < 0 || idxHp_Id < 0)
        return FALSE;
    
    id = GetProperty(idxId)->GetValueI();
    poLine = poDataBlockLines->GetFeature(idxHp_Id, id);
    if (!poLine || !poLine->GetGeometry())
        return FALSE;
    
    SetGeometry(poLine->GetGeometry());
    poDataBlockLines->ResetReading();
    
    return TRUE;
}
Exemple #2
0
/*!
  \brief Load geometry (linestring SBP layer)

  \todo Really needed?

  \return TRUE on success or FALSE on failure
*/
bool VFKFeature::LoadGeometryLineStringSBP()
{
    int id, idxId, idxBp_Id, idxPCB, ipcb;
    
    VFKDataBlock *poDataBlockPoints;
    VFKFeature   *poPoint, *poLine;
    
    OGRLineString OGRLine;
    
    poDataBlockPoints = (VFKDataBlock *) m_poDataBlock->GetReader()->GetDataBlock("SOBR");
    if (!poDataBlockPoints)
        return FALSE;
    
    idxId    = poDataBlockPoints->GetPropertyIndex("ID");
    idxBp_Id = m_poDataBlock->GetPropertyIndex("BP_ID");
    idxPCB   = m_poDataBlock->GetPropertyIndex("PORADOVE_CISLO_BODU");
    if (idxId < 0 || idxBp_Id < 0 || idxPCB < 0)
        return false;
    
    poLine = this;
    while (TRUE)
    {
        id   = poLine->GetProperty(idxBp_Id)->GetValueI();
        ipcb = poLine->GetProperty(idxPCB)->GetValueI();
        if (OGRLine.getNumPoints() > 0 && ipcb == 1)
        {
            m_poDataBlock->GetPreviousFeature(); /* push back */
            break;
        }
        
        poPoint = poDataBlockPoints->GetFeature(idxId, id);
        if (!poPoint)
        {
            continue;
        }
        OGRPoint *pt = (OGRPoint *) poPoint->GetGeometry();
        OGRLine.addPoint(pt);
        
        poLine = (VFKFeature *) m_poDataBlock->GetNextFeature();
        if (!poLine)
            break;
    };
    
    OGRLine.setCoordinateDimension(2); /* force 2D */
    SetGeometry(&OGRLine);
    
    /* reset reading */
    poDataBlockPoints->ResetReading();
    
    return TRUE;
}
Exemple #3
0
/*!
  \brief Load geometry (linestring HP/DPM layer)

  \return number of invalid features
*/
int VFKDataBlock::LoadGeometryLineStringHP()
{
    long          nInvalid;
    int           idxId, idxMy_Id, idxPCB;
    GUIntBig      id;
    
    VFKDataBlock  *poDataBlockLines;
    VFKFeature    *poFeature, *poLine;
    VFKFeatureList poLineList;
    
    nInvalid = 0;
    
    poDataBlockLines = (VFKDataBlock *) m_poReader->GetDataBlock("SBP");
    if (NULL == poDataBlockLines) {
        CPLError(CE_Failure, CPLE_NotSupported, 
                 "Data block %s not found.\n", m_pszName);
        return nInvalid;
    }
    
    poDataBlockLines->LoadGeometry();
    idxId    = GetPropertyIndex("ID");
    if (EQUAL (m_pszName, "HP"))
        idxMy_Id = poDataBlockLines->GetPropertyIndex("HP_ID");
    else
        idxMy_Id = poDataBlockLines->GetPropertyIndex("DPM_ID");
    idxPCB   = poDataBlockLines->GetPropertyIndex("PORADOVE_CISLO_BODU");
    if (idxId < 0 || idxMy_Id < 0 || idxPCB < 0) {
        CPLError(CE_Failure, CPLE_NotSupported, 
                 "Corrupted data (%s).\n", m_pszName);
        return nInvalid;
    }
    
    poLineList = poDataBlockLines->GetFeatures(idxPCB, 1); /* reduce to first segment */
    for (int i = 0; i < ((IVFKDataBlock *) this)->GetFeatureCount(); i++) {
        poFeature = (VFKFeature *) GetFeatureByIndex(i);
        id = strtoul(poFeature->GetProperty(idxId)->GetValueS(), NULL, 0);
        poLine = poDataBlockLines->GetFeature(idxMy_Id, id, &poLineList);
        if (!poLine || !poLine->GetGeometry())
            continue;
        if (!poFeature->SetGeometry(poLine->GetGeometry()))
            nInvalid++;
    }
    poDataBlockLines->ResetReading();

    return nInvalid;
}
Exemple #4
0
/*!
  \brief Load geometry (linestring SBP layer)

  \return number of invalid features
*/
int VFKDataBlock::LoadGeometryLineStringSBP()
{
    int      idxId, idxBp_Id, idxPCB;
    GUIntBig id, ipcb;
    int      nInvalid;
    
    VFKDataBlock *poDataBlockPoints;
    VFKFeature   *poFeature, *poPoint, *poLine;
    
    OGRLineString oOGRLine;
    
    nInvalid  = 0;
    poLine    = NULL;
    
    poDataBlockPoints = (VFKDataBlock *) m_poReader->GetDataBlock("SOBR");
    if (NULL == poDataBlockPoints) {
        CPLError(CE_Failure, CPLE_NotSupported, 
                 "Data block %s not found.\n", m_pszName);
        return nInvalid;
    }
    
    poDataBlockPoints->LoadGeometry();
    idxId    = poDataBlockPoints->GetPropertyIndex("ID");
    idxBp_Id = GetPropertyIndex("BP_ID");
    idxPCB   = GetPropertyIndex("PORADOVE_CISLO_BODU");
    if (idxId < 0 || idxBp_Id < 0 || idxPCB < 0) {
        CPLError(CE_Failure, CPLE_NotSupported, 
                 "Corrupted data (%s).\n", m_pszName);
        return nInvalid;
    }
    
    for (int j = 0; j < ((IVFKDataBlock *) this)->GetFeatureCount(); j++) {
        poFeature = (VFKFeature *) GetFeatureByIndex(j);
        poFeature->SetGeometry(NULL);
        id   = strtoul(poFeature->GetProperty(idxBp_Id)->GetValueS(), NULL, 0);
        ipcb = strtoul(poFeature->GetProperty(idxPCB)->GetValueS(), NULL, 0);
        if (ipcb == 1) {
            if (!oOGRLine.IsEmpty()) {
                oOGRLine.setCoordinateDimension(2); /* force 2D */
                if (!poLine->SetGeometry(&oOGRLine))
                    nInvalid++;
                oOGRLine.empty(); /* restore line */
            }
            poLine = poFeature;
        }
        else {
            poFeature->SetGeometryType(wkbUnknown);
        }
        poPoint = poDataBlockPoints->GetFeature(idxId, id);
        if (!poPoint)
            continue;
        OGRPoint *pt = (OGRPoint *) poPoint->GetGeometry();
        oOGRLine.addPoint(pt);
    }
    /* add last line */
    oOGRLine.setCoordinateDimension(2); /* force 2D */
    if (poLine) {
        if (!poLine->SetGeometry(&oOGRLine))
            nInvalid++;
    }
    poDataBlockPoints->ResetReading();

    return nInvalid;
}
Exemple #5
0
/*!
  \brief Get data blocks (&B)

  Call LoadData() before this function.

  \return FALSE on error
  \return TRUE on success
*/
int VFKReader::LoadDataBlocks()
{ 
    char         *pszChar;
    char         *pszLine;
    char         *pszBlockName;
    int           nRow;
    
    VFKDataBlock *poNewDataBlock;

    if (m_pszWholeText == NULL)
        return FALSE;

    poNewDataBlock = NULL;
    pszBlockName = NULL;
    nRow = 0;

    /* read lines */
    pszChar = m_pszWholeText;
    pszLine = m_pszWholeText;
    while (*pszChar != '\0') {
	if (*pszChar == '\r' && *(pszChar+1) == '\n') {
	    nRow++;
	    if (*pszLine == '&' && *(pszLine+1) == 'B') {
		/* add data block */
		pszBlockName = GetDataBlockName(pszLine);
                if (pszBlockName == NULL)
                    break;

		poNewDataBlock = new VFKDataBlock(pszBlockName, this);
		CPLFree(pszBlockName);
		pszBlockName = NULL;
		poNewDataBlock->SetGeometryType();
		poNewDataBlock->SetProperties(pszLine);
		AddDataBlock(poNewDataBlock);
	    }
	    else if (*pszLine == '&' && *(pszLine+1) == 'D') {
		/* data row */
		pszBlockName = GetDataBlockName(pszLine);
                if (pszBlockName == NULL)
                    break;

		poNewDataBlock = GetDataBlock(pszBlockName);
		if (poNewDataBlock == NULL) {
		    if (!EQUAL(pszBlockName, "KATUZE")) {
			/* ignore KATUZE block */
			CPLError(CE_Warning, CPLE_AppDefined, 
				 "Data block '%s' not found.\n", pszBlockName);
		    }
		}
		else 
		    poNewDataBlock->AddFeature(pszLine);

		CPLFree(pszBlockName);
		pszBlockName = NULL;
	    }
	    else if (*pszLine == '&' && *(pszLine+1) == 'H') {
		/* header - metadata */
		AddInfo(pszLine);
	    }
	    else if (*pszLine == '&' && *(pszLine+1) == 'K') {
		/* end of file */
		break;
	    }
	    pszChar++;
	    pszLine = pszChar + 1;
	}
	pszChar++;
    }

    return TRUE;
}