コード例 #1
0
  public void testInsertSrsName() throws Exception {
    String q =
        "wfs?request=getfeature&service=wfs&version=1.1&typeName="
            + MockData.POLYGONS.getLocalPart();
    Document dom = getAsDOM(q);
    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());
  }
コード例 #2
0
  @Test
  public void testReproject() throws Exception {
    FeatureTypeInfo fti = getCatalog().getFeatureTypeByName(MockData.POLYGONS.getLocalPart());
    assertEquals("EPSG:4326", fti.getSRS());
    assertEquals(ProjectionPolicy.REPROJECT_TO_DECLARED, fti.getProjectionPolicy());
    FeatureCollection fc = fti.getFeatureSource(null, null).getFeatures();
    assertEquals(CRS.decode("EPSG:4326"), fc.getSchema().getCoordinateReferenceSystem());
    FeatureIterator fi = fc.features();
    Feature f = fi.next();

    // test that geometry was actually reprojected
    Geometry g = (Geometry) f.getDefaultGeometryProperty().getValue();
    assertFalse(
        g.equalsExact(
            WKT.read(
                "POLYGON((500225 500025,500225 500075,500275 500050,500275 500025,500225 500025))")));
    fi.close();
    assertEquals(CRS.decode("EPSG:4326"), f.getType().getCoordinateReferenceSystem());
  }
コード例 #3
0
  public void testUpdate() throws Exception {
    String q =
        "wfs?request=getfeature&service=wfs&version=1.1&typeName="
            + MockData.POLYGONS.getLocalPart();

    Document dom = getAsDOM(q);
    //        print(dom);

    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);

    // perform an update
    String xml =
        "<wfs:Transaction service=\"WFS\" version=\"1.1.0\" "
            + "xmlns:cgf=\"http://www.opengis.net/cite/geometry\" "
            + "xmlns:ogc=\"http://www.opengis.net/ogc\" "
            + "xmlns:wfs=\"http://www.opengis.net/wfs\" "
            + "xmlns:gml=\"http://www.opengis.net/gml\"> "
            + "<wfs:Update typeName=\"cgf:Polygons\" > "
            + "<wfs:Property>"
            + "<wfs:Name>polygonProperty</wfs:Name>"
            + "<wfs:Value>"
            + "<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>"
            + "</wfs:Value>"
            + "</wfs:Property>"
            + "<ogc:Filter>"
            + "<ogc:PropertyIsEqualTo>"
            + "<ogc:PropertyName>id</ogc:PropertyName>"
            + "<ogc:Literal>t0002</ogc:Literal>"
            + "</ogc:PropertyIsEqualTo>"
            + "</ogc:Filter>"
            + "</wfs:Update>"
            + "</wfs:Transaction>";

    dom = postAsDOM("wfs", xml);
    assertEquals("wfs:TransactionResponse", dom.getDocumentElement().getNodeName());
    Element totalUpdated = getFirstElementByTagName(dom, "wfs:totalUpdated");
    assertEquals("1", totalUpdated.getFirstChild().getNodeValue());

    dom = getAsDOM(q);
    polygonProperty = getFirstElementByTagName(dom, "cgf:polygonProperty");
    posList = getFirstElementByTagName(polygonProperty, "gml:posList");
    double[] c1 = posList(posList.getFirstChild().getNodeValue());

    assertEquals(c.length, c1.length);
    for (int i = 0; i < c.length; i++) {
      int x = (int) (c[i] + 0.5);
      int y = (int) (c1[i] + 0.5);

      assertEquals(x, y);
    }
  }