# Parse which tileset the tile is using

**URL:** <https://discourse.mapeditor.org/t/parse-which-tileset-the-tile-is-using/3950>\
**Category:** Questions\
**Created:** [June 7, 2019, 4:25pm UTC](https://discourse.mapeditor.org/t/parse-which-tileset-the-tile-is-using/3950 "2019-06-07T16:25:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Elvis\_L](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.mapeditor.org/elvis_l/32/2335_2.png) [@Elvis\_L](https://discourse.mapeditor.org/u/Elvis_L)\
**Post date:** [June 7, 2019, 4:25pm UTC](https://discourse.mapeditor.org/t/parse-which-tileset-the-tile-is-using/3950/1 "2019-06-07T16:25:33Z")

</div>

I"m parsing the tmx file directly as a XML file, and I was wondering if there is any way to know which tileset the tile is using? I see that If i’m using two tilesets it just puts as an attribute the “gid”, so there is no way I can guess which tileset is using

---

<div class="post-metadata">

**Author:** ![bjorn](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.mapeditor.org/bjorn/32/1599_2.png) [@bjorn](https://discourse.mapeditor.org/u/bjorn)\
**Post date:** [June 8, 2019, 7:58pm UTC](https://discourse.mapeditor.org/t/parse-which-tileset-the-tile-is-using/3950/2 "2019-06-08T19:58:39Z")

</div>

Hey @Elvis_L, welcome to the forums!

This part is covered by the [following section in the manual](http://doc.mapeditor.org/en/stable/reference/tmx-map-format/#data):

> Whatever format you choose for your layer data, you will always end up with so called “global tile IDs” (gids). They are global, since they may refer to a tile from any of the tilesets used by the map. In order to find out from which tileset the tile is you need to find the tileset with the highest `firstgid` that is still lower or equal than the gid. The tilesets are always stored with increasing `firstgid`s.

You can scroll further down for a small code example of how this could be done. A linear search over the tilesets as done there will generally work out fine since most maps refer to only a few tilesets. Of course, you could also prepare an array or map to potentially make the lookup faster.

---

<div class="post-metadata">

**Author:** ![Elvis\_L](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.mapeditor.org/elvis_l/32/2335_2.png) [@Elvis\_L](https://discourse.mapeditor.org/u/Elvis_L)\
**Post date:** [June 8, 2019, 11:01pm UTC](https://discourse.mapeditor.org/t/parse-which-tileset-the-tile-is-using/3950/3 "2019-06-08T23:01:42Z")

</div>

Thank you very much! I was wondering if it was something like that, since the gid that a second tileset I was using was bigger than the higher gid I was getting from the first tileset, but I wanted to be sure, thank you very much!
