Attention! Do you have any ideas for reorganizing and updating the Mapki? Please leave a note here. Thank you!

EvilC's Hierarchical Bunching Method-Intro

From Google Mapki

Jump to: navigation, search

Database>>

Introduction

In this article, I will detail the method I have developed for a Heirarchical Bunching System that I developed for my open source project GP.

I will be using PHP as the server side language in any code examples I may use but there is no reason other languages should not work. I will be using MySQL as the database, specifically version 4.1 MySQL 4.1 introduces "Geospatial Extensions", which allows a field type that can hold points, lines, polygons in one field. Easier than having a Lat and Lng field and having to do calculations yourself. With GeoSpatial extensions you can just include a clause in your WHERE statement that specifies the corners of a box and it does the work for you. This is possible in other databases, eg Postgres, and the syntax may be similar.

The Z factor: Zooms

Obviously the way to go is to show different things for the same area dependant on what you can see. If Texas fills the sceen, why draw the 500 points in Dallas ? It will just be a mess nyway. Draw a marker for Dallas, which, helpfully, has an infowindow with a link that zooms you to a point Dallas fills the screen and you can clearly make out the points in the city. Wherever you are in google maps, you are viewing from a certain zoom level. 0 is "zoomed out" or "low zoom" meaning that you can see the whole world in one window. Positive zooms are progressively (?2x than the last?) zoomed in. At first, in V1, the zoom levels were the other way around, but they were switched to make it easier to add more and more levels of zoom. Max zoom varies, but 17 is about the average limit for supported areas. This article uses V2 style zoom (0 is zoomed out, see the whole world). Each bunch point has a zoom value associated with it. That zoom value is the zoom at which it becomes meaningless. The bunch point for the state of texas becomes meaningless once you can see the whole of texas. This number would be a different zoom value than the one for the state of connecticut seeing as it is much smaller. You could zoom in more to connecticut and still be able to see all of it.

Hierarchies

Hierarchies in databases are commonly done by using what is called an "Adjacency List". That is, each record in the hierarchy has a parent_id field which lists the record number of the parent. This is robust and useful, but pulling entire parts of the tree is not possible with just one query. There is a method that I read about here called "nested set" which does allow entire branches of the tree to be pulled in one query. However, the drawback of this method is that if you add anything to the tree, you must rebuild the tree. This is a minor thing really though since the tree data is held in two numeric fields in the record ("lft" and "rgt") which are otherwise meaningless. I will use an Adjacency list as well as the "master" list in case the nested set list gets damaged. Rebuilding the tree is a case involves a function that recursively walks the adjacency list tree and rebuilds the nested set tree lft and rgt fields as needs be.

Database>>

Personal tools