Creating Polyline Feature

4650
7
Jump to solution
03-31-2015 07:06 AM
KK2014
by
New Contributor III

I drawed polyline in my application but I can't create a new one in line layer.

Here is my code beolow:

CreateFeature.JPG

Here is my consol output below:

Create.JPG

Thanks.

0 Kudos
1 Solution

Accepted Solutions
KK2014
by
New Contributor III

Problem solved when I set symbolid value,line appeared on map.Because symbolid value was null.

   var feature = ArcGISRuntime.createObject("Feature");

feature.geometry = userPolyline;
feature.setAttributeValue("symbolid",'19');
offLineLayer.featureTable.addFeature(feature);

Thanks Lucas .

View solution in original post

0 Kudos
7 Replies
LucasDanzinger
Esri Frequent Contributor

I suggest you try something like the following:

var feature = ArcGISRuntime.createObject("Feature");
feature.geometry = userPolyline;
offlineLayer.featureTable.addFeature(feature);
0 Kudos
KK2014
by
New Contributor III

I changed my code like your code but polyline cannot created.Below is console output :

CapturePolyline.JPG

Thanks.

0 Kudos
LucasDanzinger
Esri Frequent Contributor

KK-

Can you please post your project, or a snippet that reproduces the issue?

Thanks,

Luke

0 Kudos
KK2014
by
New Contributor III

Hi,

Here is the project below:

// Copyright 2015 ESRI

//

// All rights reserved under the copyright laws of the United States

// and applicable international laws, treaties, and conventions.

//

// You may freely redistribute and use this sample code, with or

// without modification, provided you include the original copyright

// notice and use restrictions.

//

// See the Sample code usage restrictions document for further information.

//

import QtQuick 2.0

import QtQuick.Dialogs 1.2

import QtQuick.Layouts 1.1

import QtQuick.Window 2.0

import ArcGIS.Runtime.Toolkit.Dialogs 1.0

import ArcGIS.Runtime.Toolkit.Controls 1.0

import QtQuick 2.3

import QtQuick.Controls 1.2

import QtQuick.Controls.Styles 1.2

import ArcGIS.Extras 1.0

import ArcGIS.Runtime 10.25

ApplicationWindow {

    id: appWindow

    width: 800

    height: 600

    title: "OfflinePolygonEditing"

    property double scaleFactor: System.displayScaleFactor

    property bool firstPoint: true

    property bool firstLinePoint: true

    property bool createPoint: false

    property bool isDone: false

    property int  polyGraphicId

    property int  lineGraphicId

    property int fontSize: 15 * scaleFactor

    property bool isOnline: true

    property string featuresUrl: "http://sampleserver6.arcgisonline.com/arcgis/rest/services/Sync/WildfireSync/FeatureServer"

    property string gdbPath: "~/ArcGIS/Runtime/Data/Test/offlineSample.geodatabase"

    property var selectedFeatureId: null

    property var xProp: null

    property var yProp: null

    Envelope

    {

      id: sfExtent

           xMin: 1930934.6938406308          //turkey

           yMin: 3850498.260784086

           xMax: 5912392.6567565575

           yMax: 5564737.105928443

       spatialReference: mainMap.spatialReference

    }

    Map {

         id: mainMap

         anchors.fill: parent

         extent: sfExtent

         focus: true

         ArcGISTiledMapServiceLayer {

             url: "http://services.arcgisonline.com/ArcGIS/rest/services/Canvas/World_Light_Gray_Base/MapServer"

                  }

         FeatureLayer

         {

            id: offLineLayer

            featureTable: appWindow.isOnline ? featureServiceTable : local

            selectionColor: "cyan"

         }

         GraphicsLayer {

             id: graphicsLayer

         }

         onStatusChanged: {

             if (status === Enums.MapStatusReady) {

             }

         }

         onMouseClicked: {

             if (isDone)

             {

                 return;

             }

             if(createPoint)

             {

               addLinePoint(mouse.mapPoint);

             }

             else

             {

                addPoint(mouse.mapPoint);

             }

         }

     }

//END MAP

    GeodatabaseFeatureTable {

        id: local

        geodatabase: gdb.valid ? gdb : null

        featureServiceLayerId: 0

    }

    GeodatabaseFeatureServiceTable {

        id: featureServiceTable

        url: featuresUrl + "/1"

    }

    ServiceInfoTask {

        id: serviceInfoTask

        url: featuresUrl

        onFeatureServiceInfoStatusChanged:{

            if (featureServiceInfoStatus === Enums.FeatureServiceInfoStatusCompleted)

            {

                statusText.text = "Servis bilgisi alındı.Çalışma Alanı çizimini yapın";

            }

            else if (featureServiceInfoStatus === Enums.FeatureServiceInfoStatusErrored) {

                 statusText.text = "Error:";

                generateButton.enabled = false;

                cancelButton.text = "Start Over";

            }

        }

    }

    Feature {

        id: featureToEdit

    }

    Rectangle {

        anchors {

            fill: controlsColumn

            margins: -10 * scaleFactor

        }

        color: "lightgrey"

        radius: 5 * scaleFactor

        border.color: "black"

        opacity: 0.77

        MouseArea {

            anchors.fill: parent

            onClicked: (mouse.accepted = true)

        }

    }

    Column {

        id: controlsColumn

        anchors {

            left: parent.left

            top: parent.top

            margins: 20 * scaleFactor

        }

        spacing: 7

        Row {

            id: row

            spacing: 10 * scaleFactor

        }

        Button {

            id:silButton

            text: "Çalışma Alanı Sil"

            enabled: false

            width: generateButton.width

            style: ButtonStyle {

                label: Text {

                    text: control.text

                    color: control.enabled ? "black" : "grey"

                    horizontalAlignment: Text.AlignHCenter

                }

            }

            onClicked: {

                if (userPolygon.pathCount > 0)

                    userPolygon.removePath(0);

                isDone = false;

                firstPoint = true;

                graphicsLayer.removeAllGraphics();

                generateButton.enabled=false;

            }

        }

        Button {

            id: generateButton

            text: "Geodatabase Oluştur"

            enabled: false

            style: ButtonStyle {

                label: Text {

                    text: control.text

                    color: control.enabled ? "black" : "grey"

                    horizontalAlignment: Text.AlignHCenter

                }

            }

            onClicked: {

                generateGeodatabaseParameters.initialize(serviceInfoTask.featureServiceInfo);

                generateGeodatabaseParameters.extent = userPolygon;

                generateGeodatabaseParameters.returnAttachments = false;

                statusText.text = "Starting generate geodatabase task";

                geodatabaseSyncTask.generateGeodatabase(generateGeodatabaseParameters, gdbPath);

            }

        }

        Button {

            id: syncButton

            text: "Sync"

            width: generateButton.width

            enabled: false

            style: generateButton.style

            onClicked: {

                enabled = false;

                geodatabaseSyncTask.syncGeodatabase(gdb.syncGeodatabaseParameters, gdb);

                statusText.text = "Starting sync task";

            }

        }

        Button {

            id: cancelButton

            text: "İptal"

            width: generateButton.width

            enabled: false

            style: generateButton.style

            onClicked: {

                geodatabaseSyncTask.cancelJob(syncStatusInfo);

                enabled = false;

                text = "İptal";

            }

        }

        Row {

            id: toggleOnlineOffline

            spacing: 10

            Text {

                id: onlineStatus

                text: appWindow.isOnline ? "  Online " : "  Offline "

                color: "black"

            }

            Switch {

                id: switchToggle

                checked: appWindow.isOnline

                enabled: false

                onCheckedChanged: {

                    appWindow.isOnline = checked;

                    if (checked === true && Enums.GenerateStatusCompleted)

                        statusText.text = "Switch to Offline Mode to continue editing.";

                    else if (checked === false && Enums.GenerateStatusCompleted)

                        statusText.text = "Select a feature.";

                }

            }

        }

    }

    Geodatabase {

        id: gdb

        path: geodatabaseSyncTask.geodatabasePath

        onValidChanged: {

            if (valid) {

                var gdbtables = gdb.geodatabaseFeatureTables;

                for(var i in gdbtables) {

                    console.log (gdbtables.featureServiceLayerName);

                }

            }

        }

    }

    GeodatabaseSyncStatusInfo {

        id: syncStatusInfo

    }

    GeodatabaseSyncTask {

        id: geodatabaseSyncTask

        url: featuresUrl

        onGenerateStatusChanged: {

            if (generateStatus === Enums.GenerateStatusCompleted)

            {

                statusText.text = geodatabasePath;

                cancelButton.enabled = false;

                generateButton.enabled = false;

                appWindow.isOnline = false;

                statusText.text = "Feature Oluştur";

                createPoint= true;

            }

            else if (generateStatus === GeodatabaseSyncTask.GenerateError)

            {

                statusText.text = "Error: " + generateGeodatabaseError.message + " Code= "  + generateGeodatabaseError.code.toString() + " "  + generateGeodatabaseError.details;

                generateButton.enabled = false;

                cancelButton.text = "Start Over";

            }

        }

        onGeodatabaseSyncStatusInfoChanged: {

            if (geodatabaseSyncStatusInfo.status === Enums.GeodatabaseStatusUploadingDelta) {

                var deltaProgress = geodatabaseSyncStatusInfo.deltaUploadProgress/1000;

                var deltaSize = geodatabaseSyncStatusInfo.deltaSize/1000;

                statusText.text = geodatabaseSyncStatusInfo.statusString + " " + String(deltaProgress) + " of " + String(deltaSize) + " KBs...";

            } else

                statusText.text = geodatabaseSyncStatusInfo.statusString + "...";

            if (geodatabaseSyncStatusInfo.status !== GeodatabaseSyncStatusInfo.Cancelled)

                cancelButton.enabled = true;

            syncStatusInfo.json = geodatabaseSyncStatusInfo.json;

        }

        onSyncStatusChanged: {

            featureServiceTable.refreshFeatures();

            if (syncStatus === Enums.SyncStatusCompleted) {

                cancelButton.enabled = false;

                syncButton.enabled = false;

                statusText.text = "Sync tamamlandı.Feature editlemeye devam edebilirsin.";

                switchToggle.enabled = true;

            }

            if (syncStatus === Enums.SyncStatusErrored)

                statusText.text = "Error: " + syncGeodatabaseError.message + " Code= "  + syncGeodatabaseError.code.toString() + " "  + syncGeodatabaseError.details;

        }

    }

    GenerateGeodatabaseParameters {

        id: generateGeodatabaseParameters

    }

    Rectangle {

        id: textStatusRectangle

        anchors {

            fill: statusText

            margins: -10 * scaleFactor

        }

        visible: statusText.text.length > 0

        color: "lightgrey"

        radius: 5

        border.color: "black"

        opacity: 0.77

    }

    Text {

        id: statusText

        anchors {

            left: parent.left

            right: parent.right

            bottom: parent.bottom

            margins: 20 * scaleFactor

        }

        wrapMode: Text.WordWrap

        color: "black"

    }

    Component.onCompleted:

    {

        statusText.text = "Getting service info";

        serviceInfoTask.fetchFeatureServiceInfo();

    }

     Polygon {

         id: userPolygon

         spatialReference: mainMap.spatialReference

     }

     Polyline {

         id: userPolyline

         spatialReference: mainMap.spatialReference

     }

     Graphic {

         id: redPointGraphic

         symbol: SimpleMarkerSymbol {

             color: "red"

             style: Enums.SimpleMarkerSymbolStyleCircle

             size: 5

         }

     }

     Graphic {

         id: polygonGraphic

         symbol: SimpleFillSymbol {

             color: Qt.rgba(0.5, 0, 0.0, 0.25)

             outline:  SimpleLineSymbol {

                 color: "red"

                 style: Enums.SimpleLineSymbolStyleSolid

                 width: 2

             }

         }

     }

     Graphic {

         id: blueLineGraphic

         symbol: SimpleLineSymbol {

             color: "blue"

             style: Enums.SimpleLineSymbolStyleSolid

             width: 5

         }

     }

     Graphic {

         id: bluePointGraphic

         symbol: SimpleMarkerSymbol {

             color: "blue"

             style: Enums.SimpleMarkerSymbolStyleCircle

             size: 5

         }

     }

     function addPoint(mapPoint) {

         var newPoint = redPointGraphic.clone();

         newPoint.geometry = mapPoint;

         graphicsLayer.addGraphic(newPoint);

         var graphicClone = polygonGraphic.clone();

         if (firstPoint) {

             firstPoint = false;

             userPolygon.startPath(mapPoint.x, mapPoint.y);

             graphicClone.geometry = userPolygon;

             polyGraphicId = graphicsLayer.addGraphic(graphicClone);

         } else {

             userPolygon.lineTo(mapPoint.x, mapPoint.y);

             graphicClone.geometry = userPolygon;

             graphicsLayer.updateGraphic(polyGraphicId, graphicClone);

             if (userPolygon.pointCount > 2)

             {

                 silButton.enabled = true

                 generateButton.enabled = true;//tener ekledi

                 statusText.text = "Geodatabase Oluştur Buttonuna basın";//eski

             }

         }

     }

     function addLinePoint(mapPoint)

     {

         var newPoint = bluePointGraphic.clone();

         newPoint.geometry = mapPoint;

         var graphicClone;

        graphicsLayer.addGraphic(newPoint);

        graphicClone = blueLineGraphic.clone();

        if (firstLinePoint) {

           firstLinePoint = false;

           userPolyline.startPath(mapPoint.x, mapPoint.y);

           graphicClone.geometry = userPolyline;

           lineGraphicId = graphicsLayer.addGraphic(graphicClone);

          } else {

           userPolyline.lineTo(mapPoint.x, mapPoint.y);

           graphicClone.geometry = userPolyline;

           graphicsLayer.updateGraphic(lineGraphicId, graphicClone);

           loadLayerColumn.visible = true;

        }

     }

     Rectangle {

         anchors.fill: parent

         color: "transparent"

         border {

             width: 0.5 * scaleFactor

             color: "black"

         }

     }

     Rectangle {

         color: "lightgrey"

         radius: 5

         border.color: "black"

         opacity: 0.77

         visible: loadLayerColumn.visible

         anchors {

             fill: loadLayerColumn

             margins: -10 * scaleFactor

         }

     }

     ColumnLayout {

         id: loadLayerColumn

         anchors {

             left: parent.left

             bottom: parent.bottom

             right: parent.right

             margins: 20 * scaleFactor

         }

         spacing: 10

         visible: false

         Text {

             text: "Descrption özellik değerini gir"

         }

         TextField {

             id: featureTextField

             Layout.fillWidth: true

             visible:true

             text: "Özellik Değeri"

         }

         Row {

             spacing: 10

             Button {

                 id: okButton

                 text: "Ok"

                 onClicked: {

                     messageDialog.text = "";

                     loadLayerColumn.visible = false;

                       var feature = ArcGISRuntime.createObject("Feature");

                       feature.geometry = userPolyline;

                       offLineLayer.featureTable.addFeature(feature);

                      syncButton.enabled = true;

                      statusText.text = "Feature Servise düzenlemeleri kaydetme için Sync butonuna bas";

                 }

                 MessageDialog

                 {

                     id: messageDialog

                     title: "Error"

                     icon: StandardIcon.Warning

                     modality: Qt.WindowModal

                     standardButtons: StandardButton.Ok

                 }

             }

             Button {

                 text: "İptal"

                 onClicked: loadLayerColumn.visible = false

             }

         }

     }

}

0 Kudos
LucasDanzinger
Esri Frequent Contributor

I didn't debug the whole thing, but I think the reason you are getting this failure debug message is because your feature table is for layer id "0" in the feature service, which is a point, and you are trying to add in a polyline to that feature table. It doesn't match the correct geometry, so it is rejecting the addFeature() call. I recommend switching the GeodatabaseFeatureTable and the GeodatabaseFeatureServiceTable both be 1.

-Luke

0 Kudos
KK2014
by
New Contributor III

I updated the GeodatabaseFeatureTable and the GeodatabaseFeatureServiceTable both to 1, but can't create polyline.

Thanks.

0 Kudos
KK2014
by
New Contributor III

Problem solved when I set symbolid value,line appeared on map.Because symbolid value was null.

   var feature = ArcGISRuntime.createObject("Feature");

feature.geometry = userPolyline;
feature.setAttributeValue("symbolid",'19');
offLineLayer.featureTable.addFeature(feature);

Thanks Lucas .

0 Kudos