1. 程式人生 > >arcgis呼叫國家天地圖wfs服務

arcgis呼叫國家天地圖wfs服務

public class Simapledemo {

    /**
     * 該程式簡單給出一個請求天地圖wfs服務的簡單市裡,請求串按字串拼接的形式給出,XMl格式的請求可以根據給出的請求串自行生成
     * 請求記錄最多支援300條
     * 不支援只含有*的搜尋,必須有明確的搜尋關鍵詞
     * 目前不支援視野內搜尋,不支援統計搜尋,如果需要的可以等待我們網站api出爐
     * 搜尋格式 全國搜尋 在 <ogc:Literal>***北京 超市**</ogc:Literal>  *之間只輸入關鍵字就可以  如果指定城市搜尋 輸入 城市名 + “ ” +搜尋關鍵字
     * 
@param args */ public static void main(String[] args) throws Exception { try { URL url = new URL("http://www.tianditu.com/wfssearch.shtml"); HttpURLConnection con = (HttpURLConnection) url.openConnection(); con.setDoOutput(true); con.setRequestMethod(
"POST"); OutputStream out = con.getOutputStream(); String strQuest = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<wfs:GetFeature maxFeatures=\"100\" service=\"WFS\" version=\"1.0.0\" xsi:schemaLocation=\"http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/wfs.xsd\" xmlns:wfs=\"http://www.opengis.net/wfs\" xmlns:gml=\"http://www.opengis.net/gml\" xmlns:ogc=\"http://www.opengis.net/ogc\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"> " + " <wfs:Query typeName=\"DOMAIN_POI_NEW\" srsName=\"EPSG:4326\">" + "<ogc:Filter>" + "<ogc:And> " + "<ogc:PropertyIsLike wildCard=\"*\" singleChar=\".\" escape=\"!\"> " + " <ogc:PropertyName>NAME</ogc:PropertyName>" + " <ogc:Literal>***北京 超市**</ogc:Literal> " + //
請求的時候僅需要替換 超市 這個關鍵詞就好,如果指定城市搜尋,搜尋關鍵詞為指定城市的名稱 加上空格要搜尋的關鍵字就可以 "</ogc:PropertyIsLike>" + " </ogc:And>" + "</ogc:Filter>" + "</wfs:Query>" + "</wfs:GetFeature>"; out.write(strQuest.getBytes()); out.close(); BufferedReader br = new BufferedReader(new InputStreamReader(con .getInputStream())); String line = ""; FileWriter fw = null; fw = new FileWriter("seachresult.xml", false); for (line = br.readLine(); line != null; line = br.readLine()) { fw.write(line); System.out.println(line); } fw.close(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } }