Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
I need to get a looped if else ruleset to parse a code into coordinates.
I'm importing map based SVGs into my data set and I want to extract information from the SVG itself. Importing poses no issue, I can extract the ID and path of each object embedded within the SVG.
For those not familiar with SVGs, the path gives instructions on how to move from each vertex of a polygon to the next. If I can extract the coordinates from the SVG, I can then calculate new information, such as the size of the object, what quadrant of the map it is in, etc, every time I get an updated map or sets of maps from my team.
An example of a path (d) might be:
d="m 117.7,106.2 27.7,-0.14 V 46.1 h -16.9 l 0.1,21.0 -10.7,0.5 v 39.1 z"
Which can be parsed as follows in english:
Operator | English | X | Y |
m 117.7,106.2 | Path starts (m) at Coords (X:Y) '117.7,106.2' | 117.7 | 106.2 |
27.7,-0.14 | Path then moves X coord by 27.7, Y coord by -0.14 | 145.4 | 106.06 |
V 46.1 | Path then moves X coordinate only TO 46.1' | 46.1 | 106.06 |
h -16.9 | Path then moves Y coordinate only by '-16.9' | 46.1 | 89.16 |
l 0.1,21.0 | Path then moves X coord by 0.1, Y coord by 21.0 | 46.2 | 110.16 |
-10.7,0.5 | ...and then to Coord(X:Y) '10.7,0.5' | 56.9 | 110.66 |
v 39.1 | Path then moves X coordinate only by '39.1' | 96 | 110.66 |
z | Path returns to start (z) | 117.7 | 106.2 |
It's a fairly simple instruction set which can be summarised with the ruleset below.
Couple of complications are;
Uppercase mean move coord TO this value, lowercase mean move the coord BY this value.
A set of coords with no preceeding operator means: apply the rules from the last operator in the sequence.
m | Start (format: 'x,y') |
M | Start (format: 'X Y') |
H | GOTO X |
V | GOTO Y |
h | Move X by h |
v | Move Y by v |
z | End, back to m/M(start) |
l | move h by x + move v by y |
L | GOTO X + Y |
l 'x','y' " " 'x','y' " " 'x','y' " " 'x','y' " " 'x','y' | move prior h by x + move prior v by y |
Delimiters are always spaces and commas.
See example transformed paths below.
So what I'm asking for is how to get the above columns, or the original to conform to the general ruleset above.
I can make this work in the power query or with a calculated column, but only using an ugly 99 step if nest..
Is it possible make a more general loop instruction set either from the original path, or the transformed columns in Dax?
The output needed are the two columns of X + Y coordinates.
I don't need anyone to do the whole thing to the Nth degree, but a few pointers would go a long way.
Solved! Go to Solution.
You may try Table.
You may try Table.
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
109 | |
98 | |
80 | |
64 | |
57 |
User | Count |
---|---|
145 | |
111 | |
92 | |
84 | |
66 |