Ignore:
Timestamp:
2011-10-09T23:41:21+02:00 (13 years ago)
Author:
pieren
Message:

Add a new possibility to shift cadastre vector maps (not saved in cache)

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/DownloadWMSVectorImage.java

    r26509 r26823  
    3636                    if (CacheControl.cacheEnabled) {
    3737                        if (wmsLayer.grabThread.getCacheControl().loadCacheIfExist()) {
    38                             Main.map.mapView.zoomTo(wmsLayer.getCommuneBBox().toBounds());
     38                            Main.map.mapView.zoomTo(wmsLayer.getFirstViewFromCacheBBox().toBounds());
    3939                            //Main.map.mapView.repaint();
    4040                            return;
  • applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/GeorefImage.java

    r24955 r26823  
    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;
    3134    // bbox of the georeferenced original image (raster only) (inclined if rotated and before cropping)
    3235    // P[0] is bottom,left then next are clockwise.
     
    107110            return;
    108111
    109         Point minPt = nc.getPoint(min), maxPt = nc.getPoint(max);
     112        // 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));
    110115
    111116        if (!g.hitClip(minPt.x, maxPt.y, maxPt.x - minPt.x, minPt.y - maxPt.y))
     
    171176        double maxMaskNorth = (georefImage.max.north() < this.max.north()) ? georefImage.max.north() : this.max.north();
    172177        if ((maxMaskNorth - minMaskNorth) > 0 && (maxMaskEast - minMaskEast) > 0) {
    173             double pixelPerEast = (max.east() - min.east()) / image.getWidth();
    174             double pixelPerNorth = (max.north() - min.north()) / image.getHeight();
    175             int minXMaskPixel = (int) ((minMaskEast - min.east()) / pixelPerEast);
    176             int minYMaskPixel = (int) ((max.north() - maxMaskNorth) / pixelPerNorth);
    177             int widthXMaskPixel = Math.abs((int) ((maxMaskEast - minMaskEast) / pixelPerEast));
    178             int heightYMaskPixel = Math.abs((int) ((maxMaskNorth - minMaskNorth) / pixelPerNorth));
     178            double pxPerEast = (max.east() - min.east()) / image.getWidth();
     179            double pxPerNorth = (max.north() - min.north()) / image.getHeight();
     180            int minXMaskPixel = (int) ((minMaskEast - min.east()) / pxPerEast);
     181            int minYMaskPixel = (int) ((max.north() - maxMaskNorth) / pxPerNorth);
     182            int widthXMaskPixel = Math.abs((int) ((maxMaskEast - minMaskEast) / pxPerEast));
     183            int heightYMaskPixel = Math.abs((int) ((maxMaskNorth - minMaskNorth) / pxPerNorth));
    179184            Graphics g = image.getGraphics();
    180185            for (int x = minXMaskPixel; x < minXMaskPixel + widthXMaskPixel; x++)
     
    279284        }
    280285    }
    281 
     286   
    282287    /**
    283288     * Change this image scale by moving the min,max coordinates around an anchor
     
    364369    }
    365370
     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    }
    366380}
  • applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/WMSAdjustAction.java

    r24934 r26823  
    1212import java.awt.event.MouseListener;
    1313import java.awt.event.MouseMotionListener;
    14 import java.util.ArrayList;
    1514
    1615import javax.swing.JOptionPane;
     
    2221import org.openstreetmap.josm.data.coor.EastNorth;
    2322import org.openstreetmap.josm.tools.ImageProvider;
    24 import org.openstreetmap.josm.gui.layer.Layer;
    2523
    2624public class WMSAdjustAction extends MapMode implements
     
    2826
    2927    private static final long serialVersionUID = 1L;
    30     private ArrayList<WMSLayer> modifiedLayers = new ArrayList<WMSLayer>();
    31     WMSLayer selectedLayer;
     28    private WMSLayer modifiedLayer = null;
    3229    private boolean rasterMoved;
    3330    private EastNorth prevEastNorth;
     
    3835    public WMSAdjustAction(MapFrame mapFrame) {
    3936        super(tr("Adjust WMS"), "adjustxywms",
    40                         tr("Adjust the position of the WMS layer (raster images only)"), mapFrame,
     37                        tr("Adjust the position of the WMS layer (saved for raster images only)"), mapFrame,
    4138                        ImageProvider.getCursor("normal", "move"));
    4239    }
     
    4441    @Override public void enterMode() {
    4542        if (Main.map != null) {
    46             selectedLayer = null;
    47             WMSLayer possibleLayer = null;
    48             int cRasterLayers = 0;
    49             for (Layer l : Main.map.mapView.getAllLayers()) {
    50                 if (l instanceof WMSLayer && ((WMSLayer)l).isRaster()) {
    51                     possibleLayer = (WMSLayer)l;
    52                     cRasterLayers++;
    53                 }
    54             }
    55             Layer activeLayer = Main.map.mapView.getActiveLayer();
    56             if (activeLayer instanceof WMSLayer && ((WMSLayer)activeLayer).isRaster()) {
    57                 selectedLayer = (WMSLayer)activeLayer;
    58             } else if (cRasterLayers == 1) {
    59                 selectedLayer = possibleLayer;
    60             }
    61             if (selectedLayer != null) {
     43            if (Main.map.mapView.getActiveLayer() instanceof WMSLayer) {
     44                modifiedLayer = (WMSLayer)Main.map.mapView.getActiveLayer();
    6245                super.enterMode();
    6346                Main.map.mapView.addMouseListener(this);
    6447                Main.map.mapView.addMouseMotionListener(this);
    6548                rasterMoved = false;
    66                 selectedLayer.adjustModeEnabled = true;
     49                modifiedLayer.adjustModeEnabled = true;
    6750            } else {
    68                 JOptionPane.showMessageDialog(Main.parent,tr("This mode works only if active layer is\n"
    69                         +"a cadastre \"plan image\" (raster image)"));
     51//                JOptionPane.showMessageDialog(Main.parent,tr("This mode works only if active layer is\n"
     52//                        +"a cadastre layer"));
    7053                exitMode();
    7154                Main.map.selectMapMode((MapMode)Main.map.getDefaultButtonAction());
     
    7861        Main.map.mapView.removeMouseListener(this);
    7962        Main.map.mapView.removeMouseMotionListener(this);
    80         if (rasterMoved && CacheControl.cacheEnabled) {
     63        if (rasterMoved && CacheControl.cacheEnabled && modifiedLayer.isRaster()) {
    8164            int reply = JOptionPane.showConfirmDialog(null,
    8265                    "Save the changes in cache ?",
     
    8770            }
    8871        }
    89         modifiedLayers.clear();
    90         if (selectedLayer != null) {
    91             selectedLayer.adjustModeEnabled = false;
    92             selectedLayer = null;
     72        rasterMoved = false;
     73        if (modifiedLayer != null) {
     74            modifiedLayer.adjustModeEnabled = false;
     75            modifiedLayer = null;
    9376        }
    9477    }
     
    10184        // boolean alt = (e.getModifiers() & ActionEvent.ALT_MASK) != 0;
    10285        boolean shift = (e.getModifiers() & ActionEvent.SHIFT_MASK) != 0;
    103         if (shift && !ctrl)
     86        if (shift && !ctrl && modifiedLayer.isRaster())
    10487            mode = Mode.moveZ;
    105         else if (shift && ctrl)
     88        else if (shift && ctrl && modifiedLayer.isRaster())
    10689            mode = Mode.rotate;
    10790        else
     
    124107            prevEastNorth = newEastNorth;
    125108        }
    126         if (!modifiedLayers.contains(selectedLayer))
    127             modifiedLayers.add(selectedLayer);
    128109        Main.map.mapView.repaint();
    129110    }
     
    141122
    142123    private void displace(EastNorth start, EastNorth end) {
    143         selectedLayer.displace(end.east()-start.east(), end.north()-start.north());
     124        modifiedLayer.displace(end.east()-start.east(), end.north()-start.north());
    144125    }
    145126
    146127    private void resize(EastNorth newEastNorth) {
    147         EastNorth center = selectedLayer.getRasterCenter();
     128        EastNorth center = modifiedLayer.getRasterCenter();
    148129        double dPrev = prevEastNorth.distance(center.east(), center.north());
    149130        double dNew = newEastNorth.distance(center.east(), center.north());
    150         selectedLayer.resize(center, dNew/dPrev);
     131        modifiedLayer.resize(center, dNew/dPrev);
    151132    }
    152133
    153134    private void rotate(EastNorth start, EastNorth end) {
    154         EastNorth pivot = selectedLayer.getRasterCenter();
     135        EastNorth pivot = modifiedLayer.getRasterCenter();
    155136        double startAngle = Math.atan2(start.east()-pivot.east(), start.north()-pivot.north());
    156137        double endAngle = Math.atan2(end.east()-pivot.east(), end.north()-pivot.north());
    157138        double rotationAngle = endAngle - startAngle;
    158         selectedLayer.rotate(pivot, rotationAngle);
     139        modifiedLayer.rotate(pivot, rotationAngle);
    159140    }
    160141
    161142    private void rotateFrameOnly(EastNorth start, EastNorth end) {
    162143        if (start != null && end != null) {
    163             EastNorth pivot = selectedLayer.getRasterCenter();
     144            EastNorth pivot = modifiedLayer.getRasterCenter();
    164145            double startAngle = Math.atan2(start.east()-pivot.east(), start.north()-pivot.north());
    165146            double endAngle = Math.atan2(end.east()-pivot.east(), end.north()-pivot.north());
    166147            double rotationAngle = endAngle - startAngle;
    167             if (selectedLayer.getImage(0).orgCroppedRaster != null) {
     148            if (modifiedLayer.getImage(0).orgCroppedRaster != null) {
    168149                for (int i=0; i<4; i++) {
    169                     croppedRaster[i] = selectedLayer.getImage(0).orgCroppedRaster[i].rotate(pivot, rotationAngle);
     150                    croppedRaster[i] = modifiedLayer.getImage(0).orgCroppedRaster[i].rotate(pivot, rotationAngle);
    170151                }
    171152                croppedRaster[4] = croppedRaster[0];
     
    197178
    198179    private void saveModifiedLayers() {
    199         for (WMSLayer wmsLayer : modifiedLayers) {
    200             wmsLayer.grabThread.saveNewCache();
    201         }
     180            modifiedLayer.grabThread.saveNewCache();
    202181    }
    203182}
  • applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/WMSLayer.java

    r26509 r26823  
    1111import java.awt.RenderingHints;
    1212import java.awt.Toolkit;
     13import java.awt.event.ActionEvent;
    1314import java.awt.image.BufferedImage;
    1415import java.awt.image.ImageObserver;
     
    2930
    3031import org.openstreetmap.josm.Main;
     32import org.openstreetmap.josm.actions.JosmAction;
    3133import org.openstreetmap.josm.data.Bounds;
    3234import org.openstreetmap.josm.data.coor.EastNorth;
     
    8789    private Action cancelGrab;
    8890
     91    @SuppressWarnings("serial")
     92    class ResetOffsetActionMenu extends JosmAction {
     93        private WMSLayer wmsLayer;
     94        public ResetOffsetActionMenu(WMSLayer wmsLayer) {
     95            super(tr("Reset offset"), null, tr("Reset offset (only vector images)"), null, false);
     96            this.wmsLayer = wmsLayer;
     97        }
     98        @Override
     99        public void actionPerformed(ActionEvent arg0) {
     100            for (GeorefImage img:wmsLayer.images) {
     101                img.deltaEast = 0;
     102                img.deltaNorth = 0;
     103            }
     104            Main.map.mapView.repaint();
     105        }
     106       
     107    }
     108   
    89109    public boolean adjustModeEnabled;
    90110
     
    213233                dividedBbox.add(new EastNorthBound(mid, new EastNorth(mid.east()+c, mid.north()+c)));
    214234            }
    215 //            // simple algorithm to grab all squares
    216 //            minEast = minEast - minEast % cSquare;
    217 //            minNorth = minNorth - minNorth % cSquare;
    218 //            for (int xEast = (int)minEast; xEast < lambertMax.east(); xEast+=cSquare)
    219 //                for (int xNorth = (int)minNorth; xNorth < lambertMax.north(); xNorth+=cSquare) {
    220 //                    dividedBbox.add(new EastNorthBound(new EastNorth(xEast, xNorth),
    221 //                                new EastNorth(xEast + cSquare, xNorth + cSquare)));
    222 //            }
    223235        }
    224236    }
     
    297309        cancelGrab = new MenuActionCancelGrab(this);
    298310        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));
    299313        return new Action[] {
    300314                LayerListDialog.getInstance().createShowHideLayerAction(),
     
    303317                saveAsPng,
    304318                cancelGrab,
     319                resetOffset,
    305320                new LayerListPopup.InfoAction(this),
    306321
     
    566581        return communeBBox;
    567582    }
     583   
     584    public EastNorthBound getFirstViewFromCacheBBox() {
     585        if (isRaster) {
     586            return communeBBox;
     587        }
     588        double min_x = Double.MAX_VALUE;
     589        double max_x = Double.MIN_VALUE;
     590        double min_y = Double.MAX_VALUE;
     591        double max_y = Double.MIN_VALUE;
     592        for (GeorefImage image:images){
     593            min_x = image.min.east() < min_x ? image.min.east() : min_x;
     594            max_x = image.max.east() > max_x ? image.max.east() : max_x;
     595            min_y = image.min.north() < min_y ? image.min.north() : min_y;
     596            max_y = image.max.north() > max_y ? image.max.north() : max_y;
     597        }
     598        EastNorthBound maxGrabbedBBox = new EastNorthBound(new EastNorth(min_x, min_y), new EastNorth(max_x, max_y));
     599        return maxGrabbedBBox;
     600    }
    568601
    569602    public void setCommuneBBox(EastNorthBound entireCommune) {
     
    588621
    589622    public void displace(double dx, double dy) {
    590         this.rasterMin = new EastNorth(rasterMin.east() + dx, rasterMin.north() + dy);
    591         this.rasterMax = new EastNorth(rasterMax.east() + dx, rasterMax.north() + dy);
    592         images.get(0).shear(dx, dy);
     623        if (isRaster) {
     624            this.rasterMin = new EastNorth(rasterMin.east() + dx, rasterMin.north() + dy);
     625            this.rasterMax = new EastNorth(rasterMax.east() + dx, rasterMax.north() + dy);
     626            images.get(0).shear(dx, dy);
     627        } else {
     628            for (GeorefImage image:images)
     629                image.tempShear(dx, dy);
     630        }
    593631    }
    594632
Note: See TracChangeset for help on using the changeset viewer.