Geoserver中如何將CQL轉換OGC的xml過濾,針對這個問題,這篇文章詳細介紹了相對應的分析和解答,希望可以幫助更多想解決這個問題的小伙伴找到更簡單易行的方法。
在Geoserver的wfs查詢中,支持CQL的數據查詢過濾,但是常用的OGC的查詢中,是以post的形式,通過傳遞一個xml文件的格式,返回查詢數據的結果。這在arcgis server,sfs server中都能夠進行支持的,因為這些服務都支持OGC的標準查詢。
CQL使用類似文本語法的格式,具有很高的可讀性和適用性。
這里分享一個使用GeoTools將CQL轉換為OGC過濾查詢的代碼樣例,具體的英文網址在原文鏈接中。
GeoTools是一個開源的java版gis工具集,里邊有許多gis方面的相關方法,可在網上直接下載編譯好的jar包進行使用。
轉換代碼如下:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import org.geotools.filter.text.cql2.CQL;
import org.geotools.filter.text.cql2.CQLException;
import org.opengis.filter.Filter;
public class CQLToOGC {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String line;
org.geotools.xml.Configuration configuration = new org.geotools.filter.v1_0.OGCConfiguration();
org.geotools.xml.Encoder encoder = new org.geotools.xml.Encoder(
configuration);
encoder.setIndenting(true);
while (!(line = reader.readLine()).isEmpty()) {
try {
Filter filter = CQL.toFilter(line);
// System.out.println("\t" + filter);
encoder.encode(filter, org.geotools.filter.v1_0.OGC.Filter, System.out);
} catch (CQLException e) {
e.printStackTrace();
}
}
}}轉換的結果:
CQL樣式
prop = 23
轉換結果:
<?xml version="1.0" encoding="UTF-8"?><ogc:Filter xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ogc="http://www.opengis.net/ogc" xmlns:gml="http://www.opengis.net/gml">
<ogc:PropertyIsEqualTo>
<ogc:PropertyName>prop</ogc:PropertyName>
<ogc:Literal>23</ogc:Literal>
</ogc:PropertyIsEqualTo></ogc:Filter>
空間查詢轉換的效果:
CQL語句:
INTERSECTS(SP_GEOMETRY, POLYGON ((142578.64599609 252217.79003906, 73781.897460938 141983.61767578, 287078.38037109 146764.85888672, 142578.64599609 252217.79003906)))
轉換結果:
<?xml version="1.0" encoding="UTF-8"?><ogc:Filter xmlns:ogc="http://www.opengis.net/ogc" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:gml="http://www.opengis.net/gml">
<ogc:Intersects>
<ogc:PropertyName>SP_GEOMETRY</ogc:PropertyName>
<gml:Polygon>
<gml:outerBoundaryIs>
<gml:LinearRing>
<gml:coordinates>142578.64599609,252217.79003906 73781.897460938,141983.61767578 287078.38037109,146764.85888672 142578.64599609,252217.79003906</gml:coordinates>
</gml:LinearRing>
</gml:outerBoundaryIs>
</gml:Polygon>
</ogc:Intersects></ogc:Filter>
關于Geoserver中如何將CQL轉換OGC的xml過濾問題的解答就分享到這里了,希望以上內容可以對大家有一定的幫助,如果你還有很多疑惑沒有解開,可以關注億速云行業資訊頻道了解更多相關知識。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。