Changeset 20390 in osm for applications
- Timestamp:
- 2010-03-09T22:02:00+01:00 (15 years ago)
- Location:
- applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr
- Files:
-
- 2 added
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CacheControl.java
r19371 r20390 94 94 public boolean loadCacheIfExist() { 95 95 try { 96 String extension = String.valueOf((wmsLayer.getLambertZone() + 1)); 97 if (Main.proj instanceof LambertCC9Zones) 98 extension = cLambertCC9Z + extension; 99 else if (Main.proj instanceof UTM_20N_France_DOM) 100 extension = cUTM20N + extension; 101 File file = new File(CadastrePlugin.cacheDir + wmsLayer.getName() + "." + extension); 96 File file = new File(CadastrePlugin.cacheDir + wmsLayer.getName() + "." + WMSFileExtension()); 102 97 if (file.exists()) { 103 98 JOptionPane pane = new JOptionPane( … … 127 122 public void deleteCacheFile() { 128 123 try { 129 String extension = String.valueOf((wmsLayer.getLambertZone() + 1)); 130 if (Main.proj instanceof LambertCC9Zones) 131 extension = cLambertCC9Z + extension; 132 delete(new File(CadastrePlugin.cacheDir + wmsLayer.getName() + "." + extension)); 124 delete(new File(CadastrePlugin.cacheDir + wmsLayer.getName() + "." + WMSFileExtension())); 133 125 } catch (Exception e) { 134 126 e.printStackTrace(System.out); … … 182 174 imagesLock.unlock(); 183 175 if (size > 0) { 184 String extension = String.valueOf((wmsLayer.getLambertZone() + 1)); 185 if (Main.proj instanceof LambertCC9Zones) 186 extension = cLambertCC9Z + extension; 187 else if (Main.proj instanceof UTM_20N_France_DOM) 188 extension = cUTM20N + extension; 189 File file = new File(CadastrePlugin.cacheDir + wmsLayer.getName() + "." + extension); 176 File file = new File(CadastrePlugin.cacheDir + wmsLayer.getName() + "." + WMSFileExtension()); 190 177 try { 191 178 if (file.exists()) { … … 219 206 } 220 207 } 208 209 private String WMSFileExtension() { 210 String ext = String.valueOf((wmsLayer.getLambertZone() + 1)); 211 if (Main.proj instanceof LambertCC9Zones) 212 ext = cLambertCC9Z + ext; 213 else if (Main.proj instanceof UTM_20N_France_DOM) 214 ext = cUTM20N + ext; 215 return ext; 216 } 217 221 218 } -
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CadastreGrabber.java
r20247 r20390 35 35 imageModified = new RasterImageModifier(img); 36 36 else 37 imageModified = new VectorImageModifier(img );37 imageModified = new VectorImageModifier(img, false); 38 38 return new GeorefImage(imageModified.bufferedImage, lambertMin, lambertMax); 39 39 } catch (MalformedURLException e) { … … 42 42 } 43 43 44 public GeorefImage grabBuildings(WMSLayer wmsLayer, EastNorth lambertMin, EastNorth lambertMax) throws IOException, OsmTransferException { 45 try { 46 URL url = getURLVectorBuildings(lambertMin, lambertMax); 47 BufferedImage img = grab(url); 48 ImageModifier imageModified = new VectorImageModifier(img, true); 49 return new GeorefImage(imageModified.bufferedImage, lambertMin, lambertMax); 50 } catch (MalformedURLException e) { 51 throw (IOException) new IOException(tr("CadastreGrabber: Illegal url.")).initCause(e); 52 } 53 } 54 55 public GeorefImage grabParcels(WMSLayer wmsLayer, EastNorth lambertMin, EastNorth lambertMax) throws IOException, OsmTransferException { 56 try { 57 URL url = getURLVectorParcels(lambertMin, lambertMax); 58 BufferedImage img = grab(url); 59 //ImageModifier imageModified = new VectorImageModifier(img, true); 60 return new GeorefImage(/*imageModified.bufferedImage*/img, lambertMin, lambertMax); 61 } catch (MalformedURLException e) { 62 throw (IOException) new IOException(tr("CadastreGrabber: Illegal url.")).initCause(e); 63 } 64 } 65 44 66 private URL getURLRaster(WMSLayer wmsLayer, EastNorth lambertMin, EastNorth lambertMax) throws MalformedURLException { 45 67 // GET /scpc/wms?version=1.1&request=GetMap&layers=CDIF:PMC@QH4480001701&format=image/png&bbox=-1186,0,13555,8830&width=576&height=345&exception=application/vnd.ogc.se_inimage&styles= HTTP/1.1 … … 49 71 str += wmsLayer.getCodeCommune(); 50 72 str += "&format=image/png"; 73 //str += "&format=image/jpeg"; 51 74 str += "&bbox="; 52 75 str += wmsLayer.eastNorth2raster(lambertMin, lambertMax); 53 //str += "&width=1000&height=800"; // maximum allowed by wms server54 76 str += "&width="+cRasterX+"&height="; // maximum allowed by wms server (576/345, 800/378, 1000/634) 55 77 str += (int)(cRasterX*(wmsLayer.communeBBox.max.getY() - wmsLayer.communeBBox.min.getY())/(wmsLayer.communeBBox.max.getX() - wmsLayer.communeBBox.min.getX())); 56 str += "&exception=application/vnd.ogc.se_inimage&styles="; 78 str += "&exception=application/vnd.ogc.se_inimage&styles="; // required for raster images 79 System.out.println("URL="+str); 57 80 return new URL(str.replace(" ", "%20")); 58 81 } 59 82 60 private URL getURLVector(EastNorth lambertMin, EastNorth lambertMax) throws MalformedURLException { 83 private URL buildURLVector(String layers, String styles, 84 int width, int height, 85 EastNorth lambertMin, EastNorth lambertMax) throws MalformedURLException { 61 86 String str = new String(wmsInterface.baseURL+"/scpc/wms?version=1.1&request=GetMap"); 62 str += "&layers="+ CadastrePlugin.grabLayers;87 str += "&layers="+ layers; 63 88 str += "&format=image/png"; 64 89 //str += "&format=image/jpeg"; … … 67 92 str += lambertMax.east() + ","; 68 93 str += lambertMax.north(); 69 str += "&width="+ CadastrePlugin.imageWidth+"&height="+CadastrePlugin.imageHeight;70 //str += "&exception=application/vnd.ogc.se_inimage"; // used by normal client but not required71 str += "&styles=" +CadastrePlugin.grabStyles;94 str += "&width="+width+"&height="+height; 95 str += "&exception=application/vnd.ogc.se_inimage"; // works also without (but slower ?) 96 str += "&styles=" + styles; 72 97 System.out.println("URL="+str); 73 98 return new URL(str.replace(" ", "%20")); 99 } 100 101 private URL getURLVector(EastNorth lambertMin, EastNorth lambertMax) throws MalformedURLException { 102 return buildURLVector(CadastrePlugin.grabLayers, CadastrePlugin.grabStyles, 103 CadastrePlugin.imageWidth, CadastrePlugin.imageHeight, 104 lambertMin, lambertMax); 105 } 106 107 private URL getURLVectorBuildings(EastNorth lambertMin, EastNorth lambertMax) throws MalformedURLException { 108 return buildURLVector("CDIF:LS2", "LS2_90", 1000, 800, lambertMin, lambertMax); 109 } 110 111 private URL getURLVectorParcels(EastNorth lambertMin, EastNorth lambertMax) throws MalformedURLException { 112 return buildURLVector("CDIF:PARCELLE", "PARCELLE_90", 1000, 800, lambertMin, lambertMax); 74 113 } 75 114 -
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CadastrePlugin.java
r20262 r20390 90 90 * 1.6 28-Nov-2009 - Fix minor issues if Grab is called without layer (possible since projection rework) 91 91 * 1.7 12-Dec-2009 - Change URL's changes for cookie and downgrade imgs resolution due to WMS changes 92 * 1.8 xxx- filter the mouse button 1 during georeferencing92 * 1.8 09-Mar-2010 - filter the mouse button 1 during georeferencing 93 93 * - retry if getting a new cookie failed (10 times during 30 seconds) 94 94 * - cookie expiration automatically detected and renewed (after 30 minutes) … … 188 188 // temporary disabled: 189 189 //JMenuItem menuActionBoundaries = new JMenuItem(new MenuActionBoundaries()); 190 //JMenuItem menuActionBuildings = new JMenuItem(new MenuActionBuildings());190 JMenuItem menuActionBuildings = new JMenuItem(new MenuActionBuildings()); 191 191 192 192 cadastreJMenu.add(menuGrab); … … 196 196 //cadastreJMenu.add(menuResetCookie); not required any more 197 197 //cadastreJMenu.add(menuLambertZone); 198 if (Main.pref.getBoolean("cadastrewms.buildingsMenu", false)) 199 cadastreJMenu.add(menuActionBuildings); 198 200 cadastreJMenu.add(menuLoadFromCache); 199 201 // all SVG features disabled until official WMS is released 200 202 //cadastreJMenu.add(menuActionBoundaries); 201 //cadastreJMenu.add(menuActionBuildings);202 203 } 203 204 setEnabledAll(menuEnabled); … … 224 225 imageWidth = 600; imageHeight = 400; 225 226 } 226 grabLayers = ""; 227 grabStyles = ""; 228 if (Main.pref.getBoolean("cadastrewms.layerWater", true)) { 229 grabLayers += "CDIF:LS3,"; 230 grabStyles += "LS3_90,"; 231 } 232 if (Main.pref.getBoolean("cadastrewms.layerBuilding", true)) { 233 grabLayers += "CDIF:LS2,"; 234 grabStyles += "LS2_90,"; 235 } 236 if (Main.pref.getBoolean("cadastrewms.layerSymbol", true)) { 237 grabLayers += "CDIF:LS1,"; 238 grabStyles += "LS1_90,"; 239 } 240 if (Main.pref.getBoolean("cadastrewms.layerParcel", true)) { 241 grabLayers += "CDIF:PARCELLE,"; 242 grabStyles += "PARCELLE_90,"; 243 } 244 if (Main.pref.getBoolean("cadastrewms.layerNumero", true)) { 245 grabLayers += "CDIF:NUMERO,"; 246 grabStyles += "NUMERO_90,"; 247 } 248 if (Main.pref.getBoolean("cadastrewms.layerLabel", true)) { 249 grabLayers += "CDIF:PT3,CDIF:PT2,CDIF:PT1,"; 250 grabStyles += "PT3_90,PT2_90,PT1_90,"; 251 } 252 if (Main.pref.getBoolean("cadastrewms.layerLieudit", true)) { 253 grabLayers += "CDIF:LIEUDIT,"; 254 grabStyles += "LIEUDIT_90,"; 255 } 256 if (Main.pref.getBoolean("cadastrewms.layerSection", true)) { 257 grabLayers += "CDIF:SUBSECTION,CDIF:SECTION,"; 258 grabStyles += "SUBSECTION_90,SECTION_90,"; 259 } 260 if (Main.pref.getBoolean("cadastrewms.layerCommune", true)) { 261 grabLayers += "CDIF:COMMUNE,"; 262 grabStyles += "COMMUNE_90,"; 263 } 264 if (grabLayers.length() > 0) { // remove the last ',' 265 grabLayers = grabLayers.substring(0, grabLayers.length()-1); 266 grabStyles = grabStyles.substring(0, grabStyles.length()-1); 267 } 227 refreshLayersURL(); 268 228 269 229 // overwrite F11 shortcut used from the beginning by this plugin and recently used … … 296 256 refreshMenu(); 297 257 } 258 259 private static void refreshLayersURL() { 260 grabLayers = ""; 261 grabStyles = ""; 262 if (Main.pref.getBoolean("cadastrewms.layerWater", true)) { 263 grabLayers += "CDIF:LS3,"; 264 grabStyles += "LS3_90,"; 265 } 266 if (Main.pref.getBoolean("cadastrewms.layerBuilding", true)) { 267 grabLayers += "CDIF:LS2,"; 268 grabStyles += "LS2_90,"; 269 } 270 if (Main.pref.getBoolean("cadastrewms.layerSymbol", true)) { 271 grabLayers += "CDIF:LS1,"; 272 grabStyles += "LS1_90,"; 273 } 274 if (Main.pref.getBoolean("cadastrewms.layerParcel", true)) { 275 grabLayers += "CDIF:PARCELLE,"; 276 grabStyles += "PARCELLE_90,"; 277 } 278 if (Main.pref.getBoolean("cadastrewms.layerNumero", true)) { 279 grabLayers += "CDIF:NUMERO,"; 280 grabStyles += "NUMERO_90,"; 281 } 282 if (Main.pref.getBoolean("cadastrewms.layerLabel", true)) { 283 grabLayers += "CDIF:PT3,CDIF:PT2,CDIF:PT1,"; 284 grabStyles += "PT3_90,PT2_90,PT1_90,"; 285 } 286 if (Main.pref.getBoolean("cadastrewms.layerLieudit", true)) { 287 grabLayers += "CDIF:LIEUDIT,"; 288 grabStyles += "LIEUDIT_90,"; 289 } 290 if (Main.pref.getBoolean("cadastrewms.layerSection", true)) { 291 grabLayers += "CDIF:SUBSECTION,CDIF:SECTION,"; 292 grabStyles += "SUBSECTION_90,SECTION_90,"; 293 } 294 if (Main.pref.getBoolean("cadastrewms.layerCommune", true)) { 295 grabLayers += "CDIF:COMMUNE,"; 296 grabStyles += "COMMUNE_90,"; 297 } 298 if (grabLayers.length() > 0) { // remove the last ',' 299 grabLayers = grabLayers.substring(0, grabLayers.length()-1); 300 grabStyles = grabStyles.substring(0, grabStyles.length()-1); 301 } 302 } 298 303 299 304 @Override … … 322 327 Main.map.addMapMode(new IconToggleButton 323 328 (new WMSAdjustAction(Main.map))); 329 Main.map.addMapMode(new IconToggleButton 330 (new Buildings(Main.map))); 324 331 } else if (oldFrame != null && newFrame == null) { 325 332 setEnabledAll(false); -
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/DownloadSVGBuilding.java
r20240 r20390 129 129 130 130 // simplify ways and check if we can reuse existing OSM nodes 131 for (Way wayToAdd : svgDataSet.getWays())132 new SimplifyWay().simplifyWay(wayToAdd, svgDataSet, 0.5);131 // for (Way wayToAdd : svgDataSet.getWays()) 132 // new SimplifyWay().simplifyWay(wayToAdd, svgDataSet, 0.5); 133 133 // check if the new way or its nodes is already in OSM layer 134 134 for (Node n : svgDataSet.getNodes()) { -
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/DownloadSVGTask.java
r20240 r20390 123 123 124 124 // simplify the way 125 double threshold = Double.parseDouble(Main.pref.get("cadastrewms.simplify-way-boundary", "1.0"));126 new SimplifyWay().simplifyWay(wayToAdd, Main.main.getCurrentDataSet(), threshold);125 // double threshold = Double.parseDouble(Main.pref.get("cadastrewms.simplify-way-boundary", "1.0")); 126 // new SimplifyWay().simplifyWay(wayToAdd, Main.main.getCurrentDataSet(), threshold); 127 127 128 128 cmds.add(new AddCommand(wayToAdd)); -
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/DownloadWMSPlanImage.java
r18544 r20390 66 66 } else { 67 67 // next steps follow in method finish() when download is terminated 68 wmsLayer.join RasterImages();68 wmsLayer.joinBufferedImages(); 69 69 } 70 70 } else { -
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/DownloadWMSVectorImage.java
r18838 r20390 16 16 17 17 private Bounds bounds; 18 18 19 19 private CadastreGrabber grabber = CadastrePlugin.cadastreGrabber; 20 20 21 public DownloadWMSVectorImage(WMSLayer wmsLayer, Bounds bounds ) {21 public DownloadWMSVectorImage(WMSLayer wmsLayer, Bounds bounds, boolean buildingsOnly) { 22 22 super(tr("Downloading {0}", wmsLayer.getName())); 23 23 24 24 this.wmsLayer = wmsLayer; 25 25 this.bounds = bounds; 26 this.wmsLayer.setBuildingsOnly(buildingsOnly); 26 27 } 27 28 … … 73 74 } 74 75 75 public static void download(WMSLayer wmsLayer ) {76 public static void download(WMSLayer wmsLayer, boolean buildingsOnly) { 76 77 MapView mv = Main.map.mapView; 77 78 Bounds bounds = new Bounds(mv.getLatLon(0, mv.getHeight()), mv.getLatLon(mv.getWidth(), 0)); 78 79 79 Main.worker.execute(new DownloadWMSVectorImage(wmsLayer, bounds ));80 Main.worker.execute(new DownloadWMSVectorImage(wmsLayer, bounds, buildingsOnly)); 80 81 81 82 } -
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/GeorefImage.java
r20211 r20390 337 337 int newWidth = Math.abs(sx2 - sx1); 338 338 int newHeight = Math.abs(sy2 - sy1); 339 BufferedImage new_img = new BufferedImage(newWidth, newHeight, BufferedImage.TYPE_INT_ARGB);339 BufferedImage new_img = new BufferedImage(newWidth, newHeight, image.getType()); 340 340 Graphics g = new_img.getGraphics(); 341 341 g.drawImage(image, 0, 0, newWidth-1, newHeight-1, -
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/ImageModifier.java
r20247 r20390 3 3 package cadastre_fr; 4 4 5 import java.awt.Color; 5 6 import java.awt.Transparency; 6 7 import java.awt.image.BufferedImage; … … 17 18 private static final long serialVersionUID = 1L; 18 19 20 protected int parcelColor = Color.RED.getRGB(); 21 19 22 public BufferedImage bufferedImage; 23 24 public static int[] cRoofColors = new int[] {-197380, -592138}; 25 public static int[] cBuilingFootColors = new int[] {-256}; 20 26 21 27 protected BufferedImage convert1(BufferedImage src) { … … 107 113 return dest; 108 114 } 115 116 public boolean isBuildingColor(int rgb, boolean ignoreParcelColor) { 117 for (int i = 0; i < cBuilingFootColors.length; i++) 118 if (rgb == cBuilingFootColors[i]) 119 return true; 120 if (ignoreParcelColor && (rgb == parcelColor)) 121 return true; 122 return false; 123 } 124 125 public boolean isRoofColor(int rgb, boolean ignoreParcelColor) { 126 for (int i = 0; i < cRoofColors.length; i++) 127 if (rgb == cRoofColors[i]) 128 return true; 129 if (ignoreParcelColor && (rgb == parcelColor)) 130 return true; 131 return false; 132 } 133 134 public boolean isBuildingOrRoofColor(BufferedImage img, int x, int y, boolean ignoreParcelColor) { 135 int rgb = img.getRGB(x, y); 136 boolean ret = isBuildingColor(rgb, ignoreParcelColor) || isRoofColor(rgb, ignoreParcelColor); 137 return ret; 138 } 139 140 public boolean isBuildingOrRoofColor(BufferedImage img, int x, int y, boolean colorType, boolean ignoreParcelColor) { 141 int rgb = img.getRGB(x, y); 142 boolean ret; 143 if (colorType) 144 ret = isBuildingColor(rgb, ignoreParcelColor); 145 else 146 ret = isRoofColor(rgb, ignoreParcelColor); 147 return ret; 148 } 149 150 /** 151 * Checks if the rgb value is the black background color 152 * @param 153 * @return 154 */ 155 public boolean isBackgroundColor(BufferedImage img, int x, int y) { 156 return (img.getRGB(x, y) == -1); 157 } 158 109 159 } -
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/MenuActionBuildings.java
r18544 r20390 13 13 public class MenuActionBuildings extends JosmAction { 14 14 15 public static String name = " Building footprints";15 public static String name = "Grab buildings only"; 16 16 17 17 private static final long serialVersionUID = 1L; 18 private WMSLayer wmsLayer = null;19 18 20 19 public MenuActionBuildings() { 21 super(tr(name), "cadastre_small", tr(" Extract building footprints"), null, false);20 super(tr(name), "cadastre_small", tr("Grab building layer only"), null, false); 22 21 } 23 22 24 public void actionPerformed(ActionEvent arg0) { 25 wmsLayer = WMSDownloadAction.getLayer(); 26 if (wmsLayer != null) { 27 if (wmsLayer.isRaster()) { 23 public void actionPerformed(ActionEvent e) { 24 if (Main.map != null) { 25 if (CadastrePlugin.isCadastreProjection()) { 26 WMSLayer wmsLayer = WMSDownloadAction.getLayer(); 27 if (wmsLayer != null) 28 DownloadWMSVectorImage.download(wmsLayer, true); 29 } else { 28 30 JOptionPane.showMessageDialog(Main.parent, 29 tr(" Only on vectorized layers"), tr("Error"),30 JOptionPane.ERROR_MESSAGE);31 return;31 tr("To enable the cadastre WMS plugin, change\n" 32 + "the current projection to one of the cadastre\n" 33 + "projections and retry")); 32 34 } 33 DownloadSVGBuilding.download(wmsLayer);34 }35 } else 36 new MenuActionNewLocation().actionPerformed(e); 35 37 } 36 38 -
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/MenuActionGrab.java
r18838 r20390 33 33 WMSLayer wmsLayer = WMSDownloadAction.getLayer(); 34 34 if (wmsLayer != null) 35 DownloadWMSVectorImage.download(wmsLayer );35 DownloadWMSVectorImage.download(wmsLayer, false); 36 36 } else { 37 37 JOptionPane.showMessageDialog(Main.parent, -
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/MenuActionNewLocation.java
r19928 r20390 32 32 WMSLayer wmsLayer = addNewLayer(new ArrayList<WMSLayer>()); 33 33 if (wmsLayer != null) 34 DownloadWMSVectorImage.download(wmsLayer );34 DownloadWMSVectorImage.download(wmsLayer, false); 35 35 } 36 36 -
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/SimplifyWay.java
r19078 r20390 3 3 4 4 import java.util.ArrayList; 5 6 import java.util.Collection;7 import java.util.Collections;8 import java.util.HashSet;9 import java.util.LinkedList;10 5 import java.util.List; 11 6 12 import org.openstreetmap.josm.Main;13 import org.openstreetmap.josm.command.ChangeCommand;14 import org.openstreetmap.josm.command.Command;15 import org.openstreetmap.josm.command.DeleteCommand;16 import org.openstreetmap.josm.command.SequenceCommand;17 import org.openstreetmap.josm.data.osm.DataSet;18 7 import org.openstreetmap.josm.data.osm.Node; 19 import org.openstreetmap.josm.data.osm.OsmPrimitive;20 8 import org.openstreetmap.josm.data.osm.Way; 21 import static org.openstreetmap.josm.tools.I18n.trn;22 23 24 9 25 10 /** … … 29 14 */ 30 15 public class SimplifyWay { 31 public void simplifyWay(Way w , DataSet dataSet, double threshold) {16 public void simplifyWay(Way w/*, DataSet dataSet*/, double threshold) { 32 17 Way wnew = new Way(w); 33 18 34 int toI = wnew.getNodesCount() - 1; 35 List<OsmPrimitive> parents = new ArrayList<OsmPrimitive>(); 36 for (int i = wnew.getNodesCount() - 1; i >= 0; i--) { 37 //CollectBackReferencesVisitor backRefsV = new CollectBackReferencesVisitor(dataSet, false); 38 //backRefsV.visit(wnew.getNode(i)); 39 parents.addAll(w.getNode(i).getReferrers()); 40 boolean used = false; 41 if (parents.size() == 1) { 42 used = Collections.frequency(w.getNodes(), wnew.getNode(i)) > 1; 43 } else { 44 //backRefsV.getData().remove(w); 45 parents.remove(w); 46 used = !parents.isEmpty(); 47 } 48 if (!used) 49 used = wnew.getNode(i).isTagged(); 19 // int toI = wnew.getNodesCount() - 1; 20 // List<OsmPrimitive> parents = new ArrayList<OsmPrimitive>(); 21 // for (int i = wnew.getNodesCount() - 1; i >= 0; i--) { 22 // //CollectBackReferencesVisitor backRefsV = new CollectBackReferencesVisitor(dataSet, false); 23 // //backRefsV.visit(wnew.getNode(i)); 24 // parents.addAll(w.getNode(i).getReferrers()); 25 // boolean used = false; 26 // if (parents.size() == 1) { 27 // used = Collections.frequency(w.getNodes(), wnew.getNode(i)) > 1; 28 // } else { 29 // //backRefsV.getData().remove(w); 30 // parents.remove(w); 31 // used = !parents.isEmpty(); 32 // } 33 // if (!used) 34 // used = wnew.getNode(i).isTagged(); 35 // 36 // if (used) { 37 // simplifyWayRange(wnew, i, toI, threshold); 38 // toI = i; 39 // } 40 // } 41 simplifyWayRange(wnew, 0, wnew.getNodesCount() - 1, threshold); 42 w.setNodes(wnew.getNodes()); 43 // HashSet<Node> delNodes = new HashSet<Node>(); 44 // delNodes.addAll(w.getNodes()); 45 // delNodes.removeAll(wnew.getNodes()); 50 46 51 if (used) { 52 simplifyWayRange(wnew, i, toI, threshold); 53 toI = i; 54 } 55 } 56 simplifyWayRange(wnew, 0, toI, threshold); 57 58 HashSet<Node> delNodes = new HashSet<Node>(); 59 delNodes.addAll(w.getNodes()); 60 delNodes.removeAll(wnew.getNodes()); 61 62 if (wnew.getNodesCount() != w.getNodesCount()) { 63 Collection<Command> cmds = new LinkedList<Command>(); 64 cmds.add(new ChangeCommand(w, wnew)); 65 cmds.add(new DeleteCommand(delNodes)); 66 Main.main.undoRedo.add(new SequenceCommand(trn("Simplify Way (remove {0} node)", "Simplify Way (remove {0} nodes)", delNodes.size(), delNodes.size()), cmds)); 67 Main.map.repaint(); 68 } 47 // if (wnew.getNodesCount() != w.getNodesCount()) { 48 // Collection<Command> cmds = new LinkedList<Command>(); 49 // cmds.add(new ChangeCommand(w, wnew)); 50 // cmds.add(new DeleteCommand(delNodes)); 51 // Main.main.undoRedo.add(new SequenceCommand(trn("Simplify Way (remove {0} node)", "Simplify Way (remove {0} nodes)", delNodes.size(), delNodes.size()), cmds)); 52 // Main.map.repaint(); 53 // } 69 54 } 70 55 -
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/VectorImageModifier.java
r20247 r20390 18 18 private int backgroundPixel = 0; 19 19 20 public VectorImageModifier(BufferedImage bi) { 20 public VectorImageModifier() {super();} 21 22 public VectorImageModifier(BufferedImage bi, boolean monocolor) { 21 23 bufferedImage = bi; 22 24 if (Main.pref.getBoolean("cadastrewms.backgroundTransparent")) … … 26 28 if (Main.pref.getBoolean("cadastrewms.invertGrey")) 27 29 invertGrey(); 28 //bufferedImage = convert8(convert1(bufferedImage)); 30 if (monocolor) 31 bufferedImage = convert8(convert4(bufferedImage)); 29 32 } 30 33 -
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/WMSDownloadAction.java
r19894 r20390 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.awt.event.ActionEvent;6 //import java.awt.event.ActionEvent; 7 7 import java.util.ArrayList; 8 8 … … 10 10 11 11 import org.openstreetmap.josm.Main; 12 import org.openstreetmap.josm.actions.JosmAction;12 //import org.openstreetmap.josm.actions.JosmAction; 13 13 import org.openstreetmap.josm.gui.layer.Layer; 14 14 15 public class WMSDownloadAction extends JosmAction{15 public class WMSDownloadAction /*extends JosmAction */{ 16 16 17 17 private static final long serialVersionUID = 1L; 18 18 19 public WMSDownloadAction(String layerName) {20 super(layerName, "wmsmenu", tr("Download WMS tile from {0}",layerName), null, false);21 }22 23 public void actionPerformed(ActionEvent e) {24 DownloadWMSVectorImage.download(getLayer());25 }19 // public WMSDownloadAction(String layerName) { 20 // super(layerName, "wmsmenu", tr("Download WMS tile from {0}",layerName), null, false); 21 // } 22 // 23 // public void actionPerformed(ActionEvent e) { 24 // DownloadWMSVectorImage.download(getLayer()); 25 // } 26 26 27 27 public static WMSLayer getLayer() { … … 30 30 if (Main.map != null) { 31 31 Layer activeLayer = Main.map.mapView.getActiveLayer(); 32 if (activeLayer instanceof WMSLayer )32 if (activeLayer instanceof WMSLayer && !((WMSLayer)activeLayer).isBuildingsOnly()) 33 33 return (WMSLayer) activeLayer; 34 34 for (Layer l : Main.map.mapView.getAllLayers()) { 35 if (l instanceof WMSLayer ) {35 if (l instanceof WMSLayer && !((WMSLayer)l).isBuildingsOnly()) { 36 36 existingWMSlayers.add((WMSLayer)l); 37 37 } -
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/WMSLayer.java
r20240 r20390 19 19 import java.io.ObjectOutputStream; 20 20 import java.util.ArrayList; 21 import java.util.HashSet; 21 22 import java.util.Vector; 22 23 … … 72 73 73 74 private boolean isRaster = false; 74 75 75 private boolean isAlreadyGeoreferenced = false; 76 76 private boolean buildingsOnly = false; 77 77 public double X0, Y0, angle, fX, fY; 78 78 … … 86 86 public boolean adjustModeEnabled; 87 87 88 88 89 public WMSLayer() { 89 90 this(tr("Blank Layer"), "", -1); … … 91 92 92 93 public WMSLayer(String location, String codeCommune, int lambertZone) { 93 super(buildName(location, codeCommune ));94 super(buildName(location, codeCommune, false)); 94 95 this.location = location; 95 96 this.codeCommune = codeCommune; … … 113 114 } 114 115 115 private static String buildName(String location, String codeCommune ) {116 private static String buildName(String location, String codeCommune, boolean buildingOnly) { 116 117 String ret = new String(location.toUpperCase()); 117 118 if (codeCommune != null && !codeCommune.equals("")) 118 119 ret += "(" + codeCommune + ")"; 120 if (buildingOnly) 121 ret += ".b"; 119 122 return ret; 120 123 } 121 124 122 125 private String rebuildName() { 123 return buildName(this.location.toUpperCase(), this.codeCommune );126 return buildName(this.location.toUpperCase(), this.codeCommune, this.buildingsOnly); 124 127 } 125 128 … … 133 136 b = new Bounds(Main.proj.eastNorth2latlon(rasterMin), Main.proj.eastNorth2latlon(rasterMax)); 134 137 divideBbox(b, Integer.parseInt(Main.pref.get("cadastrewms.rasterDivider", 135 CadastrePreferenceSetting.DEFAULT_RASTER_DIVIDER))); 136 } else 137 divideBbox(b, Integer.parseInt(Main.pref.get("cadastrewms.scale", Scale.X1.toString()))); 138 CadastrePreferenceSetting.DEFAULT_RASTER_DIVIDER)), 0); 139 } else if (buildingsOnly) 140 divideBbox(b, 5, 80); // hard coded size of 80 meters per box 141 else 142 divideBbox(b, Integer.parseInt(Main.pref.get("cadastrewms.scale", Scale.X1.toString())), 0); 138 143 } else 139 divideBbox(b, 1); 140 144 divideBbox(b, 1, 0); 145 146 int lastSavedImage = images.size(); 141 147 for (EastNorthBound n : dividedBbox) { 142 148 GeorefImage newImage; 143 149 try { 144 newImage = grabber.grab(this, n.min, n.max); 150 if (buildingsOnly == false) 151 newImage = grabber.grab(this, n.min, n.max); 152 else { // TODO 153 GeorefImage buildings = grabber.grabBuildings(this, n.min, n.max); 154 GeorefImage parcels = grabber.grabParcels(this, n.min, n.max); 155 new BuildingsImageModifier(buildings, parcels); 156 newImage = buildings; 157 } 145 158 } catch (IOException e) { 146 159 System.out.println("Download action cancelled by user or server did not respond"); … … 166 179 } 167 180 images.add(newImage); 168 saveToCache(newImage);169 181 Main.map.mapView.repaint(); 170 182 } 183 if (buildingsOnly) 184 joinBufferedImages(); 185 for (int i=lastSavedImage; i < images.size(); i++) 186 saveToCache(images.get(i)); 171 187 } 172 188 … … 177 193 * 2 = source bbox divided by 2x2 smaller boxes 178 194 * 3 = source bbox divided by 3x3 smaller boxes 179 * 4 = hard coded size of boxes (100 meters) rounded allowing 180 * grabbing of next contiguous zone 181 */ 182 private void divideBbox(Bounds b, int factor) { 195 * 4 = configurable size from preferences (100 meters per default) rounded 196 * allowing grabbing of next contiguous zone 197 * 5 = use the size provided in next argument optionalSize 198 * @param optionalSize box size used when factor is 5. 199 */ 200 private void divideBbox(Bounds b, int factor, int optionalSize) { 183 201 EastNorth lambertMin = Main.proj.latlon2eastNorth(b.getMin()); 184 202 EastNorth lambertMax = Main.proj.latlon2eastNorth(b.getMax()); … … 196 214 } else { 197 215 // divide to fixed size squares 198 int cSquare = Integer.parseInt(Main.pref.get("cadastrewms.squareSize", "100"));216 int cSquare = factor == 4 ? Integer.parseInt(Main.pref.get("cadastrewms.squareSize", "100")) : optionalSize; 199 217 minEast = minEast - minEast % cSquare; 200 218 minNorth = minNorth - minNorth % cSquare; … … 298 316 public boolean isOverlapping(Bounds bounds) { 299 317 GeorefImage georefImage = 300 new GeorefImage(n ew BufferedImage(1,1,BufferedImage.TYPE_INT_RGB ), // not really important318 new GeorefImage(null, 301 319 Main.proj.latlon2eastNorth(bounds.getMin()), 302 320 Main.proj.latlon2eastNorth(bounds.getMax())); … … 358 376 public void setCodeCommune(String codeCommune) { 359 377 this.codeCommune = codeCommune; 378 setName(rebuildName()); 379 } 380 381 public boolean isBuildingsOnly() { 382 return buildingsOnly; 383 } 384 385 public void setBuildingsOnly(boolean buildingsOnly) { 386 this.buildingsOnly = buildingsOnly; 360 387 setName(rebuildName()); 361 388 } … … 412 439 oos.writeInt(this.lambertZone); 413 440 oos.writeBoolean(this.isRaster); 441 oos.writeBoolean(this.buildingsOnly); 414 442 if (this.isRaster) { 415 443 oos.writeDouble(this.rasterMin.getX()); … … 443 471 this.lambertZone = ois.readInt(); 444 472 this.setRaster(ois.readBoolean()); 473 if (currentFormat >= 4) 474 this.setBuildingsOnly(ois.readBoolean()); 445 475 if (this.isRaster) { 446 476 double X = ois.readDouble(); … … 491 521 /** 492 522 * Join the grabbed images into one single. 493 * Works only for images grabbed from non-georeferenced images (Feuilles cadastrales)(same amount of 494 * images in x and y) 495 */ 496 public void joinRasterImages() { 523 */ 524 public void joinBufferedImages() { 497 525 if (images.size() > 1) { 498 526 EastNorth min = images.get(0).min; … … 500 528 int oldImgWidth = images.get(0).image.getWidth(); 501 529 int oldImgHeight = images.get(0).image.getHeight(); 502 int newWidth = oldImgWidth*(int)Math.sqrt(images.size()); 503 int newHeight = oldImgHeight*(int)Math.sqrt(images.size()); 504 BufferedImage new_img = new BufferedImage(newWidth, newHeight, BufferedImage.TYPE_INT_ARGB); 530 HashSet<Double> lx = new HashSet<Double>(); 531 HashSet<Double> ly = new HashSet<Double>(); 532 for (GeorefImage img : images) { 533 lx.add(img.min.east()); 534 ly.add(img.min.north()); 535 } 536 int newWidth = oldImgWidth*lx.size(); 537 int newHeight = oldImgHeight*ly.size(); 538 BufferedImage new_img = new BufferedImage(newWidth, newHeight, images.get(0).image.getType()/*BufferedImage.TYPE_INT_ARGB*/); 505 539 Graphics g = new_img.getGraphics(); 506 540 // Coordinate (0,0) is on top,left corner where images are grabbed from bottom left 507 541 int rasterDivider = (int)Math.sqrt(images.size()); 508 for (int h = 0; h < rasterDivider; h++) {509 for (int v = 0; v < rasterDivider; v++) {542 for (int h = 0; h < lx.size(); h++) { 543 for (int v = 0; v < ly.size(); v++) { 510 544 int newx = h*oldImgWidth; 511 545 int newy = newHeight - oldImgHeight - (v*oldImgHeight); … … 543 577 rasterRatio = (rasterMax.getX()-rasterMin.getX())/(communeBBox.max.getX() - communeBBox.min.getX()); 544 578 } 545 579 546 580 public EastNorthBound getCommuneBBox() { 547 581 return communeBBox;
Note:
See TracChangeset
for help on using the changeset viewer.