#native_company# #native_desc#

GIS Mapping with PHP; Part Two

By Simon Moss
on February 9, 2004

In my previous article I described a very simple method of plotting longitude
and latitude coordinates onto a drawn map of the world. With a very small amount
of work modifying the script in the article – adding a FOR loop and some database
code ) you could quite easily come up with a system like www.geoURL.com.
The main limitation with this system is that you are restricted as to what
background you can use. You have to have a predrawn raster image drawn in the
correct scale and projection for the information you want to display. What if
all you want to show is the location of a house in Prince Edward Island? Where
do you get that raster image? What if the house is on the edge of the island
and you want it centered on the screen? What if you want to zoom in and out
without a significant loss of quality? What if goats overthrow the goverments
of the world and forced us to wear itchy beards?. The answer to these questions
is to draw your own background images dynamically. You can then scale, move,
center, color to your hearts content. As for the goats .. well .. be nice to
them and they will be nice to you.

What’s the point of Vector?

So then first step is to get and process the data for the background image.
The data we need is called vector data ( as opposed to the Raster image we were
viously dealing with ). This is normally stored as a list of points divided
into regions which make up complete polygon shape of the state / province /
country. These points are normally listed as longitude and latitudes, which
is great because we already have a function from the previous article to convert
long/lats into screen coordinates – getlocactioncoords. Vector maps allow for
easy scaling and movement. You can rotate, stretch and skew with a minimum of
fuss and bother.
Now the big problem is finding the vector data in the first place. You can
buy this information, or you can find basic vector information around the web.
www.geogratis.com is a good place to start. Also check the US/Canadian Enviromental
sites. Remember, normally the purchased products will have a greater level of
detail. Most of the world is available for free in 1:1000000 scale, including
outline maps for US and Canadian states/provinces … just give google a try.
For those lucky lucky people with access to Mapinfo check the sample disks that
come with it. You should find coverage for North America plus a geocoded US
Gazeteer. Another good google keyword to keep in mind is DCW – the digital chart
of the world. This gives you polygons for every country in the world, plus more
detailed information for North America ( states and provinces ). You can also
find lakes, rivers, roads and outlines of major population areas.
Ok, so you’ve downloaded a chunk of data. We now run into our next problem.
Most of the vector data on the web is in Arcview format ( .E00 ). We need to
load this data into PHP in to variables which we can them read and manipulate.
We need to be able to differentiate between the different types of vector information
and also ( in later stages ) be able to assign colors and formating to the data.
The E00 format is text based ( in uncompressed form ) and there a few PHP routines
out there that will load the various elements of an E00 file and draw it onto
an image. However, in this article I will have -converted all my E00 into Mapinfo
MIF format. “Why?” you ask. “You swine, we thought you were going
to tell us how to load E00 directly” you scream. Well, for starters the
MIF format is very easy to read and load in a script, and also allows for various
attributes to be associated with the polygon region ( which although we ignore
could be usefull to some people ). The other reason is that I use Mapinfo is
that if you are serious about GIS, Mapinfo is a very handy tool to have. I’m
not on a commission ( though a free mug would be nice ) , but from experience
a proper GIS application becomes invaluable when dealing with large amounts
of information and will allow you to export a wide variety of GEO vector data
into the PHP scripts I’ve given you. It is great for splitting large vector
regions into smaller, more manageable chunks ( think Quebec, a bit map at the
best of times ) – the smaller the chunks of data you deal with the faster the
processing time and the less work PHP will have to do. The other benefit is
being able to align downloaded data and “triming” regions which are
out of alignment. Remember free data from different sources will always have
different levels of accuracy. Being able to align and trim data to a base map
will make your maps look much more professional. Remember PHP will never be
able to offer the complete functionality a true GIS application can, so if you
are serious about mapping its worth splashing out on a licence on good GIS tool.
For those without access to GIS tools ( c’mon guys, there are some free utilities
out there ), the import routine provided in this article could easily be modified
to read from E00 files, and if I have time I will add the routine to do this
in another article at a later date. If someone wants to do one and let me see
it, even better. I will see if I can incorporate it.
Anyho, back to getting our data in.