Ignore:
Timestamp:
2011-10-12T00:39:26+02:00 (13 years ago)
Author:
pieren
Message:

Fixed issues with new offset in grabbing vector images

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

Legend:

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

    r26228 r26835  
    140140    public boolean loadCache(File file, int currentLambertZone) {
    141141        boolean successfulRead = false;
    142         try {
    143             FileInputStream fis = new FileInputStream(file);
    144             ObjectInputStream ois = new ObjectInputStream(fis);
     142        FileInputStream fis = null;
     143        ObjectInputStream ois = null;
     144        try {
     145            fis = new FileInputStream(file);
     146            ois = new ObjectInputStream(fis);
    145147            successfulRead = wmsLayer.read(ois, currentLambertZone);
    146             ois.close();
    147             fis.close();
    148148        } catch (Exception ex) {
    149149            ex.printStackTrace(System.out);
    150150            JOptionPane.showMessageDialog(Main.parent, tr("Error loading file.\nProbably an old version of the cache file."), tr("Error"), JOptionPane.ERROR_MESSAGE);
    151151            return false;
     152        } finally {
     153            try {
     154                ois.close();
     155                fis.close();
     156            } catch (Exception e) {
     157                e.printStackTrace();
     158            }
    152159        }
    153160        if (successfulRead && wmsLayer.isRaster()) {
  • applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CadastreGrabber.java

    r24907 r26835  
    3636            else
    3737                imageModified = new VectorImageModifier(img, false);
    38             return new GeorefImage(imageModified.bufferedImage, lambertMin, lambertMax);
     38            return new GeorefImage(imageModified.bufferedImage, lambertMin, lambertMax, wmsLayer);
    3939        } catch (MalformedURLException e) {
    4040            throw (IOException) new IOException(tr("CadastreGrabber: Illegal url.")).initCause(e);
  • applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/GeorefImage.java

    r26823 r26835  
    2929    public EastNorth min;
    3030    public EastNorth max;
    31     // offset for vector images temporarily shifted (correcting Cadastre artifacts), in pixels
    32     public double deltaEast=0;
    33     public double deltaNorth=0;
    3431    // bbox of the georeferenced original image (raster only) (inclined if rotated and before cropping)
    3532    // P[0] is bottom,left then next are clockwise.
     
    4340
    4441    public BufferedImage image;
     42    public WMSLayer wmsLayer;
    4543
    4644    private double pixelPerEast;
    4745    private double pixelPerNorth;
    48 
    49     public GeorefImage(BufferedImage img, EastNorth min, EastNorth max) {
     46   
     47
     48    public GeorefImage(BufferedImage img, EastNorth min, EastNorth max, WMSLayer wmsLayer) {
    5049        image = img;
    5150 
     
    6362        this.imageOriginalHeight = (img == null ? 1 : img.getHeight());
    6463        this.imageOriginalWidth = (img == null ? 1 : img.getWidth());
     64        this.wmsLayer = wmsLayer;
    6565        updatePixelPer();
    6666    }
     
    111111
    112112        // apply offsets defined manually when vector images are translated manually (not saved in cache)
    113         Point minPt = nc.getPoint(new EastNorth(min.east()+deltaEast, min.north()+deltaNorth));
    114         Point maxPt = nc.getPoint(new EastNorth(max.east()+deltaEast, max.north()+deltaNorth));
     113        double dx=0, dy=0;
     114        if (wmsLayer!=null) {
     115            dx = wmsLayer.deltaEast;
     116            dy = wmsLayer.deltaNorth;
     117        }
     118        Point minPt = nc.getPoint(new EastNorth(min.east()+dx, min.north()+dy));
     119        Point maxPt = nc.getPoint(new EastNorth(max.east()+dx, max.north()+dy));
    115120
    116121        if (!g.hitClip(minPt.x, maxPt.y, maxPt.x - minPt.x, minPt.y - maxPt.y))
     
    127132                Point[] croppedPoint = new Point[5];
    128133                for (int i=0; i<4; i++)
    129                     croppedPoint[i] = nc.getPoint(orgCroppedRaster[i]);
     134                    croppedPoint[i] = nc.getPoint(
     135                            new EastNorth(orgCroppedRaster[i].east()+dx, orgCroppedRaster[i].north()+dy));
    130136                croppedPoint[4] = croppedPoint[0];
    131137                for (int i=0; i<4; i++) {
     
    369375    }
    370376
    371     /**
    372      * Add a temporary translation (dx, dy) to this image (for vector images only)
    373      * @param dx delta added to X image coordinate
    374      * @param dy delta added to Y image coordinate
    375      */
    376     public void tempShear(double dx, double dy) {
    377         this.deltaEast+=dx;
    378         this.deltaNorth+=dy;
    379     }
    380377}
  • applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/WMSLayer.java

    r26823 r26835  
    8585    private double rasterRatio;
    8686
     87    // offset for vector images temporarily shifted (correcting Cadastre artifacts), in pixels
     88    public double deltaEast=0;
     89    public double deltaNorth=0;
     90
    8791    private Action saveAsPng;
    8892
     
    9195    @SuppressWarnings("serial")
    9296    class ResetOffsetActionMenu extends JosmAction {
    93         private WMSLayer wmsLayer;
    94         public ResetOffsetActionMenu(WMSLayer wmsLayer) {
     97        public ResetOffsetActionMenu() {
    9598            super(tr("Reset offset"), null, tr("Reset offset (only vector images)"), null, false);
    96             this.wmsLayer = wmsLayer;
    9799        }
    98100        @Override
    99101        public void actionPerformed(ActionEvent arg0) {
    100             for (GeorefImage img:wmsLayer.images) {
    101                 img.deltaEast = 0;
    102                 img.deltaNorth = 0;
    103             }
     102            deltaEast = 0;
     103            deltaNorth = 0;
    104104            Main.map.mapView.repaint();
    105105        }
     
    180180        EastNorth lambertMin = Main.getProjection().latlon2eastNorth(b.getMin());
    181181        EastNorth lambertMax = Main.getProjection().latlon2eastNorth(b.getMax());
    182         double minEast = lambertMin.east();
    183         double minNorth = lambertMin.north();
     182        double minEast = lambertMin.east()+deltaEast;
     183        double minNorth = lambertMin.north()+deltaNorth;
    184184        double dEast = (lambertMax.east() - minEast) / factor;
    185185        double dNorth = (lambertMax.north() - minNorth) / factor;
     
    309309        cancelGrab = new MenuActionCancelGrab(this);
    310310        cancelGrab.setEnabled(!isRaster && grabThread.getImagesToGrabSize() > 0);
    311         Action resetOffset = new ResetOffsetActionMenu(this);
    312         resetOffset.setEnabled(!isRaster && images.size() > 0 && (images.get(0).deltaEast!=0.0 || images.get(0).deltaNorth!=0.0));
     311        Action resetOffset = new ResetOffsetActionMenu();
     312        resetOffset.setEnabled(!isRaster && images.size() > 0 && (deltaEast!=0.0 || deltaNorth!=0.0));
    313313        return new Action[] {
    314314                LayerListDialog.getInstance().createShowHideLayerAction(),
     
    338338            new GeorefImage(null,
    339339            Main.getProjection().latlon2eastNorth(bounds.getMin()),
    340             Main.getProjection().latlon2eastNorth(bounds.getMax()));
     340            Main.getProjection().latlon2eastNorth(bounds.getMax()), this);
    341341        for (GeorefImage img : images) {
    342342            if (img.overlap(georefImage))
     
    509509                        }
    510510                    }
     511                    newImage.wmsLayer = this;
    511512                    this.images.add(newImage);
    512513                }
     
    550551            synchronized(this) {
    551552                images.clear();
    552                 images.add(new GeorefImage(new_img, min, max));
     553                images.add(new GeorefImage(new_img, min, max, this));
    553554            }
    554555        }
     
    626627            images.get(0).shear(dx, dy);
    627628        } else {
    628             for (GeorefImage image:images)
    629                 image.tempShear(dx, dy);
     629            deltaEast+=dx;
     630            deltaNorth+=dy;
    630631        }
    631632    }
Note: See TracChangeset for help on using the changeset viewer.