Created
January 13, 2014 16:57
-
-
Save futuraprime/8403749 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
import json | |
import numpy as np | |
from BeautifulSoup import BeautifulStoneSoup as Stone | |
f = open('new-basemap-borders-01.svg') | |
svg = f.read() | |
f.close() | |
soup = Stone(svg) | |
polys = soup.findAll('polyline') | |
listing = [] | |
t = [15.7475,0.0,0.0,15.7475,98.351,147.526] # the transform params | |
#t = [1.0, 0.0, 0.0, 0.0, 1.0, 0.0] | |
mat = np.matrix([ | |
[ t[0], t[2], t[4] ], | |
[ t[1], t[3], t[5] ], | |
[ 0.0, 0.0, 1.0 ] | |
]) | |
for poly in polys: | |
string = poly['points'].strip() | |
string = re.sub( ' ?[\r\n]{1,2}\t+', ' ', string ) | |
# print string | |
points = string.split(' ') | |
for i, point in enumerate(points): | |
p = map( lambda x: [ float(x) ], point.split(',') ) | |
p.append( [ 1.0 ] ) | |
pm = np.matrix( p ) | |
xform = mat * pm | |
formd = map(lambda x: str( round( x, 3 ) ), xform.transpose().tolist()[0][0:2]) | |
points[i] = ','.join(formd) | |
string = ' '.join(points) | |
listing.append( string ) | |
print json.dumps( listing ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment