I have file (*.shp used in GIS) that contains collection of polygons and maybe other vector objects (but polygons are most important for me). I need to remove non printable objects it.
I don't know what criteria chose. I think removing objects with small border length would be better then removing objects with small area (so long objects will reduce to line). But maybe there is special algorithm for that?
In other words I want to find only that objects that are开发者_Python百科 visible at given zoom level.
Thats quite simple. As you dont mention any language consider the following pseudocode
drawRect = myDevice.GetDrawRect();
for(oneShape in allShapes)
{
shapeRect = oneShape.GetRect()
if(! drawRect.Contains(shapeRect))
oneShape.MarkAsInvisible();
else
oneShape.Draw();
}
the Contains() function would look something like that, assuming that y-values increase from bottom to top:
bool Rect::Contains(OtherRect)
{
if(left <= OtherRect.right &&
right >= OtherRect.left &&
top >= OtherRect.bottom &&
bottom <= OtherRect.top)
return true
return false;
}
The polygons to eliminate would depend on the dpi of the image you wish to create. If a line is only going to fill one pixel it should be eliminated or replaced with a point representation. Of course this will be effected by the width of the line. A lot of these sort of problems would be solved by using a dedicated mapping library such as mapnik.org
精彩评论