Exemplo n.º 1
0
OGRErr GMLHandler::startElementDefault(const char *pszName, int nLenName, void* attr )

{
/* -------------------------------------------------------------------- */
/*      Is it a feature?  If so push a whole new state, and return.     */
/* -------------------------------------------------------------------- */
    int nClassIndex;
    if( (nClassIndex = m_poReader->GetFeatureElementIndex( pszName, nLenName )) != -1 )
    {
        const char* pszFilteredClassName = m_poReader->GetFilteredClassName();
        if ( pszFilteredClassName != NULL &&
             strcmp(pszName, pszFilteredClassName) != 0 )
        {
            m_nDepthFeature = m_nDepth;

            PUSH_STATE(STATE_IGNORED_FEATURE);

            return OGRERR_NONE;
        }
        else
        {
            m_poReader->PushFeature( pszName, GetFID(attr), nClassIndex );

            m_nDepthFeature = m_nDepth;

            PUSH_STATE(STATE_FEATURE);

            return OGRERR_NONE;
        }
    }

    else if( nLenName == 9 && strcmp(pszName, "boundedBy") == 0 )
    {
        m_inBoundedByDepth = m_nDepth;

        PUSH_STATE(STATE_BOUNDED_BY);

        return OGRERR_NONE;
    }

/* -------------------------------------------------------------------- */
/*      Push the element onto the current state's path.                 */
/* -------------------------------------------------------------------- */
    m_poReader->GetState()->PushPath( pszName, nLenName );

    return OGRERR_NONE;
}
Exemplo n.º 2
0
OGRBoolean OGRFeature::Equal( OGRFeature * poFeature )

{
    if( poFeature == this )
        return TRUE;

    if( GetFID() != poFeature->GetFID() )
        return FALSE;
    
    if( GetDefnRef() != poFeature->GetDefnRef() )
        return FALSE;

    //notdef: add testing of attributes at a later date.

    if( GetGeometryRef() != NULL
        && (!GetGeometryRef()->Equal( poFeature->GetGeometryRef() ) ) )
        return FALSE;

    return TRUE;
}
Exemplo n.º 3
0
void OGRFeature::DumpReadable( FILE * fpOut )

{
    fprintf( fpOut, "OGRFeature(%s):%ld\n", poDefn->GetName(), GetFID() );
    for( int iField = 0; iField < GetFieldCount(); iField++ )
    {
        OGRFieldDefn    *poFDefn = poDefn->GetFieldDefn(iField);
        
        fprintf( fpOut, "  %s (%s) = ",
                 poFDefn->GetNameRef(),
                 OGRFieldDefn::GetFieldTypeName(poFDefn->GetType()) );

        if( IsFieldSet( iField ) )
            fprintf( fpOut, "%s\n", GetFieldAsString( iField ) );
        else
            fprintf( fpOut, "(null)\n" );
            
    }
    
    if( poGeometry != NULL )
        poGeometry->dumpReadable( fpOut, "  " );

    fprintf( fpOut, "\n" );
}
Exemplo n.º 4
0
OGRErr GMLHandler::startElement(const char *pszName, void* attr )

{
    GMLReadState *poState = m_poReader->GetState();

    if (m_bIgnoreFeature && m_nDepth >= m_nDepthFeature)
    {
        m_nDepth ++;
        return CE_None;
    }

    if ( m_nDepth == 0 )
    {
        if (strcmp(pszName, "CityModel") == 0 )
        {
            m_bIsCityGML = TRUE;
        }
        else if (strcmp(pszName, "AIXMBasicMessage") == 0)
        {
            m_bIsAIXM = m_bReportHref = TRUE;
        }
    }
    else if ( m_nDepth == 2 && m_bInBoundedBy )
    {
        if ( strcmp(pszName, "Envelope") == 0 )
        {
            char* pszGlobalSRSName = GetAttributeValue(attr, "srsName");
            if (pszGlobalSRSName != NULL &&
                strncmp(pszGlobalSRSName, "EPSG:", 5) == 0 &&
                CSLTestBoolean(CPLGetConfigOption("GML_CONSIDER_EPSG_AS_URN", "NO")))
            {
                char* pszNew = CPLStrdup(CPLSPrintf("urn:ogc:def:crs:EPSG::%s", pszGlobalSRSName+5));
                CPLFree(pszGlobalSRSName);
                pszGlobalSRSName = pszNew;
            }
            m_poReader->SetGlobalSRSName(pszGlobalSRSName);
            CPLFree(pszGlobalSRSName);
        }
    }

/* -------------------------------------------------------------------- */
/*      If we are in the midst of collecting a feature attribute        */
/*      value, then this must be a complex attribute which we don't     */
/*      try to collect for now, so just terminate the field             */
/*      collection.                                                     */
/* -------------------------------------------------------------------- */
    if( m_pszCurField != NULL )
    {
        CPLFree( m_pszCurField );
        m_pszCurField = NULL;
    }

    if ( m_bInCityGMLGenericAttr )
    {
        if( strcmp(pszName, "value") == 0 )
        {
            CPLFree( m_pszCurField );
            m_pszCurField = CPLStrdup("");
        }
    }

/* -------------------------------------------------------------------- */
/*      If we are collecting geometry, or if we determine this is a     */
/*      geometry element then append to the geometry info.              */
/* -------------------------------------------------------------------- */
    else if( poState->m_poFeature != NULL &&
             (m_pszGeometry != NULL
              || IsGeometryElement( pszName )
              || (m_bIsAIXM && strcmp( pszName, "ElevatedPoint") == 0)) )
    {
        int bReadGeometry;

        if( m_pszGeometry == NULL )
        {
            /* If the <GeometryElementPath> is defined in the .gfs, use it */
            /* to read the appropriate geometry element */
            const char* pszGeometryElement = (poState->m_poFeature) ?
                    poState->m_poFeature->GetClass()->GetGeometryElement() : NULL;
            if (pszGeometryElement != NULL)
                bReadGeometry = strcmp(poState->m_pszPath, pszGeometryElement) == 0;
            else
            {
                /* AIXM special case: for RouteSegment, we only want to read Curve geometries */
                /* not 'start' and 'end' geometries */
                if (m_bIsAIXM &&
                    strcmp(poState->m_poFeature->GetClass()->GetName(), "RouteSegment") == 0)
                    bReadGeometry = strcmp( pszName, "Curve") == 0;
                else
                    bReadGeometry = TRUE;
            }
            CPLAssert(m_nGeometryDepth == 0);
            m_nGeometryDepth = m_nDepth;
        }
        else
            bReadGeometry = TRUE;

        if (bReadGeometry)
        {
            char* pszAttributes = GetAttributes(attr);
            size_t nLNLenBytes = strlen(pszName);

            /* Some CityGML lack a srsDimension="3" in posList, such as in */
            /* http://www.citygml.org/fileadmin/count.php?f=fileadmin%2Fcitygml%2Fdocs%2FFrankfurt_Street_Setting_LOD3.zip */
            /* So we have to add it manually */
            if (m_bIsCityGML && strcmp(pszName, "posList") == 0 &&
                strstr(pszAttributes, "srsDimension") == NULL)
            {
                CPLFree(pszAttributes);
                pszAttributes = CPLStrdup(" srsDimension=\"3\"");
            }

            if( m_nGeomLen + nLNLenBytes + 4 + strlen( pszAttributes ) >
                m_nGeomAlloc )
            {
                m_nGeomAlloc = (size_t) (m_nGeomAlloc * 1.3 + nLNLenBytes + 1000 +
                                    strlen( pszAttributes ));
                char* pszNewGeometry = (char *)
                    VSIRealloc( m_pszGeometry, m_nGeomAlloc);
                if (pszNewGeometry == NULL)
                {
                    CPLFree(pszAttributes);
                    return CE_Failure;
                }
                m_pszGeometry = pszNewGeometry;
            }

            strcpy( m_pszGeometry+m_nGeomLen++, "<" );
            strcpy( m_pszGeometry+m_nGeomLen, pszName );
            m_nGeomLen += nLNLenBytes;
            /* saving attributes */
            strcat( m_pszGeometry + m_nGeomLen, pszAttributes );
            m_nGeomLen += strlen( pszAttributes );
            CPLFree(pszAttributes);
            strcat( m_pszGeometry + (m_nGeomLen++), ">" );
        }
    }

    else if (m_nGeometryDepth != 0 && m_nDepth > m_nGeometryDepth)
    {
        ;
    }

    else if( m_bInBoundedBy)
    {
        ;
    }

/* -------------------------------------------------------------------- */
/*      Is it a feature?  If so push a whole new state, and return.     */
/* -------------------------------------------------------------------- */
    else if( m_nDepthFeature == 0 &&
             m_poReader->IsFeatureElement( pszName ) )
    {
        const char* pszFilteredClassName = m_poReader->GetFilteredClassName();
        if ( pszFilteredClassName != NULL &&
             strcmp(pszName, pszFilteredClassName) != 0 )
        {
            m_bIgnoreFeature = TRUE;
            m_nDepthFeature = m_nDepth;
            m_nDepth ++;

            return CE_None;
        }

        m_bIgnoreFeature = FALSE;

        char* pszFID = GetFID(attr);

        m_poReader->PushFeature( pszName, pszFID);

        CPLFree(pszFID);

        m_nDepthFeature = m_nDepth;
        m_nDepth ++;

        return CE_None;
    }

    else if( strcmp(pszName, "boundedBy") == 0 )
    {
        m_bInBoundedBy = TRUE;
        m_inBoundedByDepth = m_nDepth;
    }

/* -------------------------------------------------------------------- */
/*      Is it a CityGML generic attribute ?                             */
/* -------------------------------------------------------------------- */
    else if( m_poReader->IsCityGMLGenericAttributeElement( pszName, attr ) )
    {
        m_bInCityGMLGenericAttr = TRUE;
        CPLFree(m_pszCityGMLGenericAttrName);
        m_pszCityGMLGenericAttrName = GetAttributeValue(attr, "name");
        m_inCityGMLGenericAttrDepth = m_nDepth;
    }

/* -------------------------------------------------------------------- */
/*      If it is (or at least potentially is) a simple attribute,       */
/*      then start collecting it.                                       */
/* -------------------------------------------------------------------- */
    else if( m_poReader->IsAttributeElement( pszName ) )
    {
        CPLFree( m_pszCurField );
        m_pszCurField = CPLStrdup("");
        if (m_bReportHref)
        {
            CPLFree(m_pszHref);
            m_pszHref = GetAttributeValue(attr, "xlink:href");
        }
        CPLFree(m_pszUom);
        m_pszUom = GetAttributeValue(attr, "uom");
        CPLFree(m_pszValue);
        m_pszValue = GetAttributeValue(attr, "value");
    }
    else if( m_bReportHref && m_poReader->IsAttributeElement( CPLSPrintf("%s_href", pszName ) ) )
    {
        CPLFree( m_pszCurField );
        m_pszCurField = CPLStrdup("");
        CPLFree(m_pszHref);
        m_pszHref = GetAttributeValue(attr, "xlink:href");
    }

/* -------------------------------------------------------------------- */
/*      Push the element onto the current state's path.                 */
/* -------------------------------------------------------------------- */
    poState->PushPath( pszName );

    m_nDepth ++;

    return CE_None;
}
Exemplo n.º 5
0
OGRErr GMLHandler::startElement(const char *pszName, void* attr )

{
    GMLReadState *poState = m_poReader->GetState();

    int nLNLenBytes = strlen(pszName);

/* -------------------------------------------------------------------- */
/*      If we are in the midst of collecting a feature attribute        */
/*      value, then this must be a complex attribute which we don't     */
/*      try to collect for now, so just terminate the field             */
/*      collection.                                                     */
/* -------------------------------------------------------------------- */
    if( m_pszCurField != NULL )
    {
        CPLFree( m_pszCurField );
        m_pszCurField = NULL;
    }

/* -------------------------------------------------------------------- */
/*      If we are collecting geometry, or if we determine this is a     */
/*      geometry element then append to the geometry info.              */
/* -------------------------------------------------------------------- */
    if( m_pszGeometry != NULL 
        || IsGeometryElement( pszName ) )
    {
        /* should save attributes too! */

        if( m_pszGeometry == NULL )
            m_nGeometryDepth = poState->m_nPathLength;
        
        char* pszAttributes = GetAttributes(attr);

        if( m_nGeomLen + nLNLenBytes + 4 + strlen( pszAttributes ) >
            m_nGeomAlloc )
        {
            m_nGeomAlloc = (int) (m_nGeomAlloc * 1.3 + nLNLenBytes + 1000 +
                                  strlen( pszAttributes ));
            char* pszNewGeometry = (char *) 
                VSIRealloc( m_pszGeometry, m_nGeomAlloc);
            if (pszNewGeometry == NULL)
            {
                CPLFree(pszAttributes);
                return CE_Failure;
            }
            m_pszGeometry = pszNewGeometry;
        }

        strcpy( m_pszGeometry+m_nGeomLen++, "<" );
        strcpy( m_pszGeometry+m_nGeomLen, pszName );
        m_nGeomLen += nLNLenBytes;
        /* saving attributes */
        strcat( m_pszGeometry + m_nGeomLen, pszAttributes );
        m_nGeomLen += strlen( pszAttributes );
        CPLFree(pszAttributes);
        strcat( m_pszGeometry + (m_nGeomLen++), ">" );
    }
    
/* -------------------------------------------------------------------- */
/*      Is it a feature?  If so push a whole new state, and return.     */
/* -------------------------------------------------------------------- */
    else if( m_poReader->IsFeatureElement( pszName ) )
    {
        char* pszFID = GetFID(attr);

        m_poReader->PushFeature( pszName, pszFID);

        CPLFree(pszFID);

        m_nDepthFeature = m_nDepth;
        m_nDepth ++;

        return CE_None;
    }

/* -------------------------------------------------------------------- */
/*      If it is (or at least potentially is) a simple attribute,       */
/*      then start collecting it.                                       */
/* -------------------------------------------------------------------- */
    else if( m_poReader->IsAttributeElement( pszName ) )
    {
        CPLFree( m_pszCurField );
        m_pszCurField = CPLStrdup("");
    }

/* -------------------------------------------------------------------- */
/*      Push the element onto the current state's path.                 */
/* -------------------------------------------------------------------- */
    poState->PushPath( pszName );

    m_nDepth ++;

    return CE_None;
}
Exemplo n.º 6
0
BOOL CPropFile::PropPageProc( HWND hwnd, UINT uMessage, WPARAM wParam, LPARAM lParam )
{
    switch(uMessage)
    {
    case WM_INITDIALOG:
        {
            CPropFile * sheetpage = (CPropFile*) ((LPPROPSHEETPAGE) lParam)->lParam;
            SetWindowLongPtr (hwnd, GWLP_USERDATA, (LONG_PTR) sheetpage);
            sheetpage->SetHwnd(hwnd);
            AfxSetResourceHandle(m_hInst);

            CString sText;

            if (filenames.GetCount() <= 0) {

                ShowWindow(GetDlgItem(m_hwnd, IDC_REMOVEMOUNTPOINT), SW_HIDE);
                ShowWindow(GetDlgItem(m_hwnd, IDC_SYMLINK_LABEL), SW_HIDE);
                ShowWindow(GetDlgItem(m_hwnd, IDC_MOUNTPOINT_LABEL), SW_HIDE);
                EnableUnixMode(FALSE);

            }
            else if(filenames.GetCount() > 1) {
                // multiple items selected
                LoadString(sText, IDS_PROP_MULTIPLEITEMS);
                SetDlgItemText(hwnd, IDC_PROP_TYPE, sText);

                ShowWindow(GetDlgItem(m_hwnd, IDC_REMOVEMOUNTPOINT), SW_HIDE);
                ShowWindow(GetDlgItem(m_hwnd, IDC_SYMLINK_LABEL), SW_HIDE);
                ShowWindow(GetDlgItem(m_hwnd, IDC_MOUNTPOINT_LABEL), SW_HIDE);
                EnableUnixMode(FALSE);

                sText = GetCellName(filenames.GetAt(0), FALSE);
                m_cellName = sText;
                SetDlgItemText(hwnd, IDC_PROP_CELL, sText);

            } else {
                if (m_bIsMountpoint)
                    LoadString(sText, IDS_PROP_TYPEMOUNTPOINT);
                else if (m_bIsSymlink)
                    LoadString(sText, IDS_PROP_TYPESYMLINK);
                else if (m_bIsDir)
                    LoadString(sText, IDS_PROP_TYPEDIRECTORY);
                else
                    LoadString(sText, IDS_PROP_TYPEFILE);

                SetDlgItemText(hwnd, IDC_PROP_TYPE, sText);

                if (m_bIsMountpoint) {
                    ShowWindow(GetDlgItem(m_hwnd, IDC_REMOVEMOUNTPOINT), SW_SHOW);
                }
                if (!m_bIsSymlink) {
                    ShowWindow(GetDlgItem(m_hwnd, IDC_SYMLINK_LABEL), SW_HIDE);
                }
                if (!m_bIsMountpoint) {
                    ShowWindow(GetDlgItem(m_hwnd, IDC_MOUNTPOINT_LABEL), SW_HIDE);
                }

                if (!m_bIsMountpoint && !m_bIsSymlink) {
                    ShowWindow(GetDlgItem(m_hwnd, IDC_EDIT), SW_HIDE);
                }

                if (m_bIsSymlink) {
                    ShowWindow(GetDlgItem(m_hwnd, IDC_REMOVESYMLINK), SW_SHOW);
                }

                CString user, group, other, suid;
                EnableUnixMode(TRUE);
                GetUnixModeBits(filenames.GetAt(0), user, group, other, suid);
                ShowUnixMode(user, group, other, suid);

                SetDlgItemText(hwnd, IDC_PROP_FILENAME, filenames.GetAt(0));
                if (!GetFID(filenames.GetAt(0), sText, TRUE))
                    sText = _T("(unknown)");
                SetDlgItemText(hwnd, IDC_PROP_FID, sText);
                sText = GetOwner(filenames.GetAt(0));
                SetDlgItemText(hwnd, IDC_PROP_OWNER, sText);
                sText = GetGroup(filenames.GetAt(0));
                SetDlgItemText(hwnd, IDC_PROP_GROUP, sText);

                if (m_bIsMountpoint){
                    sText = GetMountpoint(filenames.GetAt(0));
                    sText = sText.Mid(sText.Find('\t')+1);
                    SetDlgItemText(hwnd, IDC_PROP_SMINFO, sText);
                }
                if (m_bIsSymlink){
                    sText = GetSymlink(filenames.GetAt(0));
                    sText = sText.Mid(sText.Find('\t')+1);
                    SetDlgItemText(hwnd, IDC_PROP_SMINFO, sText);
                }

                sText = GetCellName(filenames.GetAt(0));
                m_cellName = sText;
                SetDlgItemText(hwnd, IDC_PROP_CELL, sText);
            }
            return TRUE;
        }
        break;
    case WM_NOTIFY:
        {
            LPNMHDR point = (LPNMHDR)lParam;
            int code = point->code;
            BOOL bRet = FALSE;
            switch (code)
            {
            case PSN_APPLY:
                {
                    CString user, group, other, suid;
                    MakeUnixModeString(user, group, other, suid);
                    SetUnixModeBits(filenames, user, group, other, suid);
                    // Return PSNRET_NOERROR to allow the sheet to close if the user clicked OK.
                    SetWindowLongPtr(m_hwnd, DWLP_MSGRESULT, PSNRET_NOERROR);
                }
                break;
            }
            SetWindowLongPtr(m_hwnd, DWLP_MSGRESULT, FALSE);
            return bRet;
        }
        break;
    case WM_COMMAND:
        switch (HIWORD(wParam))
        {
        case BN_CLICKED:
            switch (LOWORD(wParam))
            {
            case IDC_FLUSH:
                Flush(filenames);
                return TRUE;
            case IDC_REMOVESYMLINK:
                {
                    int nChoice = ShowMessageBox(IDS_REALLY_REMOVE_SYMLINK, MB_ICONQUESTION | MB_YESNO, IDS_REALLY_REMOVE_SYMLINK);
                    if (nChoice == IDYES)
                        RemoveSymlink(filenames.GetAt(0));
                    return TRUE;
                }
            case IDC_REMOVEMOUNTPOINT:
                {
                    int nChoice = ShowMessageBox(IDS_REALLY_DEL_MOUNT_POINTS, MB_ICONQUESTION | MB_YESNO, IDS_REALLY_DEL_MOUNT_POINTS);
                    if (nChoice == IDYES)
                        RemoveMount(filenames);
                    return TRUE;
                }
            case IDC_EDIT:
                {
                    if (m_bIsMountpoint){
                        CMakeMountPointDlg dlg;
                        dlg.SetDir(filenames.GetAt(0));
                        dlg.SetCell(m_cellName);
                        dlg.SetVol(m_volName);
                        dlg.DoModal();
                    }
                    if (m_bIsSymlink){
                        CMakeSymbolicLinkDlg dlg;
                        CStringA msg(filenames.GetAt(0));
                        int i;
                        if ((i=msg.ReverseFind('\\'))>0)
                            msg=msg.Left(i+1);
                        else if ((i=msg.ReverseFind(':'))>0)
                            msg=msg.Left(i+1)+"\\";
                        dlg.Setbase(msg);
                        dlg.m_strDir = filenames.GetAt(0);
                        dlg.m_strName = GetSymlink(filenames.GetAt(0));
                        dlg.DoModal();
                    }
                }
            case IDC_ATTR_USER_READ:
            case IDC_ATTR_USER_WRITE:
            case IDC_ATTR_USER_EXECUTE:
            case IDC_ATTR_GROUP_READ:
            case IDC_ATTR_GROUP_WRITE:
            case IDC_ATTR_GROUP_EXECUTE:
            case IDC_ATTR_OTHER_READ:
            case IDC_ATTR_OTHER_WRITE:
            case IDC_ATTR_OTHER_EXECUTE:
                SendMessage(GetParent(m_hwnd), PSM_CHANGED, (WPARAM)m_hwnd, 0);     // enable the "apply" button
                return TRUE;
            }
            break;
        }
        break;
    }

    return FALSE;
}