Ignore:
Timestamp:
2014-10-18T15:31:53+02:00 (10 years ago)
Author:
donvip
Message:

[josm_opendata] fix some sonar issues

Location:
applications/editors/josm/plugins/opendata/modules/fr.paris/src/org/openstreetmap/josm/plugins/opendata/modules/fr/paris
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/opendata/modules/fr.paris/src/org/openstreetmap/josm/plugins/opendata/modules/fr/paris/ParisConstants.java

    r30563 r30731  
    44
    55public interface ParisConstants {
    6                
    7         /**
    8         * Source
    9         */
    10         public static final String SOURCE = "opendataparis";
    11        
    12         /**
    13         * Portal
    14         */
    15         public static final String PORTAL = "http://opendata.paris.fr/opendata/";
     6       
     7    /**
     8    * Source
     9    */
     10    public static final String SOURCE = "opendataparis";
     11   
     12    /**
     13    * Portal
     14    */
     15    public static final String PORTAL = "http://opendata.paris.fr/opendata/";
    1616
    17         /**
    18         * Icons
    19         */
    20         public static final String ICON_PARIS_24 = "data.fr.paris_24.png";
     17    /**
     18    * Icons
     19    */
     20    public static final String ICON_PARIS_24 = "data.fr.paris_24.png";
    2121}
  • applications/editors/josm/plugins/opendata/modules/fr.paris/src/org/openstreetmap/josm/plugins/opendata/modules/fr/paris/ParisLicense.java

    r30340 r30731  
    66public class ParisLicense extends ODbL {
    77
    8         public ParisLicense() {
    9                 // TODO: Paris license
    10                 /*try {
    11                         setURL(PORTAL + "/la-licence", "fr");
    12                 } catch (MalformedURLException e) {
    13                         e.printStackTrace();
    14                 }*/
    15         }
     8    public ParisLicense() {
     9        // TODO: Paris license
     10        /*try {
     11            setURL(PORTAL + "/la-licence", "fr");
     12        } catch (MalformedURLException e) {
     13            e.printStackTrace();
     14        }*/
     15    }
    1616}
  • applications/editors/josm/plugins/opendata/modules/fr.paris/src/org/openstreetmap/josm/plugins/opendata/modules/fr/paris/ParisModule.java

    r30340 r30731  
    1111public class ParisModule extends AbstractModule {
    1212
    13         public ParisModule(ModuleInformation info) {
    14                 super(info);
     13    public ParisModule(ModuleInformation info) {
     14        super(info);
    1515        handlers.add(SanisettesHandler.class);
    1616        handlers.add(ArbresRemarquablesHandler.class);
  • applications/editors/josm/plugins/opendata/modules/fr.paris/src/org/openstreetmap/josm/plugins/opendata/modules/fr/paris/datasets/ParisDataSetHandler.java

    r30340 r30731  
    1111
    1212public abstract class ParisDataSetHandler extends FrenchDataSetHandler implements ParisConstants {
    13        
    14         private int documentId;
    15         private static final int portletId = 106; // FIXME
    16        
    17         public ParisDataSetHandler(int documentId) {
    18                 init(documentId);
    19         }
    20        
    21         public ParisDataSetHandler(int documentId, String relevantTag) {
    22                 super(relevantTag);
    23                 init(documentId);
    24         }
    25        
    26         public ParisDataSetHandler(int documentId, boolean relevantUnion, String ... relevantTags) {
    27                 super(relevantUnion, relevantTags);
    28                 init(documentId);
    29         }
     13   
     14    private int documentId;
     15    private static final int portletId = 106; // FIXME
     16   
     17    public ParisDataSetHandler(int documentId) {
     18        init(documentId);
     19    }
     20   
     21    public ParisDataSetHandler(int documentId, String relevantTag) {
     22        super(relevantTag);
     23        init(documentId);
     24    }
     25   
     26    public ParisDataSetHandler(int documentId, boolean relevantUnion, String ... relevantTags) {
     27        super(relevantUnion, relevantTags);
     28        init(documentId);
     29    }
    3030
    31         public ParisDataSetHandler(int documentId, String ... relevantTags) {
    32                 this(documentId, false, relevantTags);
    33         }
     31    public ParisDataSetHandler(int documentId, String ... relevantTags) {
     32        this(documentId, false, relevantTags);
     33    }
    3434
    35         public ParisDataSetHandler(int documentId, boolean relevantUnion, Tag ... relevantTags) {
    36                 super(relevantUnion, relevantTags);
    37                 init(documentId);
    38         }
     35    public ParisDataSetHandler(int documentId, boolean relevantUnion, Tag ... relevantTags) {
     36        super(relevantUnion, relevantTags);
     37        init(documentId);
     38    }
    3939
    40         private final void init(int documentId) {
    41                 this.documentId = documentId;
    42                 setLicense(new ParisLicense());
    43                 try {
    44                         if (documentId > 0) {
    45                                 setLocalPortalURL(PORTAL + "jsp/site/Portal.jsp?document_id="+documentId + "&portlet_id="+portletId);
    46                         }
    47                 } catch (MalformedURLException e) {
    48                         e.printStackTrace();
    49                 }
    50         }
     40    private final void init(int documentId) {
     41        this.documentId = documentId;
     42        setLicense(new ParisLicense());
     43        try {
     44            if (documentId > 0) {
     45                setLocalPortalURL(PORTAL + "jsp/site/Portal.jsp?document_id="+documentId + "&portlet_id="+portletId);
     46            }
     47        } catch (MalformedURLException e) {
     48            e.printStackTrace();
     49        }
     50    }
    5151
    52         @Override
    53         public String getSource() {
    54                 return SOURCE;
    55         }
     52    @Override
     53    public String getSource() {
     54        return SOURCE;
     55    }
    5656
    57         @Override
    58         public String getLocalPortalIconName() {
    59                 return ICON_PARIS_24;
    60         }
    61        
    62         protected abstract String getDirectLink();
     57    @Override
     58    public String getLocalPortalIconName() {
     59        return ICON_PARIS_24;
     60    }
     61   
     62    protected abstract String getDirectLink();
    6363
    64         @Override
    65         public URL getDataURL() {
    66                 try {
    67                         if (documentId > 0) {
    68                                 return new URL(PORTAL + "rating/download/?id_resource="+documentId + "&type_resource=document&url="+getDirectLink());
    69                         }
    70                 } catch (MalformedURLException e) {
    71                         e.printStackTrace();
    72                 }
    73                 return null;
    74         }
     64    @Override
     65    public URL getDataURL() {
     66        try {
     67            if (documentId > 0) {
     68                return new URL(PORTAL + "rating/download/?id_resource="+documentId + "&type_resource=document&url="+getDirectLink());
     69            }
     70        } catch (MalformedURLException e) {
     71            e.printStackTrace();
     72        }
     73        return null;
     74    }
    7575}
  • applications/editors/josm/plugins/opendata/modules/fr.paris/src/org/openstreetmap/josm/plugins/opendata/modules/fr/paris/datasets/ParisShpHandler.java

    r30563 r30731  
    1818
    1919public class ParisShpHandler extends FrenchShpHandler {
    20        
    21         public final Map<String, Node> nodeMap = new HashMap<>();
    22        
    23         protected OsmPrimitive dataPrimitive;
    24         protected Way closedWay;
    25         protected List<Way> ways;
    26         public List<Node> nodes;
    27        
    28         public ParisShpHandler() {
    29                 setDbfCharset(Charset.forName(OdConstants.CP850));
    30         }
    31        
    32         private Node getNode(EastNorth en, String key) {
    33                 Node n = nodeMap.get(key);
    34                 /*if (n == null) {
    35                         for (Node node : nodes.values()) {
    36                                 if (node.getEastNorth().equalsEpsilon(en, 0.0000001)) {
    37                                         return node;
    38                                 }
    39                         }
    40                 }*/
    41                 return n;
    42         }
    43        
    44         protected Node createOrGetNode(DataSet ds, EastNorth en) {
    45                 String key = en.getX()+"/"+en.getY();
    46                 Node n = getNode(en, key);
    47                 if (n == null) {
    48                         n = new Node(en);
    49                         nodeMap.put(key, n);
    50                         ds.addPrimitive(n);
    51                 }
    52                 return n;
    53         }
     20   
     21    public final Map<String, Node> nodeMap = new HashMap<>();
     22   
     23    protected OsmPrimitive dataPrimitive;
     24    protected Way closedWay;
     25    protected List<Way> ways;
     26    public List<Node> nodes;
     27   
     28    public ParisShpHandler() {
     29        setDbfCharset(Charset.forName(OdConstants.CP850));
     30    }
     31   
     32    private Node getNode(EastNorth en, String key) {
     33        Node n = nodeMap.get(key);
     34        /*if (n == null) {
     35            for (Node node : nodes.values()) {
     36                if (node.getEastNorth().equalsEpsilon(en, 0.0000001)) {
     37                    return node;
     38                }
     39            }
     40        }*/
     41        return n;
     42    }
     43   
     44    protected Node createOrGetNode(DataSet ds, EastNorth en) {
     45        String key = en.getX()+"/"+en.getY();
     46        Node n = getNode(en, key);
     47        if (n == null) {
     48            n = new Node(en);
     49            nodeMap.put(key, n);
     50            ds.addPrimitive(n);
     51        }
     52        return n;
     53    }
    5454
    55         protected final void initFeaturesPrimitives(Set<OsmPrimitive> featurePrimitives) {
    56                 dataPrimitive = null;
    57                 closedWay = null;
    58                 ways = new ArrayList<>();
    59                 nodes = new ArrayList<>();
    60                 for (OsmPrimitive p : featurePrimitives) {
    61                         if (p.hasKeys()) {
    62                                 dataPrimitive = p;
    63                         }
    64                         if (p instanceof Way) {
    65                                 Way w = (Way) p;
    66                                 ways.add(w);
    67                                 if (w.isClosed()) {
    68                                         closedWay = w;
    69                                 }
    70                         } else if (p instanceof Node) {
    71                                 nodes.add((Node) p);
    72                         }
    73                 }
    74         }
    75        
    76         protected final void removePrimitives(DataSet result) {
    77                 for (Way w : ways) {
    78                         w.setNodes(null);
    79                         result.removePrimitive(w);
    80                 }
    81                 for (Node n : nodes) {
    82                         result.removePrimitive(n);
    83                 }
    84         }
     55    protected final void initFeaturesPrimitives(Set<OsmPrimitive> featurePrimitives) {
     56        dataPrimitive = null;
     57        closedWay = null;
     58        ways = new ArrayList<>();
     59        nodes = new ArrayList<>();
     60        for (OsmPrimitive p : featurePrimitives) {
     61            if (p.hasKeys()) {
     62                dataPrimitive = p;
     63            }
     64            if (p instanceof Way) {
     65                Way w = (Way) p;
     66                ways.add(w);
     67                if (w.isClosed()) {
     68                    closedWay = w;
     69                }
     70            } else if (p instanceof Node) {
     71                nodes.add((Node) p);
     72            }
     73        }
     74    }
     75   
     76    protected final void removePrimitives(DataSet result) {
     77        for (Way w : ways) {
     78            w.setNodes(null);
     79            result.removePrimitive(w);
     80        }
     81        for (Node n : nodes) {
     82            result.removePrimitive(n);
     83        }
     84    }
    8585}
  • applications/editors/josm/plugins/opendata/modules/fr.paris/src/org/openstreetmap/josm/plugins/opendata/modules/fr/paris/datasets/deplacements/ElectriciteHandler.java

    r30340 r30731  
    77public class ElectriciteHandler extends ParisDataSetHandler {
    88
    9         public ElectriciteHandler() {
    10                 super(95);
    11                 setName("Électricité");
    12         }
     9    public ElectriciteHandler() {
     10        super(95);
     11        setName("Électricité");
     12    }
    1313
    14         @Override
    15         public boolean acceptsFilename(String filename) {
    16                 return acceptsShpFilename(filename, "electricite") || acceptsZipFilename(filename, "electricite");
    17         }
    18        
    19         @Override
    20         public void updateDataSet(DataSet ds) {
    21                 // TODO
    22         }
     14    @Override
     15    public boolean acceptsFilename(String filename) {
     16        return acceptsShpFilename(filename, "electricite") || acceptsZipFilename(filename, "electricite");
     17    }
     18   
     19    @Override
     20    public void updateDataSet(DataSet ds) {
     21        // TODO
     22    }
    2323
    24         @Override
    25         protected String getDirectLink() {
    26                 return PORTAL+"hn/electricite.zip";
    27         }
     24    @Override
     25    protected String getDirectLink() {
     26        return PORTAL+"hn/electricite.zip";
     27    }
    2828}
  • applications/editors/josm/plugins/opendata/modules/fr.paris/src/org/openstreetmap/josm/plugins/opendata/modules/fr/paris/datasets/environnement/ArbresRemarquablesHandler.java

    r30340 r30731  
    88public class ArbresRemarquablesHandler extends ParisDataSetHandler {
    99
    10         public ArbresRemarquablesHandler() {
    11                 super(107);
    12                 setName("Arbres remarquables");
    13         }
     10    public ArbresRemarquablesHandler() {
     11        super(107);
     12        setName("Arbres remarquables");
     13    }
    1414
    15         @Override
    16         public boolean acceptsFilename(String filename) {
    17                 return acceptsShpFilename(filename, "arbres_remarquables") || acceptsZipFilename(filename, "arbres_remarquables_20..");
    18         }
    19        
    20         @Override
    21         public void updateDataSet(DataSet ds) {
    22                 for (Node n : ds.getNodes()) {
    23                         n.put("natural", "tree");
    24                         replace(n, "ANNEE__PLA", "start_date");
    25                 }
    26         }
     15    @Override
     16    public boolean acceptsFilename(String filename) {
     17        return acceptsShpFilename(filename, "arbres_remarquables") || acceptsZipFilename(filename, "arbres_remarquables_20..");
     18    }
     19   
     20    @Override
     21    public void updateDataSet(DataSet ds) {
     22        for (Node n : ds.getNodes()) {
     23            n.put("natural", "tree");
     24            replace(n, "ANNEE__PLA", "start_date");
     25        }
     26    }
    2727
    28         @Override
    29         protected String getDirectLink() {
    30                 return PORTAL+"hn/arbres_remarquables_2011.zip";
    31         }
     28    @Override
     29    protected String getDirectLink() {
     30        return PORTAL+"hn/arbres_remarquables_2011.zip";
     31    }
    3232}
  • applications/editors/josm/plugins/opendata/modules/fr.paris/src/org/openstreetmap/josm/plugins/opendata/modules/fr/paris/datasets/environnement/MobilierVoiePubliqueHandler.java

    r30340 r30731  
    1414public class MobilierVoiePubliqueHandler extends ParisDataSetHandler {
    1515
    16         private final InternalShpHandler shpHandler = new InternalShpHandler();
    17        
    18         public MobilierVoiePubliqueHandler() {
    19                 super(96);
    20                 setName("Mobiliers sur voie publique");
    21                 setShpHandler(shpHandler);
    22         }
     16    private final InternalShpHandler shpHandler = new InternalShpHandler();
     17   
     18    public MobilierVoiePubliqueHandler() {
     19        super(96);
     20        setName("Mobiliers sur voie publique");
     21        setShpHandler(shpHandler);
     22    }
    2323
    24         @Override
    25         public boolean acceptsFilename(String filename) {
    26                 return acceptsShpFilename(filename, "environnement") || acceptsZipFilename(filename, "environnement");
    27         }
     24    @Override
     25    public boolean acceptsFilename(String filename) {
     26        return acceptsShpFilename(filename, "environnement") || acceptsZipFilename(filename, "environnement");
     27    }
    2828
    29         @Override
    30         protected String getDirectLink() {
    31                 return PORTAL+"hn/environnement.zip";
    32         }
    33        
    34         private final class InternalShpHandler extends ParisShpHandler {
    35                 @Override
    36                 public void notifyFeatureParsed(Object feature, DataSet result, Set<OsmPrimitive> featurePrimitives) {
    37                         initFeaturesPrimitives(featurePrimitives);
    38                         String type = dataPrimitive.get("Libelle");
    39                         if (type.startsWith("Banc ")) {
    40                                 if (closedWay == null && dataPrimitive instanceof Way && ((Way)dataPrimitive).getNodesCount() > 3) {
    41                                         // Some benches can be converted to closed ways by removing some extra nodes at the beginning
    42                                         Way copy = new Way((Way) dataPrimitive);
    43                                         while (copy.getNodesCount() > 3 && !copy.isClosed()) {
    44                                                 copy.removeNode(copy.getNode(0));
    45                                         }
    46                                         if (copy.isClosed()) {
    47                                                 closedWay = copy;
    48                                         } else {
    49                                                 // Try in the opposite direction (remove nodes from the end)
    50                                                 copy = new Way((Way) dataPrimitive);
    51                                                 while (copy.getNodesCount() > 3 && !copy.isClosed()) {
    52                                                         copy.removeNode(copy.getNode(copy.getNodesCount()-1));
    53                                                 }
    54                                                 if (copy.isClosed()) {
    55                                                         closedWay = copy;
    56                                                 }
    57                                         }
    58                                 }
    59                                 if (closedWay != null) {
    60                                         Node bench = createOrGetNode(result, Geometry.getCentroid(closedWay.getNodes()));
    61                                         bench.put("amenity", "bench");
    62                                         bench.put("description", type);
    63                                         removePrimitives(result);
    64                                 } else {
    65                                         System.err.println("Bench without closed area: "+type);
    66                                 }
    67                         } else if (type.startsWith("Poubelle") || type.startsWith("Borne de propreté")) {
    68                                 if (closedWay != null) {
    69                                         Node basket = createOrGetNode(result, Geometry.getCentroid(closedWay.getNodes()));
    70                                         basket.put("amenity", "waste_basket");
    71                                         basket.put("description", type);
    72                                         removePrimitives(result);
    73                                 } else {
    74                                         System.err.println("Waste basket without closed area: "+type);
    75                                 }
    76                         } else if (type.startsWith("Bac à sable")) {
    77                                 if (closedWay == null && dataPrimitive instanceof Way && ((Way)dataPrimitive).getNodesCount() == 2) {
    78                                         // Sandpits are badly built, fix them
    79                                         closedWay = (Way) dataPrimitive;
    80                                         for (Way w : ways) {
    81                                                 if (w.getNodesCount() == 4) {
    82                                                         Node n1 = w.getNode(1);
    83                                                         Node n2 = w.getNode(2);
    84                                                         if (closedWay.getNode(1).getCoor().distance(n1.getCoor()) < closedWay.getNode(1).getCoor().distance(n2.getCoor())) {
    85                                                                 closedWay.addNode(n1);
    86                                                                 closedWay.addNode(n2);
    87                                                         } else {
    88                                                                 closedWay.addNode(n2);
    89                                                                 closedWay.addNode(n1);
    90                                                         }
    91                                                         closedWay.addNode(closedWay.getNode(0));
    92                                                         break;
    93                                                 }
    94                                         }
    95                                 }
    96                                 if (closedWay != null) {
    97                                         // FIXME: lines commented as "sandpits" in this data set seem to be false data
    98                                         /*Node pg = createOrGetNode(result, Geometry.getCentroid(closedWay.getNodes()));
    99                                         pg.put("leisure", "playground");
    100                                         pg.put("playground", "sandpit");
    101                                         pg.put("description", type);*/
    102                                         removePrimitives(result);
    103                                 } else {
    104                                         System.err.println("Sandpit without closed area: "+type);
    105                                 }
    106                         } else if (type.startsWith("Corbeille florale")) {
    107                                 if (closedWay != null) {
    108                                         Node n = createOrGetNode(result, Geometry.getCentroid(closedWay.getNodes()));
    109                                         n.put("man_made", "floral_basket");
    110                                         n.put("description", type);
    111                                         removePrimitives(result);
    112                                 } else {
    113                                         System.err.println("Floral basket without closed area: "+type);
    114                                 }
    115                         } else if (type.startsWith("Objet sans identification particulière")) {
    116                                 //dataPrimitive.put("FIXME", "unknown object. DO NOT upload as it !");
    117                                 removePrimitives(result);
    118                         } else {
    119                                 System.err.println("Unsupported object type: "+type);
    120                         }
    121                 }
    122         }
    123        
    124         @Override
    125         public void updateDataSet(DataSet ds) {
    126                 // Done in notifyFeatureParsed() for drastic performance reasons
    127                 shpHandler.nodes.clear();
    128         }
     29    @Override
     30    protected String getDirectLink() {
     31        return PORTAL+"hn/environnement.zip";
     32    }
     33   
     34    private final class InternalShpHandler extends ParisShpHandler {
     35        @Override
     36        public void notifyFeatureParsed(Object feature, DataSet result,    Set<OsmPrimitive> featurePrimitives) {
     37            initFeaturesPrimitives(featurePrimitives);
     38            String type = dataPrimitive.get("Libelle");
     39            if (type.startsWith("Banc ")) {
     40                if (closedWay == null && dataPrimitive instanceof Way && ((Way)dataPrimitive).getNodesCount() > 3) {
     41                    // Some benches can be converted to closed ways by removing some extra nodes at the beginning
     42                    Way copy = new Way((Way) dataPrimitive);
     43                    while (copy.getNodesCount() > 3 && !copy.isClosed()) {
     44                        copy.removeNode(copy.getNode(0));
     45                    }
     46                    if (copy.isClosed()) {
     47                        closedWay = copy;
     48                    } else {
     49                        // Try in the opposite direction (remove nodes from the end)
     50                        copy = new Way((Way) dataPrimitive);
     51                        while (copy.getNodesCount() > 3 && !copy.isClosed()) {
     52                            copy.removeNode(copy.getNode(copy.getNodesCount()-1));
     53                        }
     54                        if (copy.isClosed()) {
     55                            closedWay = copy;
     56                        }
     57                    }
     58                }
     59                if (closedWay != null) {
     60                    Node bench = createOrGetNode(result, Geometry.getCentroid(closedWay.getNodes()));
     61                    bench.put("amenity", "bench");
     62                    bench.put("description", type);
     63                    removePrimitives(result);
     64                } else {
     65                    System.err.println("Bench without closed area: "+type);
     66                }
     67            } else if (type.startsWith("Poubelle") || type.startsWith("Borne de propreté")) {
     68                if (closedWay != null) {
     69                    Node basket = createOrGetNode(result, Geometry.getCentroid(closedWay.getNodes()));
     70                    basket.put("amenity", "waste_basket");
     71                    basket.put("description", type);
     72                    removePrimitives(result);
     73                } else {
     74                    System.err.println("Waste basket without closed area: "+type);
     75                }
     76            } else if (type.startsWith("Bac à sable")) {
     77                if (closedWay == null && dataPrimitive instanceof Way && ((Way)dataPrimitive).getNodesCount() == 2) {
     78                    // Sandpits are badly built, fix them
     79                    closedWay = (Way) dataPrimitive;
     80                    for (Way w : ways) {
     81                        if (w.getNodesCount() == 4) {
     82                            Node n1 = w.getNode(1);
     83                            Node n2 = w.getNode(2);
     84                            if (closedWay.getNode(1).getCoor().distance(n1.getCoor()) < closedWay.getNode(1).getCoor().distance(n2.getCoor())) {
     85                                closedWay.addNode(n1);
     86                                closedWay.addNode(n2);
     87                            } else {
     88                                closedWay.addNode(n2);
     89                                closedWay.addNode(n1);
     90                            }
     91                            closedWay.addNode(closedWay.getNode(0));
     92                            break;
     93                        }
     94                    }
     95                }
     96                if (closedWay != null) {
     97                    // FIXME: lines commented as "sandpits" in this data set seem to be false data
     98                    /*Node pg = createOrGetNode(result, Geometry.getCentroid(closedWay.getNodes()));
     99                    pg.put("leisure", "playground");
     100                    pg.put("playground", "sandpit");
     101                    pg.put("description", type);*/
     102                    removePrimitives(result);
     103                } else {
     104                    System.err.println("Sandpit without closed area: "+type);
     105                }
     106            } else if (type.startsWith("Corbeille florale")) {
     107                if (closedWay != null) {
     108                    Node n = createOrGetNode(result, Geometry.getCentroid(closedWay.getNodes()));
     109                    n.put("man_made", "floral_basket");
     110                    n.put("description", type);
     111                    removePrimitives(result);
     112                } else {
     113                    System.err.println("Floral basket without closed area: "+type);
     114                }
     115            } else if (type.startsWith("Objet sans identification particulière")) {
     116                //dataPrimitive.put("FIXME", "unknown object. DO NOT upload as it !");
     117                removePrimitives(result);
     118            } else {
     119                System.err.println("Unsupported object type: "+type);
     120            }
     121        }
     122    }
     123   
     124    @Override
     125    public void updateDataSet(DataSet ds) {
     126        // Done in notifyFeatureParsed() for drastic performance reasons
     127        shpHandler.nodes.clear();
     128    }
    129129}
  • applications/editors/josm/plugins/opendata/modules/fr.paris/src/org/openstreetmap/josm/plugins/opendata/modules/fr/paris/datasets/urbanisme/EclairagePublicHandler.java

    r30340 r30731  
    1313public class EclairagePublicHandler extends ParisDataSetHandler {
    1414
    15         private final InternalShpHandler shpHandler = new InternalShpHandler();
    16        
    17         public EclairagePublicHandler() {
    18                 super(94);
    19                 setName("Éclairage public");
    20                 setShpHandler(shpHandler);
    21         }
     15    private final InternalShpHandler shpHandler = new InternalShpHandler();
     16   
     17    public EclairagePublicHandler() {
     18        super(94);
     19        setName("Éclairage public");
     20        setShpHandler(shpHandler);
     21    }
    2222
    23         @Override
    24         public boolean acceptsFilename(String filename) {
    25                 return acceptsShpFilename(filename, "eclairage_public") || acceptsZipFilename(filename, "eclairage_public");
    26         }
     23    @Override
     24    public boolean acceptsFilename(String filename) {
     25        return acceptsShpFilename(filename, "eclairage_public") || acceptsZipFilename(filename, "eclairage_public");
     26    }
    2727
    28         @Override
    29         protected String getDirectLink() {
    30                 return PORTAL+"hn/eclairage_public.zip";
    31         }
    32        
    33         private final class InternalShpHandler extends ParisShpHandler {
    34                
    35                 @Override
    36                 public void notifyFeatureParsed(Object feature, DataSet result, Set<OsmPrimitive> featurePrimitives) {
    37                         initFeaturesPrimitives(featurePrimitives);
    38                         if (dataPrimitive == null) {
    39                                 System.err.println("Found no primitive with tags");
    40                         } else if (closedWay == null) {
    41                                 // ;Objet sans identification particulière pour ce niveau et cette thématique;147;eclairage_public.zip;Niveau 18
    42                                 dataPrimitive.put("FIXME", "This way is not closed and has not been recognized as highway=street_lamp.");
    43                         } else {
    44                                 Node centroid = createOrGetNode(result, Geometry.getCentroid(closedWay.getNodes()));
    45                                 if (!centroid.hasKeys()) {
    46                                         centroid.setKeys(dataPrimitive.getKeys());
    47                                         centroid.put("highway", "street_lamp");
    48                                         replace(centroid, "Libelle", "lamp_model:fr");
    49                                 } else if (centroid.get("lamp_model:fr") != null && (dataPrimitive.get("Libelle") == null || !dataPrimitive.get("Libelle").equals(centroid.get("lamp_model:fr")))) {
    50                                         System.err.println("Found 2 street lamps at the same position with different types: '"+centroid.get("lamp_model:fr")+"' and '"+dataPrimitive.get("Libelle")+"'.");
    51                                 }
    52                                 removePrimitives(result);
    53                                
    54                                 if (centroid.get("lamp_model:fr") != null) {
    55                                         if (centroid.get("lamp_model:fr").contains("mural") && !centroid.get("lamp_model:fr").contains("au sol")) {
    56                                                 centroid.put("lamp_mount", "wall mounted");
    57                                         } else if (centroid.get("lamp_model:fr").contains("au sol") && !centroid.get("lamp_model:fr").contains("mural")) {
    58                                                 centroid.put("lamp_mount", "ground");
    59                                         } else {
    60                                                 centroid.put("lamp_mount", "pole");
    61                                         }
    62                                         centroid.remove("Info");
    63                                 }
    64                                
    65                                 /*if (dataPrimitive.get("Info") == null) {
    66                                         System.err.println("Found no primitive with tag 'Info'");
    67                                 } else if (dataPrimitive.get("Info").equals("LEA")) {           //      LEA;Lanterne électrique axiale;2834;eclairage_public.zip;Niveau 18
    68                                 } else if (dataPrimitive.get("Info").equals("LEL")) {           //      LEL;Lampadaire électrique;61337;eclairage_public.zip;Niveau 18
    69                                 } else if (dataPrimitive.get("Info").equals("LEM")) {           //      LEM;Lanterne électrique murale;789;eclairage_public.zip;Niveau 18
    70                                 } else if (dataPrimitive.get("Info").equals("LEMB")) {          //      LEMB;Lanterne électrique murale bord;14727;eclairage_public.zip;Niveau 18
    71                                 } else if (dataPrimitive.get("Info").equals("LEMRND")) {        //      LEMRND;Lanterne électrique murale renvoi à droite;5635;eclairage_public.zip;Niveau 18
    72                                 } else if (dataPrimitive.get("Info").equals("LEMRNG")) {        //      LEMRNG;Lanterne électrique murale renvoi à gauche;3822;eclairage_public.zip;Niveau 18
    73                                 } else if (dataPrimitive.get("Info").equals("LERRND")) {        //      LERRND;Lanterne électrique murale et boite raccord BT renvoi à droite;5657;eclairage_public.zip;Niveau 18
    74                                 } else if (dataPrimitive.get("Info").equals("LERRNG")) {        //      LERRNG;Lanterne électrique murale et boite raccord BT renvoi à gauche;3377;eclairage_public.zip;Niveau 18
    75                                 } else if (dataPrimitive.get("Info").equals("LSO")) {           //      LSO;Lanterne au sol;1337;eclairage_public.zip;Niveau 18
    76                                 } else if (dataPrimitive.get("Info").equals("PHO")) {           //      PHO;Poteau horaire;17;eclairage_public.zip;Niveau 18
    77                                 } else if (dataPrimitive.get("Info").equals("PPEP")) {          //      PPEP;Poteau provisoire d'éclairage public;181;eclairage_public.zip;Niveau 18
    78                                 } else if (dataPrimitive.get("Info").equals("PPR")) {           //      PPR;poteau à projecteur;67;eclairage_public.zip;Niveau 18
    79                                 } else if (dataPrimitive.get("Info").equals("PRJ")) {           //      PRJ;Projecteur au sol ou mural;1864;eclairage_public.zip;Niveau 18
    80                                 } else if (dataPrimitive.get("Info").equals("PRJRND")) {        //      PRJRND;Projecteur au sol ou mural renvoi à droite;42;eclairage_public.zip;Niveau 18
    81                                 } else if (dataPrimitive.get("Info").equals("PRJRNG")) {        //      PRJRNG;Projecteur au sol ou mural renvoi à gauche;57;eclairage_public.zip;Niveau 18
    82                                 } else {
    83                                         System.err.println("Unsupported Info: "+dataPrimitive.get("Info"));
    84                                 }*/
    85                         }
    86                 }
    87         }
    88        
    89         @Override
    90         public void updateDataSet(DataSet ds) {
    91                 // Done in notifyFeatureParsed() for drastic performance reasons
    92                 shpHandler.nodes.clear();
    93         }
     28    @Override
     29    protected String getDirectLink() {
     30        return PORTAL+"hn/eclairage_public.zip";
     31    }
     32   
     33    private final class InternalShpHandler extends ParisShpHandler {
     34       
     35        @Override
     36        public void notifyFeatureParsed(Object feature, DataSet result,    Set<OsmPrimitive> featurePrimitives) {
     37            initFeaturesPrimitives(featurePrimitives);
     38            if (dataPrimitive == null) {
     39                System.err.println("Found no primitive with tags");
     40            } else if (closedWay == null) {
     41                // ;Objet sans identification particulière pour ce niveau et cette thématique;147;eclairage_public.zip;Niveau 18
     42                dataPrimitive.put("FIXME", "This way is not closed and has not been recognized as highway=street_lamp.");
     43            } else {
     44                Node centroid = createOrGetNode(result, Geometry.getCentroid(closedWay.getNodes()));
     45                if (!centroid.hasKeys()) {
     46                    centroid.setKeys(dataPrimitive.getKeys());
     47                    centroid.put("highway", "street_lamp");
     48                    replace(centroid, "Libelle", "lamp_model:fr");
     49                } else if (centroid.get("lamp_model:fr") != null && (dataPrimitive.get("Libelle") == null || !dataPrimitive.get("Libelle").equals(centroid.get("lamp_model:fr")))) {
     50                    System.err.println("Found 2 street lamps at the same position with different types: '"+centroid.get("lamp_model:fr")+"' and '"+dataPrimitive.get("Libelle")+"'.");
     51                }
     52                removePrimitives(result);
     53               
     54                if (centroid.get("lamp_model:fr") != null) {
     55                    if (centroid.get("lamp_model:fr").contains("mural") && !centroid.get("lamp_model:fr").contains("au sol")) {
     56                        centroid.put("lamp_mount", "wall mounted");
     57                    } else if (centroid.get("lamp_model:fr").contains("au sol") && !centroid.get("lamp_model:fr").contains("mural")) {
     58                        centroid.put("lamp_mount", "ground");
     59                    } else {
     60                        centroid.put("lamp_mount", "pole");
     61                    }
     62                    centroid.remove("Info");
     63                }
     64               
     65                /*if (dataPrimitive.get("Info") == null) {
     66                    System.err.println("Found no primitive with tag 'Info'");
     67                } else if (dataPrimitive.get("Info").equals("LEA")) {        //    LEA;Lanterne électrique axiale;2834;eclairage_public.zip;Niveau 18
     68                } else if (dataPrimitive.get("Info").equals("LEL")) {        //    LEL;Lampadaire électrique;61337;eclairage_public.zip;Niveau 18
     69                } else if (dataPrimitive.get("Info").equals("LEM")) {        //    LEM;Lanterne électrique murale;789;eclairage_public.zip;Niveau 18
     70                } else if (dataPrimitive.get("Info").equals("LEMB")) {        //    LEMB;Lanterne électrique murale bord;14727;eclairage_public.zip;Niveau 18
     71                } else if (dataPrimitive.get("Info").equals("LEMRND")) {    //    LEMRND;Lanterne électrique murale renvoi à droite;5635;eclairage_public.zip;Niveau 18
     72                } else if (dataPrimitive.get("Info").equals("LEMRNG")) {    //    LEMRNG;Lanterne électrique murale renvoi à gauche;3822;eclairage_public.zip;Niveau 18
     73                } else if (dataPrimitive.get("Info").equals("LERRND")) {    //    LERRND;Lanterne électrique murale et boite raccord BT renvoi à droite;5657;eclairage_public.zip;Niveau 18
     74                } else if (dataPrimitive.get("Info").equals("LERRNG")) {    //    LERRNG;Lanterne électrique murale et boite raccord BT renvoi à gauche;3377;eclairage_public.zip;Niveau 18
     75                } else if (dataPrimitive.get("Info").equals("LSO")) {        //    LSO;Lanterne au sol;1337;eclairage_public.zip;Niveau 18
     76                } else if (dataPrimitive.get("Info").equals("PHO")) {        //    PHO;Poteau horaire;17;eclairage_public.zip;Niveau 18
     77                } else if (dataPrimitive.get("Info").equals("PPEP")) {        //    PPEP;Poteau provisoire d'éclairage public;181;eclairage_public.zip;Niveau 18
     78                } else if (dataPrimitive.get("Info").equals("PPR")) {        //    PPR;poteau à projecteur;67;eclairage_public.zip;Niveau 18
     79                } else if (dataPrimitive.get("Info").equals("PRJ")) {        //    PRJ;Projecteur au sol ou mural;1864;eclairage_public.zip;Niveau 18
     80                } else if (dataPrimitive.get("Info").equals("PRJRND")) {    //    PRJRND;Projecteur au sol ou mural renvoi à droite;42;eclairage_public.zip;Niveau 18
     81                } else if (dataPrimitive.get("Info").equals("PRJRNG")) {    //    PRJRNG;Projecteur au sol ou mural renvoi à gauche;57;eclairage_public.zip;Niveau 18
     82                } else {
     83                    System.err.println("Unsupported Info: "+dataPrimitive.get("Info"));
     84                }*/
     85            }
     86        }
     87    }
     88   
     89    @Override
     90    public void updateDataSet(DataSet ds) {
     91        // Done in notifyFeatureParsed() for drastic performance reasons
     92        shpHandler.nodes.clear();
     93    }
    9494}
  • applications/editors/josm/plugins/opendata/modules/fr.paris/src/org/openstreetmap/josm/plugins/opendata/modules/fr/paris/datasets/urbanisme/SanisettesHandler.java

    r30701 r30731  
    1515public class SanisettesHandler extends ParisDataSetHandler {
    1616
    17         public SanisettesHandler() {
    18                 super(93);
    19                 setName("Sanisettes");
    20                 getShpHandler().setCheckNodeProximity(true);
    21         }
     17    public SanisettesHandler() {
     18        super(93);
     19        setName("Sanisettes");
     20        getShpHandler().setCheckNodeProximity(true);
     21    }
    2222
    23         @Override
    24         public boolean acceptsFilename(String filename) {
    25                 return acceptsShpFilename(filename, "sanisettes") || acceptsZipFilename(filename, "sanisettes");
    26         }
     23    @Override
     24    public boolean acceptsFilename(String filename) {
     25        return acceptsShpFilename(filename, "sanisettes") || acceptsZipFilename(filename, "sanisettes");
     26    }
    2727
    28         private boolean wayBelongsTo(Way a, List<Way> ways) {
    29                 for (Way b : ways) {
    30                         if (a.getNode(0).equals(b.getNode(0)) || a.getNode(0).equals(b.getNode(b.getNodesCount()-1))
    31                         || a.getNode(a.getNodesCount()-1).equals(b.getNode(0)) || a.getNode(a.getNodesCount()-1).equals(b.getNode(b.getNodesCount()-1))) {
    32                                 return true;
    33                         }
    34                 }
    35                 return false;
    36         }
    37        
    38         private boolean wayProcessed(Way a, List<List<Way>> waysToCombine) {
    39                 for (List<Way> ways : waysToCombine) {
    40                         for (Way b : ways) {
    41                                 if (a.equals(b)) {
    42                                         return true;
    43                                 }
    44                         }
    45                 }
    46                 return false;
    47         }
    48        
    49         @Override
    50         public void updateDataSet(DataSet ds) {
    51                
    52                 List<Way> sourceWays = new ArrayList<>(ds.getWays());
    53                 List<List<Way>> waysToCombine = new ArrayList<>();
    54                
    55                 for (Iterator<Way> it = sourceWays.iterator(); it.hasNext();) {
    56                         Way w = it.next();
    57                         it.remove();
    58                         if (!wayProcessed(w, waysToCombine)) {
    59                                 List<Way> list = new ArrayList<>();
    60                                 list.add(w);
    61                                 boolean finished = false;
    62                                 List<Way> sourceWays2 = new ArrayList<>(sourceWays);
    63                                 while (!finished) {
    64                                         int before = list.size();
    65                                         for (Iterator<Way> it2 = sourceWays2.iterator(); it2.hasNext();) {
    66                                                 Way w2 = it2.next();
    67                                                 if (wayBelongsTo(w2, list)) {
    68                                                         list.add(w2);
    69                                                         it2.remove();
    70                                                 }
    71                                         }
    72                                         int after = list.size();
    73                                         finished = (after == before);
    74                                 }
    75                                 if (list.size() > 1) {
    76                                         waysToCombine.add(list);
    77                                 }
    78                         }
    79                 }
    80                                
    81                 for (List<Way> ways : waysToCombine) {
    82                         try {
    83                                 WayCombiner.combineWays(ways);
    84                         } catch (UserCancelException e) {
    85                                 return;
    86                         }
    87                 }
    88                
    89                 for (Way w : ds.getWays()) {
    90                         if (w.getNodesCount() <= 3) {
    91                                 ds.removePrimitive(w);
    92                                 for (Node n : w.getNodes()) {
    93                                         ds.removePrimitive(n);
    94                                 }
    95                         } else {
    96                                 w.put("amenity", "toilets");
    97                         }
    98                 }
    99         }
     28    private boolean wayBelongsTo(Way a, List<Way> ways) {
     29        for (Way b : ways) {
     30            if (a.getNode(0).equals(b.getNode(0)) || a.getNode(0).equals(b.getNode(b.getNodesCount()-1))
     31            || a.getNode(a.getNodesCount()-1).equals(b.getNode(0)) || a.getNode(a.getNodesCount()-1).equals(b.getNode(b.getNodesCount()-1))) {
     32                return true;
     33            }
     34        }
     35        return false;
     36    }
     37   
     38    private boolean wayProcessed(Way a, List<List<Way>> waysToCombine) {
     39        for (List<Way> ways : waysToCombine) {
     40            for (Way b : ways) {
     41                if (a.equals(b)) {
     42                    return true;
     43                }
     44            }
     45        }
     46        return false;
     47    }
     48   
     49    @Override
     50    public void updateDataSet(DataSet ds) {
     51       
     52        List<Way> sourceWays = new ArrayList<>(ds.getWays());
     53        List<List<Way>> waysToCombine = new ArrayList<>();
     54       
     55        for (Iterator<Way> it = sourceWays.iterator(); it.hasNext();) {
     56            Way w = it.next();
     57            it.remove();
     58            if (!wayProcessed(w, waysToCombine)) {
     59                List<Way> list = new ArrayList<>();
     60                list.add(w);
     61                boolean finished = false;
     62                List<Way> sourceWays2 = new ArrayList<>(sourceWays);
     63                while (!finished) {
     64                    int before = list.size();
     65                    for (Iterator<Way> it2 = sourceWays2.iterator(); it2.hasNext();) {
     66                        Way w2 = it2.next();
     67                        if (wayBelongsTo(w2, list)) {
     68                            list.add(w2);
     69                            it2.remove();
     70                        }
     71                    }
     72                    int after = list.size();
     73                    finished = (after == before);
     74                }
     75                if (list.size() > 1) {
     76                    waysToCombine.add(list);
     77                }
     78            }
     79        }
     80               
     81        for (List<Way> ways : waysToCombine) {
     82            try {
     83                WayCombiner.combineWays(ways);
     84            } catch (UserCancelException e) {
     85                return;
     86            }
     87        }
     88       
     89        for (Way w : ds.getWays()) {
     90            if (w.getNodesCount() <= 3) {
     91                ds.removePrimitive(w);
     92                for (Node n : w.getNodes()) {
     93                    ds.removePrimitive(n);
     94                }
     95            } else {
     96                w.put("amenity", "toilets");
     97            }
     98        }
     99    }
    100100
    101         @Override
    102         protected String getDirectLink() {
    103                 return PORTAL+"hn/sanisettes.zip";
    104         }
     101    @Override
     102    protected String getDirectLink() {
     103        return PORTAL+"hn/sanisettes.zip";
     104    }
    105105}
  • applications/editors/josm/plugins/opendata/modules/fr.paris/src/org/openstreetmap/josm/plugins/opendata/modules/fr/paris/datasets/urbanisme/VolumesBatisHandler.java

    r30340 r30731  
    77public class VolumesBatisHandler extends ParisDataSetHandler {
    88
    9         public VolumesBatisHandler() {
    10                 super(80);
    11                 setName("Volumes bâtis");
    12         }
     9    public VolumesBatisHandler() {
     10        super(80);
     11        setName("Volumes bâtis");
     12    }
    1313
    14         @Override
    15         public boolean acceptsFilename(String filename) {
    16                 return acceptsShpFilename(filename, "VOL_BATI") || acceptsZipFilename(filename, "VOL_BATI");
    17         }
    18        
    19         @Override
    20         public void updateDataSet(DataSet ds) {
    21                 // TODO
    22         }
     14    @Override
     15    public boolean acceptsFilename(String filename) {
     16        return acceptsShpFilename(filename, "VOL_BATI") || acceptsZipFilename(filename, "VOL_BATI");
     17    }
     18   
     19    @Override
     20    public void updateDataSet(DataSet ds) {
     21        // TODO
     22    }
    2323
    24         @Override
    25         protected String getDirectLink() {
    26                 return PORTAL+"hn/VOL_BATI.zip";
    27         }
     24    @Override
     25    protected String getDirectLink() {
     26        return PORTAL+"hn/VOL_BATI.zip";
     27    }
    2828}
  • applications/editors/josm/plugins/opendata/modules/fr.paris/src/org/openstreetmap/josm/plugins/opendata/modules/fr/paris/datasets/urbanisme/VolumesNonBatisHandler.java

    r30340 r30731  
    77public class VolumesNonBatisHandler extends ParisDataSetHandler {
    88
    9         public VolumesNonBatisHandler() {
    10                 super(106);
    11                 setName("Volumes non bâtis");
    12         }
     9    public VolumesNonBatisHandler() {
     10        super(106);
     11        setName("Volumes non bâtis");
     12    }
    1313
    14         @Override
    15         public boolean acceptsFilename(String filename) {
    16                 return acceptsShpFilename(filename, "VOL_NBATI") || acceptsZipFilename(filename, "VOL_NBATI");
    17         }
    18        
    19         @Override
    20         public void updateDataSet(DataSet ds) {
    21                 // TODO
    22         }
     14    @Override
     15    public boolean acceptsFilename(String filename) {
     16        return acceptsShpFilename(filename, "VOL_NBATI") || acceptsZipFilename(filename, "VOL_NBATI");
     17    }
     18   
     19    @Override
     20    public void updateDataSet(DataSet ds) {
     21        // TODO
     22    }
    2323
    24         @Override
    25         protected String getDirectLink() {
    26                 return PORTAL+"hn/VOL_NBATI.zip";
    27         }
     24    @Override
     25    protected String getDirectLink() {
     26        return PORTAL+"hn/VOL_NBATI.zip";
     27    }
    2828}
Note: See TracChangeset for help on using the changeset viewer.