I shouldn't have to reinvent this – tiled (geo) map pyramid generator in Haxe?

234 views
Skip to first unread message

Mike Robinson

unread,
Mar 18, 2015, 12:22:27 PM3/18/15
to haxe...@googlegroups.com
Given an arbitrary bitmap, I want to generate the "image pyramid" used in a map display ... a set of 256x256 bitmap tiles at increasing levels of magnification.  I'm finding various Python programs to do this, but I need to do it directly in OpenFL.  Where can I look?

Mike Robinson

unread,
Mar 24, 2015, 9:28:34 AM3/24/15
to haxe...@googlegroups.com
(Ping ...?)  Nothing out there?  Really ...??

Justin Donaldson

unread,
Mar 24, 2015, 1:00:09 PM3/24/15
to Haxe
Yeah, there should be something out there.  Do you know of any AS3 implementations?  Those should be a snap to port.

-Justin

On Tue, Mar 24, 2015 at 6:28 AM, Mike Robinson <sundial....@gmail.com> wrote:
(Ping ...?)  Nothing out there?  Really ...??

--
To post to this group haxe...@googlegroups.com
http://groups.google.com/group/haxelang?hl=en
---
You received this message because you are subscribed to the Google Groups "Haxe" group.
For more options, visit https://groups.google.com/d/optout.

Mike Robinson

unread,
Mar 24, 2015, 3:38:15 PM3/24/15
to haxe...@googlegroups.com
That's exactly my thought:  there should be something out there in AS3.  The only thing I'm finding is in Python.

Justin L Mills

unread,
Mar 24, 2015, 8:31:39 PM3/24/15
to haxe...@googlegroups.com
Is this java relevant?
http://www.paulinternet.nl/?page=bicubic
Would need to study it some more to work out using it for an image but I think it could work.

Mike Robinson

unread,
Mar 25, 2015, 1:31:09 PM3/25/15
to haxe...@googlegroups.com
Nope, I don't readily see how "cubic interpolations" have anything whatsoever to do with the construction of map-tile pyramids . . .  am I missing something?

Tarwin Stroh-Spijer

unread,
Mar 25, 2015, 5:05:51 PM3/25/15
to haxe...@googlegroups.com

I'm confused by what you're looking for. I just did a search for "image pyramid" because I'd never heard of it before and came up with this:

http://docs.opencv.org/doc/tutorials/imgproc/pyramids/pyramids.html

As far as I can tell it is simply a "stack" of resized versions of an image no? Hence the suggestion of the resized above?

What's the purpose of it? Are you trying to make tiles for a map?

Justin L Mills

unread,
Mar 25, 2015, 6:09:04 PM3/25/15
to haxe...@googlegroups.com

On 25/03/2015 21:05, Tarwin Stroh-Spijer wrote:

As far as I can tell it is simply a "stack" of resized versions of an image no? Hence the suggestion of the resized above?

yep it seems to be just upsampling or downsampling a 2D data source, it's just easier to do it only doubling or halving data in both directions ( pyramid ), there is no point assuming it's any more. The 256 is just the tile size, processing size is more likely 16 as in the perhaps possible link.


On Mar 25, 2015 10:31 AM, "Mike Robinson" <sundial....@gmail.com> wrote:
Nope, I don't readily see how "cubic interpolations" have anything whatsoever to do with the construction of map-tile pyramids . . .  am I missing something?

On Tuesday, March 24, 2015 at 8:31:39 PM UTC-4, JLM wrote:
Is this java relevant?
http://www.paulinternet.nl/?page=bicubic
Would need to study it some more to work out using it for an image but I think it could work.

"Bicubic interpolation

Bicubic interpolation is cubic interpolation in two dimensions. I'll only consider the case where we want to interpolate a two dimensional grid."  4x4 matrix.

The concept is that using matricies you can generate points in a sparce matrix ( fill in holes ) using predictive equations (interpolation), basically your applying an equation to a matrix so taking say a grid of 16 from your image and apply an equation to predict other points then repeating for each color so the equation essentially adds weighting to points and tries to curve fit them to a cubic.  in real coding terms matrices are often pretty inefficient way to calculate something fast, better to break down the actual operations and more or less just pass them in the output, without bothering with creating generalized matrix code structures and operators. The link was one referenced on a page about up and down sampling but one that contains real code and not just matrices, and seems to be doing this and is better than say averaging nearest or some of the other common but simpler approaches.

The code seems to be setup to upsample ( add intermediate points to the data ) I think ( but not sure ) between points although probably overlapping 4x4 grid would be needed and overlaps averaged or similar to process the whole image experimentation is probably needed to get good results but certainly this might be a good start.

To down sample you can use just some of the generated between points and throw all the other points away so for every 4 points you would get a point you interpolated that was in the middle of them.

Apparently if you wanted something even better, say using fractals you can get data that looks real when you upscale because it keeps the same amount of detail and never ends up blured, kind of hard to explain unless you read a few books on chaos, but neadless to say that is probably going to be fairly slow processing if you try to use fractals unless your very smart in use?

Bicubic is probably one of the drop down options on photoshop export for web when resizing an image.

I figured the code might be enough if ported and understood to work in a recursive pyramid or a structure that process all groups of 16. Often it's tricky to work out how to put maths into code and this seemed to contain some of the essence although I admit even the author suggests that it's a bit more work to apply to an image.  I suspect the python code does similar, but python is less close to haxe so maybe no so easy to port.


Mike Robinson

unread,
Mar 25, 2015, 9:18:12 PM3/25/15
to haxe...@googlegroups.com, tar...@touchmypixel.com
Yes, precisely.  Given a fairly large and detailed map, ideally one provided in SVG format, generate the tile-pyramid (of 256x256 pixel tiles) needed to properly display the map, say with HaxeMaps, Leaflet.js, or maybe ModestMaps.  Dump it, say, to an "MBTiles" (SQLite...) database.

... in Haxe / OpenFL.

Chii Chan

unread,
Mar 26, 2015, 6:06:11 AM3/26/15
to haxe...@googlegroups.com
but what's a tile pyramid? There's tile textures (which could be packed together in a batch), there's tile-maps (like what tiled might produce). Never heard of a tile pyramid before.

Tarwin Stroh-Spijer

unread,
Mar 26, 2015, 6:40:23 PM3/26/15
to haxe...@googlegroups.com
If it's SVG simply resize it and read chunks out one at a time, resize again, repeat. Would that not work ? The mapping between one piece and another should be simple if you're doubling/halving as they say.



Tarwin Stroh-Spijer
_______________________

phone: +1 650 842 0920

Developer at Fanplayr Inc. (Palo Alto)
Original at Touch My Pixel (touchmypixel.com)
_______________________

On Thu, Mar 26, 2015 at 3:06 AM, Chii Chan <sangoh...@gmail.com> wrote:
but what's a tile pyramid? There's tile textures (which could be packed together in a batch), there's tile-maps (like what tiled might produce). Never heard of a tile pyramid before.

Mike Robinson

unread,
Mar 29, 2015, 5:12:46 PM3/29/15
to haxe...@googlegroups.com
A "tile pyramid" is a technique that's used in mapping.  For instance, when you display a map of your country on Google Maps, MapQuest, Open Streetmaps, or <<anything else>>, you notice that it gets filled-in as a series of squares.  When you zoom the map, the map gets redrawn – again, a square at a time – with more detail.  In fact, you might notice that each of the less-detailed squares on the display is replaced by four squares at a great level of detail in the same geographic position., and that if you zoom in once more, each of those squares are replaced by four more.  If you zoom out, four squares are replaced by one less detailed-one.

The standard way that this is done is to divide the map into 256x256 pixel tiles at levels of magnification which are powers-of-two.  Let's say that the very top of the pyramid is a single cell with a tiny map of the world.  At zoom-level one, that one tile is divided into 4 tiles.  At zoom-level two, each of those tiles are divided into 4 tiles.  And so on.  The pyramid at each level is, of course, at a different scale.  

I'm finding lots of "map tilers," commercial and otherwise, but not yet a Flash/AS3 or Haxe one.

Justin L Mills

unread,
Mar 29, 2015, 9:23:39 PM3/29/15
to haxe...@googlegroups.com
Mike

I really don't see the problem, you don't need acurate rescaling code, you just want code for positioning a grid of rectangles?

If you have some online data say 3 levels then it should not be hard to implement, normally easier to start with some test data, you have not mentioned the horrors of longtitude and latitude calculations so presume you really want something quite simple, you just want two for loops with some calculation on where to start them.

//my first guess which I have not thought deeply about or considered edge cases might be along the lines of..

container.x = -left;
container.y = -top;

var tileWidth = 256;
var tileHi = 256;

// calculate tiles to show
var tileStartX = left%tileWidth;
var tileEndX = (right-tileWidth)%tileWidth;
var tileStartY = top%tileHi;
var tileEndY = (bottom-tileHi)%tileHi;

// calculate offset position
var dx = left - tileStartX*tileWidth;
var dy = top - tileStartY*tileHi;
 
// remove all tiles ( lazy but fine as a starting point ).
for( arrTiles in tiles ) for( yTile in arrTiles ) container.removeChild( yTile );

var tile: Sprite;
// add tiles needed at relevent position.
for( x in tileStartX...tileEndX ){
  for( y in tileStartY...tileEndY ){
    tile = tiles[x][y];
    tile.x = x*tileStartX - dx;
    tile.y = y*tileStartY - dy;
    container.addChild( tile );
  }
}

if you want to load them in 4 structures you just need a loops with a 2 step size and process the four inside.

I have missed out the scaling aspect but that just effects the left, right, top, bottom values you input, well to be honest I would have to have a play with some real data, but I don't really understand what the problem it's just some for loops and some calculations.

Best

Justin
--

Mike Robinson

unread,
Apr 8, 2015, 2:53:58 PM4/8/15
to haxe...@googlegroups.com
No, the (simple) task is to generate the set of tiles.

There's a standard Python script called "gdal2tiles.py" that is an example of this.

And the actual requirement is drop-dead simple ... which leaves me puzzled why no one has done it in Haxe.  We have, in "haxeMaps," much of the necessary logic – the math is not hard – but not an actual generator program.

I guess I'll have to write one myself, after all.

David Peek

unread,
Apr 9, 2015, 7:11:08 AM4/9/15
to haxe...@googlegroups.com
If the requirement -is- dropdead simple, and there are existing, cross-platform, mature solutions to the problem, why on earth do you need to rewrite it in Haxe? Just call the python script using Sys.command and be done with it? Even better I'm sure there are multiplatform binaries out there so users don't need python installed.

Mike Robinson

unread,
Apr 9, 2015, 8:47:49 AM4/9/15
to haxe...@googlegroups.com
Well, for one thing, while there are commercial products out there which do it ... they used to be open but no more ... I'd like to be able to generate the tiles on-the-fly in my own code.  (It's a bit of a long story.)  I'm certainly able to do it, but I'm rather startled to have to do it.  :)  I rather assumed that I'd missed it on Github.
Reply all
Reply to author
Forward
0 new messages