-
1. Re: Tough mapping question! Join if you dare
ThinkingThings Feb 27, 2012 7:52 AM (in response to BreachofMind)SO -- what do you have so far in terms of a script? Do you need some help with syntax or logic or are you just looking for someone to do this for you?
-
2. Re: Tough mapping question! Join if you dare
BreachofMind Feb 27, 2012 1:17 PM (in response to ThinkingThings)I have been scripting for about a year, mostly in InDesign. I'd prefer to do the script myself, I'd say I'm more than adequate. What I'm curious about is the strategy... in other words, how to go about doing it.
I developed an ok script today.. It accepts a string of county names which breaks them into an array that it compares to the textFrameItem it finds. If the string of counties matches a found county on the map, the script will select it and I can apply a different stroke color to the text to highlight it among the sea of other county names. However, I'd like to take it further and have the script highlight the outline of the county itself.
Have any ideas? I figure that since the X and Y coord of the text object (which has the county name in it) lies within the boundary of the county, we might be able to develop a script that can change the fill color of the county below the text object once the List of input counties matches the document ones.
let me know if I need to clarify more... I probably should add some images.
-
3. Re: Tough mapping question! Join if you dare
[Jongware] Feb 28, 2012 10:51 AM (in response to BreachofMind)I'm not familiar with the GIS data -- you already have a vector map in which each separate county can be clicked and set to another fill? Or are they just unconnected lines? (Which would be a problem.)
If you can select each individual county by clicking inside it, you could try to make a database first. Write a separate script for that: loop over all county outlines and calculate their mathematical center. Do the same for each county name, and then find the closest match for each pair. Make sure to test this -- give all "recognized" counties a color, and throw an error if it tries to assign a name to an already taken county.
This will give you a link between object id in Illustrator (the id of each county outline) and its name, which you can then use in the script you already wrote.
(Alternatively, assign the name as a *label* to each county, that might make it easier to manually tidy up any leftovers.)
-
4. Re: Tough mapping question! Join if you dare
BreachofMind Feb 28, 2012 1:38 PM (in response to [Jongware])Luckily the maps offered by nationalatlas.gov all have closed polygon shapes for each part. Right now, I have separate layers for the county outlines, which are all closed polygons, and a layer for Labels, which contain the county names. You can select a county outline and Shift-X it to make it filled. Very handy.
I also have a database with all the county names, so your suggestion could go a long way.
Sounds like a bunch of coding ahead...
Thanks!
-Mike
-
5. Re: Tough mapping question! Join if you dare
BreachofMind Jul 10, 2012 1:54 PM (in response to BreachofMind)Months later, I have a solution when I looked at it again.
First, this piece of code is very useful for other purposes, but suits mine really well (It's a variation of Randolph Franklin's PNPOLY c++ code at http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html
function PnPoly (polygon, testPt) {
var nVert = polygon.pathPoints.length; // Total number of vertices of a polygon
var xVerts = new Array();
var yVerts = new Array();
for (var i=0; i<nVert; i++) {
xVerts.push (polygon.pathPoints[i].anchor[0]);
yVerts.push (polygon.pathPoints[i].anchor[1]);
}
var xTest = testPt[0];
var yTest = testPt[1];
var i, j, c = 0;
for (i = 0, j = nVert-1; i < nVert; j = i++) {
if (
((yVerts[i]>yTest) != (yVerts[j]>yTest)) &&
(xTest < (xVerts[j]-xVerts[i]) * (yTest-yVerts[i]) / (yVerts[j]-yVerts[i]) + xVerts[i])
) {c = !c};
}
return c;
}
What this function does is take any closed polygon (such as a PathItem or PageItem) and a test point inside or outside the polygon (TestPt- could be an anchor point coordinate to a text frame, such as textFrame.anchor).
It will then return "true" if the test point is inside the polygon, or "0" if not.
Writing the rest of the code was simple. I simply loop through each text frame (which has the name of the county), and use each textframes anchor point as a test point for PNPOLY. I then loop it against each county outline, which is your polygon for PNPOLY. If the text frame anchor is inside the county outline, it re-names the item in the layer panel as the appropriate county name.
Now, I can write a script that looks up the county name in the layer panel and applies a fill color to it.
Cheers, hope this thread helps yall.
-Mike


