Select to view content in your preferred language

Combine line and point feature classes attributes

6069
22
Jump to solution
08-17-2015 08:15 AM
MathewSuran
Regular Contributor

I have a line feature class and point feature class in a gdb that is hosted on our server. 

I want to utilize these in a webapp using the REST url. 

I want to ultimately be able to only display a line feature and be able to select it to display both line and point attributes. 

After doing some searching, I think I need to create a relationship class in the gdb. 

Can anyone lend some expertise on best way to accomplish this?

0 Kudos
22 Replies
MathewSuran
Regular Contributor

I completely agree, thanks for the advise.  Can you elaborate on how to create views on the backend?  Im using MSSQL.

0 Kudos
sapnas
by
Frequent Contributor

this link might get you started

resources.arcgis.com/en/help/main/10.1/index.html#//006z00000039000000

0 Kudos
MathewSuran
Regular Contributor

Thanks for that.  How would I reference this view to plug-in to my webapp?

0 Kudos
sapnas
by
Frequent Contributor

Add view to your mxd and publish it as rest map service

0 Kudos
MathewSuran
Regular Contributor

Ok, will try first thing tomorrow.

0 Kudos
williamcarr
Frequent Contributor

Could you clarify on how the line and point are related?

From my understanding, you have a line and a point with a common field, then select a line and display the point attribute with the line attribute based on a similar field?

I have a few apps where I pull a single attribute from a feature I just selected. I use it to get water hydrant ID's when our service guys click on a hydrant.

hydrantRecord = evt.graphic.attributes.HydrantID;

This is how I pull the hydrant ID from a relationship query. Then I take this universal variable and plug it into my forms. It seems this would make your attribute data available for query later on.

Are you planning on using the attribute inspector, infowindow....?

MathewSuran
Regular Contributor

I have a similar field for both line and point features that specifies the location.  The similar field will only be used for location purposes.  When the line is selected, I want to display (in the form of a graph) the points elevation (Field name=Z) that relate to the same location of the line.  The line is basically the template for where the points should be taken.  Since displaying the location of the points is not important here, this is why I want to just display the line and have all of the points elevation data be referenced when it is selected.

I am looking for the best way to set this up in the gdb I am pulling the features from.  Whether it is creating a relationship class or what Sapna suggested above.

No need for the attribute inspector or infowindow, since the elevation data will be automatically populated in the line graph.

0 Kudos
williamcarr
Frequent Contributor

Ahhh.

here is the whole function that I use to pull an attribute from a feature.(Sorry I don't have time to clean it up or test it or figure out the necessary portions. .)

You could be able to extract that attribute, in this example 'hydrantRecord', and use it in your query.

If i get some more time I'll try to come up with a better tested example if I get some time today.

          map.on("click", function(evt) {

              var selectionQuery = new esri.tasks.Query();

        var tol = map.extent.getWidth()/map.width * 30;

        var x = evt.mapPoint.x;

        var y = evt.mapPoint.y;

        var queryExtent = new esri.geometry.Extent(x-tol,y-tol,x+tol,y+tol,evt.mapPoint.spatialReference);

        selectionQuery.geometry = queryExtent;

           

        asdf.selectFeatures(selectionQuery, FeatureLayer.SELECTION_NEW, function(features) {

            

               //store the current feature

                updateFeature = features[0]; console.log("adf");

                map.infoWindow.setTitle(features[0].getLayer().name); console.log("adf");

                map.infoWindow.show(evt.screenPoint,map.getInfoWindowAnchor(evt.screenPoint)); console.log("adf");

    

            });

          });

    var record = document.getElementById('record');

//add event listener

record.addEventListener('click', function(e3) {

  m5.on("click", lang.hitch(this, onLayerClick2));

    var relatedTable2 = new FeatureLayer("http:", {

        mode: FeatureLayer.MODE_ONDEMAND,

        outFields: ["*"],

        id: "relatedTable2"

    });

  console.log("Ran over the related table");

 

 

      relatedTable.on("load", lang.hitch(this, function () {

      console.log("RelatedTable Load");

        var layerInfos = [

        {

   

            'featureLayer': relatedTable2,

                'showAttachments': false,

                'isEditable': true,

                'fieldInfos': arrayUtils.map(relatedTable2.fields, function (field) {

                return {

                    'fieldName': field.name,

                        'isEditable': field.editable,

                        'tooltip': field.type,

                        'label': field.alias

                };

            })

        }         

        ];

       

        var attInspector = new AttributeInspector({

            layerInfos: layerInfos

        }, domConstruct.create("div"));

        attInspector.on("attribute-change", function (evt) {

            evt.feature.attributes[evt.fieldName] = evt.fieldValue;

            evt.feature.getLayer().applyEdits(null, [evt.feature], null);

        });

        attInspector.on("delete", function (evt) {

            evt.feature.getLayer().applyEdits(null, null, [evt.feature]);

            map.infoWindow.hide();

        });

        map.infoWindow.setContent(attInspector.domNode);

        map.infoWindow.resize(350, 400);

    }));

   

  console.log("Record start")

 

      function onLayerClick2(evt) {

   

            map.infoWindow.setTitle("Searching for related items...");

            map.infoWindow.show(evt.screenPoint, map.getInfoWindowAnchor(evt.screenPoint));

             

//-------------------this is what is pulling the attribute for querying

  //-------------------this is what is pulling the attribute for querying

  hydrantRecord = evt.graphic.attributes.HydrantID;

console.log(hydrantRecord);

  //-------------------this is what is pulling the attribute for querying

  //-------------------this is what is pulling the attribute for querying     

//Done pulling the valve ID           

var graphicAttributes = evt.graphic.attributes;

            var title = graphicAttributes[m5.displayField];

            var objectId = graphicAttributes[m5.objectIdField];

            var relatedQuery = new RelationshipQuery();

            relatedQuery.outFields = ["*"];

            relatedQuery.relationshipId = 5;

            relatedQuery.objectIds = [objectId];

console.log("relate found?");

console.log(relatedQuery.objectIds)

            m5.queryRelatedFeatures(relatedQuery, lang.hitch(this, function (relatedRecords) {

                var fset = relatedRecords[objectId];

                if (fset) {

                    map.infoWindow.setTitle(title || "No Title");

                    var relatedObjectIds = arrayUtils.map(fset.features, function (feature) {

                        return feature.attributes[relatedTable2.objectIdField];

                    });

                    var selectQuery = new Query();

                    selectQuery.objectIds = relatedObjectIds;

                    relatedTable2.selectFeatures(selectQuery, FeatureLayer.SELECTION_NEW);

console.log(feature.attributes)

                } else {

                    map.infoWindow.setTitle("No Related Items");

                }

            }));

       

    }

    });

0 Kudos
MathewSuran
Regular Contributor

Thanks.  Just to clarify, did you create a relationship class in your gdb?  How do you have your data set up?

0 Kudos
williamcarr
Frequent Contributor

Yes, I created a relationship in my MapService, but I don't think you will need one.

How did you initially planned to select the feature?

0 Kudos