We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Loading an SVG file
Page Index Toggle Pages: 1
Loading an SVG file (Read 2127 times)
Loading an SVG file
Dec 3rd, 2009, 5:49am
 
Hi there

I am trying to the load the SVG file found here (http://upload.wikimedia.org/wikipedia/commons/5/5f/USA_Counties_with_FIPS_and_na...
). I have added the file to my instance (sketch Add File) and have the following code:

Code:

import processing.candy.*;
import processing.xml.*;

PShape s;

void setup()
{
   int width = 556;
   int height = 352;
       
   s = loadShape("USA_Counties.svg");  
   noLoop();
}

void draw()
{
  shape(s,10,10,width,height);
}



Processing reports "shape command not handled" with the dump of:

Code:


Ignoring  <metadata> tag.
Ignoring  <sodipodi:namedview> tag.
parsed: M,82.37398,5.202,L,82.62298,5.9,L,82.74798,6.436,L,82.99598,8.907,L,82.97398,9.056,L,82.20798,9.614,L,82.06398,9.655,L,81.16198,9.488,L,80.68398,9.506,L,77.84098,8.735,L,70.64298,6.676,L,67.75798,5.869,L,67.56798,5.851,L,67.54198,4.905,L,66.73898,3.719,L,65.99098,2.052,L,65.84698,1.389,L,65.85198,1.344,L,65.93298,1.217,L,66.16698,1.033,L,66.40998,0.893,L,66.58598,0.794,L,69.49298,1.628,L,72.03498,2.353,L,74.89298,3.214,L,80.08498,4.584,L,82.37398,5.202,M,63.84098,2.026157e
unparsed: -014,L,63.89498,0.014,L,64.29698,0.131,L,64.32298,0.469,L,64.25598,0.492,L,63.80498,0.329,L,63.84098,2.026157e,-014
Exception in thread "Animation Thread" java.lang.RuntimeException: shape command not handled: -014
at processing.core.PShapeSVG.parsePath(PShapeSVG.java:690)
at processing.core.PShapeSVG.parseChild(PShapeSVG.java:324)
at processing.core.PShapeSVG.parseChildren(PShapeSVG.java:264)
at processing.core.PShapeSVG.<init>(PShapeSVG.java:254)
at processing.core.PShapeSVG.<init>(PShapeSVG.java:152)
at processing.core.PShapeSVG.<init>(PShapeSVG.java:144)
at processing.core.PApplet.loadShape(PApplet.java:3645)
at first.setup(first.java:33)
at processing.core.PApplet.handleDraw(PApplet.java:1402)
at processing.core.PApplet.run(PApplet.java:1327)
at java.lang.Thread.run(Thread.java:613)


I am rather confused, could you shed some light on this?
Re: Loading an SVG file
Reply #1 - Dec 3rd, 2009, 6:29am
 
This svg is 1.9 MB of size. That is really alot. I am pretty sure, there are some lines of code that can not be interpreted by processing as not all svg features are yet supported. Just try to use a much simpler svg, if its working, i guess thats the problem.

seems like every single department, in this map is a new shape+outline+names. So if you only need a map of the us you will find something else.


Re: Loading an SVG file
Reply #2 - Dec 3rd, 2009, 7:23am
 
Hi there

Yes it is rather large, and yes I need that detail. I want to fill each segment relevant to external data values. Is there any other way processing can handle this file?

thanks
Re: Loading an SVG file
Reply #3 - Dec 3rd, 2009, 10:05am
 
I managed to load it Smiley

The problem is in the data; specifically in "Whatcom, WA".  Load up the SVG file in a text editor and search for a coordinate from the unparsed data in the error message - e.g. "63.89498".  You'll see just before that there's: "2.026157e-014" which I'm assuming is what's causing the problem.  If you remove the Whatcom path the file loads with no errors; though I don't think it will look the way you want it...

BTW - if you're running the latest processing you don't need to import Candy - it's part of the core now...
Re: Loading an SVG file
Reply #4 - Dec 3rd, 2009, 12:06pm
 
Well spotted, blindfish.
The solution is actually to replace the 2.026157e-014 value by 0, as it is close anyway.

It is a bug in Processing's parsing of path: it assumes a minus sign can happen only at the start of a number, it doesn't handle correctly a number like 1E-2.

[EDIT] Reported as Bug 1408.
Re: Loading an SVG file
Reply #5 - Dec 4th, 2009, 1:26am
 
Thank you very much Blindfish! Well spotted!

It doesn't quite look how I expected, but it has a certain old fashioned feel about it which I quite like.

Thanks again. Smiley
Page Index Toggle Pages: 1