state names as lable on shape file from local repository

320
4
01-27-2020 05:08 AM
anshushrivastava
New Contributor II

Hello,

I am new in arcgis .I am trying to load shapefile with state names .I want to load state names from local file not online data .I have .shx,.shp.dbf and .geodatabase files in my system .Please give some solution

my code

void CTacticalViewClass::LoadingOfServiceFeatureFile()
{
        ServiceFeatureTable* servicefeatureTable = new ServiceFeatureTable(QUrl("https://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer/layers/2"), this);
        FeatureLayer* featureLayer = new FeatureLayer(servicefeatureTable, this);
        connect(featureLayer, &FeatureLayer::doneLoading, [this, featureLayer](Error e)
        {
          if (!e.isEmpty())
            return;

          m_mapShapeView->setViewpoint(Viewpoint(featureLayer->fullExtent().center(), 56759600));
        });

        m_Shapemap->operationalLayers()->append(featureLayer);

        // Apply labels to the feature layer
        const QString labelJson = createLabelJson();
        LabelDefinition* labelDef = LabelDefinition::fromJson(labelJson, this);
        featureLayer->labelDefinitions()->append(labelDef);
        featureLayer->setLabelsEnabled(true);

        m_mapShapeView->setMap(m_Shapemap);
}

ServiceFeatureTable will contain which kind of local file.

Aditya PeriAlexandra GajewskiAllen ThompsonJon FisknessGary ChryslerHuailin wang@

0 Kudos
4 Replies
LucasDanzinger
Esri Frequent Contributor
0 Kudos
anshushrivastava
New Contributor II

Thanku for reply.

I Have taken a look at the labeling sample  -arcgis-runtime-samples-qt/ShowLabelsOnLayers.cpp at master · Esri/arcgis-runtime-samples-qt · GitHub .

After code change  i am not able to get state names and  getting some error like this

Exception thrown in Feature_source_layer::Feature_source_layer_label_data_source::get_next_feature() - "SQL error or missing database" - "no such column: rte_num1"

which file i have to prefer for column name .shp, .shx or .dbf file

please check this code

void CTacticalViewClass::LoadingOfServiceFeatureFile()
{

    ShapefileFeatureTable* servicefeatureTable = new ShapefileFeatureTable("/home/GIS/Desktop/ChartEngineMainFolder/ChartEngine/ArcGIS/Runtime/Data/shp/India/india_st.shp", this);
    servicefeatureTable->load();

    FeatureLayer* featureLayer = new FeatureLayer(servicefeatureTable, this);

    connect(featureLayer, &FeatureLayer::doneLoading, [this, featureLayer](Error e)
    {
        if (!e.isEmpty())
            return;

        m_mapShapeView->setViewpoint(Viewpoint(featureLayer->fullExtent().center(), 56759600));
    });

    m_Shapemap->operationalLayers()->append(featureLayer);

    // Apply labels to the feature layer
    const QString labelJson = createLabelJson();
    LabelDefinition* labelDef = LabelDefinition::fromJson(labelJson, this);
    featureLayer->labelDefinitions()->append(labelDef);
    featureLayer->setLabelsEnabled(true);

}

QString CTacticalViewClass::createLabelJson() const
{
    return QString(QStringLiteral("{\"labelExpressionInfo\":{\"expression\":\"'I - ' + $feature.rte_num1\"},\"labelPlacement\":\"esriServerLinePlacementAboveAlong\",\"where\":\"rte_num1 <> ' '\",\"symbol\": {\"angle\":0,\"backgroundColor\":[0,0,0,0],\"borderLineColor\":[0,0,0,0],\"borderLineSize\":0,\"color\":[0,0,255,255],\"font\": {\"decoration\":\"none\",\"size\":15,\"style\":\"normal\",\"weight\":\"normal\"},\"haloColor\":[255,255,0,255],\"haloSize\":1.5,\"horizontalAlignment\":\"center\",\"kerning\":false,\"type\":\"esriTS\",\"verticalAlignment\":\"middle\",\"xoffset\":0,\"yoffset\":0}}"));
}

 

0 Kudos
LucasDanzinger
Esri Frequent Contributor

Do you have a column/field named "rte_num1"? The label json specifies that the label should be based on a field named "rte_num1" and use a where clause where that field isn't an empty string. The sample was setup to use this field but you should update it to match your data's schema.

0 Kudos
anshushrivastava
New Contributor II

hi,

    I understand what you want to tell.But My confusion is related to database file which will contain tables.I have India.shp , India.shx and India.dbf file.To Know column names which file i will use (India.shp, India.shx or India.dbf) or anyother file will be required .If possible can you give some example of your used shape file and database file.It will be more helpfull.

Thanku

0 Kudos