Archive for the ‘php scripting’ Category

Finding Duplicate Points in a Shapefile

Wednesday, September 2nd, 2009

[Editor's note: When building the 6,600 cities for Natural Earth vector, we had 6 extra townspots than town labels. Bound to happen on larger projects. One could take the halving approach and select half, see if the number of symbols matches the number of text objects, if so skip, if not subdivide in 1/2 again and reevaluate. Or if you use MaPublisher with Illustrator and/or Vectorworks to export out as a SHP file, we can open the DBF up in Excel and use the "countif" function and "conditional formatting" to quickly identify the exact features to resolve. By sorting the resulting "true" and "false" columns on lat, long, and feature name, we can quickly evaluate if there are multiple features at the same geographic location and compare their names. If they are the same name, assume 1 is a duplicate and remove it.]

Republished from Microsoft.

You can locate duplicates in a range of data by using conditional formatting and the COUNTIF function. Here are the details on how to make that work.

Set up the first conditional formatting formula

I’ll start by setting up a conditional format for the first data cell. Later, I’ll copy that conditional format for the whole range.

In my example, cell A1 contains a column heading (Invoice), so I will select cell A2, and then click Conditional Formatting on the Format menu. The Conditional Formatting dialog box opens. The first box contains the text, Cell Value Is. If you click the arrow next to this box, you can choose Formula Is.

Example

After you click Formula Is, the dialog box changes appearance. Instead of boxes for between x and y, there is now a single formula box. This formula box is incredibly powerful. You can use it to enter any formula that you can dream up, as long as that formula will evaluate to TRUE or FALSE.

In this case, we need to use a COUNTIF formula. The formula to type in the box is:


=COUNTIF(A:A,A2)>1

This formula says: Look through the entire range of column A. Count how many cells in that range have the same value as cell A2. Then, compare to see if that count is greater than 1.

When there are no duplicates, the count will always be 1; because cell A2 is in the range, we should find exactly one cell in column A that contains the same value as A2.

Note In this formula, A2 represents the current cell — that is, the cell for which you are setting up the conditional format. So, if your data is in column E and you are setting up the first conditional format in cell E5, the formula would be =COUNTIF(E:E,E5)>1.

Choose a color to highlight duplicated entries

Now it is time to select an obnoxious (that is, obvious) format to identify any duplicates that are found. In the Conditional Formatting dialog box, click the Format button.

Example

Click the Patterns tab and click a bright color swatch, like red or yellow. Then click OK to close the Format Cells dialog box.

Example

You will see the selected format in the preview box. Click OK to close the Conditional Formatting dialog box, and…

Example

Nothing happens. Wow. If this is your first time setting up conditional formatting, it would be really nice to get some feedback here that it worked. But, unless you are lucky enough that the data in cell A2 is a duplicate of the data in some other cell, the condition is FALSE and no formatting is applied.

Continue reading at Microsoft . . .

Building the Data Desk: Lessons From the L.A. Times (Knight Digital Media Center)

Thursday, December 4th, 2008

[Editor's note: Great article on how data, including GIS, maps, and Google mashups can be leveraged in news media environments from a veteran of the LA Times. Thanks Aly! (and bon voyage)]

Republished from Knight Digital Media Center (OJR). By Eric Ulken on Nov. 21, 2008.

In early 2007, when the Los Angeles Times launched its Homicide Report blog — an effort to chronicle every homicide in Los Angeles County — it was clear that there were important geographic and demographic dimensions to the information that a blog format wouldn’t fully capture. What we needed was a ChicagoCrime.org-style map that would let users focus on areas of interest to them, with filters that would enable them to “play” with the data and explore trends and patterns for themselves. Problem was, the web staff (of which I was a part) lacked the tools and the expertise to build such a thing, so the blog launched without a map. (Sound familar?)

It took several months to secure the tech resources and a couple more months to create wireframes and spec out requirements for what would become the Homicide Map, with the help of a couple of talented developers and a project manager on part-time loan from the website’s IT department. We were fortunate, of course: We actually had access to this kind of expertise, and since then we’ve hired a couple of dedicated editorial developers. I’m aware that others might not have it so good.

Last week, Robert Niles argued that news organizations should be in the business of creating “killer apps”. Put another way, there is a need to develop tools that hew to the content rather than the other way around. But creating the functionality Robert describes takes a closer connection between news thinking and tech thinking than is possible within news organizations’ traditional structures and skill sets.

In this post, I’ll try to squeeze some wisdom out of the lessons we learned in the process of assembling the Times’ Data Desk, a cross-functional team of journalists responsible for collecting, analyzing and presenting data online and in print. (Note: I left the Times earlier this month to work on some independent projects. I am writing this piece with the blessing of my former bosses there.)

Here, then, are 10 pieces of advice for those of you building or looking to build a data team in your newsroom:

  1. Find the believers: You’ll likely discover enthusiasts and experts in places you didn’t expect. In our case, teaming up with the Times’ computer-assisted reporting staff, led by Doug Smith, was a no-brainer. Doug was publishing data to the web before the website had anybody devoted to interactive projects. But besides Doug’s group, we found eager partners on the paper’s graphics staff, where, for example, GIS expert Tom Lauder had already been playing with Flash and web-based mapping tools for a while. A number of reporters were collecting data for their stories and wondering what else could be done with it. We also found people on the tech side with a good news sense who intuitively understood what we were trying to do.
  2. Get buy-in from above: For small projects, you might be able to collaborate informally with your fellow believers, but for big initiatives, you need the commitment of top editors who control the newsroom departments whose resources you’ll draw on. At the Times, a series of meetings among senior editors to chart a strategic vision for the paper gave us an opportunity to float the data desk idea. This led to plans to devote some reporting resources to gathering data and to move members of the data team into a shared space near the editorial library (see #8).
  3. Set some priorities: Your group may come from a variety of departments, but if their priorities are in alignment, disparate reporting structures might not be such a big issue. We engaged in “priority alignment” by inviting stakeholders from all the relevant departments (and their bosses) to a series of meetings with the goal of drafting a data strategy memo and setting some project priorities. (We arrived at these projects democratically by taping a big list on the wall and letting people vote by checkmark; ideas with the most checks made the cut.) Priorities will change, of course, but having some concrete goals to guide you will help.
  4. Go off the reservation: No matter how good your IT department is, their priorities are unlikely to be in sync with yours. They’re thinking big-picture product roadmaps with lots of moving pieces. Good luck fitting your database of dog names (oh yes, we did one of those) into their pipeline. Early on, database producer Ben Welsh set up a Django box at projects.latimes.com, where many of the Times’ interactive projects live. There are other great solutions besides Django, including Ruby on Rails (the framework that powers the Times’ articles and topics pages and many of the great data projects produced by The New York Times) and PHP (an inline scripting language so simple even I managed to learn it). Some people (including the L.A. Times, occasionally) are using Caspio to create and host data apps, sans programming. I am not a fan, for reasons Derek Willis sums up much better than I could, but if you have no other options, it’s better than sitting on your hands.
  5. Templatize: Don’t build it unless you can reuse it. The goal of all this is to be able to roll out projects rapidly (see #6), so you need templates, code snippets, Flash components, widgets, etc., that you can get at, customize and turn around quickly. Interactive graphics producer Sean Connelley was able to use the same county-level California map umpteen times as the basis for various election visualizations in Flash.
  6. Do breaking news: Your priority list may be full of long-term projects like school profiles and test scores, but often it’s the quick-turnaround stuff that has the biggest immediate effect. This is where a close relationship with your newsgathering staff is crucial. At the Times, assistant metro editor Megan Garvey has been overseeing the metro staff’s contributions to data projects for a few months now. When a Metrolink commuter train collided with a freight train on Sept. 12, Megan began mobilizing reporters to collect key information on the victims while Ben adapted an earlier Django project (templatizing in action!) to create a database of fatalities, complete with reader comments. Metro staffers updated the database via Django’s easy-to-use admin interface. (We’ve also used Google Spreadsheets for drama-free collaborative data entry.) … Update 11/29/2008: I was remiss in not pointing out Ben’s earlier post on this topic.
  7. Develop new skills: Disclaimer: I know neither Django nor Flash, so I’m kind of a hypocrite here. I’m a lucky hypocrite, though, because I got to work with guys who dream in ActionScript and Python. If you don’t have access to a Sean or a Ben — and I realize few newsrooms have the budget to hire tech gurus right now — then train and nurture your enthusiasts. IRE runs occasional Django boot camps, and there are a number of good online tutorials, including Jeff Croft’s explanation of Django for non-programmers. Here’s a nice primer on data visualization with Flash.
  8. Cohabitate (but marriage is optional): This may be less of an issue in smaller newsrooms, but in large organizations, collaboration can suffer when teams are split among several floors (or cities). The constituent parts of the Times’ Data Desk — print and web graphics, the computer-assisted reporting team and the interactive projects team — have only been in the same place for a couple months, but the benefits to innovation and efficiency are already clear. For one thing, being in brainstorming distance of all the people you might want to bounce ideas off of is ideal, especially in breaking news situations. Also, once we had everybody in the same place, our onetime goal of unifying the reporting structure became less important. The interactive folks still report to latimes.com managing editor Daniel Gaines, and the computer-assisted reporting people continue to report to metro editor David Lauter. The graphics folks still report to their respective bosses. Yes, there are the occasional communication breakdowns and mixed messages. But there is broad agreement on the major priorities and regular conversation on needs and goals.
  9. Integrate: Don’t let your projects dangle out there with a big ugly search box as their only point of entry. Weave them into the fabric of your site. We were inspired by the efforts of a number of newspapers — in particular the Indianapolis Star and its Gannett siblings — to make data projects a central goal of their newsgathering operations. But we wanted to do more than publish data for data’s sake. We wanted it to have context and depth, and we didn’t want to relegate data projects to a “Data Central“-type page, something Matt Waite (of Politifact fame) memorably dubbed the “data ghetto.” (I would link to Waite’s thoughtful post, but his site unfortunately reports that it “took a dirt nap recently.”) I should note that the Times recently did fashion a data projects index of its own, but only as a secondary way in. The most important routes into data projects are still through related Times content and search engines.
  10. Give back: Understand that database and visualization projects demand substantial resources at a time when they’re in very short supply. Not everyone in your newsroom will see the benefit. Make clear the value your work brings to the organization by looking for ways to pipe the best parts (interesting slices of data, say, or novel visualizations) into your print or broadcast product. For example, some of the election visualizations the data team produced were adapted for print use, and another was used on the air by a partner TV station.

When I shared this post with Meredith Artley, latimes.com’s executive editor and my former boss, she pointed to the formation about a year ago of the interactive projects team within the web staff (Ben, Sean and me; Meredith dubbed us the “cool kids,” a name that stuck):

“For me, the big step was creating the cool kids team — actually forming a unit with a mandate to experiment and collaborate with everyone in the building with the sole intention of creating innovative, interactive projects.”

And maybe that should have been my first piece of advice: Before you can build a data team, you need one or more techie-journalists dedicated full-time to executing online the great ideas they’ll dream up.

What else did I miss? If you’ve been through this process (or are going through it, or are about to), I hope you’ll take a minute to share your insights.

Open Source GIS Stack (Mikel Maron)

Sunday, November 16th, 2008

[Editor's note: If you want to stay away from Google, Microsoft, and ESRI to get your interactive, online map on, here's how. Also check out this interesting PDF article on GeoDjango.]

Republished from Brainoff.com on Oct. 31st, 2008.

There’s a need for a good, high level description of the alternatives within in the “gently settling” stack of open source geoweb application development.

The OpenGeo Stack is the epitome of clarity, breaking down their tool set in a nice executive summary. But the OpenGeo stack only covers their tools, not all the available options. So I’m going to make a quick first pass of a high level overview. It’s useful for me, maybe for others. If you think I’ve done a poor job, help improve it in the comments, or on some wiki somewhere.

OpenGeo breaks things down into FrontEnd, Tiling, ApplicationFramework, Database. I’ll add Rendering, since in other tool sets this is split into different packages.

FrontEnd
the slippy map

* OpenLayers the Ajax gold standard
* ModestMaps for mind blowing Flash, ala Stamen
* Mapstraction don’t want to tax your mind? it looks just like the Google/Yahoo/Microsoft API

Tiling
be nice to your database or WMS and cache map images into tiles, just like Google and friends

* TileCache simple bit of python
* GeoWebCache same thing in Java
* mod_tile it’s kinda OpenStreetMap specific, but an apache module is a good idea too

Rendering
make pretty maps

* Mapnik looks beautiful. getting somewhat less painful to install.
* Mapserver does it all. also a pain to configure. looking better.
* GeoServer

ApplicationFramework
where the the main logic of the app goes. MVC. CRUD. etc.

* GeoDjango making great progress on a complete package.
* GeoRails more a bunch of plugins than a package, but definitely useable
* GeoServer the standard for open geo standards. Java.

Database

* Postgres + PostGIS
* MySQL sure, it has spatial extensions too. just not as fast or fully implemented as PostGIS

Random notes, other good sources

Architect your interfaces on Geo RESTful services. Andrew breaks down the formats and approaches for Neogeography and the GeoWeb in this presentation and book. For Ajax smooveness, use jQuery or prototype. Paul Ramsey has a good deep overview of open source GIS. Mecklenburg County GIS is a nice example of an instance of the stack.

There really is a need for a new book on this stuff, the O’Reilly trio of paper geo titles are great but out of date, and the landscape of osgeowebappdev is stabilising. Of course, no one wants to write it.

GBIF data heat maps – Heat maps over Google Maps for Flash (Biodivertido)

Wednesday, September 3rd, 2008

[Editor's note: Fascinating proof-of-concept for how to create and display heat-maps in Google Maps for Flash/Flex AS3 using PHP back-end for calculation and Flash for front-end. More information for using Google Maps in Flash CS3 download and reference and tutorial. Similar to some nifty work Zach Johnson is working up at Universal Mind for spatialkey.com.]

Reprinted from Biodivertido.

Maps like everything else seems to be trendy. And nowadays the sexy thing in mapping is the creation of Heat Maps. The best way to understand what they are is to see them:

You can also take a look at this post from one of my favorite blogs on what is and what is not a heat map.
Well for long time I wanted to give it a try and yesterday I had the time to experiment a bit. The idea was to display GBIF available data as a Heat Map over Google Maps. Here you have an screenshot for Quercus ilex:
And if you want to try for yourself here it is (some usability issue, the search box is on the bottom right corner):
So how does it work? It was actually easier than I expected:
1) Get the data: I am using the so called “Density tables” from GBIF. You can access them through GBIF web services API at http://es.mirror.gbif.org/ws/rest/density . For example in a query like this one for Quercus ilex (of course you need to get the taxonconceptkey from a previous request to the services): 
This works fine but has some problems. The first one is that GBIF goes down almost every evening. Tim can maybe explain why. Thats why I am using the spanish mirror (look at the url) and I recommend you to do the same.
Second problem is the verbosity of the XML schema being used. For downloading the Animalia, well thats the biggest concept you can get probably, the result is 14.1 MB of XML. And thats just to get a list of cellIds (if anybody is interested we can post details about CellIds) with counts on them, exactly an array of 34,871 numbers. Even worst is handling them on a web client like this one, parsing such a huge xml output kills the browser. The GBIF webservices API deserve its own blog post I would say together with Tim.
But what is new is that I have supercow powers on GBIF :D I am working for GBIF right now and have access to a test database. In a testing environment I developed a little server app that publish the same density service but using theAMF protocol. I used AMFPHP for this if anybody is interested. There are two good things about using AMF: The output now is around 150 KB for the same thing and AMF is natively supported by Flash so there is no need to be parsed it goes straight into memory as AS3 Objects.
2) Create a Het Map from the data: Once the data is on the client I make use of a Class from Jordi Boggiano called HeatMap.as that creates Sprites as the result. In my case I decided to create a Spring, think like an Image, of 1 pixel per cellId creating a 360×180 pixel image (cellId is equivalent to a 1 degree box).
3) Overlay the image on Google Maps: When you have the Sprite, or even earlier but thats too many details, what you do is overlaying in Google Maps for Flash using a GroundOverlay object that takes care of the reprojection and adapting it to the map. The GroundOverlay is explained in the doc as a way to overlay images but it accepts actually any Sprite.
Done! (almost)
4) Ok, there are some problems: Yes, it is not perfect, these are the pending issues:
  • The GroundOverlay seems to not be reprojecting correctly the Sprite I generate and in the very north and south everything is not correctly overlayed.
  • The resolution of the Heat Map is a little bit poor, bu actually represent the quality of the data we have. Some interpolation could be done to make it look nicer.
  • The colours of the Heat Map do not fit well with the actual Google Maps layers. When there is small data then you can not see it almost.
I still dont feel confident with the code to release it yet. I hope I can work a little bit more on it so that i can be proud, but if you desperately need it let me know.
Just another notice. Yesterday Universal Mind released a preview of a new product: Spatial Key. I am always impressed with what this people does and follow the blogs from their developers (like this one and this one). They are kind of my RIA and web GIS heroes. The new product they have released actually look very much like what I wanted to do in Biodiversity Atlas for data anlysis. It lets people explore geographically and temporally huge datasets. Tim suggested me to contact them and I will do. Nevertheless it is great to have such a great tool available to get ideas on interaction design. Good job Universal Mind, you really rock.
We want to see your comments!
Update: 
Some people asked for different quality settings on the heat map. I have modified the application so that you get now a set of controls to define different quality and drawing options. By default the app tries to figure out depending on the number of occurrences, but maybe thats not the best, depends on how the data is dsitributed. In a final product I think I would NOT provide this functionality to the user, too much for my taste. You know, less is more.

ESRI ArcMap Web Mashup Services (Recap)

Wednesday, July 9th, 2008

The Spring edition of ArcNews recaps some important ESRI announcements about version 9.3′s ability to create mashups on par with Google Maps that were announced at the 2008 ESRI Developer Summit. More than 1,200 developers representing 69 organizations in 49 countries attended the conference. Images and summaries below from ESRI. [ ] enclose my comments.

esri 2008 conf 1

“The ArcGIS 9.3 platform places a much greater emphasis on the Web,” said [Scott] Morehouse [director of Software Development at ESRI]. “The technology platform for GIS has evolved over the years. Initially, the focus was on leveraging minicomputers and workstations with an emphasis on high-performance computing and end-user interactivity. Then, the focus shifted to the database with an emphasis on information modeling and transactional data management. Now, the focus is on the Web. We have been working to put the Web at the center of everything that we’re doing with the ArcGIS system.”

JavaScript and REST APIs

The new APIs were showcased at the Plenary Session and in technical sessions presented by the ArcGIS engineers who developed them. In the REST API session, there were demonstrations of how to use JavaScript, Python, Ruby, and Yahoo! Pipes to access backend REST services powered and published by ArcGIS Server. All resources and operations exposed by the REST API are accessible through a URL.

In the ArcGIS JavaScript APIs session, there were demonstrations on how mashups can be built using JavaScript with REST that add map layers and tasks from ArcGIS Server to Google Maps and Microsoft Virtual Earth. The JavaScript API comes in three flavors: ArcGIS JavaScript API, ArcGIS JavaScript Extension for Microsoft Virtual Earth, and ArcGIS JavaScript Extension for Google Maps. [A Flash based API is also planned].

ArcGIS Server 9.3 Offers New and Enhanced Support for OGC Standards

At 9.3, ArcGIS Server provides enhanced support for the three leading Open Geospatial Consortium (OGC) Web standards: Web Map Service (WMS), Web Feature Service (WFS), and Web Coverage Service (WCS). In addition, with the recent announcement from OGC that Keyhole Markup Language (KML) 2.2 is now an official OGC standard, ArcGIS Server at 9.3 will comply with the OGC KML specification by allowing users to publish their geographic data as KML 2.2. Read more.

esri 2008 conf 3

New Features in ArcGIS Engine 9.3 Coming Soon

ArcGIS Engine developers can also now use the integrated Eclipse 3.3 plug-in to inspect the state of ArcObjects. In addition, ArcGIS Engine 9.3 supports the Java Development Kit version 6 on the latest platforms. Read more.

ESRI to also support Flash interface

Monday, May 12th, 2008

Why are mashups via ESRI important? It will allow cartographers to create custom maps with our own look-and-feel, with thematic data, and still be fully enabled with the “mashup” web 2.0 mentality using APIs similar to those from Google and Yahoo.

The earlier post mentions a REST javascript API for interfacing with the Arc Server to create mashups. That’s true in the first release, but a followup release will allow Flash / Flex integration as well. 

Read more from flex888.com and see an example

More info on the REST api from mandownnz.com.

Info Design Patterns

Monday, May 12th, 2008

the form of facts and figures 

(Thanks Peter! Description via eismann-sf.com)

Christian Behrens, a Berlin native, created this website of information design patterns for his masters thesis at Postdam University of Applied Science. The website is a web-representation of content he has formatted into book form, and judging from the screenshots on his site of the book he’s rocking the design of the printed matter.

Christian’s website has a Flash based interface akin to Color Brewer or Type Brewer for picking what visualization should be paired up with what data. Each visualization includes a Fact Sheet with a description, general layout, implementation, and real-world example.

the form of fact and figures example

Take Control of Your Maps (A List Apart)

Monday, May 12th, 2008

(Reprinted from A List Apart. Thanks Peter! Paul Smith is is a co-founder and developer at EveryBlock, see this blog post. He has been creating sites and applications on the Web since 1994. He’s also co-creator of the Election Day Advent Calendar, and a founding member of Friends of the Bloomingdale Trail. He lives in Chicago, Illinois.)

by PAUL SMITH

map a list apart

We live in the era of Google Maps. What started off as an impressive refresh of Mapquest-style maps now fuels web mashups. With APIs official and unofficial, Google Maps is simple enough for front-end designers to embed and for back-end programmers to target. Along the way to becoming nearly ubiquitous, it has played a major role in the “democratization of mapping.” For the practical developer who wants to add geospatial information to a site or application, the Google Maps API has been an easy call.

But, perhaps no longer. As websites mature and the demand for geographic applications grow, the old mashup arrangement is starting to chafe. Mapping components are more and more vital, and so we demand greater control, expressiveness, and functionality from them.

Fortunately, as in many aspects of internet technology, an ecology of open source online mapping tools has emerged alongside the market leader. It is now possible to replicate Google Maps’ functionality with open source software and produce high-quality mapping applications tailored to our design goals. The question becomes, then, how?

Continue reading how to create a custom web map . . .

– And skipping right to the conclusion –

Conclusion

One of the great things about online mapping is that it straddles the line between the artistry and communication of cartography, and the precision and programmability of GIS. You can produce great-looking maps that are highly functional and integrate smoothly with your application. It’s my hope that this article demystified the web map stack and will get you thinking about how you can take control of the maps in your site.

RESOURCES/EXTERNAL LINKS

There are many open source projects related to online mapping and GIS. This article touched on these:

In addition, just to name a few: Modest Maps and Mapstraction are browser UI libraries similar to OpenLayers, in Flash and JavaScript, respectively. GeoServer and MapServer are alternatives to Mapnik in the map rendering department. You owe it to yourself to investigate these alternatives, as they each excel in different ways and one may meet your needs better than the others.

How Tag Clouds Work (indiemaps.com)

Wednesday, May 7th, 2008

Zach Johnson has a good post about how Tag Clouds work from a cartographic perspective on his indiemaps.com blog. While we have been trained to scale objects based on their area, he concludes tag clouds might be best scaled by size (height) alone.

I have done some Illustrator scipting that take into account the ink area and the raw results are unsatisfactory and must be scaled again by the width of the tag character count to still make visual sense. All this work does not significantly change how the tag cloud is read (indeed, it may make it harder) and must be done in a graphics environment like Illustrator or Flash (not simple HTML).

Read Zach’s full post here…

zack johnson tag cloud

Getting from Google Earth KML to Google Maps Javascript markup

Thursday, November 29th, 2007

It irks me to no end you have to have the Pro version of Google Earth to import Shapefiles. This is useful if you want to turn shapefiles into KML and pass them around, use them as an overlay on a plain vanilla Google map, etc. But why can’t I just save out marker points and polygons into the Google Maps javascript markup?

This PHP script helps with converting kml POLYGONS to google maps polygons. It needs some tweeking to adapt to PLACEMARKS, which I’m more interested in.

Script source from the google-maps-api Google Group originally seen here:

<?php

$kmlfile = 'http://maps.google.com/maps/ms?ie=UTF8&hl=en&msa=0&output=kml&msid=109250181535574469723.00043cb961e5234cea628';

$xml = simplexml_load_file($kmlfile) or die("url not loading");

echo "var states = { <br/>";
foreach($xml->Document->Placemark as $placemark) {
  $name = $placemark->name;
  echo "'" . $name . "' : [";
  $coords = $placemark->Polygon->outerBoundaryIs->LinearRing->coordinates;
  $coordsArray = split("\n", $coords);
  for ($i = 0; $i < count($coordsArray); $i++) {
    $latlngArray = split(",", $coordsArray[$i]);
      if (count($latlngArray) == 3) {
      $lat = $latlngArray[1];
      $lng = $latlngArray[0];
      echo "new GLatLng(" . $lat . "," . $lng . ")";
      if ($i != count($coordsArray) -2) echo ", ";
    }
  }
  echo "],<br/>";
}
echo "}";
?>

Sample results here which are used by this HTML page to draw the polygons using this function (below):

function initialize() {
   if (GBrowserIsCompatible()) {
     map = new GMap2(document.getElementById("map_canvas"), {draggableCursor: 'crosshair'});
     map.setCenter(new GLatLng(42, -99), 3);
     map.addControl(new GSmallMapControl());
     for (stateCode in stateBorders) {
       var polygon = createPoly(stateCode);
       map.addOverlay(polygon);
     }
  }
}

So still not there, but closer.