Changeset 32394 in osm for applications/editors/josm/plugins/seachart/src/s57/S57box.java
- Timestamp:
- 2016-06-24T03:48:12+02:00 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/seachart/src/s57/S57box.java
r32082 r32394 12 12 import java.util.ArrayList; 13 13 14 import s57.S57map.*; 15 import s57.S57obj.*; 14 import s57.S57map.Edge; 15 import s57.S57map.Feature; 16 import s57.S57map.Pflag; 17 import s57.S57map.Rflag; 18 import s57.S57map.Snode; 19 import s57.S57obj.Obj; 16 20 17 21 public class S57box { //S57 bounding box truncation 18 19 enum Ext {I, N, W, S, E } 20 21 static Ext getExt(S57map map, double lat, double lon) { 22 if ((lat >= map.bounds.maxlat) && (lon < map.bounds.maxlon)) { 23 return Ext.N; 24 } else if (lon <= map.bounds.minlon) { 25 return Ext.W; 26 } else if (lat <= map.bounds.minlat) { 27 return Ext.S; 28 } else if (lon >= map.bounds.maxlon) { 29 return Ext.E; 30 } return Ext.I; 31 } 32 33 public static void bBox(S57map map) { 34 /* Truncations 35 * Points: delete point features outside BB 36 * Lines: Truncate edges at BB boundaries 37 * Areas: Truncate edges of outers & inners and add new border edges. Merge inners to outer where necessary 38 * Remove nodes outside BB 39 * Remove edges that are completely outside BB 40 */ 41 class Land { 42 long first; 43 Snode start; 44 Ext sbound; 45 long last; 46 Snode end; 47 Ext ebound; 48 Feature land; 22 // CHECKSTYLE.OFF: LineLength 49 23 50 Land(Feature l) { 51 land = l; 52 first = last = 0; 53 start = end = null; 54 sbound = ebound = Ext.I; 55 } 56 } 57 if (map.features.get(Obj.COALNE) != null) { 58 ArrayList<Feature> coasts = new ArrayList<>(); 59 ArrayList<Land> lands = new ArrayList<>(); 60 if (map.features.get(Obj.LNDARE) == null) { 61 map.features.put(Obj.LNDARE, new ArrayList<Feature>()); 62 } 63 for (Feature feature : map.features.get(Obj.COALNE)) { 64 Feature land = map.new Feature(); 65 land.id = ++map.xref; 66 land.type = Obj.LNDARE; 67 land.reln = Rflag.MASTER; 68 land.objs.put(Obj.LNDARE, map.new ObjTab()); 69 land.objs.get(Obj.LNDARE).put(0, map.new AttMap()); 70 if (feature.geom.prim == Pflag.AREA) { 71 land.geom = feature.geom; 72 map.features.get(Obj.LNDARE).add(land); 73 } else if (feature.geom.prim == Pflag.LINE) { 74 land.geom.prim = Pflag.LINE; 75 land.geom.elems.addAll(feature.geom.elems); 76 coasts.add(land); 77 } 78 } 79 while (coasts.size() > 0) { 80 Feature land = coasts.remove(0); 81 Edge fedge = map.edges.get(land.geom.elems.get(0).id); 82 long first = fedge.first; 83 long last = map.edges.get(land.geom.elems.get(land.geom.elems.size() - 1).id).last; 84 if (coasts.size() > 0) { 85 boolean added = true; 86 while (added) { 87 added = false; 88 for (int i = 0; i < coasts.size(); i++) { 89 Feature coast = coasts.get(i); 90 Edge edge = map.edges.get(coast.geom.elems.get(0).id); 91 if (edge.first == last) { 92 land.geom.elems.add(coast.geom.elems.get(0)); 93 last = edge.last; 94 coasts.remove(i--); 95 added = true; 96 } else if (edge.last == first) { 97 land.geom.elems.add(0, coast.geom.elems.get(0)); 98 first = edge.first; 99 coasts.remove(i--); 100 added = true; 101 } 102 } 103 } 104 } 105 lands.add(new Land(land)); 106 } 107 ArrayList<Land> islands = new ArrayList<>(); 108 for (Land land : lands) { 109 map.sortGeom(land.land); 110 if (land.land.geom.prim == Pflag.AREA) { 111 islands.add(land); 112 map.features.get(Obj.LNDARE).add(land.land); 113 } 114 } 115 for (Land island : islands) { 116 lands.remove(island); 117 } 118 for (Land land : lands) { 119 land.first = map.edges.get(land.land.geom.elems.get(0).id).first; 120 land.start = map.nodes.get(land.first); 121 land.sbound = getExt(map, land.start.lat, land.start.lon); 122 land.last = map.edges.get(land.land.geom.elems.get(land.land.geom.comps.get(0).size - 1).id).last; 123 land.end = map.nodes.get(land.last); 124 land.ebound = getExt(map, land.end.lat, land.end.lon); 125 } 126 islands = new ArrayList<>(); 127 for (Land land : lands) { 128 if ((land.sbound == Ext.I) || (land.ebound == Ext.I)) { 129 islands.add(land); 130 } 131 } 132 for (Land island : islands) { 133 lands.remove(island); 134 } 135 for (Land land : lands) { 136 Edge nedge = map.new Edge(); 137 nedge.first = land.last; 138 nedge.last = land.first; 139 Ext bound = land.ebound; 140 while (bound != land.sbound) { 141 switch (bound) { 142 case N: 143 nedge.nodes.add(1l); 144 bound = Ext.W; 145 break; 146 case W: 147 nedge.nodes.add(2l); 148 bound = Ext.S; 149 break; 150 case S: 151 nedge.nodes.add(3l); 152 bound = Ext.E; 153 break; 154 case E: 155 nedge.nodes.add(4l); 156 bound = Ext.N; 157 break; 158 default: 159 continue; 160 } 161 } 162 map.edges.put(++map.xref, nedge); 163 land.land.geom.elems.add(map.new Prim(map.xref)); 164 land.land.geom.comps.get(0).size++; 165 land.land.geom.prim = Pflag.AREA; 166 map.features.get(Obj.LNDARE).add(land.land); 167 } 168 } 169 return; 24 enum Ext { I, N, W, S, E } 170 25 171 } 26 static Ext getExt(S57map map, double lat, double lon) { 27 if ((lat >= map.bounds.maxlat) && (lon < map.bounds.maxlon)) { 28 return Ext.N; 29 } else if (lon <= map.bounds.minlon) { 30 return Ext.W; 31 } else if (lat <= map.bounds.minlat) { 32 return Ext.S; 33 } else if (lon >= map.bounds.maxlon) { 34 return Ext.E; 35 } 36 return Ext.I; 37 } 38 39 public static void bBox(S57map map) { 40 /* Truncations 41 * Points: delete point features outside BB 42 * Lines: Truncate edges at BB boundaries 43 * Areas: Truncate edges of outers & inners and add new border edges. Merge inners to outer where necessary 44 * Remove nodes outside BB 45 * Remove edges that are completely outside BB 46 */ 47 class Land { 48 long first; 49 Snode start; 50 Ext sbound; 51 long last; 52 Snode end; 53 Ext ebound; 54 Feature land; 55 56 Land(Feature l) { 57 land = l; 58 first = last = 0; 59 start = end = null; 60 sbound = ebound = Ext.I; 61 } 62 } 63 64 if (map.features.get(Obj.COALNE) != null) { 65 ArrayList<Feature> coasts = new ArrayList<>(); 66 ArrayList<Land> lands = new ArrayList<>(); 67 if (map.features.get(Obj.LNDARE) == null) { 68 map.features.put(Obj.LNDARE, new ArrayList<Feature>()); 69 } 70 for (Feature feature : map.features.get(Obj.COALNE)) { 71 Feature land = map.new Feature(); 72 land.id = ++map.xref; 73 land.type = Obj.LNDARE; 74 land.reln = Rflag.MASTER; 75 land.objs.put(Obj.LNDARE, map.new ObjTab()); 76 land.objs.get(Obj.LNDARE).put(0, map.new AttMap()); 77 if (feature.geom.prim == Pflag.AREA) { 78 land.geom = feature.geom; 79 map.features.get(Obj.LNDARE).add(land); 80 } else if (feature.geom.prim == Pflag.LINE) { 81 land.geom.prim = Pflag.LINE; 82 land.geom.elems.addAll(feature.geom.elems); 83 coasts.add(land); 84 } 85 } 86 while (coasts.size() > 0) { 87 Feature land = coasts.remove(0); 88 Edge fedge = map.edges.get(land.geom.elems.get(0).id); 89 long first = fedge.first; 90 long last = map.edges.get(land.geom.elems.get(land.geom.elems.size() - 1).id).last; 91 if (coasts.size() > 0) { 92 boolean added = true; 93 while (added) { 94 added = false; 95 for (int i = 0; i < coasts.size(); i++) { 96 Feature coast = coasts.get(i); 97 Edge edge = map.edges.get(coast.geom.elems.get(0).id); 98 if (edge.first == last) { 99 land.geom.elems.add(coast.geom.elems.get(0)); 100 last = edge.last; 101 coasts.remove(i--); 102 added = true; 103 } else if (edge.last == first) { 104 land.geom.elems.add(0, coast.geom.elems.get(0)); 105 first = edge.first; 106 coasts.remove(i--); 107 added = true; 108 } 109 } 110 } 111 } 112 lands.add(new Land(land)); 113 } 114 ArrayList<Land> islands = new ArrayList<>(); 115 for (Land land : lands) { 116 map.sortGeom(land.land); 117 if (land.land.geom.prim == Pflag.AREA) { 118 islands.add(land); 119 map.features.get(Obj.LNDARE).add(land.land); 120 } 121 } 122 for (Land island : islands) { 123 lands.remove(island); 124 } 125 for (Land land : lands) { 126 land.first = map.edges.get(land.land.geom.elems.get(0).id).first; 127 land.start = map.nodes.get(land.first); 128 land.sbound = getExt(map, land.start.lat, land.start.lon); 129 land.last = map.edges.get(land.land.geom.elems.get(land.land.geom.comps.get(0).size - 1).id).last; 130 land.end = map.nodes.get(land.last); 131 land.ebound = getExt(map, land.end.lat, land.end.lon); 132 } 133 islands = new ArrayList<>(); 134 for (Land land : lands) { 135 if ((land.sbound == Ext.I) || (land.ebound == Ext.I)) { 136 islands.add(land); 137 } 138 } 139 for (Land island : islands) { 140 lands.remove(island); 141 } 142 for (Land land : lands) { 143 Edge nedge = map.new Edge(); 144 nedge.first = land.last; 145 nedge.last = land.first; 146 Ext bound = land.ebound; 147 while (bound != land.sbound) { 148 switch (bound) { 149 case N: 150 nedge.nodes.add(1L); 151 bound = Ext.W; 152 break; 153 case W: 154 nedge.nodes.add(2L); 155 bound = Ext.S; 156 break; 157 case S: 158 nedge.nodes.add(3L); 159 bound = Ext.E; 160 break; 161 case E: 162 nedge.nodes.add(4L); 163 bound = Ext.N; 164 break; 165 default: 166 continue; 167 } 168 } 169 map.edges.put(++map.xref, nedge); 170 land.land.geom.elems.add(map.new Prim(map.xref)); 171 land.land.geom.comps.get(0).size++; 172 land.land.geom.prim = Pflag.AREA; 173 map.features.get(Obj.LNDARE).add(land.land); 174 } 175 } 176 return; 177 178 } 172 179 173 180 }
Note:
See TracChangeset
for help on using the changeset viewer.