示例#1
0
/*!
  \brief Load geometry (point layers)

  \return number of invalid features
*/
int VFKDataBlock::LoadGeometryPoint()
{
    /* -> wkbPoint */
    long   nInvalid;
    double x, y;
    int    i_idxX, i_idxY;
    
    VFKFeature *poFeature;
    
    nInvalid = 0;
    i_idxY = GetPropertyIndex("SOURADNICE_Y");
    i_idxX = GetPropertyIndex("SOURADNICE_X");
    if (i_idxY < 0 || i_idxX < 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);
        x = -1.0 * poFeature->GetProperty(i_idxY)->GetValueD();
        y = -1.0 * poFeature->GetProperty(i_idxX)->GetValueD();
        OGRPoint pt(x, y);
        if (!poFeature->SetGeometry(&pt))
            nInvalid++;
    }
    
    return nInvalid;
}
示例#2
0
    BOOL ModuleRoot::GetProperty(Var originalInstance, PropertyId propertyId, Var* value, PropertyValueInfo* info, ScriptContext* requestContext)
    {
        PropertyIndex index = GetPropertyIndex(propertyId);
        if (index != Constants::NoSlot)
        {
            *value = this->GetSlot(index);
            if (info) // Avoid testing IsWritable if info not being queried
            {
                PropertyValueInfo::Set(info, this, index, IsWritable(propertyId) ? PropertyWritable : PropertyNone);
                if (this->IsFixedProperty(propertyId))
                {
                    PropertyValueInfo::DisableStoreFieldCache(info);
                }
            }
            return TRUE;
        }
        if (this->hostObject && JavascriptOperators::GetProperty(this->hostObject, propertyId, value, requestContext))
        {
            return TRUE;
        }

        //
        // Try checking the global object
        // if the module root doesn't have the property and the host object also doesn't have it
        //

        GlobalObject* globalObj = this->GetLibrary()->GetGlobalObject();
        return globalObj->GlobalObject::GetProperty(originalInstance, propertyId, value, NULL, requestContext);
    }
示例#3
0
    BOOL ModuleRoot::SetProperty(PropertyId propertyId, Var value, PropertyOperationFlags flags, PropertyValueInfo* info)
    {
        PropertyIndex index = GetPropertyIndex(propertyId);
        if (index != Constants::NoSlot)
        {
            if (this->IsWritable(propertyId) == FALSE)
            {
                JavascriptError::ThrowCantAssignIfStrictMode(flags, this->GetScriptContext());

                if (!this->IsFixedProperty(propertyId))
                {
                    PropertyValueInfo::Set(info, this, index, PropertyNone); // Try to cache property info even if not writable
                }
                else
                {
                    PropertyValueInfo::SetNoCache(info, this);
                }
                return FALSE;
            }
            this->SetSlot(SetSlotArguments(propertyId, index, value));
            if (!this->IsFixedProperty(propertyId))
            {
                PropertyValueInfo::Set(info, this, index);
            }
            else
            {
                PropertyValueInfo::SetNoCache(info, this);
            }
            return TRUE;
        }
        else if (this->hostObject && this->hostObject->HasProperty(propertyId))
        {
            return this->hostObject->SetProperty(propertyId, value, flags, NULL);
        }

        //
        // Try checking the global object
        // if the module root doesn't have the property and the host object also doesn't have it
        //
        GlobalObject* globalObj = this->GetLibrary()->GetGlobalObject();
        BOOL setAttempted = TRUE;
        if (globalObj->SetExistingProperty(propertyId, value, NULL, &setAttempted))
        {
            return TRUE;
        }

        //
        // Set was attempted. But the set operation returned false.
        // This happens, when the property is read only.
        // In those scenarios, we should be setting the property with default attributes
        //
        if (setAttempted)
        {
            return FALSE;
        }

        return DynamicObject::SetProperty(propertyId, value, flags, info);
    }
示例#4
0
 BOOL ModuleRoot::DeleteProperty(PropertyId propertyId, PropertyOperationFlags flags)
 {
     int index = GetPropertyIndex(propertyId);
     if (index != Constants::NoSlot)
     {
         return FALSE;
     }
     else if (this->hostObject && this->hostObject->HasProperty(propertyId))
     {
         return this->hostObject->DeleteProperty(propertyId, flags);
     }
     return this->GetLibrary()->GetGlobalObject()->GlobalObject::DeleteProperty(propertyId, flags);
 }
示例#5
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;
}
示例#6
0
/*!
  \brief Get feature count based on property value

  \param pszName property name
  \param pszValue property value

  \return number of features
  \return -1 on error
*/
int VFKDataBlock::GetFeatureCount(const char *pszName, const char *pszValue)
{
    int nfeatures, propIdx;
    VFKFeature *poVFKFeature;

    propIdx = GetPropertyIndex(pszName);
    if (propIdx < 0)
        return -1;
    
    nfeatures = 0;
    for (int i = 0; i < ((IVFKDataBlock *) this)->GetFeatureCount(); i++) {
        poVFKFeature = (VFKFeature *) ((IVFKDataBlock *) this)->GetFeature(i);
        if (!poVFKFeature)
            return -1;
        if (EQUAL (poVFKFeature->GetProperty(propIdx)->GetValueS(), pszValue))
            nfeatures++;
    }

    return nfeatures;
}
示例#7
0
/*!
  \brief Load geometry (polygon BUD/PAR layers)

  \return number of invalid features
*/
int VFKDataBlock::LoadGeometryPolygon()
{
    long nInvalid;
    bool bIsPar, bNewRing, bFound;
        
    GUIntBig id, idOb;
    int  nCount, nCountMax;
    int idxId, idxPar1, idxPar2, idxBud, idxOb, idxIdOb;
    
    VFKFeature   *poFeature;
    VFKDataBlock *poDataBlockLines1, *poDataBlockLines2;
    
    VFKFeatureList   poLineList;
    PointListArray   poRingList; /* first is to be considered as exterior */
    
    OGRLinearRing ogrRing;
    OGRPolygon    ogrPolygon;
    
    idxPar1 = idxPar2 = idxBud = idxOb = idxIdOb = 0;
    nInvalid = 0;
    if (EQUAL (m_pszName, "PAR")) {
        poDataBlockLines1 = (VFKDataBlock *) m_poReader->GetDataBlock("HP");
        poDataBlockLines2 = poDataBlockLines1;
        bIsPar = TRUE;
    }
    else {
        poDataBlockLines1 = (VFKDataBlock *) m_poReader->GetDataBlock("OB");
        poDataBlockLines2 = (VFKDataBlock *) m_poReader->GetDataBlock("SBP");
        bIsPar = FALSE;
    }
    if (NULL == poDataBlockLines1 || NULL == poDataBlockLines2) {
        CPLError(CE_Failure, CPLE_NotSupported, 
                 "Data block %s not found.\n", m_pszName);
        return nInvalid;
    }
    
    poDataBlockLines1->LoadGeometry();
    poDataBlockLines2->LoadGeometry();
    idxId = GetPropertyIndex("ID");
    if (idxId < 0) {
        CPLError(CE_Failure, CPLE_NotSupported, 
                 "Corrupted data (%s).\n", m_pszName);
        return nInvalid;
    }
    
    if (bIsPar) {
        idxPar1 = poDataBlockLines1->GetPropertyIndex("PAR_ID_1");
        idxPar2 = poDataBlockLines1->GetPropertyIndex("PAR_ID_2");
        if (idxPar1 < 0 || idxPar2 < 0) {
            CPLError(CE_Failure, CPLE_NotSupported, 
                     "Corrupted data (%s).\n", m_pszName);
            return nInvalid;
        }
    }
    else { /* BUD */
        idxIdOb  = poDataBlockLines1->GetPropertyIndex("ID");
        idxBud = poDataBlockLines1->GetPropertyIndex("BUD_ID");
        idxOb  = poDataBlockLines2->GetPropertyIndex("OB_ID");
        if (idxIdOb < 0 || idxBud < 0 || idxOb < 0) {
            CPLError(CE_Failure, CPLE_NotSupported, 
                     "Corrupted data (%s).\n", m_pszName);
            return nInvalid;
        }
    }
    
    for (int i = 0; i < ((IVFKDataBlock *) this)->GetFeatureCount(); i++) {
        poFeature = (VFKFeature *) GetFeatureByIndex(i);
        id = strtoul(poFeature->GetProperty(idxId)->GetValueS(), NULL, 0);
        if (bIsPar) {
            poLineList = poDataBlockLines1->GetFeatures(idxPar1, idxPar2, id);
        }
        else {
            VFKFeature *poLineOb, *poLineSbp;
            std::vector<VFKFeature *> poLineListOb;
            poLineListOb = poDataBlockLines1->GetFeatures(idxBud, id);
            for (std::vector<VFKFeature *>::const_iterator iOb = poLineListOb.begin(), eOb = poLineListOb.end();
                 iOb != eOb; ++iOb) {
                poLineOb = (*iOb);
                idOb = strtoul(poLineOb->GetProperty(idxIdOb)->GetValueS(), NULL, 0);
                poLineSbp = poDataBlockLines2->GetFeature(idxOb, idOb);
                if (poLineSbp)
                    poLineList.push_back(poLineSbp);
            }
        }
        if (poLineList.size() < 1)
            continue;
        
        /* clear */
        ogrPolygon.empty();
        poRingList.clear();
        
        /* collect rings (points) */
        bFound = FALSE;
        nCount = 0;
        nCountMax = poLineList.size() * 2;
        while (poLineList.size() > 0 && nCount < nCountMax) {
            bNewRing = !bFound ? TRUE : FALSE;
            bFound = FALSE;
            for (VFKFeatureList::iterator iHp = poLineList.begin(), eHp = poLineList.end();
                 iHp != eHp; ++iHp) {
                const OGRLineString *pLine = (OGRLineString *) (*iHp)->GetGeometry();
                if (pLine && AppendLineToRing(&poRingList, pLine, bNewRing)) {
                    bFound = TRUE;
                    poLineList.erase(iHp);
                    break;
                }
            }
            nCount++;
        }
        /* create rings */
        for (PointListArray::const_iterator iRing = poRingList.begin(), eRing = poRingList.end();
             iRing != eRing; ++iRing) {
            PointList *poList = *iRing;
            ogrRing.empty();
            for (PointList::iterator iPoint = poList->begin(), ePoint = poList->end();
                 iPoint != ePoint; ++iPoint) {
                ogrRing.addPoint(&(*iPoint));
            }
            ogrPolygon.addRing(&ogrRing);
        }
        /* set polygon */
        ogrPolygon.setCoordinateDimension(2); /* force 2D */
        if (!poFeature->SetGeometry(&ogrPolygon))
            nInvalid++;
    }
    
    /* free ring list */
    for (PointListArray::iterator iRing = poRingList.begin(),
             eRing = poRingList.end(); iRing != eRing; ++iRing) {
        delete (*iRing);
        *iRing = NULL;
    }
    poDataBlockLines1->ResetReading();
    poDataBlockLines2->ResetReading();

    return nInvalid;
}
示例#8
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;
}