[postgis-users] SVG Render Issue

James Dominy james at sun.ac.za
Sat Sep 6 05:11:11 PDT 2008


Toby Rainthorpe wrote:
> I am outputting EPSG 4326 (WGS84) polygon data as svg from postgis. I am
> however struggling to get anything to render as SVG. Does anyone know
> the correct viewBox and path transform setup to allow this type of data
> to render as svg. Or should I be using a different method?
> 
> Here is an example of what I am currently doing. The path should render
> a low res polygon of Oxford, UK.
> 
> Thanks for your help,
> 
> Toby
> 
> <?xml version="1.0"?>
> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
> "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
> <svg width="1000px" height="1000px" viewBox="0 0 1000 1000"
> version="1.1" xmlns="http://www.w3.org/2000/svg">
> 
>   <path transform="rotate(-90) scale(100, 100)" d="M 0.921728857893816
> -51.667439178992964 -0.943648406641863 -51.632171437283979
> -1.034036852747396 -51.615081510110407 -1.039191311589453
> -51.598091782046289 -1.033829707386365 -51.556789304415609
> -1.1425733621232 -51.557652243792148 -1.145679223489618
> -51.547423329173235 -1.189737584965937 -51.532259424970057
> -1.229532663338833 -51.530540163435404 -1.250685053075961
> -51.535731015755111 -1.312050535540559 -51.548417712963399
> -1.425623923601573 -51.509218583082671 -1.428279846417039
> -51.508871866780524 -1.513905752021219 -51.547390754456636
> -1.559539348757429 -51.544194212449625 -1.552142863881142
> -51.552808047302449 -1.541332522749044 -51.592135260652277
> -1.485423223611759 -51.612046530991961 -1.451764485328202
> -51.660426172863772 -1.434161967168025 -51.707327545117195
> -1.47848156540616 -51.702245140035409 -1.609807649184428
> -51.689850777223604 -1.620999799213429 -51.740828342840693
> -1.628372901372629 -51.754888694562183 -1.722123487421185
> -51.786808960161039 -1.708360615052025 -51.839001461487797
> -1.704942063318551 -51.840116976257576 -1.690786233278003
> -51.880706380276834 -1.603332789259012 -51.953422473934495
> -1.587297429691924 -51.973814827929104 -1.523602838008319
> -51.984481534794249 -1.543869897542569 -52.09381155015555
> -1.512481859689253 -52.068455261898272 -1.444721028482055
> -52.135737033033088 -1.427704375949055 -52.138631878072097
> -1.331856824432614 -52.168816391950621 -1.262767634105308
> -52.14457688819958 -1.207370939790454 -52.127537934403819
> -1.16423442917146 -52.121737089323943 -1.159184763425933
> -52.1075121412795 -1.179247124874321 -52.086972310756543
> -1.242617144599129 -52.060726831549047 -1.248283132968878
> -52.058641011110218 -1.224176087740303 -51.986702353558726
> -1.148267250655421 -51.972959616664077 -1.094743177288104
> -51.971670104237695 -1.090899221646197 -51.9673693174175
> -1.015796442422725 -51.922784982564536 -1.008801622188257
> -51.920118492786557 -1.010300996939166 -51.905500861451756
> -1.037320729582182 -51.875178460936723 -1.045299326181702
> -51.863391677882802 -1.095584860875437 -51.833557109123397
> -1.106668344949025 -51.824307819728489 -1.059837346061549
> -51.746986223607081 -0.998140121763855 -51.759686293695736
> -0.96995159142063 -51.764519051940162 -0.932876409075794
> -51.751189639314866 -0.90604174112355 -51.733290639496737
> -0.881141004715887 -51.688327043177416 Z" fill="red" stroke="blue"
> stroke-width="3" />
> 
> </svg>_______________________________________________
> postgis-users mailing list
> postgis-users at postgis.refractions.net
> http://postgis.refractions.net/mailman/listinfo/postgis-users

Hi Toby,

Change your viewBox to "-100 -100 0 0" and drop the transform. The viewBox
specifies the clipping area, and since most (if not all) your coordinates are
negative, you wont see anything using a clipping area that doesn't include
negative points. What I normally do in this situation is parse through the
points looking the top-leftmost and the bottom-rightmost, then use a transform
to move all the points so they are centered on the origin, and use
viewBox="-0.5*width -0.5*height width height". This yields a nicely scaled and
centered image. Check out the SVG spec oespecially the section on coordinate
systems, tranforms and viewboxes.

Cheers,
James



More information about the postgis-users mailing list