Changeset 13426 in osm for applications/editors
- Timestamp:
- 2009-01-28T21:44:10+01:00 (16 years ago)
- Location:
- applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr
- Files:
-
- 1 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CacheControl.java
r13382 r13426 18 18 import javax.swing.JOptionPane; 19 19 import org.openstreetmap.josm.Main; 20 import org.openstreetmap.josm.data.coor.EastNorth;21 20 22 21 public class CacheControl implements Runnable { … … 112 111 FileInputStream fis = new FileInputStream(file); 113 112 ObjectInputStream ois = new ObjectInputStream(fis); 114 int sfv = ois.readInt(); 115 if (sfv != wmsLayer.serializeFormatVersion) { 116 JOptionPane.showMessageDialog(Main.parent, tr("Unsupported WMS file version; found {0}, expected {1}", 117 sfv, wmsLayer.serializeFormatVersion), tr("Cache Format Error"), JOptionPane.ERROR_MESSAGE); 113 if (wmsLayer.read(ois, currentLambertZone) == false) 118 114 return false; 119 }120 wmsLayer.setLocation((String) ois.readObject());121 wmsLayer.setCodeCommune((String) ois.readObject());122 wmsLayer.lambertZone = ois.readInt();123 wmsLayer.setRaster(ois.readBoolean());124 wmsLayer.setRasterMin((EastNorth) ois.readObject());125 wmsLayer.setRasterCenter((EastNorth) ois.readObject());126 wmsLayer.setRasterRatio(ois.readDouble());127 if (wmsLayer.lambertZone != currentLambertZone) {128 JOptionPane.showMessageDialog(Main.parent, tr("Lambert zone {0} in cache "+129 " incompatible with current Lambert zone {1}",130 wmsLayer.lambertZone+1, currentLambertZone), tr("Cache Lambert Zone Error"), JOptionPane.ERROR_MESSAGE);131 return false;132 }133 boolean EOF = false;134 try {135 while (!EOF) {136 GeorefImage newImage = (GeorefImage) ois.readObject();137 for (GeorefImage img : wmsLayer.images) {138 if (CadastrePlugin.backgroundTransparent) {139 if (img.overlap(newImage))140 // mask overlapping zone in already grabbed image141 img.withdraw(newImage);142 else143 // mask overlapping zone in new image only when144 // new image covers completely the existing image145 newImage.withdraw(img);146 }147 }148 wmsLayer.images.add(newImage);149 }150 } catch (EOFException e) {}151 115 ois.close(); 152 116 fis.close(); … … 155 119 JOptionPane 156 120 .showMessageDialog(Main.parent, tr("Error loading file"), tr("Error"), JOptionPane.ERROR_MESSAGE); 121 return false; 157 122 } 158 123 return true; … … 205 170 ObjectOutputStream oos = new ObjectOutputStream( 206 171 new BufferedOutputStream(new FileOutputStream(file))); 207 oos.writeInt(wmsLayer.serializeFormatVersion); 208 oos.writeObject(wmsLayer.getLocation()); 209 oos.writeObject(wmsLayer.getCodeCommune()); 210 oos.writeInt(wmsLayer.lambertZone); 211 oos.writeBoolean(wmsLayer.isRaster()); 212 oos.writeObject(wmsLayer.getRasterMin()); 213 oos.writeObject(wmsLayer.getRasterCenter()); 214 oos.writeDouble(wmsLayer.getRasterRatio()); 215 for (GeorefImage img : images) { 216 oos.writeObject(img); 217 } 172 wmsLayer.write(oos, images); 218 173 oos.close(); 219 174 } -
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CadastreInterface.java
r13382 r13426 18 18 19 19 import org.openstreetmap.josm.Main; 20 import org.openstreetmap.josm.data.coor.EastNorth; 20 21 import org.openstreetmap.josm.gui.layer.Layer; 21 22 import org.openstreetmap.josm.tools.GBC; … … 38 39 final String c0ptionListStart = "<option value=\""; 39 40 final String cOptionListEnd = "</option>"; 41 final String cBBoxCommunStart = "new GeoBox("; 42 final String cBBoxCommunEnd = ")"; 40 43 41 44 final String cInterfaceVector = "afficherCarteCommune.do"; … … 310 313 } 311 314 315 public EastNorthBound retrieveCommuneBBox() throws IOException { 316 if (interfaceRef == null) 317 return null; 318 String ln = null; 319 String line = null; 320 // send GET opening normally the small window with the commune overview 321 String content = baseURL + "/scpc/" + interfaceRef; 322 content += "&dontSaveLastForward&keepVolatileSession="; 323 searchFormURL = new URL(content); 324 System.out.println("HEAD:"+content); 325 urlConn = (HttpURLConnection)searchFormURL.openConnection(); 326 urlConn.setRequestMethod("GET"); 327 setCookie(); 328 urlConn.connect(); 329 if (urlConn.getResponseCode() != HttpURLConnection.HTTP_OK) { 330 throw (IOException) new IOException("Cannot get Cadastre response."); 331 } 332 BufferedReader in = new BufferedReader(new InputStreamReader(urlConn.getInputStream())); 333 while ((ln = in.readLine()) != null) { 334 line += ln; 335 } 336 in.close(); 337 urlConn.disconnect(); 338 return parseBBoxCommune(line); 339 } 340 341 private EastNorthBound parseBBoxCommune(String input) { 342 if (input.indexOf(cBBoxCommunStart) != -1) { 343 input = input.substring(input.indexOf(cBBoxCommunStart)); 344 int i = input.indexOf(","); 345 double minx = Double.parseDouble(input.substring(cBBoxCommunStart.length(), i)); 346 int j = input.indexOf(",", i+1); 347 double miny = Double.parseDouble(input.substring(i+1, j)); 348 int k = input.indexOf(",", j+1); 349 double maxx = Double.parseDouble(input.substring(j+1, k)); 350 int l = input.indexOf(cBBoxCommunEnd, k+1); 351 double maxy = Double.parseDouble(input.substring(k+1, l)); 352 return new EastNorthBound(new EastNorth(minx,miny), new EastNorth(maxx,maxy)); 353 } 354 return null; 355 } 356 312 357 private void checkLayerDuplicates(WMSLayer wmsLayer) throws DuplicateLayerException { 313 358 if (Main.map != null) { -
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CadastrePlugin.java
r13417 r13426 64 64 * - minor fixes due to changes in JOSM core classes 65 65 * - first draft of raster image support 66 * 0.9 draft - grab vectorized full commune bbox and save it in cache 66 67 */ 67 68 public class CadastrePlugin extends Plugin { -
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/DownloadWMSTask.java
r13382 r13426 29 29 try { 30 30 if (grabber.getWmsInterface().retrieveInterface(wmsLayer)) { 31 if (wmsLayer.i sRaster() && wmsLayer.images.isEmpty())32 wmsLayer.setRasterBounds(bounds);33 if (CacheControl.cacheEnabled && wmsLayer.images.isEmpty()) {34 // images loaded from cache35 if (wmsLayer.getCacheControl().loadCacheIfExist()) {36 Main.map.mapView.repaint();37 return;31 if (wmsLayer.images.isEmpty()) { 32 // first time we grab an image for this layer 33 if (CacheControl.cacheEnabled) { 34 if (wmsLayer.getCacheControl().loadCacheIfExist()) { 35 Main.map.mapView.repaint(); 36 return; 37 } 38 38 } 39 if (wmsLayer.isRaster()) 40 // set raster image commune bounding box based on current view (before adjustment) 41 wmsLayer.setRasterBounds(bounds); 42 else 43 // set vectorized commune bounding box by opening the standard web window 44 wmsLayer.setCommuneBBox( grabber.getWmsInterface().retrieveCommuneBBox()); 39 45 } 40 46 // grab new images from wms server into active layer -
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/MenuActionLoadFromCache.java
r13382 r13426 60 60 // create layer and load cache 61 61 WMSLayer wmsLayer = new WMSLayer("", "", Integer.parseInt(ext)-1); 62 wmsLayer.getCacheControl().loadCache(file, Lambert.layoutZone);63 Main.main.addLayer(wmsLayer);62 if (wmsLayer.getCacheControl().loadCache(file, Lambert.layoutZone)) 63 Main.main.addLayer(wmsLayer); 64 64 } 65 65 -
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/WMSLayer.java
r13382 r13426 9 9 import java.awt.event.ActionEvent; 10 10 import java.awt.image.BufferedImage; 11 import java.io.EOFException; 11 12 import java.io.File; 12 13 import java.io.FileInputStream; … … 45 46 public class WMSLayer extends Layer { 46 47 47 public class EastNorthBound {48 public EastNorth min, max;49 public EastNorthBound(EastNorth min, EastNorth max) {50 this.min = min;51 this.max = max;52 }53 @Override public String toString() {54 return "EastNorthBound[" + min.east() + "," + min.north() + "," + max.east() + "," + max.north() + "]";55 }56 }57 58 48 Component[] component = null; 59 49 … … 65 55 protected ArrayList<GeorefImage> images = new ArrayList<GeorefImage>(); 66 56 67 protected final int serializeFormatVersion = 1;57 protected final int serializeFormatVersion = 2; 68 58 69 59 private ArrayList<EastNorthBound> dividedBbox = new ArrayList<EastNorthBound>(); … … 74 64 75 65 private String codeCommune = ""; 66 67 private EastNorthBound communeBBox = new EastNorthBound(new EastNorth(0,0), new EastNorth(0,0)); 76 68 77 69 private boolean isRaster = false; … … 492 484 } 493 485 } 486 487 /** 488 * Called by CacheControl when a new cache file is created on disk 489 * @param oos 490 * @throws IOException 491 */ 492 public void write(ObjectOutputStream oos, ArrayList<GeorefImage> imgs) throws IOException { 493 oos.writeInt(this.serializeFormatVersion); 494 oos.writeObject(this.location); 495 oos.writeObject(this.codeCommune); 496 oos.writeInt(this.lambertZone); 497 oos.writeBoolean(this.isRaster); 498 if (this.isRaster) { 499 oos.writeObject(this.rasterMin); 500 oos.writeObject(this.rasterCenter); 501 oos.writeDouble(this.rasterRatio); 502 } else { 503 oos.writeObject(this.communeBBox); 504 } 505 for (GeorefImage img : imgs) { 506 oos.writeObject(img); 507 } 508 } 509 510 /** 511 * Called by CacheControl when a cache file is read from disk 512 * @param ois 513 * @throws IOException 514 * @throws ClassNotFoundException 515 */ 516 public boolean read(ObjectInputStream ois, int currentLambertZone) throws IOException, ClassNotFoundException { 517 int sfv = ois.readInt(); 518 if (sfv != this.serializeFormatVersion) { 519 JOptionPane.showMessageDialog(Main.parent, tr("Unsupported cache file version; found {0}, expected {1}\nCreate a new one.", 520 sfv, this.serializeFormatVersion), tr("Cache Format Error"), JOptionPane.ERROR_MESSAGE); 521 return false; 522 } 523 this.setLocation((String) ois.readObject()); 524 this.setCodeCommune((String) ois.readObject()); 525 this.lambertZone = ois.readInt(); 526 this.isRaster = ois.readBoolean(); 527 if (this.isRaster) { 528 this.rasterMin = (EastNorth) ois.readObject(); 529 this.rasterCenter = (EastNorth) ois.readObject(); 530 this.rasterRatio = ois.readDouble(); 531 } else { 532 this.communeBBox = (EastNorthBound) ois.readObject(); 533 } 534 if (this.lambertZone != currentLambertZone) { 535 JOptionPane.showMessageDialog(Main.parent, tr("Lambert zone {0} in cache "+ 536 " incompatible with current Lambert zone {1}", 537 this.lambertZone+1, currentLambertZone), tr("Cache Lambert Zone Error"), JOptionPane.ERROR_MESSAGE); 538 return false; 539 } 540 boolean EOF = false; 541 try { 542 while (!EOF) { 543 GeorefImage newImage = (GeorefImage) ois.readObject(); 544 for (GeorefImage img : this.images) { 545 if (CadastrePlugin.backgroundTransparent) { 546 if (img.overlap(newImage)) 547 // mask overlapping zone in already grabbed image 548 img.withdraw(newImage); 549 else 550 // mask overlapping zone in new image only when 551 // new image covers completely the existing image 552 newImage.withdraw(img); 553 } 554 } 555 this.images.add(newImage); 556 } 557 } catch (EOFException ex) { 558 // expected exception when all images are read 559 } 560 return true; 561 } 494 562 495 563 public double getRasterRatio() { … … 509 577 } 510 578 579 public EastNorthBound getCommuneBBox() { 580 return communeBBox; 581 } 582 583 public void setCommuneBBox(EastNorthBound entireCommune) { 584 this.communeBBox = entireCommune; 585 } 586 511 587 }
Note:
See TracChangeset
for help on using the changeset viewer.