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

Last change on this file since 18207 was 18207, checked in by pieren, 15 years ago

Use the new cadastre projection LambertCC9Zones

  • Property svn:eol-style set to native
File size: 4.4 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.data.coor.EastNorth;
15import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
16import org.openstreetmap.josm.io.OsmTransferException;
17import org.openstreetmap.josm.io.ProgressInputStream;
18
19public class CadastreGrabber {
20
21 public final static double epsilon = 1e-11;
22
23 private CadastreInterface wmsInterface = new CadastreInterface();
24
25 public GeorefImage grab(WMSLayer wmsLayer, EastNorth lambertMin, EastNorth lambertMax) throws IOException, OsmTransferException {
26
27 try {
28 URL url = null;
29 if (wmsLayer.isRaster())
30 url = getURLRaster(wmsLayer, lambertMin, lambertMax);
31 else
32 url = getURLVector(lambertMin, lambertMax);
33 BufferedImage img = grab(url);
34 ImageModifier imageModified;
35 if (wmsLayer.isRaster())
36 imageModified = new RasterImageModifier(img);
37 else
38 imageModified = new VectorImageModifier(img);
39 return new GeorefImage(imageModified.bufferedImage, lambertMin, lambertMax);
40 } catch (MalformedURLException e) {
41 throw (IOException) new IOException(tr("CadastreGrabber: Illegal url.")).initCause(e);
42 }
43 }
44
45 private URL getURLRaster(WMSLayer wmsLayer, EastNorth lambertMin, EastNorth lambertMax) throws MalformedURLException {
46 // GET /scpc/wms?version=1.1&request=GetMap&layers=CDIF:PMC@QH4480001701&format=image/png&bbox=-1186,0,13555,8830&width=576&height=345&exception=application/vnd.ogc.se_inimage&styles= HTTP/1.1
47 final int cRasterX = 1000; // keep width constant and adjust width to original image proportions
48 String str = new String(wmsInterface.baseURL+"/scpc/wms?version=1.1&request=GetMap");
49 str += "&layers=CDIF:PMC@";
50 str += wmsLayer.getCodeCommune();
51 str += "&format=image/png";
52 str += "&bbox=";
53 str += wmsLayer.eastNorth2raster(lambertMin, lambertMax);
54 //str += "&width=800&height=800"; // maximum allowed by wms server
55 str += "&width="+cRasterX+"&height="; // maximum allowed by wms server (576/345, 800/378, 1000/634)
56 str += (int)(cRasterX*(wmsLayer.communeBBox.max.getY() - wmsLayer.communeBBox.min.getY())/(wmsLayer.communeBBox.max.getX() - wmsLayer.communeBBox.min.getX()));
57 str += "&exception=application/vnd.ogc.se_inimage&styles=";
58 return new URL(str.replace(" ", "%20"));
59 }
60
61 private URL getURLVector(EastNorth lambertMin, EastNorth lambertMax) throws MalformedURLException {
62 String str = new String(wmsInterface.baseURL+"/scpc/wms?version=1.1&request=GetMap");
63 str += "&layers=CDIF:LS3,CDIF:LS2,CDIF:LS1,CDIF:PARCELLE,CDIF:NUMERO";
64 str += ",CDIF:PT3,CDIF:PT2,CDIF:PT1,CDIF:LIEUDIT";
65 str += ",CDIF:SUBSECTION";
66 str += ",CDIF:SECTION";
67 str += ",CDIF:COMMUNE";
68 str += "&format=image/png";
69 //str += "&format=image/jpeg";
70 str += "&bbox="+lambertMin.east()+",";
71 str += lambertMin.north() + ",";
72 str += lambertMax.east() + ",";
73 str += lambertMax.north();
74 //str += "&width=800&height=600"; // maximum allowed by wms server
75 str += "&width=1000&height=800"; // maximum allowed by wms server
76 //str += "&exception=application/vnd.ogc.se_inimage"; // used by normal client but not required
77 str += "&styles=LS3_90,LS2_90,LS1_90,PARCELLE_90,NUMERO_90,PT3_90,PT2_90,PT1_90,LIEUDIT_90";
78 str += ",SUBSECTION_90";
79 str += ",SECTION_90";
80 str += ",COMMUNE_90";
81 System.out.println("URL="+str);
82 return new URL(str.replace(" ", "%20"));
83 }
84
85 private BufferedImage grab(URL url) throws IOException, OsmTransferException {
86 wmsInterface.urlConn = (HttpURLConnection)url.openConnection();
87 wmsInterface.urlConn.setRequestMethod("GET");
88 wmsInterface.setCookie();
89 InputStream is = new ProgressInputStream(wmsInterface.urlConn, NullProgressMonitor.INSTANCE);
90 BufferedImage img = ImageIO.read(is);
91 is.close();
92 return img;
93 }
94
95 public CadastreInterface getWmsInterface() {
96 return wmsInterface;
97 }
98
99}
Note: See TracBrowser for help on using the repository browser.