I have an application that allows the user to add a point (in this case, pipe breaks) and snap to a line (water main). I have been asked to pre-populate one of the attributes in the point feature with the same attribute from the line that it is snapped to. Simple enough, theoretically, yet complicated, I believe, programmatically. I should also mention that I am not a good programmer. I am also using the GitHub CMV template, but since this is so outside the realm of CMV, I did not post there. So, has anyone done this?

1 Answer 1


You are probably going to want to find either a good programmer or start reading and figuring out JS.

The basic way to do this would be to either find the feature being snapped to (might be a property of the event) or run a spatial query from the feature you added to find the nearest feature in the other layer (assume distance = 0). I do this in a .NET application and here is my process. In complete pseudocode/gibberish, by the way.

//typically I add things by clicking a point or something

//I handle my mouse click event, get the x/y (map or screen coordinates)

//create the new feature..you might already have it though

newFeature = new Point(x,y);

//find the feature(s) nearest -- depending on the query API if it returns a

//single or collection of features

nearFeatures = myJoiningLayer.GetFeaturesNearest(newFeature); //collection

nearFeature = myJoiningLayer.GetNearestFeature(newFeature);//single

//if there is a collection, you'll need to iterate through it to find the closest

//there might be a distance column add (some of ESRI tools do it)

//or there may be the need to individually compare each feature to the source

myJoiningFeature = ;//whatever process it takes to get a feature

//then you take your feature and move field values from one to the other

foreach (object value in myJoiningFeature.fieldValues){
newFeature.valueField = value;

//you'll have to determine how to access the mutator of this object

//save your feature and be done

This may be a lot of gibberish, but it should give you an idea of what process you need to take to get to the end. I have seen different APIs code things very differently. You'll probably find it easier to set up a geoprocessing service on your server (if you're hosting the data) and return either a new feature with the transferred values or some JSON that gets parsed and new values pulled from there and moved on the client side.

There are numerous options to get this done, too. While writing, I thought of taking the geometry from your new point and passing it back as an IdentifyTask of sorts and intercepting the return JSON (or some other data set) to be manually interpreted.

Overall, you might not be able to figure this out, and you might find it easier to just post-process the data (spatial join) to grab the attributes you want. I do it on the fly on my collection program because we need to establish that relationship up front instead of waiting, but your case may be different.

  • Thank you, Branco, for your response and sorry I am so late on the thanks.
    – slowe
    Commented Oct 19, 2015 at 13:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.