VEX: comparing two sets

   4310   2   1
User Avatar
Member
2 posts
Joined: Sept. 2018
Offline
Hi all,

Complete VEX noob here, and I'm stuck with something that sounds like it probably shouldn't be too hard but I can't wrap my head around it. I'm trying to compare two sets of points with different point counts based on an existing sequential attribute (let's call it @seq). Where they don't have a match, I'd like to delete the non-matching point.

For example:
First set, six points with @seq: 1 2 3 4 5 6
Second set, three points with @seq: 3 4 6

I'd like to delete 1 2 5 out of the first set because they don't have a match in the second set. My inclination would be to create an array with all @seq values from the second set, and then compare the @seq for each point in the first set with that array. If there is no match, then delete the point in the first set.

Problem is, I have no clue how to write that into a wrangle..

Any ideas?
User Avatar
Member
2182 posts
Joined: Sept. 2015
Offline
If you have a single source in this case of 9 points, then:

int Matched = -1;;

for(int Count = 0; Count < npoints(geoself()); Count++)
{
if(Count != @ptnum)
{
if(i@Seq == int(point(geoself(), "Seq", Count))) Matched = 1;
}
}

if(Matched == -1) removepoint(geoself(), @ptnum, 1);
User Avatar
Member
2 posts
Joined: Sept. 2018
Offline
Works like a charm BabaJ, thanks so much!

In this case, I have two sources, but pointing to the second geometry stream instead of geoself in the if statement did the trick:

if(i@Seq == int(point(1, "Seq", Count))) Matched = 1;

The actual data tables have 3000+ entries and I was hand-matching them like a fool before. This is *such* a time saver!
  • Quick Links