0

I’m trying to use wikimapia API.

The coordinates that I receive from them looks like e.g. X=148163437, Y=99238706 for a place with lat=42.406425N, lon=18.702075E. What’s even more funny, objects residing in Argentina (both latitude and longitude are negative) still have positive coordinates.

How do I convert coordinates from Wikimapia’s proprietary coordinate system into the normal one?

P.S. I'm requesting JSON data with Mercator option.

Soonts
  • 20,079
  • 9
  • 57
  • 130
  • You say "e.g. X=148163437, Y=99238706" Are those the actual values or values you made up? What are the actual numbers you get back? – John Sep 20 '13 at 23:38
  • @John, it's the actual values, namely the north-west coordinate of some ancient church on an island nearby. – Soonts Sep 20 '13 at 23:58
  • 1
    http://stackoverflow.com/questions/14329691/covert-latitude-longitude-point-to-a-pixels-x-y-on-mercator-projection – Preston Guillot Sep 21 '13 at 00:17

2 Answers2

1

This looks like a quadtree system sometimes used for co-ordinate storage. By design it allows for quick indexing, and simple recollection of data. Essentially the 360 by 180 planet is divided up into 4 quadrants (or any multiple thereof - usually less than 8 if pure numericals are used. but can be expanded if alphanumericals are adopted). Each resulting division further divided, and so on. Ie the top left most block will be 1111 in a system where a simple recursive quartering is used 4 times.

I am afraid that unless you know the strategy that was implemented, deciphering the actual allocation can only be calculated is you have a good distribution of know co-ordinates and their quadtree counterparts.

Please note this is my take of your post . . .

GeoManiac
  • 11
  • 1
0

To decode coordinates it's not enough to have only two values (x, y). As I understand they pass MBR in response, not direct coordinates. It really depends on tile's boundary coordinates. I'll give an example of decoding. First, you should have tile's boundary.

If we have tile for all world they have them as:

-1800000000|1800000000|-850511288|850511288

That will be converted to:

let left = -1800000000 / 1e7
let right = 1800000000 / 1e7
let bottom = -850511288 / 1e7
let top = 850511288 / 1e7

And then if you have line of information like this:

30870710|2492727202|1200141117|20170|8177|18| Bagram

It contains MBR of an object and additional information. You can decode it using such code:

let str = '30870710|2492727202|1200141117|20170|8177|18| Bagram'
let temp = str.split('|')

let mbr = {
   left: left + parseInt(temp[1], 10) / 1e7,
   top: bottom + parseInt(temp[2], 10) / 1e7,
   bottom: parseInt(temp[4], 10) / 1e7,
   right: parseInt(temp[3], 10) / 1e7
}

// mbr correction
mbr.bottom = mbr.top - mbr.bottom
mbr.right = mbr.left + mbr.right

let obj = {
    type: "Feature",
    properties: {
       "id": temp[0],
       "name": temp[6],
       "zoom": parseInt(temp[5], 10),
       "mbr": mbr,
    },
    geometry: {
       type: "Point",
       coordinates: [(mbr.left + mbr.right) / 2, (mbr.bottom + mbr.top) / 2]
    }
}