source: osm/applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CadastreGrabber.java@ 13727

Last change on this file since 13727 was 13497, checked in by skela, 16 years ago

applications/editors/josm: Set svn:eol-style native on all *.java files
in plugins. Normalize the eol-style in
plugins/lakewalker/src/org/openstreetmap/josm/plugins/lakewalker/StringEnumConfigurer.java.

  • Property svn:eol-style set to native
File size: 3.6 KB
Line 
1package cadastre_fr;
2
3import static org.openstreetmap.josm.tools.I18n.tr;
4
5import java.awt.image.BufferedImage;
6import java.io.IOException;
7import java.io.InputStream;
8import java.net.HttpURLConnection;
9import java.net.MalformedURLException;
10import java.net.URL;
11
12import javax.imageio.ImageIO;
13
14import org.openstreetmap.josm.Main;
15import org.openstreetmap.josm.data.coor.EastNorth;
16import org.openstreetmap.josm.io.ProgressInputStream;
17
18public class CadastreGrabber {
19
20 public static final double epsilon = 1e-11;
21
22 private CadastreInterface wmsInterface = new CadastreInterface(this);
23 private String lastWMSLayerName = null;
24
25 CadastreGrabber() {
26 getWmsInterface().downloadCancelled = false;
27 }
28
29 public GeorefImage grab(WMSLayer wmsLayer, EastNorth lambertMin, EastNorth lambertMax) throws IOException {
30
31 try {
32 URL url = null;
33 if (wmsLayer.isRaster())
34 url = getURLRaster(wmsLayer, lambertMin, lambertMax);
35 else
36 url = getURLVector(lambertMin, lambertMax);
37 System.out.println("grab:"+url);
38 BufferedImage img = grab(url);
39 ImageModifier imageModified = new ImageModifier(img);
40 return new GeorefImage(imageModified.bufferedImage, lambertMin, lambertMax);
41 } catch (MalformedURLException e) {
42 throw (IOException) new IOException(tr("CadastreGrabber: Illegal url.")).initCause(e);
43 }
44 }
45
46 private URL getURLRaster(WMSLayer wmsLayer, EastNorth lambertMin, EastNorth lambertMax) throws MalformedURLException {
47 String str = new String(wmsInterface.baseURL+"/scpc/wms?version=1.1&request=GetMap");
48 str += "&layers=CDIF:PMC@";
49 str += wmsLayer.getCodeCommune();
50 str += "&format=image/png";
51 str += "&bbox=";
52 str += wmsLayer.eastNorth2raster(lambertMin, lambertMax);
53 str += "&width=600&height=600"; // maximum allowed by wms server
54 str += "&exception=application/vnd.ogc.se_inimage&styles=";
55 return new URL(str.replace(" ", "%20"));
56 }
57
58 private URL getURLVector(EastNorth lambertMin, EastNorth lambertMax) throws MalformedURLException {
59 String str = new String(wmsInterface.baseURL+"/scpc/wms?version=1.1&request=GetMap");
60 str += "&layers=CDIF:LS3,CDIF:LS2,CDIF:LS1,CDIF:PARCELLE,CDIF:NUMERO";
61 str += ",CDIF:PT3,CDIF:PT2,CDIF:PT1,CDIF:LIEUDIT";
62 str += ",CDIF:SUBSECTION";
63 str += ",CDIF:SECTION";
64 str += ",CDIF:COMMUNE";
65 str += "&format=image/png";
66 //str += "&format=image/jpeg";
67 str += "&bbox="+lambertMin.east()+",";
68 str += lambertMin.north() + ",";
69 str += lambertMax.east() + ",";
70 str += lambertMax.north();
71 str += "&width=800&height=600"; // maximum allowed by wms server
72 str += "&styles=LS3_90,LS2_90,LS1_90,PARCELLE_90,NUMERO_90,PT3_90,PT2_90,PT1_90,LIEUDIT_90";
73 str += ",SUBSECTION_90";
74 str += ",SECTION_90";
75 str += ",COMMUNE_90";
76 System.out.println("URL="+str);
77 return new URL(str.replace(" ", "%20"));
78 }
79
80 private BufferedImage grab(URL url) throws IOException {
81 wmsInterface.urlConn = (HttpURLConnection)url.openConnection();
82 wmsInterface.urlConn.setRequestMethod("GET");
83 wmsInterface.setCookie();
84 InputStream is = new ProgressInputStream(wmsInterface.urlConn, Main.pleaseWaitDlg);
85 BufferedImage img = ImageIO.read(is);
86 is.close();
87 return img;
88 }
89
90 public CadastreInterface getWmsInterface() {
91 return wmsInterface;
92 }
93
94 public String getLastWMSLayerName() {
95 return lastWMSLayerName;
96 }
97
98 public void setLastWMSLayerName(String lastWMSLayerName) {
99 this.lastWMSLayerName = lastWMSLayerName;
100 }
101
102}
Note: See TracBrowser for help on using the repository browser.