#native_company# #native_desc#
#native_cta#

GIS Mapping with PHP; Part Two Page 7

By Simon Moss
on February 9, 2004

And thats it … you have drawn a map of PEI and plotted my house on it. By
altering the value of $scale you can zoom in and out. By adding/subtracting
variables to $min_x and $min_y you can provide scrolling. You could also just
save the image and use it as a base map for other maps or as a server side cache
to speed things up. Tidy it up in Photoshop or add custom symbols for even better
base maps with no copyright as you made it!!!!. Take it out to dinner and let
it meet your parents.
Now althougth this map just shows PEI, there is no reason why you could not
have a bunch of MIF files ( or one big one ) containing the whole of North America,
or even the world. Then you have a scalable, scrollable map of the freakin’
world! But before you go off celebrating, there are a few things to remember.

Don’t stress out PHP

First and formost is speed. We love PHP and we know it does its best, but we
are not far off doing some major number crunching here. PEI is the smallest
province around ( awwww .. cutie!!! )… when you get to a complicated region
like Quebec with 30000 polygons in it ( or even the world ) .. things really
start to get slow … very slow. These problems will be addressed in the next
article as we let POSTGRESQL do some of the hard work, and we also talk about
making a custom PHP module in C to do some of the donkeywork. However, as a
work-around, consider the following options/modifications:

Make a bunch of scale dependant MIF/E00 file. You are looking at PEI at a scale
of 100000 – you don’t need all that coastline detail. So create another MIF
file with less details, and load it dependant on a preset scale range ( ie pei_1_to_60000.mif,
pei_60000_to_100000.mif and so on ).

We give you the max/min coordinates of a polygon when we load it in LoadMIF
( and you said that code wasn’t being used .. shame on you ), feel free to use
them. If a polygon is outside your display, don’t bother with it. Don’t convert
it and don’t display it! ( this is dealt with in the next article along with
a “reverse” getlocationcoords for this purpose ). This is where a
GIS tool comes in handy. Calculate the scale/size you use most often and split
your map into chunks that just cover that area.
Then comes memory. Be mindfull of PHPs memory usage. The default 8meg allocated
to a script on most PHP installations is not enough to handle a large MIF file
with thousands of polygons ( like British Columbia ). POSTGRESQL will cure some
of this, but try to split large maps into smaller chunks. You can then filter
them in the LoadMIF program ( with some tweaking ).

Summary

So, there you have it. Next time we learn how to get this data into and out
of POSTGRESQL. You want roads? Where we’re going we don’t need roads, but I
show you how to plot them anyway. And maybe we’ll do some work on caching …
you never know.
A formatted copy of the source code can be found here. This does work, I’ve tried it! Please don’t email me asking for map data or
conversion tools. All the things you need are out there for free, just look
for them. Thats how I found them.

1
|
2
|
3
|
4
|
5
|
6
|
7