Changeset 20390 in osm for applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/WMSLayer.java
- Timestamp:
- 2010-03-09T22:02:00+01:00 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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.