View Full Version : New to forum - Using SVG maps generated by php from data in mysql

Simon Tomlin
09-14-2011, 07:45 AM
Hi All,

I am based in London UK and am working on a map of Roman Britain. It is in fact a game so the map changes over time. It is also interactive with some JavaScript but mostly via hyper-links.

It is a vehicle for me to learn how to write an application which can be used across any compliant device which can process SVG. SVG is also used for symbolism and iconography to vacillate the reduction of text.

I would be interested in anybody else doing the same - its been a lonely year so far.

I find that the cartography not only very great fun to work on but the community seems the most advanced for what I want to achieve.

At the moment I hand code all my SVG usually via php, for example roads, population centres where the data is stored in a MySQL database.

Anyway, just thought I'd drop a line to introduce myself.


The title should be Data in MySQL not date but cannot edit it

09-14-2011, 07:59 AM
Title fixed.

Sounds like you are writing your own GIS application!

Welcome aboard!

-Rob A>

Simon Tomlin
09-14-2011, 08:25 AM
Thanks for changing the title.

I had to google GIS application, so I am behind in the cartographers worlds lexicon. However reading the Wikipedia entry and what I am doing is similar, albeit on a more modest scale.

At the moment I am using a OS map but it was hard work getting the data into the database and was wondering if anybody else had tried the same thing. I could use satellite maps I guess since its the topography I am interested in.

I have only just signed up and will trawl the posts as I am sure to find some golden nuggets of information here.

09-14-2011, 09:08 AM
I think the responses depend on whether you are after the map or after the knowledge about how to make the map using the PHP, MySQL and SVG. As Rob has said your writing a GIS app and there are loads of them about, some big and expensive like say ArcGIS and others free and open source - QGis I think is a free one.

Isomage here had some maps which were done from some scripts and generated SVG. I know Inkscape will export SVG vector data if you want to look at any or check compatibilities at any stage. I know that some browsers like Firefox will display SVG directly so its a case of writing out some text files and sending to the browser. I.e. doing a web page SVG map is not a big deal. Getting the right SVG from the data is where the effort is of course.

Anyway, look forward to seeing what you come up with.

Steel General
09-14-2011, 09:50 AM
Welcome Aboard!

Simon Tomlin
09-14-2011, 10:35 AM
I have the knowledge of PHP, MySQL and SVG. perhaps if I explain where I am and the problems I have or foresee.
I have a map of Southern Britain which is taken from an OS Map of Roman Britain.

I am actually interested in the period 350BC but it does not matter really. The map is at the scale of 100m, so below that is not represented. I have 10 tribes in this area which do varied economic activities such as wood cutting, trail building, building stone circles and also having military units. These activities impact the environment which is recorded by the database which is then used by php scripts to create the SVG which is then sent to the browser. Military armies can also move over the map using the roads/trails for efficiency. All this is in turn based real time which at the moment is set at 8 mins equals one day so a year is approx 48 hrs in real time. Each one of the tribes can be either human controlled or by the AI. Combat is carried out by taking the map data and expending it by a factor of 100 to give the dimensions of 1 metre per user unit. This new map it created purely to record the battle and its results. The actual logic for this is in PHP which then creates the SVG so that the battle is displayed via animation so a player can view the battle. Some browsers have the ability to pause and VCR like control the animation but most just play it through.

This all works fine except the graphics are poor due to my lack of artistic talent and also I have to code all the graphics which means they have to be somewhat minimal however the main issue is keeping the transmission size down since I want it to be usable on small devices such as mobile phones where data traffic can be costly for the user.

The problem I have is it needs to expand to cover the rest of Britain and Wales plus Gaul and ultimately the entire area at the height of the Roman empire. Hand coding from OS maps is not the answer so I need to find a better method and cartographers are the obvious folks who have this expertise. I think I have learnt something useful already with the GIS app information that has been provided. I really have no intention of trying to replicate something already in place. I will take a look at QGis.

I have used Inkscape and although very good for detailed drawings it is of limited use due to its large file size. I have to go back and edit all the files anyway so I find it easier to hand draw what I want and then code it.

Another issue I have which has not been resolved was displaying the forestation of the landscape. In the beginning I would paint the trees on the map according to a formula which worked well except the file size was too much. I tried using patterns but I need them to be placed in specific areas or they can clash with over features. I then tried simple colouration which would display the level of forestation by shades of green. This was a horrible failure as it was just plain ugly.

I am currently rewriting a version for single players which will be the tutorial. I will post the link but its not mapping to any advanced level. It would only be of interest to someone who wanted to use some of the technology.

Anyway thank you for the tips and I'll post some maps - maybe when the game is at the later stages and the maps have some data on them. Although the quality on here is at a much higher artistic quality than a coder like myself can create.

Let me have a look around and find the correct group to post in.

Thanks again for the reply
Simon T

Hugo Solis
09-14-2011, 10:58 AM
Welcome Simon!

09-14-2011, 12:09 PM
Hi again, Simon. Also wanted to point you to: http://dev.mysql.com/doc/refman/5.0/en/spatial-extensions.html just in case you weren't aware of them. I think the GIS extension is fairly new to MySQL as a few years back I was forced to use postgres to get that functionality.

-Rob A>

Simon Tomlin
09-14-2011, 01:41 PM
Hi I actually posted a reply to Redrobes but for some reason it said waiting for a moderator to approve?

The GIS extensions are totally new to me and I am grateful for the link.

I'll have a look at them and keep you posted. Could be a massive bonus for me. Thanks

Simon T

09-14-2011, 06:29 PM
Hi I actually posted a reply to Redrobes but for some reason it said waiting for a moderator to approve?

The GIS extensions are totally new to me and I am grateful for the link.

I'll have a look at them and keep you posted. Could be a massive bonus for me. Thanks

Simon T

I approved the post. The auto-mod caught it in the queue.

-Rob A>

09-14-2011, 06:53 PM
It took me a while to figure out "OS" meant "Ordnance Survey". It's not a term used outside the UK.

Try taking a look at OpenStreetMap for free vector data. It's modern, rather than roman, but it's free (assuming the CC license works for you) and there are already tools for converting it to SVG, Mapnik and Osmarender being the two big names.

You might also find OpenLayers helpful, it provides "slippymap" functionality (The OpenStreetMap main page, Google Maps, Bing Maps, etc) and can incorporate map services provided by Mapnik or OSM (or Google Maps), along with raw geographic vector data like GML, GeoJSON, etc which can be symbolized, selected, edited, etc.

09-14-2011, 08:10 PM
Hmm thats quite some project then.

I think maybe you should look at Hai's idea of grabbing some of the OpenStreetMap data and echo the CC licensing note. But it would get you the coastal outlines and some of the features you need quite quickly.

In terms of getting trees and stuff its all starting to sound like a full on game engine and maybe what we call a VTT - a Virtual Table Top which is a mapping system where people can make role playing moves and get those adjustments to the map delivered via the internet to all the other clients logged in. I write one of those and I am grokking the kind of low bandwidth and tree icon stamping that you are looking at. See my sig for more info and the VTT section here on the forums.

In terms of AI for combatants thats a pretty involved problem all by itself. I wrote an app and a thread about it here called mapping with economics which you might also want to have a browse at.


I found that quite a challenge to get even that far and I didn't think it made much of an effect of simulating the world conflict even in a small space. Maybe I haven't quite got the gist of it right.

Anyways there's a few more things to consider. And I would think that you meant 350 AD not BC if were talking about Romans in the UK.

Simon Tomlin
09-15-2011, 04:19 AM
Hai-Etliks suggestions sounds very useful and I will certainly follow those up. My most time consuming and also badly done aspect of the mapping so far is the coast lines and rivers. The thought of getting the coast lines mapped and the difficult rivers sounds very appealing thank you very much for the suggestions. Sorry for the cryptic OS reference.

Redrobes, your economic project is very interesting but much more advanced than the system I am using or need. For example the trees symbolism is only to show the level of woodland. Woodland is important in the economic system for food, fuel and of cause timber. At this period of time there is no shortage of woodland in Southern Britain but it will be an impact in other areas such as the Mediterranean coastlines where ship building is more comprehensive and populations larger.

There is also the other side of the coin where clearing lands aids in the development of farming and husbandry. It also has a military impact for battlefields lack of an open spaces impacts military formations and the deployment of certain weaponry (basically it becomes more close quarters and communication becomes an issue).

However, it does share your projects desire to model the living aspect of the community, house building, roads farms etc.
So its the level of detail which is the difference. Yours is a lot higher. Basically players want to see change happening in their world and so when a new settlement is made a house is shown, a road being completed is nice to see it snake along to conclusion. Stone circles look good on the map as well as they convey a sense of development.

The time is correct at 350BC and there is a reasoning behind this. It is a convenient starting point with Persia being the most powerful, Greece on the ascent after Phillips hegemony, the start of Rome and the Carthaginian Navy controlling the southern Mediterranean. During this time Britain is a back water which makes it convenient for a place to start since its very basic and not much is known about it so historical accuracy is not so important - realistic is the demand rather than historic.

I will definitely check out the VTT threads. I did find a natural attraction to the board gaming subject since the military system has some roots in a board game GMTs Great Battles of History. However I think you are right that its natural placing is in the VTT world due to the number of players and eventual scale.

Once again thanks for your help, very impressed with the site and the members.

Simon Tomlin
09-15-2011, 01:40 PM
Reply waiting for moderation

09-15-2011, 01:46 PM
Fixed - sorry to have missed that earlier.

09-16-2011, 12:58 PM
Welcome to the Guild!