| 1 | package org.openstreetmap.josm.data.osm;
|
|---|
| 2 |
|
|---|
| 3 | import java.util.List;
|
|---|
| 4 |
|
|---|
| 5 | import org.openstreetmap.josm.data.Bounds;
|
|---|
| 6 |
|
|---|
| 7 | /**
|
|---|
| 8 | * DataSet is the data behind one window in the application. It can consist of only a few
|
|---|
| 9 | * points up to the whole osm database. DataSet's can be merged together, split up into
|
|---|
| 10 | * several different ones, saved, (up/down/disk)loaded etc.
|
|---|
| 11 | *
|
|---|
| 12 | * Note, that DataSet is not an osm-primitive, so it has no key association but a few
|
|---|
| 13 | * members to store some information.
|
|---|
| 14 | *
|
|---|
| 15 | * @author imi
|
|---|
| 16 | */
|
|---|
| 17 | public class DataSet implements Cloneable {
|
|---|
| 18 |
|
|---|
| 19 | /**
|
|---|
| 20 | * human readable name of the data.
|
|---|
| 21 | */
|
|---|
| 22 | public String name;
|
|---|
| 23 |
|
|---|
| 24 | /**
|
|---|
| 25 | * human readable description of what the data is about. Space for comments.
|
|---|
| 26 | */
|
|---|
| 27 | public String desc;
|
|---|
| 28 |
|
|---|
| 29 | /**
|
|---|
| 30 | * Who recorded/created it.
|
|---|
| 31 | */
|
|---|
| 32 | public String author;
|
|---|
| 33 |
|
|---|
| 34 | /**
|
|---|
| 35 | * All nodes goes here, even when included in other data (tracks etc) listed.
|
|---|
| 36 | * This enables the instant conversion of the whole DataSet by iterating over
|
|---|
| 37 | * this data structure.
|
|---|
| 38 | */
|
|---|
| 39 | public List<Node> allNodes;
|
|---|
| 40 |
|
|---|
| 41 | /**
|
|---|
| 42 | * All tracks (Streets etc.) in the DataSet.
|
|---|
| 43 | *
|
|---|
| 44 | * The nodes of the track segments of this track must be objects from
|
|---|
| 45 | * the nodes list, however the track segments are stored only in the
|
|---|
| 46 | * track list.
|
|---|
| 47 | */
|
|---|
| 48 | public List<Track> tracks;
|
|---|
| 49 |
|
|---|
| 50 | /**
|
|---|
| 51 | * Return the bounds of this DataSet, depending on X/Y values.
|
|---|
| 52 | * The min of the return value is the upper left GeoPoint, the max the lower
|
|---|
| 53 | * down GeoPoint, regarding to the X/Y values.
|
|---|
| 54 | *
|
|---|
| 55 | * Return null, if any point not converted yet or if there are no points at all.
|
|---|
| 56 | *
|
|---|
| 57 | * @return Bounding coordinate structure.
|
|---|
| 58 | */
|
|---|
| 59 | public Bounds getBoundsXY() {
|
|---|
| 60 | if (allNodes.size() == 0)
|
|---|
| 61 | return null;
|
|---|
| 62 |
|
|---|
| 63 | Bounds b = new Bounds(allNodes.get(0).coor.clone(), allNodes.get(0).coor.clone());
|
|---|
| 64 | for (Node w : allNodes)
|
|---|
| 65 | {
|
|---|
| 66 | if (Double.isNaN(w.coor.x) || Double.isNaN(w.coor.y))
|
|---|
| 67 | return null;
|
|---|
| 68 | if (w.coor.x < b.min.x)
|
|---|
| 69 | b.min.x = w.coor.x;
|
|---|
| 70 | if (w.coor.y < b.min.y)
|
|---|
| 71 | b.min.y = w.coor.y;
|
|---|
| 72 | if (w.coor.x > b.max.x)
|
|---|
| 73 | b.max.x = w.coor.x;
|
|---|
| 74 | if (w.coor.y > b.max.y)
|
|---|
| 75 | b.max.y = w.coor.y;
|
|---|
| 76 | }
|
|---|
| 77 | return b;
|
|---|
| 78 | }
|
|---|
| 79 |
|
|---|
| 80 | /**
|
|---|
| 81 | * Return the bounds of this DataSet, depending on lat/lon values.
|
|---|
| 82 | * The min of the return value is the upper left GeoPoint, the max the lower
|
|---|
| 83 | * down GeoPoint.
|
|---|
| 84 | *
|
|---|
| 85 | * Return null, if any point does not have lat/lon or if there are no
|
|---|
| 86 | * points at all.
|
|---|
| 87 | *
|
|---|
| 88 | * @return Bounding coordinate structure.
|
|---|
| 89 | */
|
|---|
| 90 | public Bounds getBoundsLatLon() {
|
|---|
| 91 | if (allNodes.size() == 0)
|
|---|
| 92 | return null;
|
|---|
| 93 |
|
|---|
| 94 | Bounds b = new Bounds(allNodes.get(0).coor.clone(), allNodes.get(0).coor.clone());
|
|---|
| 95 | for (Node w : allNodes)
|
|---|
| 96 | {
|
|---|
| 97 | if (Double.isNaN(w.coor.lat) || Double.isNaN(w.coor.lon))
|
|---|
| 98 | return null;
|
|---|
| 99 | if (w.coor.lat < b.min.lat)
|
|---|
| 100 | b.min.lat = w.coor.lat;
|
|---|
| 101 | if (w.coor.lon < b.min.lon)
|
|---|
| 102 | b.min.lon = w.coor.lon;
|
|---|
| 103 | if (w.coor.lat > b.max.lat)
|
|---|
| 104 | b.max.lat = w.coor.lat;
|
|---|
| 105 | if (w.coor.lon > b.max.lon)
|
|---|
| 106 | b.max.lon = w.coor.lon;
|
|---|
| 107 | }
|
|---|
| 108 | return b;
|
|---|
| 109 | }
|
|---|
| 110 |
|
|---|
| 111 | public DataSet clone() {
|
|---|
| 112 | try {return (DataSet)super.clone();} catch (CloneNotSupportedException e) {}
|
|---|
| 113 | return null;
|
|---|
| 114 | }
|
|---|
| 115 | }
|
|---|