sách gpt4 ai đã đi

svg - 如何将形状优美的多边形转换为 SVG?

In lại 作者:行者123 更新时间:2023-12-05 08:20:30 30 4
mua khóa gpt4 Nike

我可以通过以下方式创建多边形:

#!/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())

trở lại


这不是有效的 SVG 文件。如何获得有效的 SVG?

我试过了

#!/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('')
f.write(area.svg())
f.write('')

当我查看它时,视口(viewport)对于多边形来说太大了。使用 Inkscape 手动编辑它并调整它的大小:


<>
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">
<>
id="metadata10">

<>
rdf:about="">
image/svg+xml
<>
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />




<>
id="defs8" />
<>
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" />
<>
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" />

有没有办法自动获取这个?

1 Câu trả lời

尝试:

with open('test.svg', 'w') as f:
f.write(area._repr_svg_())

BaseGeometry._repr_svg_ 函数用于 IPython/Jupyter 集成,以便在 Jupyter 笔记本中内联渲染 Shapely 对象。因此这里定义了“内部”命名: http://ipython.readthedocs.io/en/stable/api/generated/IPython.display.html

实际上,它会生成有效的 SVG 输出。

关于svg - 如何将形状优美的多边形转换为 SVG?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49147707/

30 4 0
行者123
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com