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 & HelpPrograms › Parsing SVG map / polygons
Page Index Toggle Pages: 1
Parsing SVG map / polygons (Read 760 times)
Parsing SVG map / polygons
Nov 3rd, 2008, 5:32pm
 
Hello,
I'm trying to create a sketch to adjust the fills of neighborhoods (polygons) on a map as they correlate with county election data. The map and the web site of the election dept display the same neighborhoods, and importing and parsing the data is going to be relatively simple --- it's getting the SVG to load correctly where I'm having trouble.

I'm able to load a bordering rectangle but have no luck displaying any of the polygons (map elements). Are there any tips for SVG formatting in processing?

I have a sneaking suspicion that my problem may be the particulars of my SVG, as I had to generate it from GIS and other data formats which I am not too familiar with.

You can see the SVG here,
http://thecoocoup.com/neighborhoods.svg

A sample program, it will even acknowledge child elements, but not render them on the screen!

PShape s;
s = loadShape("neighborhoods.svg"); // load neighborhoods
size(int(s.getWidth()),int(s.getHeight())); // set width/height to svg values
smooth();
s.disableStyle();
stroke(255,0,0);
shape(s, 0, 0, width/2, height/2); // draw shape
PShape t =  s.getChild("4"); // look up the child
t.disableStyle();
stroke(255,0,0);
println(t); // it's not null
shape(t, 0,0,width/2, height/2);

Thank you for any help, it is much appreciated!
============
UPDATE: after trying several methods of converting my data to SVG, and much fuss in Illustrator I was able to get things working well enough. It's not perfect but it's good enough for election night :)
Re: Parsing SVG map / polygons
Reply #1 - Nov 4th, 2008, 10:26am
 
open your svg in a texteditor and look for id="...". these are the names to pass to getChild("theID"). for example try: "mpac2".

F
Re: Parsing SVG map / polygons
Reply #2 - Nov 4th, 2008, 4:26pm
 
Thanks --- my original SVG generated from a shapefile with shp2svg was not working (http://www.carto.net/papers/svg/utils/shp2svg/), it had ids, but I have a feeling it was something about the formatting.

I live traced a bitmap and then manually annotated the ids on the output in Illustrator --- the above linked image now reflects this. It seems that processing takes to the illustrator SVG output a lot better.
Page Index Toggle Pages: 1