|
Last change
on this file since 11277 was 11277, checked in by Don-vip, 9 years ago |
|
sonar - fix recently added warnings
|
-
Property svn:eol-style
set to
native
|
|
File size:
1.4 KB
|
| Line | |
|---|
| 1 | // License: GPL. For details, see LICENSE file.
|
|---|
| 2 | package org.openstreetmap.josm.tools;
|
|---|
| 3 |
|
|---|
| 4 | import java.awt.geom.Area;
|
|---|
| 5 | import java.util.Collection;
|
|---|
| 6 |
|
|---|
| 7 | import org.openstreetmap.josm.data.coor.LatLon;
|
|---|
| 8 | import org.openstreetmap.josm.data.osm.BBox;
|
|---|
| 9 | import org.openstreetmap.josm.data.osm.Way;
|
|---|
| 10 |
|
|---|
| 11 | /**
|
|---|
| 12 | * Implementation of simple boolean {@link GeoProperty}.
|
|---|
| 13 | */
|
|---|
| 14 | public class DefaultGeoProperty implements GeoProperty<Boolean> {
|
|---|
| 15 |
|
|---|
| 16 | private Area area;
|
|---|
| 17 |
|
|---|
| 18 | /**
|
|---|
| 19 | * Create DefaultGeoProperty based on a collection of closed ways.
|
|---|
| 20 | *
|
|---|
| 21 | * @param ways the ways forming the area
|
|---|
| 22 | */
|
|---|
| 23 | public DefaultGeoProperty(Collection<Way> ways) {
|
|---|
| 24 | for (Way w : ways) {
|
|---|
| 25 | Area tmp = Geometry.getAreaLatLon(w.getNodes());
|
|---|
| 26 | if (area == null) {
|
|---|
| 27 | area = tmp;
|
|---|
| 28 | } else {
|
|---|
| 29 | area.add(tmp);
|
|---|
| 30 | }
|
|---|
| 31 | }
|
|---|
| 32 | }
|
|---|
| 33 |
|
|---|
| 34 | @Override
|
|---|
| 35 | public Boolean get(LatLon ll) {
|
|---|
| 36 | return area.contains(ll.lon(), ll.lat());
|
|---|
| 37 | }
|
|---|
| 38 |
|
|---|
| 39 | @Override
|
|---|
| 40 | public Boolean get(BBox box) {
|
|---|
| 41 | Area abox = new Area(box.toRectangle());
|
|---|
| 42 | Geometry.PolygonIntersection is = Geometry.polygonIntersection(abox, area, 1e-10 /* using deg and not meters */);
|
|---|
| 43 | switch (is) {
|
|---|
| 44 | case FIRST_INSIDE_SECOND:
|
|---|
| 45 | return Boolean.TRUE;
|
|---|
| 46 | case OUTSIDE:
|
|---|
| 47 | return Boolean.FALSE;
|
|---|
| 48 | default:
|
|---|
| 49 | return null;
|
|---|
| 50 | }
|
|---|
| 51 | }
|
|---|
| 52 |
|
|---|
| 53 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.