<p>I have a SVG which contains rectangles with other shapes. How can I extract all rectangle details(co-ordinates, height and width)? Find below svg details where I kept only one rectangle for reference.</p>
<pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;svg width=&quot;301.36mm&quot; height=&quot;174.36mm&quot; viewBox=&quot;0 0 1139 659&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;
    &lt;g fill=&quot;none&quot; stroke=&quot;black&quot; stroke-width=&quot;1&quot; fill-rule=&quot;evenodd&quot; stroke-linecap=&quot;square&quot; stroke-linejoin=&quot;bevel&quot;&gt;
        &lt;defs&gt;
            &lt;clipPath id=&quot;clip27&quot;&gt;
                &lt;path d=&quot;M-272.5,-2.5 L866.5,-2.5 L866.5,656.5 L-272.5,656.5 L-272.5,-2.5 z&quot;/&gt;
            &lt;/clipPath&gt;
        &lt;/defs&gt;&lt;g clip-path=&quot;url(#clip27)&quot; fill=&quot;none&quot; opacity=&quot;1&quot; stroke=&quot;#000000&quot; stroke-linecap=&quot;butt&quot; stroke-linejoin=&quot;miter&quot; stroke-miterlimit=&quot;2&quot; stroke-opacity=&quot;1&quot; stroke-width=&quot;1&quot; transform=&quot;matrix(1,0,0,1,272.5,2.5)&quot;&gt;
            &lt;path d=&quot;M0,0 L110,0 L110,176 L0,176 L0,0 z&quot; fill-rule=&quot;evenodd&quot; vector-effect=&quot;none&quot;/&gt;
        &lt;/g&gt;
        &lt;defs&gt;
            &lt;clipPath id=&quot;clip34&quot;&gt;
                &lt;path d=&quot;M0,0 L112,0 L112,15 L0,15 L0,0 z&quot;/&gt;
            &lt;/clipPath&gt;
        &lt;/defs&gt;&lt;g clip-path=&quot;url(#clip34)&quot; fill=&quot;none&quot; opacity=&quot;1&quot; stroke=&quot;#000000&quot; stroke-linecap=&quot;square&quot; stroke-linejoin=&quot;bevel&quot; stroke-opacity=&quot;1&quot; stroke-width=&quot;1&quot; transform=&quot;matrix(1,0,0,1,271.07,180)&quot;&gt;
            &lt;text fill=&quot;#000000&quot; fill-opacity=&quot;1&quot; font-family=&quot;Arial&quot; font-size=&quot;10&quot; font-style=&quot;normal&quot; font-weight=&quot;400&quot; stroke=&quot;none&quot; textLength=&quot;109.859&quot; x=&quot;1&quot; xml:space=&quot;preserve&quot; y=&quot;11&quot;&gt;BoostDiagSlow_Release&lt;/text&gt;
        &lt;/g&gt;
    &lt;/g&gt;
&lt;/svg&gt;
</code></pre>

CC BY-SA 4.0
2022-08-29T15:35:10.110Z
If the shapes are defined by just a series of line drawing commands (go to point X, draw to point Y, etc), there's not a simple way to know what is a "rectangle". It would be better if you could get the author of the file to use some naming conventions to tell you which things are "rectangles".
Nicol Bolas
CC BY-SA 4.0
2022-08-30T05:56:26.223Z
Well, you could do this. Its not super practical though. As there are quite a bit of corner cases.
joojaa
<vector-graphics><java>
How to programmatically extract all rectangle shapes from SVG file?
Srikant
# How to programmatically extract all rectangle shapes from SVG file?

(Asked by: username_0 on 2022-08-29)

I have a SVG which contains rectangles with other shapes. How can I extract all rectangle details(co-ordinates, height and width)? Find below svg details where I kept only one rectangle for reference.

```
<?xml version="1.0" encoding="UTF-8"?>
<svg width="301.36mm" height="174.36mm" viewBox="0 0 1139 659" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
    <g fill="none" stroke="black" stroke-width="1" fill-rule="evenodd" stroke-linecap="square" stroke-linejoin="bevel">
        <defs>
            <clipPath id="clip27">
                <path d="M-272.5,-2.5 L866.5,-2.5 L866.5,656.5 L-272.5,656.5 L-272.5,-2.5 z"/>
            </clipPath>
        </defs><g clip-path="url(#clip27)" fill="none" opacity="1" stroke="#000000" stroke-linecap="butt" stroke-linejoin="miter" stroke-miterlimit="2" stroke-opacity="1" stroke-width="1" transform="matrix(1,0,0,1,272.5,2.5)">
            <path d="M0,0 L110,0 L110,176 L0,176 L0,0 z" fill-rule="evenodd" vector-effect="none"/>
        </g>
        <defs>
            <clipPath id="clip34">
                <path d="M0,0 L112,0 L112,15 L0,15 L0,0 z"/>
            </clipPath>
        </defs><g clip-path="url(#clip34)" fill="none" opacity="1" stroke="#000000" stroke-linecap="square" stroke-linejoin="bevel" stroke-opacity="1" stroke-width="1" transform="matrix(1,0,0,1,271.07,180)">
            <text fill="#000000" fill-opacity="1" font-family="Arial" font-size="10" font-style="normal" font-weight="400" stroke="none" textLength="109.859" x="1" xml:space="preserve" y="11">BoostDiagSlow_Release</text>
        </g>
    </g>
</svg>

```

**Tags:** vector-graphics, java

> **Comments:**
> **username_1**: If the shapes are defined by just a series of line drawing commands (go to point X, draw to point Y, etc), there's not a simple way to know what is a "rectangle". It would be better if you could get the author of the file to use some naming conventions to tell you which things are "rectangles".  
> **username_2**: Well, you could do this. Its not super practical though. As there are quite a bit of corner cases.  

---

## 0 answers

