Hi,
Your algorithm uses a temporary list which is modified. That is not very effective, it is much better to do the selection directly and never create any temporary list (see example attached below for an example).
If you have 600 POI's it is really noy that much. Given that you do not read the XML from disk eveytime (that is expensive!) and do not create intermediate lists it should be fast.
But one way of getting the solution to be faster is to group all POIs in a 2-dimensional array gruping the POIs on location so only a subset of them has to be searched.
Here is a quick and dirty implementation (not tested, and unfortunately in C# - but I don't do VB.NET :cool:). It should give you a hint of how to get faster implementation:
public class POI {
public int X { get; set; }
public int Y { get; set; }
public string Value { get; set; }
}
public class PoiStore {
public const int MAP_SIZE_X = 7000;
public const int MAP_SIZE_Y = 2000;
public const int DELTA = 100;
private readonly IList<POI>[,] _array = new IList<POI>[MAP_SIZE_X/DELTA, MAP_SIZE_Y/DELTA];
private void Store(POI poi) {
var x = poi.X / DELTA;
var y = poi.Y / DELTA;
var list = _array[x, y];
if (list == null) {
list = new List<POI>();
_array[x, y] = list;
}
list.Add(poi);
}
public void ReadXml(string url) {
var doc = XDocument.Load(url);
foreach (var uriElement in doc.Root.Elements("URI")) {
Store(new POI {
X = int.Parse(uriElement.Element("CoordX").Value),
Y = int.Parse(uriElement.Element("CoordY").Value),
Value = uriElement.Element("Value").Value
});
}
}
public IEnumerable<POI> Find(Point from, Point to) {
for (var xIndex = from.X / DELTA; xIndex <= to.X / DELTA; xIndex++) {
for (var yIndex = from.Y / DELTA; yIndex <= to.Y / DELTA; yIndex++) {
var list = _array[xIndex,yIndex];
if (list == null) continue;
foreach (var poi in list) {
if (from.X <= poi.X && poi.X <= to.X && from.Y <= poi.Y && poi.Y <= to.Y) {
yield return poi;
}
}
}
}
}
}