Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

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.

Reply
Scollins_MER
Regular Visitor

Generate Coords from SVG path - Dax Query

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:

OperatorEnglishXY
m 117.7,106.2Path starts (m) at Coords (X:Y) '117.7,106.2'117.7106.2
 27.7,-0.14Path then moves X coord by 27.7, Y coord by -0.14145.4106.06
V 46.1Path then moves X coordinate only TO 46.1'46.1106.06
h -16.9Path then moves Y coordinate only by '-16.9'46.189.16
l 0.1,21.0Path then moves X coord by 0.1, Y coord by 21.046.2110.16
 -10.7,0.5...and then to Coord(X:Y) '10.7,0.5'56.9110.66
v 39.1Path then moves X coordinate only by '39.1'96110.66
zPath returns to start (z)117.7106.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.

SVG_Path_Example.png

 

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.

 

1 ACCEPTED SOLUTION
v-chuncz-msft
Community Support
Community Support

@Scollins_MER ,

 

You may try Table.SplitColumn and Splitter.SplitTextByCharacterTransition in Query Editor.

Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

1 REPLY 1
v-chuncz-msft
Community Support
Community Support

@Scollins_MER ,

 

You may try Table.SplitColumn and Splitter.SplitTextByCharacterTransition in Query Editor.

Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.