Add layer from geodatabase file

419
14
Jump to solution
12-10-2019 06:50 AM
jaykapalczynski
Frequent Contributor

I created a geodatabase via ArcGIS Runtime Content in ArcMap.

I am trying to add it via this reference: Create an offline map—ArcGIS Runtime SDK for Qt | ArcGIS for Developers 

BUT map.addLayer does not exist or its giving me an error

Any ideas?

//Declare the geodatabase 
Geodatabase {
        id: geodatabase
        path: "/path_to_my_geodatabase/mydata.geodatabase"
    }

FeatureLayer {
        id: featureLayer
        featureTable: geodatabase.geodatabaseFeatureTableByLayerId(0);
    }

map.addLayer(featureLayer);
0 Kudos
1 Solution

Accepted Solutions
ErwinSoekianto
Esri Regular Contributor

Jay, 

Based on the sample Feature Layer (Geodatabase), 

- AppStudio Sample - arcgis-appstudio-samples/MyApp.qml at v4.0 · Esri/arcgis-appstudio-samples · GitHub 

- ArcGIS Runtime Qt/QML Sample - Feature layer (geodatabase) | ArcGIS for Developers 

You don't need to call addLayer if you initialize the FeatureLayer inside Map, that layer is already added. 

Looping in ArcGIS Runtime SDK for Qt‌, to see why addLayer is throwing an error. 

Thank you,

Erwin

View solution in original post

0 Kudos
14 Replies
jaykapalczynski
Frequent Contributor

Forgot to add I am using QML for AppStudio

0 Kudos
ErwinSoekianto
Esri Regular Contributor

Jay, 

Based on the sample Feature Layer (Geodatabase), 

- AppStudio Sample - arcgis-appstudio-samples/MyApp.qml at v4.0 · Esri/arcgis-appstudio-samples · GitHub 

- ArcGIS Runtime Qt/QML Sample - Feature layer (geodatabase) | ArcGIS for Developers 

You don't need to call addLayer if you initialize the FeatureLayer inside Map, that layer is already added. 

Looping in ArcGIS Runtime SDK for Qt‌, to see why addLayer is throwing an error. 

Thank you,

Erwin

0 Kudos
LucasDanzinger
Esri Frequent Contributor

There is no addLayer method on Map. Instead, you can nest the layer inside the Map like you mentioned, or you can call map.operationalLayers.append(), and add the layer via that method LayerListModel QML Type | ArcGIS for Developers .

0 Kudos
jaykapalczynski
Frequent Contributor

can I still reference the index of the gdb like this

featureTable: geodatabase.geodatabaseFeatureTableByLayerId(4);

OK going to test that now.  THANKS
0 Kudos
jaykapalczynski
Frequent Contributor

Think I got it...THANK YOU SO MUCH.....

Seems I could not use

featureTable: gdb.geodatabaseFeatureTableByLayerId(4);

But had to use

featureTable: gdb.geodatabaseFeatureTablesByTableName["WMAs_1"];

import QtQuick 2.6
import QtQuick.Controls 2.2
import QtQuick.Layouts 1.3
import Esri.ArcGISRuntime 100.6
//import Esri.ArcGISExtras 1.1

Rectangle {
    id: navigateOnline
    width: 800
    height: 600

    property string errorMessage: ""
    signal previous(string message)
    property string lecaDataPath:  app.mmpkManager.fileUrl3

    // Map view UI presentation at top
    MapView {
        anchors.fill: parent

        Rectangle{
            id: stupidrectangle
            width: 300
            height: 50
            Column{
                id: searchBar22
                width: 300
                spacing: 0

               Text {
                  text: lecaDataPath
                  width: 300
                  wrapMode: Text.WordWrap
               }
            }
        }

        Map {
            id: map

            // set an initial viewpoint
            ViewpointCenter {
                Point {
                    x: -8778929
                    y: 44521052
                    spatialReference: SpatialReference { wkid: 3857 }
                }
                targetScale: 35e4
            }

            BasemapTopographic {}

            //! [FeatureLayer Geodatabase create]
            // create a feature layer
            FeatureLayer {
                // obtain the feature table from the geodatabase by name
                //featureTable: gdb.geodatabaseFeatureTableByLayerId(4);
                featureTable: gdb.geodatabaseFeatureTablesByTableName["WMAs_1"]

                // create the geodatabase
                Geodatabase {
                    id: gdb
                    path: lecaDataPath
                    onErrorChanged: errorMessage = error.message;
                }
                onErrorChanged: errorMessage = error.message;
            }
            onErrorChanged: errorMessage = error.message;
        }
        onErrorChanged: errorMessage = error.message;
    }

    Dialog {
        modal: true
        x: Math.round(parent.width - width) / 2
        y: Math.round(parent.height - height) / 2
        standardButtons: Dialog.Ok
        visible: text.length > 0
        property alias text : textLabel.text
        property alias informativeText : detailsLabel.text
        ColumnLayout {
            Text {
                id: textLabel
                text: errorMessage
            }
            Text {
                id: detailsLabel
                text: "Please consult the README.md"
            }
        }
    }
}
0 Kudos
jaykapalczynski
Frequent Contributor

Any idea how to read this geodatabase and or get a list of the features that it contains?

0 Kudos
LucasDanzinger
Esri Frequent Contributor

You could loop through the geodatabaseFeatureTables list:

Geodatabase {
    id: gdb
    path: dataPath + "geodatabase/LA_Trails.geodatabase"

    onErrorChanged: console.log(error.message)

    onLoadStatusChanged: {
        if (loadStatus === Enums.LoadStatusLoaded) {
            console.log("number of feature tables:", geodatabaseFeatureTables.length)
            for (var i = 0; i < geodatabaseFeatureTables.length; i++) {
                var ft = geodatabaseFeatureTables[i];
                var fl = ArcGISRuntimeEnvironment.createObject("FeatureLayer", {featureTable: ft});
                map.operationalLayers.append(fl);
            }
        }
    }

    Component.onCompleted: load()
}
0 Kudos
jaykapalczynski
Frequent Contributor

So your example would read the geodatabase and create multiple Feature Layer objects to display the multiple features in the geodatabase?

0 Kudos
LucasDanzinger
Esri Frequent Contributor

yes that is what this example does.

0 Kudos