Changeset 13784 in osm for applications/editors/josm/plugins/cadastre-fr
- Timestamp:
- 2009-02-18T23:31:32+01:00 (16 years ago)
- Location:
- applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CadastreGrabber.java
r13497 r13784 69 69 str += lambertMax.east() + ","; 70 70 str += lambertMax.north(); 71 str += "&width=800&height=600"; // maximum allowed by wms server 71 //str += "&width=800&height=600"; // maximum allowed by wms server 72 str += "&width=1000&height=800"; // maximum allowed by wms server 72 73 str += "&styles=LS3_90,LS2_90,LS1_90,PARCELLE_90,NUMERO_90,PT3_90,PT2_90,PT1_90,LIEUDIT_90"; 73 74 str += ",SUBSECTION_90"; -
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CadastrePlugin.java
r13727 r13784 66 66 * 0.9 05-Feb-2009 - grab vectorized full commune bbox, save in file, convert to OSM way 67 67 * and simplify 68 * 1.0 05-Feb-2009 - fix various bugs 68 * 1.0 18-Feb-2009 - fix various bugs in color management and preference dialog 69 * - increase PNG picture size requested to WMS (800x1000) 70 * - set 4th grab scale fixed size configurable (from 25 to 1000 meters) 69 71 */ 70 72 public class CadastrePlugin extends Plugin { … … 87 89 public static boolean alterColors = false; 88 90 89 public static String colorBackground;90 91 91 public static boolean backgroundTransparent = false; 92 92 … … 103 103 */ 104 104 public CadastrePlugin() throws Exception { 105 System.out.println("Pluging \"french cadastre\" started..."); 106 if (Main.proj.toString().equals(new Lambert().toString()) != true) { 107 JOptionPane.showMessageDialog(Main.parent, 108 tr("To enable the cadastre WMS plugin, change\nthe JOSM projection to Lambert and restart")); 109 return; 110 } 105 System.out.println("Pluging \"cadastre-fr\" started..."); 111 106 if (Main.pref.get("cadastrewms.cacheDir").equals("")) 112 107 cacheDir = Main.pref.getPreferencesDir()+"plugins/cadastrewms/"; … … 127 122 128 123 public void refreshMenu() throws Exception { 124 boolean isLambertProjection = Main.proj.toString().equals(new Lambert().toString()); 129 125 JMenuBar menu = Main.main.menu; 130 126 … … 133 129 cadastreJMenu.setMnemonic(KeyEvent.VK_C); 134 130 menu.add(cadastreJMenu, menu.getMenuCount()-2); 135 136 JosmAction grab = new MenuActionGrab(); 137 JMenuItem menuGrab = new JMenuItem(grab); 138 KeyStroke ks = grab.getShortcut().getKeyStroke(); 139 if (ks != null) { 140 menuGrab.setAccelerator(ks); 131 if (isLambertProjection) { 132 JosmAction grab = new MenuActionGrab(); 133 JMenuItem menuGrab = new JMenuItem(grab); 134 KeyStroke ks = grab.getShortcut().getKeyStroke(); 135 if (ks != null) { 136 menuGrab.setAccelerator(ks); 137 } 138 JMenuItem menuSettings = new JMenuItem(new MenuActionNewLocation()); 139 final JCheckBoxMenuItem menuSource = new JCheckBoxMenuItem(tr("Auto sourcing")); 140 menuSource.setSelected(autoSourcing); 141 menuSource.addActionListener(new ActionListener() { 142 public void actionPerformed(ActionEvent ev) { 143 Main.pref.put("cadastrewms.autosourcing", menuSource.isSelected()); 144 autoSourcing = menuSource.isSelected(); 145 } 146 }); 147 148 JMenuItem menuResetCookie = new JMenuItem(new MenuActionResetCookie()); 149 JMenuItem menuLambertZone = new JMenuItem(new MenuActionLambertZone()); 150 JMenuItem menuLoadFromCache = new JMenuItem(new MenuActionLoadFromCache()); 151 //JMenuItem menuActionBoundaries = new JMenuItem(new MenuActionBoundaries()); 152 //JMenuItem menuActionBuildings = new JMenuItem(new MenuActionBuildings()); 153 154 cadastreJMenu.add(menuGrab); 155 cadastreJMenu.add(menuSettings); 156 cadastreJMenu.add(menuSource); 157 cadastreJMenu.add(menuResetCookie); 158 cadastreJMenu.add(menuLambertZone); 159 cadastreJMenu.add(menuLoadFromCache); 160 // all SVG features disabled until official WMS is released 161 //cadastreJMenu.add(menuActionBoundaries); 162 //cadastreJMenu.add(menuActionBuildings); 163 } else { 164 JMenuItem hint = new JMenuItem(tr("Invalid projection")); 165 hint.setToolTipText(tr("Change the projection to {0} first.", new Lambert().toString())); 166 hint.addActionListener(new ActionListener() { 167 public void actionPerformed(ActionEvent ev) { 168 JOptionPane.showMessageDialog(Main.parent, 169 tr("To enable the cadastre WMS plugin, change\nthe JOSM projection to Lambert and restart")); 170 } 171 }); 172 cadastreJMenu.add(hint); 141 173 } 142 JMenuItem menuSettings = new JMenuItem(new MenuActionNewLocation());143 final JCheckBoxMenuItem menuSource = new JCheckBoxMenuItem(tr("Auto sourcing"));144 menuSource.setSelected(autoSourcing);145 menuSource.addActionListener(new ActionListener() {146 public void actionPerformed(ActionEvent ev) {147 Main.pref.put("cadastrewms.autosourcing", menuSource.isSelected());148 autoSourcing = menuSource.isSelected();149 }150 });151 152 JMenuItem menuResetCookie = new JMenuItem(new MenuActionResetCookie());153 JMenuItem menuLambertZone = new JMenuItem(new MenuActionLambertZone());154 JMenuItem menuLoadFromCache = new JMenuItem(new MenuActionLoadFromCache());155 JMenuItem menuActionBoundaries = new JMenuItem(new MenuActionBoundaries());156 JMenuItem menuActionBuildings = new JMenuItem(new MenuActionBuildings());157 158 cadastreJMenu.add(menuGrab);159 cadastreJMenu.add(menuSettings);160 cadastreJMenu.add(menuSource);161 cadastreJMenu.add(menuResetCookie);162 cadastreJMenu.add(menuLambertZone);163 cadastreJMenu.add(menuLoadFromCache);164 cadastreJMenu.add(menuActionBoundaries);165 //cadastreJMenu.add(menuActionBuildings);166 174 } 167 175 setEnabledAll(menuEnabled); … … 174 182 alterColors = Main.pref.getBoolean("cadastrewms.alterColors"); 175 183 drawBoundaries = Main.pref.getBoolean("cadastrewms.drawBoundaries", false); 176 colorBackground = Main.pref.get("color.background", "#FFFFFF");177 184 if (alterColors) { 178 185 backgroundTransparent = Main.pref.getBoolean("cadastrewms.backgroundTransparent"); … … 193 200 JMenuItem item = cadastreJMenu.getItem(i); 194 201 if (item != null) 195 if (item.getText().equals(MenuActionGrab.name) ||202 if (item.getText().equals(MenuActionGrab.name) /* || 196 203 item.getText().equals(MenuActionBoundaries.name) || 197 item.getText().equals(MenuActionBuildings.name) ) {204 item.getText().equals(MenuActionBuildings.name)*/) { 198 205 item.setEnabled(isEnabled); 199 206 } else if (item.getText().equals(MenuActionLambertZone.name)) { -
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CadastrePreferenceSetting.java
r13497 r13784 3 3 import static org.openstreetmap.josm.tools.I18n.tr; 4 4 5 import java.awt.Dimension;6 5 import java.awt.event.ActionEvent; 7 6 import java.awt.event.ActionListener; … … 42 41 43 42 private JRadioButton grabMultiplier4 = new JRadioButton("", true); 44 43 44 static final int DEFAULT_SQUARE_SIZE = 100; 45 private JTextField grabMultiplier4Size = new JTextField(5); 46 45 47 private JCheckBox enableCache = new JCheckBox(tr("Enable automatic caching.")); 46 48 … … 66 68 67 69 // option to alter the original colors of the wms images 68 alterColors.addActionListener(new ActionListener() {69 public void actionPerformed(ActionEvent e) {70 reversGrey.setEnabled(alterColors.isSelected());71 transparency.setEnabled(alterColors.isSelected());72 sliderTrans.setEnabled(transparency.isSelected() && alterColors.isSelected());73 }74 });75 70 alterColors.setSelected(Main.pref.getBoolean("cadastrewms.alterColors", false)); 76 71 alterColors.setToolTipText(tr("Replace the original white background by the backgound color defined in JOSM preferences.")); … … 79 74 // option to reverse the grey colors (to see texts background) 80 75 reversGrey.setSelected(Main.pref.getBoolean("cadastrewms.invertGrey", false)); 81 reversGrey.setToolTipText(tr("Invert the original texts from black to white (and all intermediate greys)."));76 reversGrey.setToolTipText(tr("Invert the original black and white colors (and all intermediate greys). Useful for texts on dark backgrounds.")); 82 77 reversGrey.setEnabled(alterColors.isSelected()); 83 cadastrewms.add(reversGrey, GBC.eop().insets( 20, 0, 0, 0));78 cadastrewms.add(reversGrey, GBC.eop().insets(00, 0, 0, 0)); 84 79 85 80 // option to enable transparency … … 91 86 transparency.setSelected(Main.pref.getBoolean("cadastrewms.backgroundTransparent", false)); 92 87 transparency.setToolTipText(tr("Allows multiple layers stacking")); 93 transparency.setEnabled(alterColors.isSelected()); 94 cadastrewms.add(transparency, GBC.eop().insets(20, 0, 0, 0)); 88 cadastrewms.add(transparency, GBC.eop().insets(0, 0, 0, 0)); 95 89 96 90 // slider for transparency level 97 sliderTrans.setPreferredSize(new Dimension(20,200));98 91 sliderTrans.setSnapToTicks(true); 99 92 sliderTrans.setToolTipText(tr("Set WMS layers transparency. Right is opaque, left is transparent.")); … … 114 107 cadastrewms.add(jLabelScale, GBC.std().insets(0, 5, 10, 0)); 115 108 ButtonGroup bg = new ButtonGroup(); 109 ActionListener multiplierActionListener = new ActionListener() { 110 public void actionPerformed(ActionEvent actionEvent) { 111 AbstractButton button = (AbstractButton) actionEvent.getSource(); 112 grabMultiplier4Size.setEnabled(button == grabMultiplier4); 113 } 114 }; 116 115 grabMultiplier1.setIcon(ImageProvider.get("preferences", "unsel_box_1")); 117 116 grabMultiplier1.setSelectedIcon(ImageProvider.get("preferences", "sel_box_1")); 117 grabMultiplier1.addActionListener( multiplierActionListener); 118 118 grabMultiplier2.setIcon(ImageProvider.get("preferences", "unsel_box_2")); 119 119 grabMultiplier2.setSelectedIcon(ImageProvider.get("preferences", "sel_box_2")); 120 grabMultiplier2.addActionListener( multiplierActionListener); 121 grabMultiplier2.setToolTipText(tr("Grab smaller images (higher quality but use more memory)")); 120 122 grabMultiplier3.setIcon(ImageProvider.get("preferences", "unsel_box_3")); 121 123 grabMultiplier3.setSelectedIcon(ImageProvider.get("preferences", "sel_box_3")); 124 grabMultiplier3.addActionListener( multiplierActionListener); 125 grabMultiplier3.setToolTipText(tr("Grab smaller images (higher quality but use more memory)")); 122 126 grabMultiplier4.setIcon(ImageProvider.get("preferences", "unsel_box_4")); 123 127 grabMultiplier4.setSelectedIcon(ImageProvider.get("preferences", "sel_box_4")); 124 String multiplierTooltip = "Grab smaller images (higher quality but use more memory)";125 grabMultiplier 3.setToolTipText(multiplierTooltip);128 grabMultiplier4.addActionListener( multiplierActionListener); 129 grabMultiplier4.setToolTipText(tr("Fixed size square (default is 100m)")); 126 130 bg.add(grabMultiplier1); 127 131 bg.add(grabMultiplier2); 128 132 bg.add(grabMultiplier3); 129 133 bg.add(grabMultiplier4); 130 if (Main.pref.get("cadastrewms.scale", "1").equals(Scale.X1)) 134 String currentScale = Main.pref.get("cadastrewms.scale", "1"); 135 if (currentScale.equals(Scale.X1.value)) 131 136 grabMultiplier1.setSelected(true); 132 if ( Main.pref.get("cadastrewms.scale", "1").equals(Scale.X2))137 if (currentScale.equals(Scale.X2.value)) 133 138 grabMultiplier2.setSelected(true); 134 if ( Main.pref.get("cadastrewms.scale", "1").equals(Scale.X3))139 if (currentScale.equals(Scale.X3.value)) 135 140 grabMultiplier3.setSelected(true); 136 if ( Main.pref.get("cadastrewms.scale", "1").equals(Scale.SQUARE_100M))141 if (currentScale.equals(Scale.SQUARE_100M.value)) 137 142 grabMultiplier4.setSelected(true); 138 143 cadastrewms.add(grabMultiplier1, GBC.std().insets(5, 0, 5, 0)); 139 144 cadastrewms.add(grabMultiplier2, GBC.std().insets(5, 0, 5, 0)); 140 145 cadastrewms.add(grabMultiplier3, GBC.std().insets(5, 0, 5, 0)); 141 cadastrewms.add(grabMultiplier4, GBC.eol().fill(GBC.HORIZONTAL).insets(5, 0, 5, 0)); 146 cadastrewms.add(grabMultiplier4, GBC.std().insets(5, 0, 5, 0)); 147 int squareSize = getNumber("cadastrewms.squareSize", DEFAULT_SQUARE_SIZE); 148 grabMultiplier4Size.setText(String.valueOf(squareSize)); 149 grabMultiplier4Size.setToolTipText(tr("Fixed size (from 25 to 1000 meters)")); 150 grabMultiplier4Size.setEnabled(currentScale.equals(Scale.SQUARE_100M.value)); 151 cadastrewms.add(grabMultiplier4Size, GBC.eol().fill(GBC.HORIZONTAL).insets(5, 5, 0, 5)); 142 152 143 153 // option to enable automatic caching … … 153 163 154 164 // option to fix the cache size(in MB) 155 int size; 156 try { 157 size = Integer.parseInt(Main.pref.get("cadastrewms.cacheSize", String.valueOf(DEFAULT_CACHE_SIZE))); 158 } catch (NumberFormatException e) { 159 size = DEFAULT_CACHE_SIZE; 160 } 165 int size = getNumber("cadastrewms.cacheSize", DEFAULT_CACHE_SIZE); 161 166 cacheSize.setText(String.valueOf(size)); 162 167 cacheSize.setToolTipText(tr("Oldest files are automatically deleted when this size is exceeded")); … … 182 187 else if (grabMultiplier3.isSelected()) 183 188 Main.pref.put("cadastrewms.scale", Scale.X3.toString()); 184 else 189 else { 185 190 Main.pref.put("cadastrewms.scale", Scale.SQUARE_100M.toString()); 191 try { 192 int squareSize = Integer.parseInt(grabMultiplier4Size.getText()); 193 if (squareSize >= 25 && squareSize <= 1000) 194 Main.pref.put("cadastrewms.squareSize", grabMultiplier4Size.getText()); 195 } catch (NumberFormatException e) { // ignore the last input 196 } 197 } 186 198 Main.pref.put("cadastrewms.enableCaching", enableCache.isSelected()); 187 199 … … 190 202 CacheControl.cacheSize = Integer.parseInt(cacheSize.getText()); 191 203 Main.pref.put("cadastrewms.cacheSize", String.valueOf(CacheControl.cacheSize)); 192 } catch (NumberFormatException e) { 193 // ignore the last input 204 } catch (NumberFormatException e) { // ignore the last input 194 205 } 195 206 CacheControl.cacheEnabled = enableCache.isSelected(); … … 199 210 } 200 211 212 private int getNumber(String pref_parameter, int def_value) { 213 try { 214 return Integer.parseInt(Main.pref.get(pref_parameter, String.valueOf(def_value))); 215 } catch (NumberFormatException e) { 216 return def_value; 217 } 218 } 201 219 } -
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/DownloadSVGBuilding.java
r13611 r13784 16 16 import java.util.Collection; 17 17 import java.util.LinkedList; 18 import java.util.List; 18 19 import javax.swing.JOptionPane; 19 20 20 21 import org.openstreetmap.josm.Main; … … 23 24 import org.openstreetmap.josm.command.SequenceCommand; 24 25 import org.openstreetmap.josm.data.coor.EastNorth; 26 import org.openstreetmap.josm.data.osm.DataSet; 25 27 import org.openstreetmap.josm.data.osm.Node; 26 28 import org.openstreetmap.josm.data.osm.Way; … … 35 37 private CadastreInterface wmsInterface; 36 38 private String svg = null; 39 private static EastNorthBound currentView = null; 37 40 private EastNorthBound viewBox = null; 38 41 … … 49 52 try { 50 53 if (wmsInterface.retrieveInterface(wmsLayer)) { 51 MapView mv = Main.map.mapView; 52 EastNorthBound enb = new EastNorthBound(mv.getEastNorth(0, mv.getHeight()), 53 mv.getEastNorth(mv.getWidth(), 0)); 54 svg = grabBoundary(enb); 54 svg = grabBoundary(currentView); 55 55 if (svg == null) 56 56 return; … … 58 58 if (viewBox == null) 59 59 return; 60 create Way(svg);60 createBuildings(svg); 61 61 } 62 62 } catch (DuplicateLayerException e) { … … 89 89 * which path element is the best fitting to the viewBox and convert it to OSM objects 90 90 */ 91 private void create Way(String svg) {92 String[] SVGpaths = new SVGParser().get Paths(svg);91 private void createBuildings(String svg) { 92 String[] SVGpaths = new SVGParser().getClosedPaths(svg); 93 93 ArrayList<ArrayList<EastNorth>> eastNorths = new ArrayList<ArrayList<EastNorth>>(); 94 Collection<Node> existingNodes = Main.ds.nodes;95 94 95 // convert SVG nodes to eastNorth coordinates 96 96 for (int i=0; i< SVGpaths.length; i++) { 97 97 ArrayList<EastNorth> eastNorth = new ArrayList<EastNorth>(); … … 100 100 eastNorths.add(eastNorth); 101 101 } 102 List<Way> wayList = new ArrayList<Way>(); 103 List<Node> nodeList = new ArrayList<Node>(); 102 103 // create nodes and closed ways 104 DataSet svgDataSet = new DataSet(); 104 105 for (ArrayList<EastNorth> path : eastNorths) { 105 List<Node> tmpNodeList = new ArrayList<Node>();106 106 Way wayToAdd = new Way(); 107 107 for (EastNorth eastNorth : path) { 108 108 Node nodeToAdd = new Node(Main.proj.eastNorth2latlon(eastNorth)); 109 109 // check if new node is not already created by another new path 110 Node nearestNewNode = checkNearestNode(nodeToAdd, tmpNodeList); 111 if (nearestNewNode == nodeToAdd) { 112 // check if new node is not already in existing OSM objects 113 nearestNewNode = checkNearestNode(nodeToAdd, existingNodes); 114 if (nearestNewNode == nodeToAdd) 115 tmpNodeList.add(nodeToAdd); 110 Node nearestNewNode = checkNearestNode(nodeToAdd, svgDataSet.nodes); 111 if (nearestNewNode == nodeToAdd) 112 svgDataSet.addPrimitive(nearestNewNode); 113 wayToAdd.nodes.add(nearestNewNode); // either a new node or an existing one 114 } 115 wayToAdd.nodes.add(wayToAdd.nodes.get(0)); // close the way 116 svgDataSet.addPrimitive(wayToAdd); 117 } 118 119 // TODO remove small boxes (4 nodes with less than 1 meter distance) 120 /* 121 for (Way w : svgDataSet.ways) 122 if (w.nodes.size() == 5) 123 for (int i = 0; i < w.nodes.size()-2; i++) { 124 if (w.nodes.get(i).eastNorth.distance(w.nodes.get(i+1).eastNorth)) 125 }*/ 126 127 // simplify ways and check if we can reuse existing OSM nodes 128 for (Way wayToAdd : svgDataSet.ways) 129 new SimplifyWay().simplifyWay(wayToAdd, svgDataSet, 0.5); 130 // check if the new way or its nodes is already in OSM layer 131 for (Node n : svgDataSet.nodes) { 132 Node nearestNewNode = checkNearestNode(n, Main.ds.nodes); 133 if (nearestNewNode != n) { 134 // replace the SVG node by the OSM node 135 for (Way w : svgDataSet.ways) { 136 int replaced = 0; 137 for (Node node : w.nodes) 138 if (node == n) { 139 node = nearestNewNode; 140 replaced++; 141 } 142 if (w.nodes.size() == replaced) 143 w.delete(true); 116 144 } 117 wayToAdd.nodes.add(nearestNewNode); // either a new node or an existing one 118 } 119 // at least two nodes have to be new, otherwise the polygon is not new (duplicate) 120 if (tmpNodeList.size() > 1) { 121 for (Node n : tmpNodeList) 122 nodeList.add(n); 123 wayToAdd.nodes.add(wayToAdd.nodes.get(0)); // close the way 124 wayList.add(wayToAdd); 125 } 126 } 145 n.delete(true); 146 } 147 148 } 149 127 150 Collection<Command> cmds = new LinkedList<Command>(); 128 for (Node node : nodeList) 129 cmds.add(new AddCommand(node)); 130 for (Way way : wayList) 131 cmds.add(new AddCommand(way)); 151 for (Node node : svgDataSet.nodes) 152 if (!node.deleted) 153 cmds.add(new AddCommand(node)); 154 for (Way way : svgDataSet.ways) 155 if (!way.deleted) 156 cmds.add(new AddCommand(way)); 132 157 Main.main.undoRedo.add(new SequenceCommand(tr("Create buildings"), cmds)); 133 158 Main.map.repaint(); … … 162 187 */ 163 188 private Node checkNearestNode(Node nodeToAdd, Collection<Node> nodes) { 164 double epsilon = 0.0 1; // smallest distance considering duplicate node189 double epsilon = 0.05; // smallest distance considering duplicate node 165 190 for (Node n : nodes) { 166 191 if (!n.deleted && !n.incomplete) { 167 192 double dist = n.eastNorth.distance(nodeToAdd.eastNorth); 168 193 if (dist < epsilon) { 169 System.out.println("distance="+dist);170 194 return n; 171 195 } … … 197 221 str += bbox.max.north(); 198 222 str += "&width=800&height=600"; // maximum allowed by wms server 223 str += "&exception=application/vnd.ogc.se_inimage"; 199 224 str += "&styles="; 200 225 str += "LS2_90"; … … 231 256 232 257 public static void download(WMSLayer wmsLayer) { 258 MapView mv = Main.map.mapView; 259 currentView = new EastNorthBound(mv.getEastNorth(0, mv.getHeight()), 260 mv.getEastNorth(mv.getWidth(), 0)); 261 if ((currentView.max.east() - currentView.min.east()) > 1000 || 262 (currentView.max.north() - currentView.min.north() > 1000)) { 263 JOptionPane.showMessageDialog(Main.parent, 264 tr("To avoid cadastre WMS overload,\nbuilding import size is limited to 1 km2 max.")); 265 return; 266 } 267 if (CadastrePlugin.autoSourcing == false) { 268 JOptionPane.showMessageDialog(Main.parent, 269 tr("Please, enable auto-sourcing and check cadastre millesime.")); 270 return; 271 } 233 272 Main.worker.execute(new DownloadSVGBuilding(wmsLayer)); 234 273 } -
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/DownloadSVGTask.java
r13611 r13784 18 18 import java.util.LinkedList; 19 19 import java.util.List; 20 21 import javax.swing.JOptionPane; 20 22 21 23 import org.openstreetmap.josm.Main; … … 94 96 */ 95 97 private void createWay(String svg) { 96 String[] SVGpaths = new SVGParser().get Paths(svg);98 String[] SVGpaths = new SVGParser().getClosedPaths(svg); 97 99 ArrayList<Double> fitViewBox = new ArrayList<Double>(); 98 100 ArrayList<ArrayList<EastNorth>> eastNorths = new ArrayList<ArrayList<EastNorth>>(); … … 116 118 } 117 119 wayToAdd.nodes.add(wayToAdd.nodes.get(0)); // close the circle 118 new SimplifyWay().simplifyWay(wayToAdd); 120 121 // simplify the way 122 double threshold = Double.parseDouble(Main.pref.get("cadastrewms.simplify-way-boundary", "1.0")); 123 new SimplifyWay().simplifyWay(wayToAdd, Main.ds, threshold); 124 119 125 cmds.add(new AddCommand(wayToAdd)); 120 126 Main.main.undoRedo.add(new SequenceCommand(tr("Create boundary"), cmds)); … … 205 211 206 212 public static void download(WMSLayer wmsLayer) { 213 if (CadastrePlugin.autoSourcing == false) { 214 JOptionPane.showMessageDialog(Main.parent, 215 tr("Please, enable auto-sourcing and check cadastre millesime.")); 216 return; 217 } 207 218 Main.worker.execute(new DownloadSVGTask(wmsLayer)); 208 219 } -
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/GeorefImage.java
r13497 r13784 16 16 import java.io.Serializable; 17 17 import javax.imageio.ImageIO; 18 18 19 import org.openstreetmap.josm.data.coor.EastNorth; 19 20 import org.openstreetmap.josm.gui.NavigatableComponent; 20 import org.openstreetmap.josm.tools.ColorHelper;21 21 22 22 public class GeorefImage implements Serializable { … … 181 181 int heightYMaskPixel = Math.abs((int) ((maxMaskNorth - minMaskNorth) / pixelPerNorth)); 182 182 Graphics g = image.getGraphics(); 183 int josmBackgroundColor = ColorHelper.html2color(CadastrePlugin.colorBackground).getRGB();184 183 for (int x = minXMaskPixel; x < minXMaskPixel + widthXMaskPixel; x++) 185 184 for (int y = minYMaskPixel; y < minYMaskPixel + heightYMaskPixel; y++) 186 if (CadastrePlugin.alterColors) 187 image.setRGB(x, y, josmBackgroundColor); 188 else 189 image.setRGB(x, y, ImageModifier.cadastreBackground); 185 image.setRGB(x, y, ImageModifier.cadastreBackgroundTransp); 190 186 g.dispose(); 191 187 } -
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/ImageModifier.java
r13611 r13784 18 18 public static final int cadastreBackground = -1; // white 19 19 20 public static final int cadastreBackgroundTransp = 1; // original white but transparent 21 20 22 public BufferedImage bufferedImage; 21 23 … … 28 30 public ImageModifier(BufferedImage bi) { 29 31 bufferedImage = bi; 30 if (Main.pref.getBoolean("cadastrewms.alterColors")) { 31 changeColors(); 32 if (Main.pref.getBoolean("cadastrewms.backgroundTransparent")) { 33 makeTransparent(); 34 } 35 } 32 if (Main.pref.getBoolean("cadastrewms.backgroundTransparent")) 33 makeTransparent(); 34 else if (Main.pref.getBoolean("cadastrewms.alterColors")) 35 replaceBackground(); 36 37 if (Main.pref.getBoolean("cadastrewms.invertGrey")) 38 invertGrey(); 36 39 } 37 40 38 41 /** 39 42 * Replace the background color by the josm color.background color. 40 * @param bi41 * @return42 43 */ 43 private void changeColors() {44 private void replaceBackground() { 44 45 int w = bufferedImage.getWidth(); 45 46 int h = bufferedImage.getHeight(); 46 int pixel; 47 int josmBackgroundColor = ColorHelper.html2color(Main.pref.get("color.background", "#FFFFFF")).getRGB(); 48 boolean invertGrey = (Main.pref.getBoolean("cadastrewms.invertGrey")); 47 int josmBackgroundColor = ColorHelper.html2color(Main.pref.get("color.background", "#000000")).getRGB(); 49 48 for (int x = 0; x < w; x++) { 50 49 for (int y = 0; y < h; y++) { 51 pixel = bufferedImage.getRGB(x, y);50 int pixel = bufferedImage.getRGB(x, y); 52 51 if (pixel == cadastreBackground) { 53 52 bufferedImage.setRGB(x, y, josmBackgroundColor); … … 56 55 backgroundSampleX = x; 57 56 backgroundSampleY = y; 58 } else if (invertGrey) { 57 } 58 } 59 } 60 } 61 62 /** 63 * Invert black/white/grey pixels (to change original black characters to white). 64 */ 65 private void invertGrey() { 66 int w = bufferedImage.getWidth(); 67 int h = bufferedImage.getHeight(); 68 for (int x = 0; x < w; x++) { 69 for (int y = 0; y < h; y++) { 70 int pixel = bufferedImage.getRGB(x, y); 71 if (pixel != cadastreBackground) { 59 72 bufferedImage.setRGB(x, y, reverseIfGrey(pixel)); 60 73 } … … 62 75 } 63 76 } 64 77 65 78 /** 66 79 * Reverse the grey value if the pixel is grey (light grey becomes dark grey) -
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/SVGParser.java
r13545 r13784 14 14 private String cViewBoxEnd = "\""; 15 15 private String cPathStart = "<path d=\""; 16 private String c PathEnd = "\"/>";16 private String cClosedPathEnd = "\"/>"; 17 17 18 18 /** … … 40 40 } 41 41 42 public String [] getPaths(String svg) { 42 /** 43 * Closed SVG paths are finishing with a "Z" at the end of the moves list. 44 * @param svg 45 * @return 46 */ 47 public String [] getClosedPaths(String svg) { 43 48 ArrayList<String> path = new ArrayList<String>(); 44 49 int i = 0; 45 50 while (svg.indexOf(cPathStart, i) != -1) { 46 51 int s = svg.indexOf(cPathStart, i) + cViewBoxStart.length(); 47 int e = svg.indexOf(c PathEnd, s);52 int e = svg.indexOf(cClosedPathEnd, s); 48 53 if (s != -1 && e != -1) { 49 path.add(svg.substring(s, e)); 54 String onePath = svg.substring(s, e); 55 if (onePath.indexOf("Z") != -1) // only closed SVG path 56 path.add(onePath); 50 57 } else 51 58 break; -
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/SimplifyWay.java
r13545 r13784 12 12 import org.openstreetmap.josm.command.DeleteCommand; 13 13 import org.openstreetmap.josm.command.SequenceCommand; 14 import org.openstreetmap.josm.data.osm.DataSet; 14 15 import org.openstreetmap.josm.data.osm.Node; 15 16 import org.openstreetmap.josm.data.osm.Way; … … 23 24 */ 24 25 public class SimplifyWay { 25 public void simplifyWay(Way w) { 26 double threshold = Double.parseDouble(Main.pref.get("simplify-way.max-error", "3")); 27 26 public void simplifyWay(Way w, DataSet dataSet, double threshold) { 28 27 Way wnew = new Way(w); 29 28 30 29 int toI = wnew.nodes.size() - 1; 31 30 for (int i = wnew.nodes.size() - 1; i >= 0; i--) { 32 CollectBackReferencesVisitor backRefsV = new CollectBackReferencesVisitor( Main.ds, false);31 CollectBackReferencesVisitor backRefsV = new CollectBackReferencesVisitor(dataSet, false); 33 32 backRefsV.visit(wnew.nodes.get(i)); 34 33 boolean used = false; -
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/WMSDownloadAction.java
r13593 r13784 41 41 return new MenuActionNewLocation().addNewLayer(existingWMSlayers); 42 42 JOptionPane.showMessageDialog(Main.parent, 43 tr("More than one WMS layer present .\nSelect one of them first, then retry."));43 tr("More than one WMS layer present\nSelect one of them first, then retry")); 44 44 } 45 45 return null; -
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/WMSLayer.java
r13545 r13784 162 162 } else { 163 163 // divide to fixed size squares 164 int cSquare = 100; // expressed in meters in projection Lambert164 int cSquare = Integer.parseInt(Main.pref.get("cadastrewms.squareSize", "100")); 165 165 minEast = minEast - minEast % cSquare; 166 166 minNorth = minNorth - minNorth % cSquare;
Note:
See TracChangeset
for help on using the changeset viewer.