| 1 |
<para> |
| 2 |
The polygon filter includes points if they are inside |
| 3 |
of a polygon. A polygon file looks like an |
| 4 |
<link linkend="filter_arc">arc</link> file, except |
| 5 |
that the arc it describes must be a closed cycle. That is, |
| 6 |
for a simple polygon, the first and last points must be the |
| 7 |
same. Here's a square: |
| 8 |
</para> |
| 9 |
<screen> |
| 10 |
# A square (not really) polygon |
| 11 |
41.0000 -85.0000 |
| 12 |
41.0000 -86.0000 |
| 13 |
42.0000 -86.0000 |
| 14 |
42.0000 -85.0000 |
| 15 |
41.0000 -85.0000 |
| 16 |
</screen> |
| 17 |
<para> |
| 18 |
Polygons may include islands and holes. To include an |
| 19 |
island or a hole, just append it to the main polygon. |
| 20 |
</para> |
| 21 |
<screen> |
| 22 |
# A square polygon with a triangular hole |
| 23 |
41.0000 -85.0000 |
| 24 |
41.0000 -86.0000 |
| 25 |
42.0000 -86.0000 |
| 26 |
42.0000 -85.0000 |
| 27 |
41.0000 -85.0000 |
| 28 |
# The hole begins here |
| 29 |
41.5000 -85.5000 |
| 30 |
41.6000 -85.5000 |
| 31 |
41.6000 -85.6000 |
| 32 |
41.5000 -85.5000 |
| 33 |
</screen> |
| 34 |
<para> |
| 35 |
As with the arc filter, you define a polygon by |
| 36 |
giving the name of the file that contains it, using |
| 37 |
the <option>file</option> option. |
| 38 |
</para> |
| 39 |
<para> |
| 40 |
Note that this filter currently will not work properly |
| 41 |
if your polygon contains one or both poles or if it spans the |
| 42 |
line of 180 degrees east or west longitude. |
| 43 |
</para> |
| 44 |
<example xml:id="example_polygon_filter"> |
| 45 |
<title>Using the polygon filter</title> |
| 46 |
<para> |
| 47 |
Suppose you have a polygon file that defines the border of your county, |
| 48 |
called mycounty.txt. This command line will give you only the points |
| 49 |
in your county: |
| 50 |
</para> |
| 51 |
<para><userinput>gpsbabel -i geo -f 1.loc -x polygon,file=mycounty.txt -o mapsend -F 2.wpt</userinput></para> |
| 52 |
</example> |
| 53 |
<example xml:id="example_in_or_close_to"> |
| 54 |
<title>Using the polygon and arc filters to find points in or nearly in a |
| 55 |
polygon</title> |
| 56 |
<para> |
| 57 |
Because the polygon and <link linkend="filter_arc">arc</link> filters use |
| 58 |
the same file format, you can use them together to find all points that are |
| 59 |
"in or nearly in" a polygon. This can be useful if your waypoints or the |
| 60 |
boundaries of your polygon are not quite perfect, so you want to provide a |
| 61 |
buffer zone around it in case there are points nearby that should be in the |
| 62 |
polygon but aren't quite. |
| 63 |
</para> |
| 64 |
<para><userinput> |
| 65 |
gpsbabel -i gpx -f points.gpx -x stack,push -x polygon,file=mycounty.txt |
| 66 |
-x stack,swap -x arc,file=mycounty.txt,distance=1k -x stack,pop,append |
| 67 |
-x duplicate,shortname -o gpx -F nearmycounty.gpx |
| 68 |
</userinput></para> |
| 69 |
<para> |
| 70 |
This command makes a copy of the points, finds the ones that are in your |
| 71 |
your county, swaps that result with the copy of the original set of points, |
| 72 |
finds the ones from that set that are within 1 km of the border of the county, |
| 73 |
puts the two lists together, and then filters out any points that appear twice |
| 74 |
(This step is necessary because points inside the county but near the county |
| 75 |
line will be kept by both the polygon and the arc filter.) |
| 76 |
</para> |
| 77 |
</example> |