検索 - User list
Full Version: Convert String sequence to points
Root » Technical Discussion » Convert String sequence to points
papsphilip
I need some help with some vex code. I have a sequence of strings that i want to convert to pairs of xy. see the image attached. every string (float) is separated with a blank space so i need to somehow get a pair of two strings each time and put them in a vector as X Y Coordinates. I am still very new to vex and i have no idea how to approach this, i only know there is a function to convert string to float but thats about it.
tamte
Attrib Wrangle in Detail mode
string raw = "1.1 1.2 2.1 2.2 3.1 3.2 4.1 4.2";
string coords[] = split(raw);
for (int i=0; i<len(coords); i+=2){
    vector P = 0;
    P.x = atof(coords[i]);
    P.y = atof(coords[i+1]);
    addpoint(0, P);
}
papsphilip
tamte
Attrib Wrangle in Detail mode
string raw = "1.1 1.2 2.1 2.2 3.1 3.2 4.1 4.2";
string coords[] = split(raw);
for (int i=0; i<len(coords); i+=2){
    vector P = 0;
    P.x = atof(coords[i]);
    P.y = atof(coords[i+1]);
    addpoint(0, P);
}

yes! thank you it worked, i had to put the wrangle in a foreach loop to do the same for every point string attribute. This would not be needed if there was a way to import shapefiles though
tamte
instead of putting it into the for each loop, just use Point Wrangle
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB