Ignore:
Timestamp:
2010-03-09T22:02:00+01:00 (15 years ago)
Author:
pieren
Message:

Many small fixes and improvements

File:
1 edited

Legend:

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

    r20240 r20390  
    1919import java.io.ObjectOutputStream;
    2020import java.util.ArrayList;
     21import java.util.HashSet;
    2122import java.util.Vector;
    2223
     
    7273
    7374    private boolean isRaster = false;
    74 
    7575    private boolean isAlreadyGeoreferenced = false;
    76 
     76    private boolean buildingsOnly = false;
    7777    public double X0, Y0, angle, fX, fY;
    7878
     
    8686    public boolean adjustModeEnabled;
    8787
     88
    8889    public WMSLayer() {
    8990        this(tr("Blank Layer"), "", -1);
     
    9192
    9293    public WMSLayer(String location, String codeCommune, int lambertZone) {
    93         super(buildName(location, codeCommune));
     94        super(buildName(location, codeCommune, false));
    9495        this.location = location;
    9596        this.codeCommune = codeCommune;
     
    113114    }
    114115   
    115     private static String buildName(String location, String codeCommune) {
     116    private static String buildName(String location, String codeCommune, boolean buildingOnly) {
    116117        String ret = new String(location.toUpperCase());
    117118        if (codeCommune != null && !codeCommune.equals(""))
    118119            ret += "(" + codeCommune + ")";
     120        if (buildingOnly)
     121            ret += ".b";
    119122        return  ret;
    120123    }
    121124
    122125    private String rebuildName() {
    123         return buildName(this.location.toUpperCase(), this.codeCommune);
     126        return buildName(this.location.toUpperCase(), this.codeCommune, this.buildingsOnly);
    124127    }
    125128
     
    133136                b = new Bounds(Main.proj.eastNorth2latlon(rasterMin), Main.proj.eastNorth2latlon(rasterMax));
    134137                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);
    138143        } else
    139             divideBbox(b, 1);
    140 
     144            divideBbox(b, 1, 0);
     145
     146        int lastSavedImage = images.size();
    141147        for (EastNorthBound n : dividedBbox) {
    142148            GeorefImage newImage;
    143149            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                }
    145158            } catch (IOException e) {
    146159                System.out.println("Download action cancelled by user or server did not respond");
     
    166179            }
    167180            images.add(newImage);
    168             saveToCache(newImage);
    169181            Main.map.mapView.repaint();
    170182        }
     183        if (buildingsOnly)
     184            joinBufferedImages();
     185        for (int i=lastSavedImage; i < images.size(); i++)
     186            saveToCache(images.get(i));
    171187    }
    172188
     
    177193     *               2 = source bbox divided by 2x2 smaller boxes
    178194     *               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) {
    183201        EastNorth lambertMin = Main.proj.latlon2eastNorth(b.getMin());
    184202        EastNorth lambertMax = Main.proj.latlon2eastNorth(b.getMax());
     
    196214        } else {
    197215            // 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;   
    199217            minEast = minEast - minEast % cSquare;
    200218            minNorth = minNorth - minNorth % cSquare;
     
    298316    public boolean isOverlapping(Bounds bounds) {
    299317        GeorefImage georefImage =
    300             new GeorefImage(new BufferedImage(1,1,BufferedImage.TYPE_INT_RGB ), // not really important
     318            new GeorefImage(null,
    301319            Main.proj.latlon2eastNorth(bounds.getMin()),
    302320            Main.proj.latlon2eastNorth(bounds.getMax()));
     
    358376    public void setCodeCommune(String codeCommune) {
    359377        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;
    360387        setName(rebuildName());
    361388    }
     
    412439        oos.writeInt(this.lambertZone);
    413440        oos.writeBoolean(this.isRaster);
     441        oos.writeBoolean(this.buildingsOnly);
    414442        if (this.isRaster) {
    415443            oos.writeDouble(this.rasterMin.getX());
     
    443471        this.lambertZone = ois.readInt();
    444472        this.setRaster(ois.readBoolean());
     473        if (currentFormat >= 4)
     474            this.setBuildingsOnly(ois.readBoolean());
    445475        if (this.isRaster) {
    446476            double X = ois.readDouble();
     
    491521    /**
    492522     * 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() {
    497525        if (images.size() > 1) {
    498526            EastNorth min = images.get(0).min;
     
    500528            int oldImgWidth = images.get(0).image.getWidth();
    501529            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*/);
    505539            Graphics g = new_img.getGraphics();
    506540            // Coordinate (0,0) is on top,left corner where images are grabbed from bottom left
    507541            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++) {
    510544                    int newx = h*oldImgWidth;
    511545                    int newy = newHeight - oldImgHeight - (v*oldImgHeight);
     
    543577        rasterRatio = (rasterMax.getX()-rasterMin.getX())/(communeBBox.max.getX() - communeBBox.min.getX());
    544578    }
    545 
     579   
    546580    public EastNorthBound getCommuneBBox() {
    547581        return communeBBox;
Note: See TracChangeset for help on using the changeset viewer.