@Test
  public void testWFSGetFeature() throws Exception {
    GetFeatureType gf = WfsFactory.eINSTANCE.createGetFeatureType();
    org.opengis.filter.Filter f1 = parseFilter("BBOX(the_geom, 40, -90, 45, -60)");
    org.opengis.filter.Filter f2 =
        parseFilter("BBOX(the_geom, 5988504.35,851278.90, 7585113.55,1950872.01)");
    QueryType q = WfsFactory.eINSTANCE.createQueryType();
    q.setTypeName(Arrays.asList(new QName("http://acme.org", "foo", "acme")));
    q.setFilter(f1);
    gf.getQuery().add(q);

    q = WfsFactory.eINSTANCE.createQueryType();
    q.setTypeName(Arrays.asList(new QName("http://acme.org", "bar", "acme")));
    gf.getQuery().add(q);
    getClass();
    q.setFilter(f2);

    Operation op = op("GetFeature", "WFS", "1.0.0", gf);
    callback.operationDispatched(new Request(), op);

    assertEquals("acme:foo", data.getResources().get(0));
    assertEquals("acme:bar", data.getResources().get(1));
    BoundingBox expected =
        new ReferencedEnvelope(53.73, 40, -60, -95.1193, CRS.decode("EPSG:4326"));
    // xMin,yMin -95.1193,40 : xMax,yMax -60,53.73
    BBoxAsserts.assertEqualsBbox(expected, data.getBbox(), 0.01);
  }
  /**
   * Takes the <code>FeatureResult</code>s generated by the <code>execute</code> method in the
   * superclass and constructs a <code>GetFeaturesResult</code> wich is passed to a <code>
   * GML2FeatureResponseDelegate</code>.
   *
   * @see AbstractFeatureInfoResponse#writeTo(OutputStream)
   */
  @SuppressWarnings({"rawtypes", "unchecked"})
  @Override
  public void write(FeatureCollectionType results, GetFeatureInfoRequest fInfoReq, OutputStream out)
      throws ServiceException, IOException {

    // the 'response' object we'll pass to our OutputFormat
    FeatureCollectionType features = WfsFactory.eINSTANCE.createFeatureCollectionType();

    // the 'request' object we'll pass to our OutputFormat
    GetFeatureType gfreq = WfsFactory.eINSTANCE.createGetFeatureType();
    gfreq.setBaseUrl(fInfoReq.getBaseUrl());

    for (Iterator i = results.getFeature().iterator(); i.hasNext(); ) {
      FeatureCollection fc = (FeatureCollection) i.next();
      features.getFeature().add(fc);

      QueryType qt = WfsFactory.eINSTANCE.createQueryType();
      String crs = GML2EncodingUtils.epsgCode(fc.getSchema().getCoordinateReferenceSystem());
      if (crs != null) {
        final String srsName = "EPSG:" + crs;
        try {
          qt.setSrsName(new URI(srsName));
        } catch (URISyntaxException e) {
          throw new ServiceException(
              "Unable to determite coordinate system for featureType "
                  + fc.getSchema().getName()
                  + ".  Schema told us '"
                  + srsName
                  + "'",
              e);
        }
      }
      gfreq.getQuery().add(qt);
    }

    // this is a dummy wrapper around our 'request' object so that the new Dispatcher will
    // accept it.
    Service serviceDesc = new Service("wms", null, null, Collections.EMPTY_LIST);
    Operation opDescriptor = new Operation("", serviceDesc, null, new Object[] {gfreq});

    final GeoServer gs = wms.getGeoServer();
    GML2OutputFormat format = new GML2OutputFormat(gs);
    format.write(features, out, opDescriptor);
  }
Пример #3
0
 /**
  * Ionic uses {@code urn:opengis:def:crs:ogc::83} instead of {@code EPSG:4269}. If that's the
  * case, the query srsName is replaced by the kown "EPSG:4269" code
  */
 @Override
 public RequestComponents createGetFeatureRequest(WFSProtocol wfs, GetFeature query)
     throws IOException {
   RequestComponents req = super.createGetFeatureRequest(wfs, query);
   GetFeatureType getFeature = req.getServerRequest();
   QueryType queryType = (QueryType) getFeature.getQuery().get(0);
   URI srsNameUri = queryType.getSrsName();
   final String overrideSrs = "urn:opengis:def:crs:ogc::83";
   if (srsNameUri != null && srsNameUri.toString().equalsIgnoreCase(overrideSrs)) {
     try {
       queryType.setSrsName(new URI("EPSG:4269"));
     } catch (URISyntaxException e) {
       throw new RuntimeException("shouln't happen: " + e.getMessage());
     }
     Map<String, String> kvpParameters = req.getKvpParameters();
     kvpParameters.put("SRSNAME", "EPSG:4269");
   }
   return req;
 }