Skip to content

Instantly share code, notes, and snippets.

@aphor
Created October 2, 2024 17:23
Show Gist options
  • Save aphor/a647d56f24b6653b9c4c11c06c25e39c to your computer and use it in GitHub Desktop.
Save aphor/a647d56f24b6653b9c4c11c06c25e39c to your computer and use it in GitHub Desktop.
Extract cartesian coordinates of SVG polylines as CSV
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "c072a755-4fd4-40f6-b159-3ec6e2bcbadc",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"167.3,496.5,167.3,370.1,167.3,325.8,167.3,482.4,167.3,299.8\n",
"172.2,497.5,172.2,251.3,172.2,336.2,172.2,476.9,172.2,308.6\n",
"177.1,495.6,177.1,256.5,177.1,321.6,177.1,476.3,177.1,307.7\n",
"182.0,492.4,182.0,310.4,182.0,318.3,182.0,475.8,182.0,284.5\n",
"186.9,502.2,186.9,408.7,186.9,318.4,186.9,453.9,186.9,309.4\n",
"191.8,504.1,191.8,429.9,191.8,311.5,191.8,444.5,191.8,283.6\n",
"196.7,513.6,196.7,432.0,196.7,331.8,196.7,447.3,196.7,297.6\n",
"201.5,512.8,201.5,433.0,201.5,338.4,201.5,484.1,201.5,321.5\n",
"206.5,512.4,206.5,440.3,206.5,351.0,206.5,457.4,206.5,322.5\n",
"211.2,516.2,211.2,439.7,211.2,367.3,211.2,460.4,211.2,341.7\n",
"216.0,511.7,216.0,418.5,216.0,355.0,216.0,470.2,216.0,317.9\n",
"220.9,500.4,220.9,430.8,220.9,339.6,220.9,489.2,220.9,321.9\n",
"225.8,496.7,225.8,356.7,225.8,315.3,225.8,492.8,225.8,314.8\n",
"230.7,489.3,230.7,254.5,230.7,316.7,230.7,473.8,230.7,291.8\n",
"235.6,471.9,235.6,218.2,235.6,285.8,235.6,473.0,235.6,295.2\n",
"240.5,482.9,240.5,277.5,240.5,316.8,240.5,466.0,240.5,276.4\n",
"245.4,496.1,245.4,387.1,245.4,340.8,245.4,454.8,245.4,295.4\n",
"250.3,489.0,250.3,422.0,250.3,313.6,250.3,437.5,250.3,296.9\n",
"255.2,497.9,255.2,434.5,255.2,326.9,255.2,449.5,255.2,318.6\n",
"260.1,505.0,260.1,426.7,260.1,318.0,260.1,474.3,260.1,339.8\n",
"265.1,499.2,265.1,430.8,265.1,297.8,265.1,463.0,265.1,333.1\n",
"269.8,498.8,269.8,426.7,269.8,311.8,269.8,470.6,269.8,333.6\n",
"274.6,492.3,274.6,403.0,274.6,296.3,274.6,463.9,274.6,315.1\n",
"279.5,483.8,279.5,402.9,279.5,286.0,279.5,475.6,279.5,308.3\n",
"284.4,476.5,284.4,350.7,284.4,293.1,284.4,475.1,284.4,296.0\n",
"289.3,470.1,289.3,238.1,289.3,287.4,289.3,462.9,289.3,313.3\n",
"294.1,454.5,294.1,219.7,294.1,273.5,294.1,463.7,294.1,293.5\n",
"299.1,470.1,299.1,286.9,299.1,294.6,299.1,454.5,299.1,294.4\n",
"304.0,486.6,304.0,382.7,304.0,302.9,304.0,436.4,304.0,302.4\n",
"308.9,478.1,308.9,400.7,308.9,276.9,308.9,433.4,308.9,286.6\n",
"313.8,495.6,313.8,410.4,313.8,311.9,313.8,441.4,313.8,304.8\n",
"318.7,502.8,318.7,411.8,318.7,314.0,318.7,468.3,318.7,344.0\n",
"323.7,501.5,323.7,420.6,323.7,303.2,323.7,461.9,323.7,339.4\n",
"328.4,504.9,328.4,414.4,328.4,308.3,328.4,478.7,328.4,355.1\n",
"333.2,495.2,333.2,388.6,333.2,282.5,333.2,459.0,333.2,316.3\n",
"338.0,488.5,338.0,403.8,338.0,281.3,338.0,470.5,338.0,327.8\n",
"342.9,470.1,342.9,340.1,342.9,262.1,342.9,469.6,342.9,303.6\n",
"347.8,459.5,347.8,209.8,347.8,251.1,347.8,440.9,347.8,298.2\n",
"352.7,459.1,352.7,219.9,352.7,260.8,352.7,463.2,352.7,287.5\n",
"357.7,467.9,357.7,271.7,357.7,264.7,357.7,455.4,357.7,284.4\n",
"362.6,482.3,362.6,367.0,362.6,278.0,362.6,424.5,362.6,290.6\n",
"367.5,473.0,367.5,387.5,367.5,274.8,367.5,430.3,367.5,280.6\n",
"372.4,483.0,372.4,386.4,372.4,276.1,372.4,438.4,372.4,300.2\n",
"377.3,476.6,377.3,378.0,377.3,251.1,377.3,456.9,377.3,305.4\n",
"382.3,480.9,382.3,395.3,382.3,292.4,382.3,450.2,382.3,319.3\n",
"387.1,485.7,387.1,391.2,387.1,313.0,387.1,468.8,387.1,323.6\n",
"391.9,474.4,391.9,363.1,391.9,291.0,391.9,459.5,391.9,293.7\n",
"396.7,466.3,396.7,358.9,396.7,259.2,396.7,456.8,396.7,273.5\n",
"401.6,471.9,401.6,300.6,401.6,283.8,401.6,464.4,401.6,289.1\n",
"406.5,461.4,406.5,181.6,406.5,273.3,406.5,442.3,406.5,277.7\n",
"411.4,448.7,411.4,212.7,411.4,274.4,411.4,459.8,411.4,269.6\n",
"416.4,442.6,416.4,240.7,416.4,293.7,416.4,451.4,416.4,259.8\n",
"421.2,456.4,421.2,348.7,421.2,311.1,421.2,436.9,421.2,270.2\n",
"426.1,456.1,426.1,383.4,426.1,303.8,426.1,427.1,426.1,274.2\n",
"431.0,471.5,431.0,387.6,431.0,318.0,431.0,452.3,431.0,296.7\n",
"435.9,477.3,435.9,389.8,435.9,307.0,435.9,476.6,435.9,318.5\n",
"440.9,474.8,440.9,399.8,440.9,299.7,440.9,458.7,440.9,318.5\n",
"445.6,485.6,445.6,395.6,445.6,323.1,445.6,468.2,445.6,326.5\n",
"450.3,467.0,450.3,350.0,450.3,250.1,450.3,457.5,450.3,266.8\n",
"455.2,466.8,455.2,375.7,455.2,298.5,455.2,465.9,455.2,282.8\n",
"460.1,454.6,460.1,303.4,460.1,284.5,460.1,464.7,460.1,255.7\n",
"465.0,444.7,465.0,163.0,465.0,293.1,465.0,449.1,465.0,269.1\n",
"469.9,431.9,469.9,131.0,469.9,257.0,469.9,455.3,469.9,216.3\n",
"474.9,435.3,474.9,230.5,474.9,285.7,474.9,458.9,474.9,262.2\n",
"479.8,450.3,479.8,339.6,479.8,299.3,479.8,430.6,479.8,261.1\n",
"484.7,444.0,484.7,359.3,484.7,276.9,484.7,422.0,484.7,250.8\n",
"489.6,461.6,489.6,385.1,489.6,310.4,489.6,435.4,489.6,286.5\n",
"494.5,456.3,494.5,385.9,494.5,297.1,494.5,462.8,494.5,291.9\n",
"499.4,450.1,499.4,382.1,499.4,264.6,499.4,440.0,499.4,290.6\n",
"504.2,463.7,504.2,392.3,504.2,277.5,504.2,456.1,504.2,308.1\n",
"508.9,458.1,508.9,361.6,508.9,244.2,508.9,438.2,508.9,280.3\n",
"513.8,460.4,513.8,375.5,513.8,247.8,513.8,470.2,513.8,277.8\n",
"518.7,436.9,518.7,280.1,518.7,254.8,518.7,457.0,518.7,266.2\n",
"523.6,437.6,523.6,161.5,523.6,244.3,523.6,438.4,523.6,257.1\n",
"528.5,428.3,528.5,147.9,528.5,248.3,528.5,457.7,528.5,258.6\n",
"533.5,433.4,533.5,188.8,533.5,211.7,533.5,444.5,533.5,251.7\n",
"538.4,448.7,538.4,329.6,538.4,236.8,538.4,437.5,538.4,282.1\n",
"543.3,439.6,543.3,363.5,543.3,223.8,543.3,437.2,543.3,269.1\n",
"548.1,450.1,548.1,380.0,548.1,220.0,548.1,439.1,548.1,289.1\n",
"553.0,460.9,553.0,379.5,553.0,225.1,553.0,465.4,553.0,296.4\n",
"558.0,454.9,558.0,387.7,558.0,199.8,558.0,439.7,558.0,296.0\n",
"562.8,464.3,562.8,377.9,562.8,240.3,562.8,458.0,562.8,324.1\n",
"567.5,447.1,567.5,354.8,567.5,177.9,567.5,462.3,567.5,297.6\n",
"572.4,446.4,572.4,363.8,572.4,176.9,572.4,465.8,572.4,283.4\n",
"577.3,432.4,577.3,283.1,577.3,172.2,577.3,461.7,577.3,274.4\n",
"582.2,424.8,582.2,145.9,582.2,184.9,582.2,438.3,582.2,267.6\n",
"587.1,414.2,587.1,126.9,587.1,174.4,587.1,453.5,587.1,277.1\n",
"592.0,419.5,592.0,203.0,592.0,197.5,592.0,442.1,592.0,276.9\n",
"596.9,437.6,596.9,300.3,596.9,213.7,596.9,443.8,596.9,285.1\n",
"601.8,434.5,601.8,345.4,601.8,205.5,601.8,417.7,601.8,286.0\n",
"606.7,435.5,606.7,370.2,606.7,166.2,606.7,435.6,606.7,290.0\n",
"611.6,435.7,611.6,378.0,611.6,157.9,611.6,470.0,611.6,307.3\n",
"616.6,434.9,616.6,390.7,616.6,141.0,616.6,442.7,616.6,320.9\n",
"621.4,444.6,621.4,375.0,621.4,148.2,621.4,453.2,621.4,337.7\n",
"626.2,433.3,626.2,384.6,626.2,125.5,626.2,460.2,626.2,303.5\n",
"631.1,434.7,631.1,418.9,631.1,158.2,631.1,459.1,631.1,303.1\n",
"636.0,418.9,636.0,397.4,636.0,148.3,636.0,441.5,636.0,293.1\n",
"640.8,419.6,640.8,375.4,640.8,149.6,640.8,430.5,640.8,304.4\n",
"645.7,410.8,645.7,350.0,645.7,171.7,645.7,442.3,645.7,286.0\n",
"650.7,415.6,650.7,361.0,650.7,213.3,650.7,431.5,650.7,284.0\n",
"655.6,429.7,655.6,373.5,655.6,224.3,655.6,432.4,655.6,294.0\n",
"660.5,421.2,660.5,383.2,660.5,189.2,660.5,397.0,660.5,263.1\n",
"665.3,436.6,665.3,400.5,665.3,168.1,665.3,432.2,665.3,303.0\n",
"670.2,443.6,670.2,400.1,670.2,158.1,670.2,458.1,670.2,309.8\n",
"675.2,443.8,675.2,392.5,675.2,140.0,675.2,425.5,675.2,303.3\n",
"679.9,447.4,679.9,406.4,679.9,181.9,679.9,431.9,679.9,329.5\n",
"684.7,429.7,684.7,391.5,684.7,118.5,684.7,440.2,684.7,294.5\n",
"689.6,407.6,689.6,400.1,689.6,152.0,689.6,456.2,689.6,303.3\n",
"694.4,387.5,694.4,378.6,694.4,128.7,694.4,450.6,694.4,281.9\n",
"699.3,383.9,699.3,374.1,699.3,166.6,699.3,442.8,699.3,287.3\n",
"704.2,355.4,704.2,341.9,704.2,191.1,704.2,442.3,704.2,268.6\n",
"709.2,371.4,709.2,347.0,709.2,231.1,709.2,400.6,709.2,275.4\n",
"714.1,394.1,714.1,344.0,714.1,241.2,714.1,426.9,714.1,299.8\n",
"719.0,387.8,719.0,359.3,719.0,198.5,719.0,420.0,719.0,295.1\n",
"723.9,394.0,723.9,364.5,723.9,160.9,723.9,443.1,723.9,319.9\n",
"728.8,410.8,728.8,373.5,728.8,91.1,728.8,470.8,728.8,317.9\n",
"733.8,416.8,733.8,386.1,733.8,104.2,733.8,452.6,733.8,335.0\n",
"738.5,413.4,738.5,387.5,738.5,166.5,738.5,453.6,738.5,352.2\n",
"743.2,382.9,743.2,347.9,743.2,76.0,743.2,437.6,743.2,332.2\n",
"748.1,398.2,748.1,343.1,748.1,99.8,748.1,454.7,748.1,331.6\n",
"753.0,388.3,753.0,255.5,753.0,100.7,753.0,438.7,753.0,318.2\n",
"757.9,387.1,757.9,136.9,757.9,120.9,757.9,445.0,757.9,315.4\n",
"762.8,390.2,762.8,113.2,762.8,199.5,762.8,442.5,762.8,316.5\n",
"767.8,394.9,767.8,174.2,767.8,234.5,767.8,414.5,767.8,324.6\n",
"772.7,399.7,772.7,249.0,772.7,229.6,772.7,415.2,772.7,325.2\n",
"777.6,394.1,777.6,328.7,777.6,200.6,777.6,421.6,777.6,317.4\n",
"782.5,408.4,782.5,380.1,782.5,152.3,782.5,439.5,782.5,329.0\n",
"787.4,422.1,787.4,378.4,787.4,148.1,787.4,467.5,787.4,334.3\n",
"792.4,421.2,792.4,377.0,792.4,137.7,792.4,440.8,792.4,335.6\n",
"797.1,423.8,797.1,403.8,797.1,141.9,797.1,458.4,797.1,359.0\n",
"801.8,381.6,801.8,358.6,801.8,103.0,801.8,432.1,801.8,308.4\n",
"806.7,398.7,806.7,352.6,806.7,99.1,806.7,447.0,806.7,314.1\n",
"811.6,400.1,811.6,243.2,811.6,107.3,811.6,444.4,811.6,314.3\n",
"816.5,392.3,816.5,84.4,816.5,147.0,816.5,434.6,816.5,303.2\n",
"821.4,382.9,821.4,69.7,821.4,157.5,821.4,447.0,821.4,300.5\n",
"826.4,376.6,826.4,116.6,826.4,216.8,826.4,403.5,826.4,298.7\n",
"831.3,395.3,831.3,250.2,831.3,211.7,831.3,437.5,831.3,307.5\n",
"836.2,405.4,836.2,324.7,836.2,187.0,836.2,420.6,836.2,306.9\n",
"841.1,412.7,841.1,338.4,841.1,103.2,841.1,431.0,841.1,307.2\n",
"846.0,439.9,846.0,365.9,846.0,114.6,846.0,476.5,846.0,335.5\n",
"850.9,442.8,850.9,376.5,850.9,110.5,850.9,445.2,850.9,341.8\n",
"855.7,418.1,855.7,359.0,855.7,87.7,855.7,435.2,855.7,334.6\n",
"860.5,410.7,860.5,323.5,860.5,86.3,860.5,408.5,860.5,321.3\n",
"865.4,417.0,865.4,335.3,865.4,93.3,865.4,448.3,865.4,318.3\n",
"870.3,420.6,870.3,226.6,870.3,92.3,870.3,442.9,870.3,297.5\n",
"875.2,418.2,875.2,109.4,875.2,117.8,875.2,432.6,875.2,301.5\n",
"880.1,395.7,880.1,108.4,880.1,142.3,880.1,441.4,880.1,294.2\n"
]
}
],
"source": [
"import urllib.request\n",
"import xml.etree.ElementTree as ET\n",
"\n",
"lines = []\n",
"\n",
"with urllib.request.urlopen('https://github.com/robbieandrew/robbieandrew.github.io/raw/refs/heads/master/norway/img/havbase_CO2_lines.svg') as response:\n",
" svgtree = ET.parse(response)\n",
" svgroot = svgtree.getroot()\n",
" for line in svgroot.findall(\"./{http://www.w3.org/2000/svg}defs/{http://www.w3.org/2000/svg}symbol/{http://www.w3.org/2000/svg}polyline\"):\n",
" lines.append(tuple((tuple(point.split(',')) for point in line.attrib['points'].split(' '))))\n",
"\n",
"\n",
"for row in zip(*lines):\n",
" print(','.join((','.join(xy) for xy in row)))"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b8f200a3-74bf-40b4-a500-e8677f7cb5c0",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.3"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment