Read tiles from map data and return position and terrain tag

I'm working on a potential complex lighting system and figured I would try and save some time by asking a somewhat simple question here. Does anyone know if RPG Maker MV has a built-in way of returning all tiles in a map? I have found some interesting functions in the Game_Map class but due to lack of documentation I'm having to spend hours reverse engineering their code to figure out poorly named variables like "d" and the like.


What I want to accomplish is:


A. Return all tiles in a map


B. Either sort out the tiles which are impassable or contain a certain terrain tag.


Once that have I data, I intend to pass it through an algorithm which builds a collision polygon of the map that I can later use for casting rays and such.


If anyone has figured this out already please let me know. I'm not beyond reverse engineering but I'm hoping someone else already has.
When you say "all tiles in a map", what exactly do you mean? Do you want the tileId? you can get that from $dataMap.data or something like that.
When you say "all tiles in a map", what exactly do you mean? Do you want the tileId? you can get that from $dataMap.data or something like that.

Sorry for not being more clear. I'm looking for a way to get the origin of each tile which matches a certain terrain tag. I can then use the origin to build a bounding box and go from there. 
Seems I have solved my own question. Since this may be useful to others, here is the code I am using:


//Get relevant tiles from map data
function parseTileData() {
var tileWidth = $gameMap.tileWidth();
var tileHeight = $gameMap.tileHeight();
var shadowTiles = [];

for(var y = 0; y < $dataMap.height; y++) {
for (var x = 0; x < $dataMap.width; x++) {
if ($gameMap.terrainTag(x, y) == 1) {
shadowTiles.push(new Point(x, y)); //Point A
shadowTiles.push(new Point(x + tileWidth, y)); //Point B
shadowTiles.push(new Point(x + tileWidth, y + tileHeight)); //Point C
shadowTiles.push(new Point(x, y + tileHeight)); //Point D
console.log("Added Tile Vertices to Array");
}
}
}
}


Please note that I have not tested this thoroughly. This is meant to return 4 points representing the rectangle occupied by a tile but can easily be modified for other purposes.

Original thread: https://forums.rpgmakerweb.com/threads/read-tiles-from-map-data-and-return-position-and-terrain-tag.60646/