title: How can I convert a shapely Polygon to an SVG?
body: <p>I can create a Polygon by:</p>
  
  <pre><code>#!/usr/bin/env python
  
  from shapely.geometry import Polygon
  
  area = Polygon(((52, 13), (57, 14), (58, 12)))
  
  with open('test.svg', 'w') as f:
      f.write(area.svg())
  </code></pre>
  
  <p>which returns</p>
  
  <pre><code>&lt;path fill-rule="evenodd" fill="#66cc99" stroke="#555555" stroke-width="2.0" opacity="0.6" d="M 52.0,13.0 L 57.0,14.0 L 58.0,12.0 L 52.0,13.0 z" /&gt;
  </code></pre>
  
  <p>This is not a valid SVG file. How can I get a valid SVG?</p>
  
  <h2>I tried</h2>
  
  <pre><code>#!/usr/bin/env python
  
  from shapely.geometry import Polygon
  
  area = Polygon(((52, 13), (57, 14), (58, 12)))
  
  with open('test.svg', 'w') as f:
      f.write('&lt;svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink= "http://www.w3.org/1999/xlink"&gt;')
      f.write(area.svg())
      f.write('&lt;/svg&gt;')
  </code></pre>
  
  <p>When I view this, the viewport is way to big for the polygon. Manually editing it with Inkscape and resizing it gives:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" standalone="no"?&gt;
  &lt;svg
     xmlns:dc="http://purl.org/dc/elements/1.1/"
     xmlns:cc="http://creativecommons.org/ns#"
     xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
     xmlns:svg="http://www.w3.org/2000/svg"
     xmlns="http://www.w3.org/2000/svg"
     xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
     xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
     version="1.1"
     id="svg2"
     inkscape:version="0.91 r13725"
     sodipodi:docname="test.svg"
     width="7.9687681"
     height="4.4396091"&gt;
    &lt;metadata
       id="metadata10"&gt;
      &lt;rdf:RDF&gt;
        &lt;cc:Work
           rdf:about=""&gt;
          &lt;dc:format&gt;image/svg+xml&lt;/dc:format&gt;
          &lt;dc:type
             rdf:resource="http://purl.org/dc/dcmitype/StillImage" /&gt;
          &lt;dc:title&gt;&lt;/dc:title&gt;
        &lt;/cc:Work&gt;
      &lt;/rdf:RDF&gt;
    &lt;/metadata&gt;
    &lt;defs
       id="defs8" /&gt;
    &lt;sodipodi:namedview
       pagecolor="#ffffff"
       bordercolor="#666666"
       borderopacity="1"
       objecttolerance="10"
       gridtolerance="10"
       guidetolerance="10"
       inkscape:pageopacity="0"
       inkscape:pageshadow="2"
       inkscape:window-width="2560"
       inkscape:window-height="1364"
       id="namedview6"
       showgrid="false"
       inkscape:zoom="2.36"
       inkscape:cx="-1.8038839"
       inkscape:cy="-34.869627"
       inkscape:window-x="0"
       inkscape:window-y="24"
       inkscape:window-maximized="1"
       inkscape:current-layer="svg2"
       fit-margin-top="0"
       fit-margin-left="0"
       fit-margin-right="0"
       fit-margin-bottom="0" /&gt;
    &lt;path
       d="m 0.19611614,2.3092357 4.99999996,1 1,-2 -5.99999996,1 z"
       id="path4"
       inkscape:connector-curvature="0"
       style="opacity:0.6;fill:#66cc99;fill-rule:evenodd;stroke:#555555;stroke-width:2" /&gt;
  &lt;/svg&gt;
  </code></pre>
  
  <p>Is there a way to get this automatically?</p>