Changeset 15961 in osm for applications/editors/josm/plugins/cadastre-fr/src
- Timestamp:
- 2009-06-17T09:46:26+02:00 (16 years ago)
- Location:
- applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr
- Files:
-
- 20 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CacheControl.java
r13545 r15961 4 4 * wait status on GUI, fast saving even in big file). A separate thread is created for each WMS 5 5 * layer to not suspend the GUI until disk I/O is terminated (a file for the cache can take 6 * several MB's). If the cache file already exists, new images are just appended to the file 7 * (performance). Since we use the ObjectStream methods, it is required to modify the standard 8 * ObjectOutputStream in order to have objects appended readable (otherwise a stream header 6 * several MB's). If the cache file already exists, new images are just appended to the file 7 * (performance). Since we use the ObjectStream methods, it is required to modify the standard 8 * ObjectOutputStream in order to have objects appended readable (otherwise a stream header 9 9 * is inserted before each append and an exception is raised at objects read). 10 10 */ … … 31 31 32 32 public static boolean cacheEnabled = true; 33 33 34 34 public static int cacheSize = 500; 35 36 35 36 37 37 public WMSLayer wmsLayer = null; 38 38 39 39 private ArrayList<GeorefImage> imagesToSave = new ArrayList<GeorefImage>(); 40 40 private Lock imagesLock = new ReentrantLock(); 41 41 42 42 public CacheControl(WMSLayer wmsLayer) { 43 43 cacheEnabled = Main.pref.getBoolean("cadastrewms.enableCaching", true); … … 55 55 new Thread(this).start(); 56 56 } 57 57 58 58 private void checkDirSize(File path) { 59 59 long size = 0; … … 69 69 } 70 70 if (size > cacheSize*1024*1024) { 71 System.out.println("Delete oldest file \""+ files[oldestFile].getName() 71 System.out.println("Delete oldest file \""+ files[oldestFile].getName() 72 72 + "\" in cache dir to stay under the limit of " + cacheSize + " MB."); 73 73 files[oldestFile].delete(); … … 75 75 } 76 76 } 77 77 78 78 public boolean loadCacheIfExist() { 79 79 try { 80 80 File file = new File(CadastrePlugin.cacheDir + wmsLayer.name + "." + String.valueOf(wmsLayer.lambertZone+1)); 81 81 if (file.exists()) { 82 int reply = JOptionPane.showConfirmDialog(null, 82 int reply = JOptionPane.showConfirmDialog(null, 83 83 "Location \""+wmsLayer.name+"\" found in cache.\n"+ 84 84 "Load cache first ?\n"+ … … 90 90 } else 91 91 file.delete(); 92 } 92 } 93 93 } catch (Exception e) { 94 94 e.printStackTrace(System.out); … … 96 96 return false; 97 97 } 98 98 99 99 public void deleteCacheFile() { 100 100 try { … … 106 106 } 107 107 } 108 108 109 109 public boolean loadCache(File file, int currentLambertZone) { 110 110 try { … … 166 166 } 167 167 } 168 169 168 } -
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CacheFileFilter.java
r13497 r15961 13 13 private final String description; 14 14 15 public static CacheFileFilter[] filters = { 15 public static CacheFileFilter[] filters = { 16 16 new CacheFileFilter("1", tr("Lambert Zone 1 cache file (.1)")), 17 17 new CacheFileFilter("2", tr("Lambert Zone 2 cache file (.2)")), 18 18 new CacheFileFilter("3", tr("Lambert Zone 3 cache file (.3)")), 19 new CacheFileFilter("4", tr("Lambert Zone 4 cache file (.4)")) 19 new CacheFileFilter("4", tr("Lambert Zone 4 cache file (.4)")) 20 20 }; 21 21 -
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CadastreGrabber.java
r13784 r15961 14 14 import org.openstreetmap.josm.Main; 15 15 import org.openstreetmap.josm.data.coor.EastNorth; 16 import org.openstreetmap.josm.io.OsmTransferException; 16 17 import org.openstreetmap.josm.io.ProgressInputStream; 17 18 18 19 public class CadastreGrabber { 19 20 20 21 22 21 public static final double epsilon = 1e-11; 22 23 private CadastreInterface wmsInterface = new CadastreInterface(this); 23 24 private String lastWMSLayerName = null; 24 25 26 getWmsInterface().downloadCancelled = false; 27 28 29 public GeorefImage grab(WMSLayer wmsLayer, EastNorth lambertMin, EastNorth lambertMax) throws IOException { 25 26 CadastreGrabber() { 27 getWmsInterface().downloadCancelled = false; 28 } 29 30 public GeorefImage grab(WMSLayer wmsLayer, EastNorth lambertMin, EastNorth lambertMax) throws IOException, OsmTransferException { 30 31 31 32 try { … … 58 59 private URL getURLVector(EastNorth lambertMin, EastNorth lambertMax) throws MalformedURLException { 59 60 String str = new String(wmsInterface.baseURL+"/scpc/wms?version=1.1&request=GetMap"); 60 61 62 63 64 65 66 67 68 69 70 71 61 str += "&layers=CDIF:LS3,CDIF:LS2,CDIF:LS1,CDIF:PARCELLE,CDIF:NUMERO"; 62 str += ",CDIF:PT3,CDIF:PT2,CDIF:PT1,CDIF:LIEUDIT"; 63 str += ",CDIF:SUBSECTION"; 64 str += ",CDIF:SECTION"; 65 str += ",CDIF:COMMUNE"; 66 str += "&format=image/png"; 67 //str += "&format=image/jpeg"; 68 str += "&bbox="+lambertMin.east()+","; 69 str += lambertMin.north() + ","; 70 str += lambertMax.east() + ","; 71 str += lambertMax.north(); 72 //str += "&width=800&height=600"; // maximum allowed by wms server 72 73 str += "&width=1000&height=800"; // maximum allowed by wms server 73 74 75 76 77 74 str += "&styles=LS3_90,LS2_90,LS1_90,PARCELLE_90,NUMERO_90,PT3_90,PT2_90,PT1_90,LIEUDIT_90"; 75 str += ",SUBSECTION_90"; 76 str += ",SECTION_90"; 77 str += ",COMMUNE_90"; 78 System.out.println("URL="+str); 78 79 return new URL(str.replace(" ", "%20")); 79 80 } 80 81 81 82 83 84 85 86 82 private BufferedImage grab(URL url) throws IOException, OsmTransferException { 83 wmsInterface.urlConn = (HttpURLConnection)url.openConnection(); 84 wmsInterface.urlConn.setRequestMethod("GET"); 85 wmsInterface.setCookie(); 86 InputStream is = new ProgressInputStream(wmsInterface.urlConn, Main.pleaseWaitDlg); 87 BufferedImage img = ImageIO.read(is); 87 88 is.close(); 88 89 return img; 89 90 } 90 91 91 92 public CadastreInterface getWmsInterface() { -
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CadastreInterface.java
r13611 r15961 41 41 final String cBBoxCommunStart = "new GeoBox("; 42 42 final String cBBoxCommunEnd = ")"; 43 43 44 44 final String cInterfaceVector = "afficherCarteCommune.do"; 45 45 final String cInterfaceRaster = "afficherCarteTa.do"; 46 46 47 47 CadastreInterface(CadastreGrabber cadastreGrabber) { 48 48 this.cadastreGrabber = cadastreGrabber; 49 49 } 50 50 51 51 public boolean retrieveInterface(WMSLayer wmsLayer) throws DuplicateLayerException { 52 52 if (wmsLayer.name.equals("")) … … 64 64 JOptionPane.showMessageDialog(Main.parent, 65 65 tr("Town/city {0} not found or not available in WMS.\n" + 66 66 "Please check its availibility on www.cadastre.gouv.fr", wmsLayer.getLocation())); 67 67 return false; 68 68 } … … 99 99 cadastreGrabber.setLastWMSLayerName(null); 100 100 } 101 101 102 102 public void resetCookieIfNewLayer(String newWMSLayerName) { 103 103 if (!newWMSLayerName.equals(cadastreGrabber.getLastWMSLayerName())) { … … 105 105 } 106 106 } 107 107 108 108 public void setCookie() { 109 109 urlConn.setRequestProperty("Cookie", cookie); 110 110 } 111 111 112 112 private void getInterface(WMSLayer wmsLayer) throws IOException, DuplicateLayerException { 113 113 // first attempt : search for given name without codeCommune … … 134 134 } 135 135 } 136 136 137 137 if (interfaceRef == null) 138 138 throw new IOException("Town/city " + wmsLayer.getLocation() + " not found."); 139 139 } 140 140 141 141 private void openInterface() throws IOException { 142 142 try { … … 158 158 } 159 159 } 160 160 161 161 /** 162 162 * Post the form with the commune name and check the returned answer which is embedded 163 163 * in HTTP XML packets. This function doesn't use an XML parser yet but that would be a good idea 164 164 * for the next releases. 165 * Two possibilities : 165 * Two possibilities : 166 166 * - either the commune name matches and we receive an URL starting with "afficherCarteCommune.do" or 167 167 * - we don't receive a single answer but a list of possible values. This answer looks like: … … 171 171 * <option value="QK066" >COLMAR - 68000</option> 172 172 * </select> 173 * 173 * 174 174 * @param location 175 175 * @param codeCommune … … 245 245 return null; 246 246 } 247 247 248 248 private void parseCommuneList(String input) { 249 249 if (input.indexOf(c0ptionListStart) != -1) { … … 264 264 } 265 265 } 266 266 267 267 private void parseTAList(String input) { 268 268 while (input.indexOf(cInterfaceRaster) != -1) { … … 272 272 if (!listOfTA.contains(codeTA)) { 273 273 System.out.println("parse "+codeTA); 274 listOfTA.add(codeTA); 274 listOfTA.add(codeTA); 275 275 } 276 276 input = input.substring(cInterfaceRaster.length()); … … 314 314 return cInterfaceRaster + "?f=" + codeCommune; 315 315 } 316 316 317 317 public EastNorthBound retrieveCommuneBBox() throws IOException { 318 318 if (interfaceRef == null) … … 340 340 return parseBBoxCommune(line); 341 341 } 342 342 343 343 private EastNorthBound parseBBoxCommune(String input) { 344 344 if (input.indexOf(cBBoxCommunStart) != -1) { … … 356 356 return null; 357 357 } 358 358 359 359 private void checkLayerDuplicates(WMSLayer wmsLayer) throws DuplicateLayerException { 360 360 if (Main.map != null) { … … 369 369 } 370 370 } 371 372 public void cancel() { 371 372 public void cancel() { 373 373 Main.pleaseWaitDlg.currentAction.setText(tr("Aborting...")); 374 374 if (urlConn != null) { -
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CadastrePlugin.java
r15904 r15961 190 190 transparency = 1.0f; 191 191 } 192 // overwrite F11 shortcut used from the beginning by this plugin and recently used 192 // overwrite F11 shortcut used from the beginning by this plugin and recently used 193 193 // for full-screen switch in JOSM core 194 194 int i = 0; … … 202 202 } 203 203 if (!alreadyRedefined) { 204 int reply = JOptionPane.showConfirmDialog(null, 204 int reply = JOptionPane.showConfirmDialog(null, 205 205 tr("Plugin cadastre-fr used traditionaly for grabbing the key shortcut F11\n"+ 206 206 "which is currently allocated for full-screen switch by default\n"+ -
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CadastrePreferenceSetting.java
r13784 r15961 15 15 /** 16 16 * Preference settings for the French Cadastre plugin 17 * 17 * 18 18 * @author Pieren <pieren3@gmail.com> 19 19 */ 20 20 public class CadastrePreferenceSetting implements PreferenceSetting { 21 21 22 22 static final int TRANS_MIN = 1; 23 23 static final int TRANS_MAX = 10; 24 private JSlider sliderTrans = new JSlider(JSlider.HORIZONTAL, TRANS_MIN, TRANS_MAX, TRANS_MAX); 25 24 private JSlider sliderTrans = new JSlider(JSlider.HORIZONTAL, TRANS_MIN, TRANS_MAX, TRANS_MAX); 25 26 26 private JTextField sourcing = new JTextField(20); 27 27 … … 29 29 30 30 private JCheckBox reversGrey = new JCheckBox(tr("Reverse grey colors (for black backgrounds).")); 31 31 32 32 private JCheckBox transparency = new JCheckBox(tr("Set background transparent.")); 33 33 34 34 private JCheckBox drawBoundaries = new JCheckBox(tr("Draw boundaries of downloaded data.")); 35 35 … … 39 39 40 40 private JRadioButton grabMultiplier3 = new JRadioButton("", true); 41 41 42 42 private JRadioButton grabMultiplier4 = new JRadioButton("", true); 43 43 … … 97 97 sliderTrans.setPaintLabels(false); 98 98 cadastrewms.add(sliderTrans, GBC.eol().fill(GBC.HORIZONTAL).insets(20, 0, 250, 0)); 99 99 100 100 // option to draw boundaries of downloaded data 101 101 drawBoundaries.setSelected(Main.pref.getBoolean("cadastrewms.drawBoundaries", false)); … … 150 150 grabMultiplier4Size.setEnabled(currentScale.equals(Scale.SQUARE_100M.value)); 151 151 cadastrewms.add(grabMultiplier4Size, GBC.eol().fill(GBC.HORIZONTAL).insets(5, 5, 0, 5)); 152 152 153 153 // option to enable automatic caching 154 154 enableCache.addActionListener(new ActionListener() { … … 197 197 } 198 198 Main.pref.put("cadastrewms.enableCaching", enableCache.isSelected()); 199 199 200 200 // spread data into objects instead of restarting the application 201 201 try { -
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CheckSourceUploadHook.java
r13611 r15961 24 24 /** 25 25 * This hook is called at JOSM upload and will check if new nodes and ways provide 26 * a tag "source=". If not and if auto-sourcing is enabled, it will add 26 * a tag "source=". If not and if auto-sourcing is enabled, it will add 27 27 * automatically a tag "source"="Cadastre..." as defined in the plugin preferences. 28 28 */ 29 29 public class CheckSourceUploadHook implements UploadHook 30 30 { 31 31 /** Serializable ID */ 32 32 private static final long serialVersionUID = -1; 33 33 … … 40 40 Collection<OsmPrimitive> sel = new HashSet<OsmPrimitive>(); 41 41 for (OsmPrimitive osm : add) { 42 if ((osm instanceof Node || osm instanceof Way) 42 if ((osm instanceof Node || osm instanceof Way) 43 43 && (osm.keys == null || !tagSourceExist(osm))) { 44 44 sel.add(osm); … … 51 51 return true; 52 52 } 53 53 54 54 /** 55 55 * Check whenever one of the keys of the object is "source" … … 65 65 return false; 66 66 } 67 67 68 68 /** 69 * Displays a screen with the list of objects which will be tagged with 69 * Displays a screen with the list of objects which will be tagged with 70 70 * source="cadastre.." if it is approved. 71 71 * @param sel the list of elements added without a key "source" 72 72 */ 73 private void displaySource(Collection<OsmPrimitive> sel) 73 private void displaySource(Collection<OsmPrimitive> sel) 74 74 { 75 75 if (!sel.isEmpty()) { … … 86 86 Main.main.undoRedo.add(new ChangePropertyCommand(sel, "source", CadastrePlugin.source)); 87 87 } 88 89 } 88 89 } 90 90 } -
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/DownloadSVGBuilding.java
r13784 r15961 29 29 import org.openstreetmap.josm.gui.MapView; 30 30 import org.openstreetmap.josm.gui.PleaseWaitRunnable; 31 import org.openstreetmap.josm.io.OsmTransferException; 31 32 import org.openstreetmap.josm.io.ProgressInputStream; 32 33 … … 39 40 private static EastNorthBound currentView = null; 40 41 private EastNorthBound viewBox = null; 41 42 42 43 public DownloadSVGBuilding(WMSLayer wmsLayer) { 43 44 super(tr("Downloading {0}", wmsLayer.name)); … … 48 49 49 50 @Override 50 public void realRun() throws IOException { 51 public void realRun() throws IOException, OsmTransferException { 51 52 Main.pleaseWaitDlg.currentAction.setText(tr("Contacting WMS Server...")); 52 53 try { … … 77 78 double[] box = new SVGParser().getViewBox(svg); 78 79 if (box != null) { 79 viewBox = new EastNorthBound(new EastNorth(box[0], box[1]), 80 viewBox = new EastNorthBound(new EastNorth(box[0], box[1]), 80 81 new EastNorth(box[0]+box[2], box[1]+box[3])); 81 82 return true; … … 84 85 return false; 85 86 } 86 87 87 88 /** 88 89 * The svg contains more than one commune boundary defined by path elements. So detect … … 92 93 String[] SVGpaths = new SVGParser().getClosedPaths(svg); 93 94 ArrayList<ArrayList<EastNorth>> eastNorths = new ArrayList<ArrayList<EastNorth>>(); 94 95 // convert SVG nodes to eastNorth coordinates 95 96 // convert SVG nodes to eastNorth coordinates 96 97 for (int i=0; i< SVGpaths.length; i++) { 97 98 ArrayList<EastNorth> eastNorth = new ArrayList<EastNorth>(); … … 107 108 for (EastNorth eastNorth : path) { 108 109 Node nodeToAdd = new Node(Main.proj.eastNorth2latlon(eastNorth)); 109 // check if new node is not already created by another new path 110 Node nearestNewNode = checkNearestNode(nodeToAdd, svgDataSet.nodes); 110 // check if new node is not already created by another new path 111 Node nearestNewNode = checkNearestNode(nodeToAdd, svgDataSet.nodes); 111 112 if (nearestNewNode == nodeToAdd) 112 113 svgDataSet.addPrimitive(nearestNewNode); … … 116 117 svgDataSet.addPrimitive(wayToAdd); 117 118 } 118 119 119 120 // TODO remove small boxes (4 nodes with less than 1 meter distance) 120 121 /* … … 130 131 // check if the new way or its nodes is already in OSM layer 131 132 for (Node n : svgDataSet.nodes) { 132 Node nearestNewNode = checkNearestNode(n, Main.ds.nodes); 133 Node nearestNewNode = checkNearestNode(n, Main.ds.nodes); 133 134 if (nearestNewNode != n) { 134 135 // replace the SVG node by the OSM node … … 145 146 n.delete(true); 146 147 } 147 148 148 149 } 149 150 … … 158 159 Main.map.repaint(); 159 160 } 160 161 161 162 private void createNodes(String SVGpath, ArrayList<EastNorth> eastNorth) { 162 163 // looks like "M981283.38 368690.15l143.81 72.46 155.86 ..." … … 170 171 } 171 172 double east = dx+=Double.parseDouble(coor[i]); 172 double north = dy+=Double.parseDouble(coor[i+1]); 173 double north = dy+=Double.parseDouble(coor[i+1]); 173 174 eastNorth.add(new EastNorth(east,north)); 174 175 } 175 // flip the image (svg using a reversed Y coordinate system) 176 // flip the image (svg using a reversed Y coordinate system) 176 177 double pivot = viewBox.min.getY() + (viewBox.max.getY() - viewBox.min.getY()) / 2; 177 178 for (EastNorth en : eastNorth) { … … 183 184 /** 184 185 * Check if node can be reused. 185 * @param nodeToAdd the candidate as new node 186 * @return the already existing node (if any), otherwise the new node candidate. 186 * @param nodeToAdd the candidate as new node 187 * @return the already existing node (if any), otherwise the new node candidate. 187 188 */ 188 189 private Node checkNearestNode(Node nodeToAdd, Collection<Node> nodes) { … … 199 200 } 200 201 201 private String grabBoundary(EastNorthBound bbox) throws IOException { 202 202 private String grabBoundary(EastNorthBound bbox) throws IOException, OsmTransferException { 203 203 try { 204 204 URL url = null; … … 210 210 } 211 211 } 212 212 213 213 private URL getURLsvg(EastNorthBound bbox) throws MalformedURLException { 214 214 String str = new String(wmsInterface.baseURL+"/scpc/wms?version=1.1&request=GetMap"); … … 228 228 } 229 229 230 private String grabSVG(URL url) throws IOException { 230 private String grabSVG(URL url) throws IOException, OsmTransferException { 231 231 wmsInterface.urlConn = (HttpURLConnection)url.openConnection(); 232 232 wmsInterface.urlConn.setRequestMethod("GET"); … … 259 259 currentView = new EastNorthBound(mv.getEastNorth(0, mv.getHeight()), 260 260 mv.getEastNorth(mv.getWidth(), 0)); 261 if ((currentView.max.east() - currentView.min.east()) > 1000 || 261 if ((currentView.max.east() - currentView.min.east()) > 1000 || 262 262 (currentView.max.north() - currentView.min.north() > 1000)) { 263 263 JOptionPane.showMessageDialog(Main.parent, -
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/DownloadSVGTask.java
r13784 r15961 29 29 import org.openstreetmap.josm.data.osm.Way; 30 30 import org.openstreetmap.josm.gui.PleaseWaitRunnable; 31 import org.openstreetmap.josm.io.OsmTransferException; 31 32 import org.openstreetmap.josm.io.ProgressInputStream; 32 33 /** 33 * Grab the SVG administrative boundaries of the active commune layer (cadastre), 34 * Grab the SVG administrative boundaries of the active commune layer (cadastre), 34 35 * isolate the SVG path of the concerned commune (other municipalities are also 35 36 * downloaded in the SVG data), convert to OSM nodes and way plus simplify. … … 43 44 private String svg = null; 44 45 private EastNorthBound viewBox = null; 45 46 46 47 public DownloadSVGTask(WMSLayer wmsLayer) { 47 48 super(tr("Downloading {0}", wmsLayer.name)); … … 52 53 53 54 @Override 54 public void realRun() throws IOException { 55 public void realRun() throws IOException, OsmTransferException { 55 56 Main.pleaseWaitDlg.currentAction.setText(tr("Contacting WMS Server...")); 56 57 try { … … 83 84 double[] box = new SVGParser().getViewBox(svg); 84 85 if (box != null) { 85 viewBox = new EastNorthBound(new EastNorth(box[0], box[1]), 86 viewBox = new EastNorthBound(new EastNorth(box[0], box[1]), 86 87 new EastNorth(box[0]+box[2], box[1]+box[3])); 87 88 return true; … … 90 91 return false; 91 92 } 92 93 93 94 /** 94 95 * The svg contains more than one commune boundary defined by path elements. So detect … … 97 98 private void createWay(String svg) { 98 99 String[] SVGpaths = new SVGParser().getClosedPaths(svg); 99 ArrayList<Double> fitViewBox = new ArrayList<Double>(); 100 ArrayList<Double> fitViewBox = new ArrayList<Double>(); 100 101 ArrayList<ArrayList<EastNorth>> eastNorths = new ArrayList<ArrayList<EastNorth>>(); 101 102 for (int i=0; i< SVGpaths.length; i++) { … … 118 119 } 119 120 wayToAdd.nodes.add(wayToAdd.nodes.get(0)); // close the circle 120 121 121 122 // simplify the way 122 123 double threshold = Double.parseDouble(Main.pref.get("cadastrewms.simplify-way-boundary", "1.0")); 123 124 new SimplifyWay().simplifyWay(wayToAdd, Main.ds, threshold); 124 125 125 126 cmds.add(new AddCommand(wayToAdd)); 126 127 Main.main.undoRedo.add(new SequenceCommand(tr("Create boundary"), cmds)); 127 128 Main.map.repaint(); 128 129 } 129 130 130 131 private double createNodes(String SVGpath, ArrayList<EastNorth> eastNorth) { 131 132 // looks like "M981283.38 368690.15l143.81 72.46 155.86 ..." … … 139 140 for (int i=3; i<coor.length; i+=2){ 140 141 double east = dx+=Double.parseDouble(coor[i]); 141 double north = dy+=Double.parseDouble(coor[i+1]); 142 double north = dy+=Double.parseDouble(coor[i+1]); 142 143 eastNorth.add(new EastNorth(east,north)); 143 minX = minX > east ? east : minX; 144 minY = minY > north ? north : minY; 145 maxX = maxX < east ? east : maxX; 146 maxY = maxY < north ? north : maxY; 147 } 148 // flip the image (svg using a reversed Y coordinate system) 144 minX = minX > east ? east : minX; 145 minY = minY > north ? north : minY; 146 maxX = maxX < east ? east : maxX; 147 maxY = maxY < north ? north : maxY; 148 } 149 // flip the image (svg using a reversed Y coordinate system) 149 150 double pivot = viewBox.min.getY() + (viewBox.max.getY() - viewBox.min.getY()) / 2; 150 151 for (EastNorth en : eastNorth) { … … 154 155 +Math.abs(minY - viewBox.min.getY())+Math.abs(maxY - viewBox.max.getY()); 155 156 } 156 157 private String grabBoundary(EastNorthBound bbox) throws IOException { 158 157 158 private String grabBoundary(EastNorthBound bbox) throws IOException, OsmTransferException { 159 159 try { 160 160 URL url = null; … … 166 166 } 167 167 } 168 168 169 169 private URL getURLsvg(EastNorthBound bbox) throws MalformedURLException { 170 170 String str = new String(wmsInterface.baseURL+"/scpc/wms?version=1.1&request=GetMap"); … … 183 183 } 184 184 185 private String grabSVG(URL url) throws IOException { 185 private String grabSVG(URL url) throws IOException, OsmTransferException { 186 186 wmsInterface.urlConn = (HttpURLConnection)url.openConnection(); 187 187 wmsInterface.urlConn.setRequestMethod("GET"); -
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/DownloadWMSTask.java
r13545 r15961 38 38 } 39 39 if (wmsLayer.isRaster()) 40 // set raster image commune bounding box based on current view (before adjustment) 40 // set raster image commune bounding box based on current view (before adjustment) 41 41 wmsLayer.setRasterBounds(bounds); 42 42 else -
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/EastNorthBound.java
r13611 r15961 8 8 9 9 private static final long serialVersionUID = 8451650309216472069L; 10 10 11 11 public EastNorth min, max; 12 12 public EastNorthBound(EastNorth min, EastNorth max) { -
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/GeorefImage.java
r13784 r15961 28 28 29 29 public BufferedImage image; 30 30 31 31 private double angle = 0; // in radian 32 32 33 33 private BufferedImage rotated_image; // only if angle <> 0 34 34 … … 47 47 max = new EastNorth(max.east() + dx, max.north() + dy); 48 48 } 49 49 50 50 public void resize(EastNorth rasterCenter, double proportion) { 51 51 min = min.interpolate(rasterCenter, proportion); … … 53 53 updatePixelPer(); 54 54 } 55 55 56 56 public void rotate(EastNorth pivot, double delta) { 57 57 if (angle == 0) { 58 org_min = min; 58 org_min = min; 59 59 org_max = max; 60 60 } 61 61 this.angle += delta; 62 62 63 63 EastNorth imageCenter = org_min.interpolate(org_max, 0.5); 64 64 EastNorth newimageCenter = imageCenter.rotate(pivot, angle); … … 74 74 max2 = max2.rotate(newimageCenter, angle); 75 75 getNewBounding(min, max, min2, max2); 76 76 77 77 rotated_image = tilt(image, angle); 78 78 } 79 79 80 80 public static BufferedImage tilt(BufferedImage image, double angle) { 81 81 double sin = Math.abs(Math.sin(angle)), cos = Math.abs(Math.cos(angle)); … … 96 96 return gd.getDefaultConfiguration(); 97 97 } 98 98 99 99 private void getNewBounding(EastNorth min, EastNorth max, EastNorth c, EastNorth d) { 100 100 EastNorth pt[] = new EastNorth[4]; … … 116 116 max.setLocation(highestEast, highestNorth); 117 117 } 118 118 119 119 public boolean contains(EastNorth en) { 120 120 return min.east() <= en.east() && en.east() <= max.east() && min.north() <= en.north() … … 165 165 /** 166 166 * Make all pixels masked by the given georefImage transparent in this image 167 * 167 * 168 168 * @param georefImage 169 169 */ -
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/ImageModifier.java
r13784 r15961 18 18 public static final int cadastreBackground = -1; // white 19 19 20 public static final int cadastreBackgroundTransp = 1; // original white but transparent 20 public static final int cadastreBackgroundTransp = 1; // original white but transparent 21 21 22 22 public BufferedImage bufferedImage; … … 25 25 26 26 private int backgroundPixel = 0; 27 27 28 28 private int backgroundSampleX, backgroundSampleY; 29 29 … … 34 34 else if (Main.pref.getBoolean("cadastrewms.alterColors")) 35 35 replaceBackground(); 36 36 37 37 if (Main.pref.getBoolean("cadastrewms.invertGrey")) 38 38 invertGrey(); … … 59 59 } 60 60 } 61 61 62 62 /** 63 63 * Invert black/white/grey pixels (to change original black characters to white). … … 78 78 /** 79 79 * Reverse the grey value if the pixel is grey (light grey becomes dark grey) 80 * Used for texts. 80 * Used for texts. 81 81 * @param pixel 82 82 * @return -
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/MenuActionGrab.java
r13497 r15961 21 21 public MenuActionGrab() { 22 22 super(tr(name), "cadastre_small", tr("Download Image from french Cadastre WMS"), 23 Shortcut.registerShortcut("cadastre:grab", tr("Cadastre: {0}", tr("Download Image from french Cadastre WMS")), 23 Shortcut.registerShortcut("cadastre:grab", tr("Cadastre: {0}", tr("Download Image from french Cadastre WMS")), 24 24 KeyEvent.VK_F11, Shortcut.GROUP_DIRECT), false); 25 25 } -
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/MenuActionLoadFromCache.java
r13497 r15961 31 31 String ext = (filename.lastIndexOf(".")==-1)?"":filename.substring(filename.lastIndexOf(".")+1,filename.length()); 32 32 String location = filename.substring(0, filename.lastIndexOf(".")); 33 // check the extension and its Lambert zone consistency 33 // check the extension and its Lambert zone consistency 34 34 try { 35 35 int cacheZone = Integer.parseInt(ext) - 1; … … 63 63 Main.main.addLayer(wmsLayer); 64 64 } 65 65 66 66 } 67 67 -
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/MenuActionNewLocation.java
r13545 r15961 21 21 public class MenuActionNewLocation extends JosmAction { 22 22 23 private static final long serialVersionUID = 1L; 24 25 public MenuActionNewLocation() { 26 super(tr("Change location"), "cadastre_small", tr("Set a new location for the next request"), null, false); 27 } 23 private static final long serialVersionUID = 1L; 28 24 29 public void actionPerformed(ActionEvent e) { 25 public MenuActionNewLocation() { 26 super(tr("Change location"), "cadastre_small", tr("Set a new location for the next request"), null, false); 27 } 28 29 public void actionPerformed(ActionEvent e) { 30 30 WMSLayer wmsLayer = addNewLayer(new ArrayList<WMSLayer>()); 31 31 if (wmsLayer != null) 32 32 DownloadWMSTask.download(wmsLayer); 33 33 } 34 35 34 35 public WMSLayer addNewLayer(ArrayList<WMSLayer> existingLayers) { 36 36 if (Main.map == null) { 37 37 JOptionPane.showMessageDialog(Main.parent, … … 88 88 System.out.println("Add new layer with Location:" + inputTown.getText()); 89 89 } else if (existingLayers != null && existingLayers.size() > 0 && inputWMSList.getSelectedIndex() > 0) { 90 wmsLayer = existingLayers.get(inputWMSList.getSelectedIndex()-1); 90 wmsLayer = existingLayers.get(inputWMSList.getSelectedIndex()-1); 91 91 resetCookie = true; 92 92 } … … 97 97 } 98 98 } 99 99 100 100 } -
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/MenuActionResetCookie.java
r13497 r15961 10 10 11 11 /** 12 * 12 * 13 13 */ 14 14 private static final long serialVersionUID = 1L; -
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/Scale.java
r13497 r15961 6 6 * view is split in 2x2 bounding boxes and X3 is 3x3 boxes. 7 7 * SQUARE_100M is a special value where bounding boxes have a fixed size of 100x100 meters 8 * and east,north are rounded to the lowest 100 meter as well, thus none of the bounding boxes 8 * and east,north are rounded to the lowest 100 meter as well, thus none of the bounding boxes 9 9 * are overlapping each others. 10 10 */ 11 public enum Scale { 12 X1("1"), 11 public enum Scale { 12 X1("1"), 13 13 X2("2"), 14 14 X3("3"), … … 19 19 */ 20 20 public final String value; 21 21 22 22 Scale(String value) { 23 23 this.value = value; -
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/WMSAdjustAction.java
r15841 r15961 1 package cadastre_fr; 1 package cadastre_fr; 2 2 3 3 import static org.openstreetmap.josm.tools.I18n.tr; … … 20 20 21 21 public class WMSAdjustAction extends MapMode implements 22 22 MouseListener, MouseMotionListener{ 23 23 24 24 private static final long serialVersionUID = 1L; 25 25 GeorefImage selectedImage; 26 26 private ArrayList<WMSLayer> modifiedLayers = new ArrayList<WMSLayer>(); 27 28 29 27 WMSLayer selectedLayer; 28 private boolean rasterMoved; 29 private EastNorth prevEastNorth; 30 30 enum Mode { moveXY, moveZ, rotate} 31 31 private Mode mode = null; 32 32 33 34 35 36 37 33 public WMSAdjustAction(MapFrame mapFrame) { 34 super(tr("Adjust WMS"), "adjustxywms", 35 tr("Adjust the position of the WMS layer (raster images only)"), mapFrame, 36 ImageProvider.getCursor("normal", "move")); 37 } 38 38 39 40 41 42 43 44 39 @Override public void enterMode() { 40 super.enterMode(); 41 Main.map.mapView.addMouseListener(this); 42 Main.map.mapView.addMouseMotionListener(this); 43 rasterMoved = false; 44 /*/ FOR TEST 45 45 for (Layer layer : Main.map.mapView.getAllLayers()) { 46 46 if (layer.visible && layer instanceof WMSLayer) { … … 50 50 } 51 51 Main.map.mapView.repaint();*/ 52 52 } 53 53 54 55 56 57 58 59 int reply = JOptionPane.showConfirmDialog(null, 54 @Override public void exitMode() { 55 super.exitMode(); 56 Main.map.mapView.removeMouseListener(this); 57 Main.map.mapView.removeMouseMotionListener(this); 58 if (rasterMoved && CacheControl.cacheEnabled) { 59 int reply = JOptionPane.showConfirmDialog(null, 60 60 "Save the changes in cache ?", 61 61 "Update cache", 62 JOptionPane.YES_NO_OPTION); 62 JOptionPane.YES_NO_OPTION); 63 63 if (reply == JOptionPane.OK_OPTION) { 64 64 saveModifiedLayers(); 65 65 } 66 67 68 66 } 67 modifiedLayers.clear(); 68 } 69 69 70 70 @Override 71 71 public void mousePressed(MouseEvent e) { 72 72 if (e.getButton() != MouseEvent.BUTTON1) … … 93 93 } 94 94 95 96 95 @Override public void mouseDragged(MouseEvent e) { 96 if(selectedImage != null && (mode == Mode.moveXY || mode == Mode.moveZ || mode == Mode.rotate)) { 97 97 EastNorth newEastNorth = Main.map.mapView.getEastNorth(e.getX(),e.getY()); 98 99 100 101 102 103 104 98 if (mode == Mode.moveXY) { 99 displace(prevEastNorth, newEastNorth); 100 } else if (mode == Mode.moveZ) { 101 resize(newEastNorth); 102 } else if (mode == Mode.rotate) { 103 rotate(prevEastNorth, newEastNorth); 104 } 105 105 rasterMoved = true; 106 106 if (!modifiedLayers.contains(selectedLayer)) … … 108 108 Main.map.mapView.repaint(); 109 109 prevEastNorth = newEastNorth; 110 111 112 113 110 } 111 } 112 113 private void displace(EastNorth start, EastNorth end) { 114 114 selectedLayer.displace(end.east()-start.east(), end.north()-start.north()); 115 116 117 115 } 116 117 private void resize(EastNorth newEastNorth) { 118 118 double dPrev = prevEastNorth.distance(selectedLayer.getRasterCenter().east(), selectedLayer.getRasterCenter().north()); 119 119 double dNew = newEastNorth.distance(selectedLayer.getRasterCenter().east(), selectedLayer.getRasterCenter().north()); 120 120 selectedLayer.resize(1 - dNew/dPrev); 121 122 123 124 125 126 121 } 122 123 private void rotate(EastNorth start, EastNorth end) { 124 EastNorth pivot = selectedLayer.getRasterCenter(); 125 double startAngle = Math.atan2(start.east()-pivot.east(), start.north()-pivot.north()); 126 double endAngle = Math.atan2(end.east()-pivot.east(), end.north()-pivot.north()); 127 127 double rotationAngle = endAngle - startAngle; 128 selectedLayer.rotate(rotationAngle); 129 128 selectedLayer.rotate(rotationAngle); 129 } 130 130 131 132 133 134 135 136 137 138 131 @Override public void mouseReleased(MouseEvent e) { 132 //Main.map.mapView.repaint(); 133 Main.map.mapView.setCursor(Cursor.getDefaultCursor()); 134 selectedImage = null; 135 prevEastNorth = null; 136 selectedLayer = null; 137 mode = null; 138 } 139 139 140 141 142 143 144 145 140 public void mouseEntered(MouseEvent e) { 141 } 142 public void mouseExited(MouseEvent e) { 143 } 144 public void mouseMoved(MouseEvent e) { 145 } 146 146 147 148 149 150 147 @Override public void mouseClicked(MouseEvent e) { 148 } 149 150 private void saveModifiedLayers() { 151 151 for (WMSLayer wmsLayer : modifiedLayers) { 152 152 wmsLayer.saveNewCache(); 153 153 } 154 154 } 155 155 } -
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/WMSDownloadAction.java
r13784 r15961 16 16 private static final long serialVersionUID = 1L; 17 17 18 public WMSDownloadAction(String layerName) { 19 super(layerName, "wmsmenu", tr("Download WMS tile from {0}",layerName), null, false); 20 } 21 22 public void actionPerformed(ActionEvent e) { 23 DownloadWMSTask.download(getLayer()); 24 } 18 public WMSDownloadAction(String layerName) { 19 super(layerName, "wmsmenu", tr("Download WMS tile from {0}",layerName), null, false); 20 } 25 21 26 public static WMSLayer getLayer() { 27 // check if we already have a layer created. if not, create; if yes, reuse. 22 public void actionPerformed(ActionEvent e) { 23 DownloadWMSTask.download(getLayer()); 24 } 25 26 public static WMSLayer getLayer() { 27 // check if we already have a layer created. if not, create; if yes, reuse. 28 28 if (Main.map != null) { 29 29 Layer activeLayer = Main.map.mapView.getActiveLayer(); … … 44 44 } 45 45 return null; 46 46 } 47 47 }; 48 48
Note:
See TracChangeset
for help on using the changeset viewer.