Board index FlightGear Development Scenery

Behind tileIndex()  Topic is solved

Questions and discussion about enhancing and populating the FlightGear world.

Behind tileIndex()

Postby rleibner » Sun Jun 28, 2020 1:54 am

Hi,
In Nasal we have the tileIndex() func. to know the stg number from de lat/long coords.
But, outside Nasal, may I know the algorithm ?
Context: I'm writing some python tools (thinking on Scenery developers).
I mean something like:
Code: Select all
#!/usr/bin/python

def stgNumber(lat, long):
    . . . .
    return number

Any clue?.
Rodolfo
*************************
Non-shared knowledge is lost knowledge
User avatar
rleibner
 
Posts: 259
Joined: Fri May 19, 2017 7:17 pm
Location: Uruguay - SUMU
Callsign: CX-BEX
Version: next
OS: Ubuntu 18.04.4

Re: Behind tileIndex()

Postby frtps » Sun Jun 28, 2020 4:28 am

I think newbucket.hxx in the simgear code has what you need:

Code: Select all
   inline long int gen_index() const {
        return ((lon + 180) << 14) + ((lat + 90) << 6) + (y << 3) + x;
    }


Note that the lat,long for each tile refers to the south west corner, and the individual tiles are 1/8 degrees of latitude. The divisions in longitude depend on latitude, see the sg_bucket_span function in the same file.
frtps
 
Posts: 103
Joined: Sun Aug 05, 2018 9:58 am

Re: Behind tileIndex()

Postby Gijs » Sun Jun 28, 2020 6:18 am

Airports: EHAM, EHLE, KSFO
Aircraft: 747-400
User avatar
Gijs
Moderator
 
Posts: 9429
Joined: Tue Jul 03, 2007 2:55 pm
Location: Amsterdam/Delft, the Netherlands
Callsign: PH-GYS
Version: Git
OS: Windows 10

Re: Behind tileIndex()

Postby portreekid » Sun Jun 28, 2020 6:36 am

There is a python implementation in osm2city. (calc_tile.calc_tile_index) and there is Java in TerraMaster.
portreekid
 
Posts: 436
Joined: Tue Jan 14, 2014 3:36 pm
Location: Leipzig
Callsign: PORTREE
Version: 2020.2.1
OS: Windows 10

Re: Behind tileIndex()

Postby rleibner » Sun Jun 28, 2020 6:07 pm


Yes, I saw it, but didn't realized how the number is generated.

There is a python implementation in osm2city. (calc_tile.calc_tile_index) ...
Thanks Gijs, it is what I was searching for. :)
Rodolfo
*************************
Non-shared knowledge is lost knowledge
User avatar
rleibner
 
Posts: 259
Joined: Fri May 19, 2017 7:17 pm
Location: Uruguay - SUMU
Callsign: CX-BEX
Version: next
OS: Ubuntu 18.04.4

Re: Behind tileIndex()  

Postby portreekid » Sun Jun 28, 2020 8:09 pm

Code: Select all
 base_y = floor(lat)
 y = trunc((lat - base_y) * 8)
 base_x = floor(floor(lon / tile_width) * tile_width)
 x = floor((lon - base_x) / tile_width)


That's basically it.
portreekid
 
Posts: 436
Joined: Tue Jan 14, 2014 3:36 pm
Location: Leipzig
Callsign: PORTREE
Version: 2020.2.1
OS: Windows 10

Re: Behind tileIndex()

Postby rleibner » Mon Jun 29, 2020 1:49 am

Solved !
Thanks.
Rodolfo
*************************
Non-shared knowledge is lost knowledge
User avatar
rleibner
 
Posts: 259
Joined: Fri May 19, 2017 7:17 pm
Location: Uruguay - SUMU
Callsign: CX-BEX
Version: next
OS: Ubuntu 18.04.4


Return to Scenery

Who is online

Users browsing this forum: No registered users and 1 guest