Changeset 20390 in osm for applications


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

Many small fixes and improvements

Location:
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr
Files:
2 added
16 edited

Legend:

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

    r19371 r20390  
    9494    public boolean loadCacheIfExist() {
    9595        try {
    96             String extension = String.valueOf((wmsLayer.getLambertZone() + 1));
    97             if (Main.proj instanceof LambertCC9Zones)
    98                 extension = cLambertCC9Z + extension;
    99             else if (Main.proj instanceof UTM_20N_France_DOM)
    100                 extension = cUTM20N + extension;
    101             File file = new File(CadastrePlugin.cacheDir + wmsLayer.getName() + "." + extension);
     96            File file = new File(CadastrePlugin.cacheDir + wmsLayer.getName() + "." + WMSFileExtension());
    10297            if (file.exists()) {
    10398                JOptionPane pane = new JOptionPane(
     
    127122    public void deleteCacheFile() {
    128123        try {
    129             String extension = String.valueOf((wmsLayer.getLambertZone() + 1));
    130             if (Main.proj instanceof LambertCC9Zones)
    131                 extension = cLambertCC9Z + extension;
    132             delete(new File(CadastrePlugin.cacheDir + wmsLayer.getName() + "." + extension));
     124            delete(new File(CadastrePlugin.cacheDir + wmsLayer.getName() + "." + WMSFileExtension()));
    133125        } catch (Exception e) {
    134126            e.printStackTrace(System.out);
     
    182174            imagesLock.unlock();
    183175            if (size > 0) {
    184                 String extension = String.valueOf((wmsLayer.getLambertZone() + 1));
    185                 if (Main.proj instanceof LambertCC9Zones)
    186                     extension = cLambertCC9Z + extension;
    187                 else if (Main.proj instanceof UTM_20N_France_DOM)
    188                     extension = cUTM20N + extension;
    189                 File file = new File(CadastrePlugin.cacheDir + wmsLayer.getName() + "." + extension);
     176                File file = new File(CadastrePlugin.cacheDir + wmsLayer.getName() + "." + WMSFileExtension());
    190177                try {
    191178                    if (file.exists()) {
     
    219206        }
    220207    }
     208   
     209    private String WMSFileExtension() {
     210        String ext = String.valueOf((wmsLayer.getLambertZone() + 1));
     211        if (Main.proj instanceof LambertCC9Zones)
     212            ext = cLambertCC9Z + ext;
     213        else if (Main.proj instanceof UTM_20N_France_DOM)
     214            ext = cUTM20N + ext;
     215        return ext;
     216    }
     217
    221218}
  • applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CadastreGrabber.java

    r20247 r20390  
    3535                imageModified = new RasterImageModifier(img);
    3636            else
    37                 imageModified = new VectorImageModifier(img);
     37                imageModified = new VectorImageModifier(img, false);
    3838            return new GeorefImage(imageModified.bufferedImage, lambertMin, lambertMax);
    3939        } catch (MalformedURLException e) {
     
    4242    }
    4343
     44    public GeorefImage grabBuildings(WMSLayer wmsLayer, EastNorth lambertMin, EastNorth lambertMax) throws IOException, OsmTransferException {
     45        try {
     46            URL url = getURLVectorBuildings(lambertMin, lambertMax);
     47            BufferedImage img = grab(url);
     48            ImageModifier imageModified = new VectorImageModifier(img, true);
     49            return new GeorefImage(imageModified.bufferedImage, lambertMin, lambertMax);
     50        } catch (MalformedURLException e) {
     51            throw (IOException) new IOException(tr("CadastreGrabber: Illegal url.")).initCause(e);
     52        }
     53    }
     54   
     55    public GeorefImage grabParcels(WMSLayer wmsLayer, EastNorth lambertMin, EastNorth lambertMax) throws IOException, OsmTransferException {
     56        try {
     57            URL url = getURLVectorParcels(lambertMin, lambertMax);
     58            BufferedImage img = grab(url);
     59            //ImageModifier imageModified = new VectorImageModifier(img, true);
     60            return new GeorefImage(/*imageModified.bufferedImage*/img, lambertMin, lambertMax);
     61        } catch (MalformedURLException e) {
     62            throw (IOException) new IOException(tr("CadastreGrabber: Illegal url.")).initCause(e);
     63        }
     64    }
     65   
    4466    private URL getURLRaster(WMSLayer wmsLayer, EastNorth lambertMin, EastNorth lambertMax) throws MalformedURLException {
    4567        // GET /scpc/wms?version=1.1&request=GetMap&layers=CDIF:PMC@QH4480001701&format=image/png&bbox=-1186,0,13555,8830&width=576&height=345&exception=application/vnd.ogc.se_inimage&styles= HTTP/1.1
     
    4971        str += wmsLayer.getCodeCommune();
    5072        str += "&format=image/png";
     73        //str += "&format=image/jpeg";
    5174        str += "&bbox=";
    5275        str += wmsLayer.eastNorth2raster(lambertMin, lambertMax);
    53         //str += "&width=1000&height=800"; // maximum allowed by wms server
    5476        str += "&width="+cRasterX+"&height="; // maximum allowed by wms server (576/345, 800/378, 1000/634)
    5577        str += (int)(cRasterX*(wmsLayer.communeBBox.max.getY() - wmsLayer.communeBBox.min.getY())/(wmsLayer.communeBBox.max.getX() - wmsLayer.communeBBox.min.getX()));
    56         str += "&exception=application/vnd.ogc.se_inimage&styles=";
     78        str += "&exception=application/vnd.ogc.se_inimage&styles="; // required for raster images
     79        System.out.println("URL="+str);
    5780        return new URL(str.replace(" ", "%20"));
    5881    }
    5982
    60     private URL getURLVector(EastNorth lambertMin, EastNorth lambertMax) throws MalformedURLException {
     83    private URL buildURLVector(String layers, String styles,
     84            int width, int height,
     85            EastNorth lambertMin, EastNorth lambertMax) throws MalformedURLException {
    6186        String str = new String(wmsInterface.baseURL+"/scpc/wms?version=1.1&request=GetMap");
    62         str += "&layers="+CadastrePlugin.grabLayers;
     87        str += "&layers="+ layers; 
    6388        str += "&format=image/png";
    6489        //str += "&format=image/jpeg";
     
    6792        str += lambertMax.east() + ",";
    6893        str += lambertMax.north();
    69         str += "&width="+CadastrePlugin.imageWidth+"&height="+CadastrePlugin.imageHeight;
    70         //str += "&exception=application/vnd.ogc.se_inimage"; // used by normal client but not required
    71         str += "&styles="+CadastrePlugin.grabStyles;
     94        str += "&width="+width+"&height="+height;
     95        str += "&exception=application/vnd.ogc.se_inimage"; // works also without (but slower ?)
     96        str += "&styles=" + styles;
    7297        System.out.println("URL="+str);
    7398        return new URL(str.replace(" ", "%20"));
     99    }
     100
     101    private URL getURLVector(EastNorth lambertMin, EastNorth lambertMax) throws MalformedURLException {
     102        return buildURLVector(CadastrePlugin.grabLayers, CadastrePlugin.grabStyles,
     103                CadastrePlugin.imageWidth, CadastrePlugin.imageHeight,
     104                lambertMin, lambertMax);
     105    }
     106
     107    private URL getURLVectorBuildings(EastNorth lambertMin, EastNorth lambertMax) throws MalformedURLException {
     108        return buildURLVector("CDIF:LS2", "LS2_90", 1000, 800, lambertMin, lambertMax);
     109    }
     110
     111    private URL getURLVectorParcels(EastNorth lambertMin, EastNorth lambertMax) throws MalformedURLException {
     112        return buildURLVector("CDIF:PARCELLE", "PARCELLE_90", 1000, 800, lambertMin, lambertMax);
    74113    }
    75114
  • applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CadastrePlugin.java

    r20262 r20390  
    9090 * 1.6 28-Nov-2009 - Fix minor issues if Grab is called without layer (possible since projection rework)
    9191 * 1.7 12-Dec-2009 - Change URL's changes for cookie and downgrade imgs resolution due to WMS changes
    92  * 1.8 xxx        - filter the mouse button 1 during georeferencing
     92 * 1.8 09-Mar-2010 - filter the mouse button 1 during georeferencing
    9393 *                 - retry if getting a new cookie failed (10 times during 30 seconds)
    9494 *                 - cookie expiration automatically detected and renewed (after 30 minutes)
     
    188188            // temporary disabled:
    189189            //JMenuItem menuActionBoundaries = new JMenuItem(new MenuActionBoundaries());
    190             //JMenuItem menuActionBuildings = new JMenuItem(new MenuActionBuildings());
     190            JMenuItem menuActionBuildings = new JMenuItem(new MenuActionBuildings());
    191191
    192192            cadastreJMenu.add(menuGrab);
     
    196196            //cadastreJMenu.add(menuResetCookie); not required any more
    197197            //cadastreJMenu.add(menuLambertZone);
     198            if (Main.pref.getBoolean("cadastrewms.buildingsMenu", false))
     199                cadastreJMenu.add(menuActionBuildings);
    198200            cadastreJMenu.add(menuLoadFromCache);
    199201            // all SVG features disabled until official WMS is released
    200202            //cadastreJMenu.add(menuActionBoundaries);
    201             //cadastreJMenu.add(menuActionBuildings);
    202203        }
    203204        setEnabledAll(menuEnabled);
     
    224225            imageWidth = 600; imageHeight = 400;
    225226        }
    226         grabLayers = "";
    227         grabStyles = "";
    228         if (Main.pref.getBoolean("cadastrewms.layerWater", true)) {
    229             grabLayers += "CDIF:LS3,";
    230             grabStyles += "LS3_90,";
    231         }
    232         if (Main.pref.getBoolean("cadastrewms.layerBuilding", true)) {
    233             grabLayers += "CDIF:LS2,";
    234             grabStyles += "LS2_90,";
    235         }
    236         if (Main.pref.getBoolean("cadastrewms.layerSymbol", true)) {
    237             grabLayers += "CDIF:LS1,";
    238             grabStyles += "LS1_90,";
    239         }
    240         if (Main.pref.getBoolean("cadastrewms.layerParcel", true)) {
    241             grabLayers += "CDIF:PARCELLE,";
    242             grabStyles += "PARCELLE_90,";
    243         }
    244         if (Main.pref.getBoolean("cadastrewms.layerNumero", true)) {
    245             grabLayers += "CDIF:NUMERO,";
    246             grabStyles += "NUMERO_90,";
    247         }
    248         if (Main.pref.getBoolean("cadastrewms.layerLabel", true)) {
    249             grabLayers += "CDIF:PT3,CDIF:PT2,CDIF:PT1,";
    250             grabStyles += "PT3_90,PT2_90,PT1_90,";
    251         }
    252         if (Main.pref.getBoolean("cadastrewms.layerLieudit", true)) {
    253             grabLayers += "CDIF:LIEUDIT,";
    254             grabStyles += "LIEUDIT_90,";
    255         }
    256         if (Main.pref.getBoolean("cadastrewms.layerSection", true)) {
    257             grabLayers += "CDIF:SUBSECTION,CDIF:SECTION,";
    258             grabStyles += "SUBSECTION_90,SECTION_90,";
    259         }
    260         if (Main.pref.getBoolean("cadastrewms.layerCommune", true)) {
    261             grabLayers += "CDIF:COMMUNE,";
    262             grabStyles += "COMMUNE_90,";
    263         }
    264         if (grabLayers.length() > 0) { // remove the last ','
    265             grabLayers = grabLayers.substring(0, grabLayers.length()-1);
    266             grabStyles = grabStyles.substring(0, grabStyles.length()-1);
    267         }
     227        refreshLayersURL();
    268228       
    269229        // overwrite F11 shortcut used from the beginning by this plugin and recently used
     
    296256        refreshMenu();
    297257    }
     258   
     259    private static void refreshLayersURL() {
     260        grabLayers = "";
     261        grabStyles = "";
     262        if (Main.pref.getBoolean("cadastrewms.layerWater", true)) {
     263            grabLayers += "CDIF:LS3,";
     264            grabStyles += "LS3_90,";
     265        }
     266        if (Main.pref.getBoolean("cadastrewms.layerBuilding", true)) {
     267            grabLayers += "CDIF:LS2,";
     268            grabStyles += "LS2_90,";
     269        }
     270        if (Main.pref.getBoolean("cadastrewms.layerSymbol", true)) {
     271            grabLayers += "CDIF:LS1,";
     272            grabStyles += "LS1_90,";
     273        }
     274        if (Main.pref.getBoolean("cadastrewms.layerParcel", true)) {
     275            grabLayers += "CDIF:PARCELLE,";
     276            grabStyles += "PARCELLE_90,";
     277        }
     278        if (Main.pref.getBoolean("cadastrewms.layerNumero", true)) {
     279            grabLayers += "CDIF:NUMERO,";
     280            grabStyles += "NUMERO_90,";
     281        }
     282        if (Main.pref.getBoolean("cadastrewms.layerLabel", true)) {
     283            grabLayers += "CDIF:PT3,CDIF:PT2,CDIF:PT1,";
     284            grabStyles += "PT3_90,PT2_90,PT1_90,";
     285        }
     286        if (Main.pref.getBoolean("cadastrewms.layerLieudit", true)) {
     287            grabLayers += "CDIF:LIEUDIT,";
     288            grabStyles += "LIEUDIT_90,";
     289        }
     290        if (Main.pref.getBoolean("cadastrewms.layerSection", true)) {
     291            grabLayers += "CDIF:SUBSECTION,CDIF:SECTION,";
     292            grabStyles += "SUBSECTION_90,SECTION_90,";
     293        }
     294        if (Main.pref.getBoolean("cadastrewms.layerCommune", true)) {
     295            grabLayers += "CDIF:COMMUNE,";
     296            grabStyles += "COMMUNE_90,";
     297        }
     298        if (grabLayers.length() > 0) { // remove the last ','
     299            grabLayers = grabLayers.substring(0, grabLayers.length()-1);
     300            grabStyles = grabStyles.substring(0, grabStyles.length()-1);
     301        }
     302    }
    298303
    299304    @Override
     
    322327                Main.map.addMapMode(new IconToggleButton
    323328                        (new WMSAdjustAction(Main.map)));
     329                Main.map.addMapMode(new IconToggleButton
     330                        (new Buildings(Main.map)));
    324331            } else if (oldFrame != null && newFrame == null) {
    325332                setEnabledAll(false);
  • applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/DownloadSVGBuilding.java

    r20240 r20390  
    129129
    130130        // simplify ways and check if we can reuse existing OSM nodes
    131         for (Way wayToAdd : svgDataSet.getWays())
    132             new SimplifyWay().simplifyWay(wayToAdd, svgDataSet, 0.5);
     131//        for (Way wayToAdd : svgDataSet.getWays())
     132//            new SimplifyWay().simplifyWay(wayToAdd, svgDataSet, 0.5);
    133133        // check if the new way or its nodes is already in OSM layer
    134134        for (Node n : svgDataSet.getNodes()) {
  • applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/DownloadSVGTask.java

    r20240 r20390  
    123123
    124124        // simplify the way
    125         double threshold = Double.parseDouble(Main.pref.get("cadastrewms.simplify-way-boundary", "1.0"));
    126         new SimplifyWay().simplifyWay(wayToAdd, Main.main.getCurrentDataSet(), threshold);
     125//        double threshold = Double.parseDouble(Main.pref.get("cadastrewms.simplify-way-boundary", "1.0"));
     126//        new SimplifyWay().simplifyWay(wayToAdd, Main.main.getCurrentDataSet(), threshold);
    127127
    128128        cmds.add(new AddCommand(wayToAdd));
  • applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/DownloadWMSPlanImage.java

    r18544 r20390  
    6666                            } else {
    6767                                // next steps follow in method finish() when download is terminated
    68                                 wmsLayer.joinRasterImages();
     68                                wmsLayer.joinBufferedImages();
    6969                            }
    7070                        } else {
  • applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/DownloadWMSVectorImage.java

    r18838 r20390  
    1616
    1717    private Bounds bounds;
    18 
     18   
    1919    private CadastreGrabber grabber = CadastrePlugin.cadastreGrabber;
    2020
    21     public DownloadWMSVectorImage(WMSLayer wmsLayer, Bounds bounds) {
     21    public DownloadWMSVectorImage(WMSLayer wmsLayer, Bounds bounds, boolean buildingsOnly) {
    2222        super(tr("Downloading {0}", wmsLayer.getName()));
    2323
    2424        this.wmsLayer = wmsLayer;
    2525        this.bounds = bounds;
     26        this.wmsLayer.setBuildingsOnly(buildingsOnly);
    2627    }
    2728
     
    7374    }
    7475
    75     public static void download(WMSLayer wmsLayer) {
     76    public static void download(WMSLayer wmsLayer, boolean buildingsOnly) {
    7677        MapView mv = Main.map.mapView;
    7778        Bounds bounds = new Bounds(mv.getLatLon(0, mv.getHeight()), mv.getLatLon(mv.getWidth(), 0));
    7879
    79         Main.worker.execute(new DownloadWMSVectorImage(wmsLayer, bounds));
     80        Main.worker.execute(new DownloadWMSVectorImage(wmsLayer, bounds, buildingsOnly));
    8081
    8182    }
  • applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/GeorefImage.java

    r20211 r20390  
    337337        int newWidth = Math.abs(sx2 - sx1);
    338338        int newHeight = Math.abs(sy2 - sy1);
    339         BufferedImage new_img = new BufferedImage(newWidth, newHeight, BufferedImage.TYPE_INT_ARGB);
     339        BufferedImage new_img = new BufferedImage(newWidth, newHeight, image.getType());
    340340        Graphics g = new_img.getGraphics();
    341341        g.drawImage(image, 0, 0, newWidth-1, newHeight-1,
  • applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/ImageModifier.java

    r20247 r20390  
    33package cadastre_fr;
    44
     5import java.awt.Color;
    56import java.awt.Transparency;
    67import java.awt.image.BufferedImage;
     
    1718    private static final long serialVersionUID = 1L;
    1819
     20    protected int parcelColor = Color.RED.getRGB();
     21   
    1922    public BufferedImage bufferedImage;
     23
     24    public static int[] cRoofColors = new int[] {-197380, -592138};
     25    public static int[] cBuilingFootColors = new int[] {-256};
    2026
    2127    protected BufferedImage convert1(BufferedImage src) {
     
    107113        return dest;
    108114      }
     115
     116    public boolean isBuildingColor(int rgb, boolean ignoreParcelColor) {
     117        for (int i = 0; i < cBuilingFootColors.length; i++)
     118            if (rgb == cBuilingFootColors[i])
     119                    return true;
     120        if (ignoreParcelColor && (rgb == parcelColor))
     121            return true;
     122        return false;
     123    }
     124
     125    public boolean isRoofColor(int rgb, boolean ignoreParcelColor) {
     126        for (int i = 0; i < cRoofColors.length; i++)
     127            if (rgb == cRoofColors[i])
     128                    return true;
     129        if (ignoreParcelColor && (rgb == parcelColor))
     130            return true;
     131        return false;
     132    }
     133
     134    public boolean isBuildingOrRoofColor(BufferedImage img, int x, int y, boolean ignoreParcelColor) {
     135        int rgb = img.getRGB(x, y);
     136        boolean ret = isBuildingColor(rgb, ignoreParcelColor) || isRoofColor(rgb, ignoreParcelColor);
     137        return ret;
     138    }
     139
     140    public boolean isBuildingOrRoofColor(BufferedImage img, int x, int y, boolean colorType, boolean ignoreParcelColor) {
     141        int rgb = img.getRGB(x, y);
     142        boolean ret;
     143        if (colorType)
     144            ret = isBuildingColor(rgb, ignoreParcelColor);
     145        else
     146            ret = isRoofColor(rgb, ignoreParcelColor);
     147        return ret;
     148    }
     149
     150    /**
     151     * Checks if the rgb value is the black background color
     152     * @param 
     153     * @return
     154     */
     155    public boolean isBackgroundColor(BufferedImage img, int x, int y) {
     156        return (img.getRGB(x, y) == -1);
     157    }
     158
    109159}
  • applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/MenuActionBuildings.java

    r18544 r20390  
    1313public class MenuActionBuildings extends JosmAction {
    1414   
    15     public static String name = "Building footprints";
     15    public static String name = "Grab buildings only";
    1616
    1717    private static final long serialVersionUID = 1L;
    18     private WMSLayer wmsLayer = null;
    1918   
    2019    public MenuActionBuildings() {
    21         super(tr(name), "cadastre_small", tr("Extract building footprints"), null, false);
     20        super(tr(name), "cadastre_small", tr("Grab building layer only"), null, false);
    2221    }
    2322
    24     public void actionPerformed(ActionEvent arg0) {
    25         wmsLayer = WMSDownloadAction.getLayer();
    26         if (wmsLayer != null) {
    27             if (wmsLayer.isRaster()) {
     23    public void actionPerformed(ActionEvent e) {
     24        if (Main.map != null) {
     25            if (CadastrePlugin.isCadastreProjection()) {
     26                WMSLayer wmsLayer = WMSDownloadAction.getLayer();
     27                if (wmsLayer != null)
     28                    DownloadWMSVectorImage.download(wmsLayer, true);
     29            } else {
    2830                JOptionPane.showMessageDialog(Main.parent,
    29                         tr("Only on vectorized layers"), tr("Error"),
    30                         JOptionPane.ERROR_MESSAGE);
    31                 return;
     31                        tr("To enable the cadastre WMS plugin, change\n"
     32                         + "the current projection to one of the cadastre\n"
     33                         + "projections and retry"));
    3234            }
    33             DownloadSVGBuilding.download(wmsLayer);
    34         }
     35        } else
     36            new MenuActionNewLocation().actionPerformed(e);
    3537    }
    3638
  • applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/MenuActionGrab.java

    r18838 r20390  
    3333                WMSLayer wmsLayer = WMSDownloadAction.getLayer();
    3434                if (wmsLayer != null)
    35                     DownloadWMSVectorImage.download(wmsLayer);
     35                    DownloadWMSVectorImage.download(wmsLayer, false);
    3636            } else {
    3737                JOptionPane.showMessageDialog(Main.parent,
  • applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/MenuActionNewLocation.java

    r19928 r20390  
    3232        WMSLayer wmsLayer = addNewLayer(new ArrayList<WMSLayer>());
    3333        if (wmsLayer != null)
    34             DownloadWMSVectorImage.download(wmsLayer);
     34            DownloadWMSVectorImage.download(wmsLayer, false);
    3535    }
    3636
  • applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/SimplifyWay.java

    r19078 r20390  
    33
    44import java.util.ArrayList;
    5 
    6 import java.util.Collection;
    7 import java.util.Collections;
    8 import java.util.HashSet;
    9 import java.util.LinkedList;
    105import java.util.List;
    116
    12 import org.openstreetmap.josm.Main;
    13 import org.openstreetmap.josm.command.ChangeCommand;
    14 import org.openstreetmap.josm.command.Command;
    15 import org.openstreetmap.josm.command.DeleteCommand;
    16 import org.openstreetmap.josm.command.SequenceCommand;
    17 import org.openstreetmap.josm.data.osm.DataSet;
    187import org.openstreetmap.josm.data.osm.Node;
    19 import org.openstreetmap.josm.data.osm.OsmPrimitive;
    208import org.openstreetmap.josm.data.osm.Way;
    21 import static org.openstreetmap.josm.tools.I18n.trn;
    22 
    23  
    249
    2510/**
     
    2914 */
    3015public class SimplifyWay {
    31     public void simplifyWay(Way w, DataSet dataSet, double threshold) {
     16    public void simplifyWay(Way w/*, DataSet dataSet*/, double threshold) {
    3217        Way wnew = new Way(w);
    3318
    34         int toI = wnew.getNodesCount() - 1;
    35         List<OsmPrimitive> parents = new ArrayList<OsmPrimitive>();
    36         for (int i = wnew.getNodesCount() - 1; i >= 0; i--) {
    37             //CollectBackReferencesVisitor backRefsV = new CollectBackReferencesVisitor(dataSet, false);
    38             //backRefsV.visit(wnew.getNode(i));
    39            parents.addAll(w.getNode(i).getReferrers());
    40             boolean used = false;
    41             if (parents.size() == 1) {
    42                 used = Collections.frequency(w.getNodes(), wnew.getNode(i)) > 1;
    43             } else {
    44                 //backRefsV.getData().remove(w);
    45                 parents.remove(w);
    46                 used = !parents.isEmpty();
    47             }
    48             if (!used)
    49                 used = wnew.getNode(i).isTagged();
     19//        int toI = wnew.getNodesCount() - 1;
     20//        List<OsmPrimitive> parents = new ArrayList<OsmPrimitive>();
     21//        for (int i = wnew.getNodesCount() - 1; i >= 0; i--) {
     22//            //CollectBackReferencesVisitor backRefsV = new CollectBackReferencesVisitor(dataSet, false);
     23//            //backRefsV.visit(wnew.getNode(i));
     24//           parents.addAll(w.getNode(i).getReferrers());
     25//            boolean used = false;
     26//            if (parents.size() == 1) {
     27//                used = Collections.frequency(w.getNodes(), wnew.getNode(i)) > 1;
     28//            } else {
     29//                //backRefsV.getData().remove(w);
     30//                parents.remove(w);
     31//                used = !parents.isEmpty();
     32//            }
     33//            if (!used)
     34//                used = wnew.getNode(i).isTagged();
     35//
     36//            if (used) {
     37//                simplifyWayRange(wnew, i, toI, threshold);
     38//                toI = i;
     39//            }
     40//        }
     41        simplifyWayRange(wnew, 0, wnew.getNodesCount() - 1, threshold);
     42        w.setNodes(wnew.getNodes());
     43//        HashSet<Node> delNodes = new HashSet<Node>();
     44//        delNodes.addAll(w.getNodes());
     45//        delNodes.removeAll(wnew.getNodes());
    5046
    51             if (used) {
    52                 simplifyWayRange(wnew, i, toI, threshold);
    53                 toI = i;
    54             }
    55         }
    56         simplifyWayRange(wnew, 0, toI, threshold);
    57 
    58         HashSet<Node> delNodes = new HashSet<Node>();
    59         delNodes.addAll(w.getNodes());
    60         delNodes.removeAll(wnew.getNodes());
    61 
    62         if (wnew.getNodesCount() != w.getNodesCount()) {
    63             Collection<Command> cmds = new LinkedList<Command>();
    64             cmds.add(new ChangeCommand(w, wnew));
    65             cmds.add(new DeleteCommand(delNodes));
    66             Main.main.undoRedo.add(new SequenceCommand(trn("Simplify Way (remove {0} node)", "Simplify Way (remove {0} nodes)", delNodes.size(), delNodes.size()), cmds));
    67             Main.map.repaint();
    68         }
     47//        if (wnew.getNodesCount() != w.getNodesCount()) {
     48//            Collection<Command> cmds = new LinkedList<Command>();
     49//            cmds.add(new ChangeCommand(w, wnew));
     50//            cmds.add(new DeleteCommand(delNodes));
     51//            Main.main.undoRedo.add(new SequenceCommand(trn("Simplify Way (remove {0} node)", "Simplify Way (remove {0} nodes)", delNodes.size(), delNodes.size()), cmds));
     52//            Main.map.repaint();
     53//        }
    6954    }
    7055
  • applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/VectorImageModifier.java

    r20247 r20390  
    1818    private int backgroundPixel = 0;
    1919
    20     public VectorImageModifier(BufferedImage bi) {
     20    public VectorImageModifier() {super();}
     21   
     22    public VectorImageModifier(BufferedImage bi, boolean monocolor) {
    2123        bufferedImage = bi;
    2224        if (Main.pref.getBoolean("cadastrewms.backgroundTransparent"))
     
    2628        if (Main.pref.getBoolean("cadastrewms.invertGrey"))
    2729            invertGrey();
    28         //bufferedImage = convert8(convert1(bufferedImage));
     30        if (monocolor)
     31            bufferedImage = convert8(convert4(bufferedImage));
    2932    }
    3033
  • applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/WMSDownloadAction.java

    r19894 r20390  
    44import static org.openstreetmap.josm.tools.I18n.tr;
    55
    6 import java.awt.event.ActionEvent;
     6//import java.awt.event.ActionEvent;
    77import java.util.ArrayList;
    88
     
    1010
    1111import org.openstreetmap.josm.Main;
    12 import org.openstreetmap.josm.actions.JosmAction;
     12//import org.openstreetmap.josm.actions.JosmAction;
    1313import org.openstreetmap.josm.gui.layer.Layer;
    1414
    15 public class WMSDownloadAction extends JosmAction {
     15public class WMSDownloadAction /*extends JosmAction */{
    1616
    1717    private static final long serialVersionUID = 1L;
    1818
    19     public WMSDownloadAction(String layerName) {
    20         super(layerName, "wmsmenu", tr("Download WMS tile from {0}",layerName), null, false);
    21     }
    22 
    23     public void actionPerformed(ActionEvent e) {
    24         DownloadWMSVectorImage.download(getLayer());
    25     }
     19//    public WMSDownloadAction(String layerName) {
     20//        super(layerName, "wmsmenu", tr("Download WMS tile from {0}",layerName), null, false);
     21//    }
     22//
     23//    public void actionPerformed(ActionEvent e) {
     24//        DownloadWMSVectorImage.download(getLayer());
     25//    }
    2626
    2727    public static WMSLayer getLayer() {
     
    3030        if (Main.map != null) {
    3131            Layer activeLayer = Main.map.mapView.getActiveLayer();
    32             if (activeLayer instanceof WMSLayer)
     32            if (activeLayer instanceof WMSLayer && !((WMSLayer)activeLayer).isBuildingsOnly())
    3333                return (WMSLayer) activeLayer;
    3434            for (Layer l : Main.map.mapView.getAllLayers()) {
    35                 if (l instanceof WMSLayer) {
     35                if (l instanceof WMSLayer && !((WMSLayer)l).isBuildingsOnly()) {
    3636                    existingWMSlayers.add((WMSLayer)l);
    3737                }
  • 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.