⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wfsreprojectiontest.java

📁 电子地图服务器,搭建自己的地图服务
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package org.geoserver.wfs.v1_1;

import java.util.StringTokenizer;

import org.geoserver.data.test.MockData;
import org.geoserver.wfs.WFSTestSupport;
import org.geotools.referencing.CRS;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
import org.opengis.referencing.operation.MathTransform;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

public class WFSReprojectionTest extends WFSTestSupport {
    /**
     * TODO: replace this back to 900913 when bug GEOT-1563 is solved
     */
    private static final String TARGET_CRS_CODE = "EPSG:3395";
    MathTransform tx;
    
    protected void setUp() throws Exception {
        super.setUp();
    
        CoordinateReferenceSystem epsgTarget = CRS.decode(TARGET_CRS_CODE);
        CoordinateReferenceSystem epsg32615 = CRS.decode("urn:x-ogc:def:crs:EPSG:6.11.2:32615");
        
        tx = CRS.findMathTransform(epsg32615, epsgTarget);
    }
    
    public void testGetFeatureGet() throws Exception {
        
        Document dom1 = getAsDOM("wfs?request=getfeature&service=wfs&version=1.0.0&typename=" + 
            MockData.POLYGONS.getLocalPart());
        Document dom2 = getAsDOM("wfs?request=getfeature&service=wfs&version=1.0.0&typename=" + 
            MockData.POLYGONS.getLocalPart() + "&srsName=" + TARGET_CRS_CODE);
        
        runTest(dom1,dom2);
    }
    
    public void testGetFeaturePost() throws Exception {
        String xml = "<wfs:GetFeature " + "service=\"WFS\" "
        + "version=\"1.0.0\" "
        + "xmlns:cdf=\"http://www.opengis.net/cite/data\" "
        + "xmlns:ogc=\"http://www.opengis.net/ogc\" "
        + "xmlns:wfs=\"http://www.opengis.net/wfs\" " + "> "
        + "<wfs:Query typeName=\"" + 
            MockData.POLYGONS.getPrefix() + ":" + MockData.POLYGONS.getLocalPart() + "\"> "
        + "<wfs:PropertyName>cgf:polygonProperty</wfs:PropertyName> "
        + "</wfs:Query> " + "</wfs:GetFeature>";
        
        Document dom1 = postAsDOM("wfs", xml);
        print(dom1);
        
        xml = "<wfs:GetFeature " + "service=\"WFS\" "
        + "version=\"1.0.0\" "
        + "xmlns:cdf=\"http://www.opengis.net/cite/data\" "
        + "xmlns:ogc=\"http://www.opengis.net/ogc\" "
        + "xmlns:wfs=\"http://www.opengis.net/wfs\" " + "> "
        + "<wfs:Query srsName=\"" + TARGET_CRS_CODE + "\" typeName=\"" + 
            MockData.POLYGONS.getPrefix() + ":" + MockData.POLYGONS.getLocalPart() + "\"> "
        + "<wfs:PropertyName>cgf:polygonProperty</wfs:PropertyName> "
        + "</wfs:Query> " + "</wfs:GetFeature>";
        Document dom2 = postAsDOM("wfs", xml);
        print(dom2);
        
        runTest(dom1, dom2);
    }
    
    public void testGetFeatureWithProjectedBoxGet() throws Exception {
        String q = "wfs?request=getfeature&service=wfs&version=1.1&typeName=" + 
            MockData.POLYGONS.getLocalPart();
        Document dom = getAsDOM( q );
        print(dom);
        Element envelope = getFirstElementByTagName(dom, "gml:Envelope" );
        String lc = getFirstElementByTagName(envelope, "gml:lowerCorner" )
            .getFirstChild().getNodeValue();
        String uc = getFirstElementByTagName(envelope, "gml:upperCorner" )
            .getFirstChild().getNodeValue();
        double[] c = new double[]{
            Double.parseDouble(lc.split( " " )[0]), Double.parseDouble(lc.split( " " )[1]),
            Double.parseDouble(uc.split( " " )[0]), Double.parseDouble(uc.split( " " )[1]) 
        };
        double[] cr = new double[4];
        tx.transform(c, 0, cr, 0, 2);
        
        q += "&bbox=" + cr[0] + "," + cr[1] + "," + cr[2] + "," + cr[3] + "," + TARGET_CRS_CODE;
        dom = getAsDOM( q );
        
        assertEquals( 1, dom.getElementsByTagName( MockData.POLYGONS.getPrefix() + ":" + MockData.POLYGONS.getLocalPart()).getLength() );
    }
    
    public void testGetFeatureWithProjectedBoxPost() throws Exception {
        String q = "wfs?request=getfeature&service=wfs&version=1.1&typeName=" + 
            MockData.POLYGONS.getLocalPart();
        Document dom = getAsDOM( q );
        Element envelope = getFirstElementByTagName(dom, "gml:Envelope" );
        String lc = getFirstElementByTagName(envelope, "gml:lowerCorner" )
            .getFirstChild().getNodeValue();
        String uc = getFirstElementByTagName(envelope, "gml:upperCorner" )
            .getFirstChild().getNodeValue();
        double[] c = new double[]{
            Double.parseDouble(lc.split( " " )[0]), Double.parseDouble(lc.split( " " )[1]),
            Double.parseDouble(uc.split( " " )[0]), Double.parseDouble(uc.split( " " )[1]) 
        };
        double[] cr = new double[4];
        tx.transform(c, 0, cr, 0, 2);
        
        String xml = "<wfs:GetFeature service=\"WFS\" version=\"1.1.0\""
            + " xmlns:" + MockData.POLYGONS.getPrefix() + "=\"" + MockData.POLYGONS.getNamespaceURI() + "\""
            + " xmlns:ogc=\"http://www.opengis.net/ogc\" "
            + " xmlns:gml=\"http://www.opengis.net/gml\" "
            + " xmlns:wfs=\"http://www.opengis.net/wfs\" " + "> "
            + "<wfs:Query typeName=\"" + MockData.POLYGONS.getPrefix() + ":" + MockData.POLYGONS.getLocalPart() + "\">"
            + "<wfs:PropertyName>cgf:polygonProperty</wfs:PropertyName> "
            + "<ogc:Filter>" 
            +  "<ogc:BBOX>"
            +   "<ogc:PropertyName>polygonProperty</ogc:PropertyName>" 
            +   "<gml:Envelope srsName=\"" + TARGET_CRS_CODE + "\">"
            +      "<gml:lowerCorner>" + cr[0] + " " + cr[1] + "</gml:lowerCorner>"
            +      "<gml:upperCorner>" + cr[2] + " " + cr[3] + "</gml:upperCorner>"
            +   "</gml:Envelope>"  
            +  "</ogc:BBOX>" 
            + "</ogc:Filter>"
            + "</wfs:Query> " + "</wfs:GetFeature>";
        
        dom = postAsDOM( "wfs", xml );
        
        assertEquals( 1, dom.getElementsByTagName( MockData.POLYGONS.getPrefix() + ":" + MockData.POLYGONS.getLocalPart()).getLength() );
    }
    
    public void testInsertSrsName() throws Exception {
        String q = "wfs?request=getfeature&service=wfs&version=1.1&typeName=" + 
            MockData.POLYGONS.getLocalPart();
        Document dom = getAsDOM( q );
        print(dom);
        assertEquals( 1, dom.getElementsByTagName( MockData.POLYGONS.getPrefix() + ":" + MockData.POLYGONS.getLocalPart()).getLength() );
        
        Element polygonProperty = getFirstElementByTagName(dom, "cgf:polygonProperty");
        Element posList = getFirstElementByTagName( polygonProperty, "gml:posList");
        
        double[] c = posList(posList.getFirstChild().getNodeValue());
        double[] cr = new double[c.length];
        tx.transform(c, 0, cr, 0, cr.length/2);
        
        String xml = "<wfs:Transaction service=\"WFS\" version=\"1.1.0\" "
        + " xmlns:wfs=\"http://www.opengis.net/wfs\" "
        + " xmlns:gml=\"http://www.opengis.net/gml\" "
        + " xmlns:cgf=\"" + MockData.CGF_URI + "\">"
        + "<wfs:Insert handle=\"insert-1\" srsName=\"" + TARGET_CRS_CODE + "\">"
        + " <cgf:Polygons>"
        +    "<cgf:polygonProperty>"
        +      "<gml:Polygon >" 
        +       "<gml:exterior>"
        +          "<gml:LinearRing>" 
        +             "<gml:posList>";
        for ( int i = 0; i < cr.length; i++ ) {
            xml += cr[i];
            if ( i < cr.length - 1 ) {
                xml += " ";
            }
        }
        xml +=        "</gml:posList>"
        +        "</gml:LinearRing>"
        +      "</gml:exterior>"
        +    "</gml:Polygon>"
        +   "</cgf:polygonProperty>"
        + " </cgf:Polygons>"
        + "</wfs:Insert>"
        + "</wfs:Transaction>";
        postAsDOM( "wfs", xml );
        
        dom = getAsDOM( q );
        print(dom);
        assertEquals( 2, dom.getElementsByTagName( MockData.POLYGONS.getPrefix() + ":" + MockData.POLYGONS.getLocalPart()).getLength() );
        
    }
    
    public void testInsertGeomSrsName() throws Exception {
        String q = "wfs?request=getfeature&service=wfs&version=1.1&typeName=" + 
            MockData.POLYGONS.getLocalPart();
        Document dom = getAsDOM( q );
        
        Element polygonProperty = getFirstElementByTagName(dom, "cgf:polygonProperty");
        Element posList = getFirstElementByTagName( polygonProperty, "gml:posList");
        
        double[] c = posList(posList.getFirstChild().getNodeValue());
        double[] cr = new double[c.length];
        tx.transform(c, 0, cr, 0, cr.length/2);
        
        String xml = "<wfs:Transaction service=\"WFS\" version=\"1.1.0\" "
        + " xmlns:wfs=\"http://www.opengis.net/wfs\" "
        + " xmlns:gml=\"http://www.opengis.net/gml\" "
        + " xmlns:cgf=\"" + MockData.CGF_URI + "\">"
        + "<wfs:Insert handle=\"insert-1\">"
        + " <cgf:Polygons>"
        +    "<cgf:polygonProperty>"
        +      "<gml:Polygon srsName=\"" + TARGET_CRS_CODE + "\">" 
        +       "<gml:exterior>"
        +          "<gml:LinearRing>" 
        +             "<gml:posList>";
        for ( int i = 0; i < cr.length; i++ ) {
            xml += cr[i];
            if ( i < cr.length - 1 ) {
                xml += " ";
            }
        }
        xml +=        "</gml:posList>"
        +        "</gml:LinearRing>"
        +      "</gml:exterior>"
        +    "</gml:Polygon>"
        +   "</cgf:polygonProperty>"
        + " </cgf:Polygons>"
        + "</wfs:Insert>"
        + "</wfs:Transaction>";
        postAsDOM( "wfs", xml );
        
        dom = getAsDOM( q );
        
        assertEquals( 2, dom.getElementsByTagName( MockData.POLYGONS.getPrefix() + ":" + MockData.POLYGONS.getLocalPart()).getLength() );
        
    }
    
    public void testUpdate() throws Exception {
        String q = "wfs?request=getfeature&service=wfs&version=1.1&typeName=" + 
        MockData.POLYGONS.getLocalPart();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -