• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Tough mapping question! Join if you dare

Community Beginner ,
Feb 27, 2012 Feb 27, 2012

Copy link to clipboard

Copied

Wow, I've got quite a conundrum. It doesn't seem hard in theory, it just involves potentially a lot of data.

Ok, Check this out. I have a map of the U.S. with every state outline and name on it. You can pick them up for free at http://nationalatlas.gov/ and either use the PDF's in illustrator (just clean them up) or download the raw map data and get a plug-in to convert the GIS data into illustrator format.

So, with a map of the states and their names, I'd like to make a script that will take a list of states and select each. The alternative is having to go in manually and select each state with the selection tool. Now, I realize I probably could take the time and select each state, name it's sub-layer and have the script select the layer. But, I will eventually be applying the script to U.S. Counties and there are thousands of them.

If the majority of states have the name of the state entrapped in them, how can I write a script to search for the state name (or county name) and select the state shape beneath it? Or at the very least, could I have the script rename the sub-layer?

The ideal solution would take a list of items separated by carriage returns and select each object on the map. I have the areas in a database.

Figuring this one out would make my job about 50x faster. I have to track newspaper market areas, and some papers cover large areas.

-Mike

TOPICS
Scripting

Views

1.2K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Engaged ,
Feb 27, 2012 Feb 27, 2012

Copy link to clipboard

Copied

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 27, 2012 Feb 27, 2012

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 28, 2012 Feb 28, 2012

Copy link to clipboard

Copied

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.)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 28, 2012 Feb 28, 2012

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 10, 2012 Jul 10, 2012

Copy link to clipboard

Copied

LATEST

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.anchor[0]);

            yVerts.push (polygon.pathPoints.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>yTest) != (yVerts>yTest)) &&

        (xTest < (xVerts-xVerts) * (yTest-yVerts) / (yVerts-yVerts) + xVerts)

        ) {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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines