views:

41

answers:

2

Hi,

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 visible at given zoom level.

A: 

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;
}
RED SOFT ADAIR
Thank You. But if I understood correctly this code only checks if oneShape belongs to particular region.I think "In other words" was confusing. Of course Your code is important to achieve that bat I also want to remove to small objects. For example at low zoom level I want to show only continents and at greater level I want to show cites. However I don't want to decide arbitrary what will be visible at given zoom level. Because if some one will print it in high resolution he should be allow to print countries at cites at low zoom level (and use magnifying glass perhaps).
Maciek Sawicki
+1  A: 

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

Matthew Snape
This is exactly what I need. But I prefer to use Geotools ( www.geotools.org )because I'm more in Java then C++. Unfortunately I don't know how to do it in Geotools.
Maciek Sawicki