Ignore:
Timestamp:
2009-10-24T20:06:29+02:00 (15 years ago)
Author:
pieren
Message:

Added autodetection and use of raster images already georeferenced

Location:
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CadastreInterface.java

    r17215 r18271  
    398398    }
    399399
    400     public EastNorthBound retrieveCommuneBBox() throws IOException {
     400    /**
     401     * Retrieve the bounding box size in pixels of the whole commune (point 0,0 at top, left corner)
     402     * and store it in given wmsLayer
     403     * In case of raster image, we also check in the same http request if the image is already georeferenced
     404     * and store the result in the wmsLayer as well.
     405     * @param wmsLayer the WMSLayer where the commune data and images are stored
     406     * @throws IOException
     407     */
     408    public void retrieveCommuneBBox(WMSLayer wmsLayer) throws IOException {
    401409        if (interfaceRef == null)
    402             return null;
     410            return;
    403411        String ln = null;
    404412        String line = null;
     
    421429        in.close();
    422430        urlConn.disconnect();
    423         return parseBBoxCommune(line);
    424     }
    425 
    426     private EastNorthBound parseBBoxCommune(String input) {
     431        parseBBoxCommune(wmsLayer, line);
     432        if (wmsLayer.isRaster() && !wmsLayer.isAlreadyGeoreferenced()) {
     433            parseGeoreferences(wmsLayer, line);
     434        }
     435    }
     436
     437    private void parseBBoxCommune(WMSLayer wmsLayer, String input) {
    427438        if (input.indexOf(cBBoxCommunStart) != -1) {
    428439            input = input.substring(input.indexOf(cBBoxCommunStart));
     
    435446            int l = input.indexOf(cBBoxCommunEnd, k+1);
    436447            double maxy = Double.parseDouble(input.substring(k+1, l));
    437             return new EastNorthBound(new EastNorth(minx,miny), new EastNorth(maxx,maxy));
    438         }
    439         return null;
     448            wmsLayer.setCommuneBBox( new EastNorthBound(new EastNorth(minx,miny), new EastNorth(maxx,maxy)));
     449        }
     450    }
     451   
     452    private void parseGeoreferences(WMSLayer wmsLayer, String input) {
     453        if (input.lastIndexOf(cBBoxCommunStart) != -1) {
     454            input = input.substring(input.lastIndexOf(cBBoxCommunStart));
     455            input = input.substring(input.indexOf(cBBoxCommunEnd)+cBBoxCommunEnd.length());
     456            int i = input.indexOf(",");
     457            int j = input.indexOf(",", i+1);
     458            double angle = Double.parseDouble(input.substring(i+1, j));
     459            int k = input.indexOf(",", j+1);
     460            double scale_origin = Double.parseDouble(input.substring(j+1, k));
     461            int l = input.indexOf(",", k+1);
     462            double dpi = Double.parseDouble(input.substring(k+1, l));
     463            int m = input.indexOf(",", l+1);
     464            double fX = Double.parseDouble(input.substring(l+1, m));
     465            int n = input.indexOf(",", m+1);
     466            double fY = Double.parseDouble(input.substring(m+1, n));
     467            int o = input.indexOf(",", n+1);
     468            double X0 = Double.parseDouble(input.substring(n+1, o));
     469            int p = input.indexOf(",", o+1);
     470            double Y0 = Double.parseDouble(input.substring(o+1, p));
     471            if (X0 != 0.0 && Y0 != 0) {
     472                wmsLayer.setAlreadyGeoreferenced(true);
     473                wmsLayer.fX = fX;
     474                wmsLayer.fY = fY;
     475                wmsLayer.angle = angle;
     476                wmsLayer.X0 = X0;
     477                wmsLayer.Y0 = Y0;
     478            }
     479            System.out.println("parse georef:"+angle+","+scale_origin+","+dpi+","+fX+","+
     480                    fY+","+X0+","+Y0);
     481        }
    440482    }
    441483
  • applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CadastrePlugin.java

    r18256 r18271  
    7676 *                 - fixed bug of raster image loaded from cache not working on Java1.6
    7777 *                 - improve mouse click bounce detection during georeferencing process
    78  * 1.4 17-Oct-2009 - add support for new Lambert CC 9 Zones projection
     78 * 1.4 23-Oct-2009 - add support for new Lambert CC 9 Zones projection
     79 *                 - add optional crosspieces display on raster image layers
     80 *                 - add automatic raster images georeferencing when WMS provides data
     81 *                 - re-implement manual adjustment mode in raster image layer 
    7982 */
    8083public class CadastrePlugin extends Plugin {
  • applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/DownloadWMSPlanImage.java

    r17181 r18271  
    5757                        if (wmsLayer.isRaster()) {
    5858                            // set raster image commune bounding box based on current view (before adjustment)
    59                             wmsLayer.setCommuneBBox( grabber.getWmsInterface().retrieveCommuneBBox());
     59                            grabber.getWmsInterface().retrieveCommuneBBox(wmsLayer);
    6060                            wmsLayer.setRasterBounds(bounds);
    6161                            // grab new images from wms server into active layer
  • applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/DownloadWMSVectorImage.java

    r18207 r18271  
    4444                    } else {
    4545                        // set vectorized commune bounding box by opening the standard web window
    46                         wmsLayer.setCommuneBBox( grabber.getWmsInterface().retrieveCommuneBBox());
     46                        grabber.getWmsInterface().retrieveCommuneBBox(wmsLayer);
    4747                        // if it is the first layer, use the communeBBox as grab bbox
    4848                        if (Main.proj instanceof LambertCC9Zones && Main.map.mapView.getAllLayers().size() == 1 ) {
  • applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/MenuActionGrabPlanImage.java

    r17702 r18271  
    9494        boolean loadedFromCache = downloadWMSPlanImage.waitFinished();
    9595        if (wmsLayer.images.size() == 1 && !loadedFromCache) {
    96             mouseClickedTime = System.currentTimeMillis();
    97             Main.map.mapView.addMouseListener(this);
    98             if (Main.pref.getBoolean("cadastrewms.noImageCropping", false) == false)
    99                 startCropping();
    100             else
    101                 startGeoreferencing();
     96            int reply = JOptionPane.CANCEL_OPTION;
     97            if (wmsLayer.isAlreadyGeoreferenced()) {
     98                reply = JOptionPane.showConfirmDialog(null,
     99                        tr("This image contains georeference data.\n"+
     100                                "Do you want to use them ?"),
     101                        null,
     102                        JOptionPane.YES_NO_OPTION);
     103            }
     104            if (reply == JOptionPane.OK_OPTION) {
     105                transformGeoreferencedImg();
     106            } else {
     107                mouseClickedTime = System.currentTimeMillis();
     108                Main.map.mapView.addMouseListener(this);
     109                if (Main.pref.getBoolean("cadastrewms.noImageCropping", false) == false)
     110                    startCropping();
     111                else
     112                    startGeoreferencing();
     113            }
    102114        } else // action cancelled or image loaded from cache (and already georeferenced)
    103115            Main.map.repaint();
     
    310322    }
    311323
     324    private void transformGeoreferencedImg() {
     325        georefpoint1 = new EastNorth(wmsLayer.X0, wmsLayer.Y0);
     326        georefpoint2 = new EastNorth(wmsLayer.X0+wmsLayer.fX*wmsLayer.communeBBox.max.getX(),
     327                wmsLayer.Y0+wmsLayer.fY*wmsLayer.communeBBox.max.getX());
     328        ea1 = new EastNorth(wmsLayer.images.get(0).min.east(), wmsLayer.images.get(0).max.north());
     329        EastNorth ea2 = wmsLayer.images.get(0).max;
     330        affineTransform(ea1, ea2, georefpoint1, georefpoint2);
     331        wmsLayer.saveNewCache();
     332        Main.map.mapView.repaint();
     333    }
     334
    312335    public void mouseEntered(MouseEvent arg0) {
    313336    }
  • applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/WMSLayer.java

    r18256 r18271  
    6464
    6565    private boolean isRaster = false;
     66   
     67    private boolean isAlreadyGeoreferenced = false;
     68   
     69    public double X0, Y0, angle, fX, fY;
    6670
    6771    private EastNorth rasterMin;
     
    320324        if (saveAsPng != null)
    321325            saveAsPng.setEnabled(isRaster);
     326    }
     327
     328    public boolean isAlreadyGeoreferenced() {
     329        return isAlreadyGeoreferenced;
     330    }
     331
     332    public void setAlreadyGeoreferenced(boolean isAlreadyGeoreferenced) {
     333        this.isAlreadyGeoreferenced = isAlreadyGeoreferenced;
    322334    }
    323335
Note: See TracChangeset for help on using the changeset viewer.