public void initialize(IInstance i) throws ThinklabException {

    Properties p = new Properties();
    p.putAll(Geospace.get().getProperties());
    IValue server = i.get("geospace:hasServiceUrl");
    if (server != null) p.put(WCSCoverage.WCS_SERVICE_PROPERTY, server.toString());
    IValue format = i.get("geospace:hasImageFormat");
    if (format != null) p.put(WCSCoverage.WCS_FORMAT_PROPERTY, format.toString());

    for (IRelationship r : i.getRelationships("geospace:hasNodataValue")) {
      IValue nodata = r.getValue();
      if (nodata != null) {
        String s = p.getProperty(AbstractRasterCoverage.NODATA_PROPERTY, "");
        if (s.length() > 0) s += ",";
        s += nodata.toString();
        p.put(AbstractRasterCoverage.NODATA_PROPERTY, nodata.toString());
      }
    }

    IValue transf = i.get(Geospace.HAS_TRANSFORMATION_EXPRESSION);
    if (transf != null) {
      this.transformation = new MVELExpression(transf.toString());
    }
    String rid = i.get("geospace:hasCoverageId").toString();

    Geospace.get().logger().info("reading WCS source " + server + "#" + rid);

    this.coverage = new WCSCoverage(rid, p);
  }
  /**
   * Try out all the configured WMS servers (in imagery.properties) stopping at the first one that
   * responds. The server will be in _wms after that; if none has responded, _wms will be null. It
   * will only run the search once, so it can safely be called multiple times with no performance
   * penalty, and should be called by each function that wants to use WMS imagery.
   */
  private void initializeWms() {

    if (_wms_index >= 0) return;

    for (int i = 0; ; i++) {

      String url =
          Geospace.get().getProperties().getProperty(WMS_IMAGERY_SERVER_PROPERTY + "." + i);

      if (url == null) break;

      try {
        WebMapServer wms = new WebMapServer(new URL(url));
        if (wms != null) _wms = wms;
      } catch (Exception e) {
        /* just try the next */
      }

      _wms_index = i;

      if (_wms != null) {
        break;
      }
    }
  }
Exemple #3
0
  public static void moveMapTo(OLmaps mp, ShapeValue value) {

    Coordinate p1 = null, p2 = null;
    ShapeValue env = new ShapeValue(value.getEnvelope());
    try {
      env = env.transform(Geospace.get().getStraightGeoCRS());
    } catch (ThinklabException e2) {
      throw new ThinklabRuntimeException(e2);
    }
    ReferencedEnvelope e = env.getEnvelope();

    try {
      p1 =
          JTS.transform(
              new Coordinate(e.getMinX(), e.getMinY()),
              null,
              ARIESWebappPlugin.get().geoToGoogleTransform);
      p2 =
          JTS.transform(
              new Coordinate(e.getMaxX(), e.getMaxY()),
              null,
              ARIESWebappPlugin.get().geoToGoogleTransform);

    } catch (TransformException e1) {
      // shouldn't happen
      throw new ThinklabRuntimeException(e1);
    }

    mp.setBounds(p1.x, p1.y, p2.x, p2.y);
  }
  public URL getWorldImageFile(String worldImage) throws ThinklabIOException {

    URL ret = worldImages.get(worldImage);

    if (ret != null) return ret;

    return Geospace.get().getResourceURL(worldImage);
  }
  /**
   * @param envelope
   * @param width
   * @param height
   * @return
   * @throws ThinklabResourceNotFoundException
   */
  private BufferedImage getWMSImage(Envelope envelope, int width, int height)
      throws ThinklabResourceNotFoundException {

    BufferedImage ret = null;
    initializeWms();

    String sig = envelope.toString() + "," + width + "," + height;

    if (_cache.containsKey(sig)) return ImageUtil.clone(_cache.get(sig));

    if (_wms != null) {

      GetMapRequest request = _wms.createGetMapRequest();
      request.setFormat("image/png");
      request.setDimensions("" + width, "" + height);
      request.setTransparent(true);

      // FIXME this assumes the envelope is in lat/lon
      request.setSRS("EPSG:4326");

      String bbox =
          (float) envelope.getMinX()
              + ","
              + (float) envelope.getMinY()
              + ","
              + (float) envelope.getMaxX()
              + ","
              + (float) envelope.getMaxY();

      request.setBBox(bbox);

      for (Layer layer : getWMSLayers()) {
        request.addLayer(layer);
      }

      GetMapResponse response = null;
      try {

        System.out.println(request.getFinalURL());

        response = (GetMapResponse) _wms.issueRequest(request);
        ret = ImageIO.read(response.getInputStream());
      } catch (Exception e) {
        Geospace.get().logger().warn("cannot get WFS imagery: " + e.getLocalizedMessage());
        return null;
      }

      /*
       * FIXME this obviously must have a limit
       */
      if (ret != null) _cache.put(sig, ImageUtil.clone(ret));
    }

    return ret;
  }
  private Collection<Layer> getWMSLayers() {

    String zp = Geospace.get().getProperties().getProperty(WMS_LAYER_PROPERTY + "." + _wms_index);
    ArrayList<Layer> layers = new ArrayList<Layer>();
    for (Layer l : WMSUtils.getNamedLayers(_wms.getCapabilities())) {
      if (zp == null || (zp != null && zp.contains(l.getName()))) {
        layers.add(l);
      }
    }
    return layers;
  }
Exemple #7
0
  public void setRegionFromGazetteer(String s) {

    if (s != null && !s.equals("")) {

      try {
        ShapeValue sh = Geospace.get().retrieveFeature(s);
        if (sh != null) {

          sh = sh.transform(Geospace.get().getGoogleCRS());

          userModel.resetRegionOfInterest(sh);
          selectionBar.idle(true);
          moveMapTo(map, sh);

          getVectorLayer().clearFeatures();
          getVectorLayer().addFeature("sel", sh.getWKT());
        }
      } catch (ThinklabException e1) {
        throw new ThinklabRuntimeException(e1);
      }
    }
  }
Exemple #8
0
  /**
   * Show an arbitrary shape on the world map. Only one shape can be seen at a time. If the passed
   * shape is null, just remove whatever shape is shown.
   *
   * @param sh
   */
  public void showRegion(ShapeValue sh) {

    if (shapeShown) {
      getVectorLayer().removeFeature("selection");
      shapeShown = false;
    }

    if (sh != null) {
      try {
        sh = sh.transform(Geospace.get().getGoogleCRS());
      } catch (ThinklabException e) {
        throw new ThinklabRuntimeException(e);
      }

      moveMapTo(map, sh);

      getVectorLayer().clearFeatures();
      getVectorLayer().addFeature("selection", sh.getWKT());

      this.shapeShown = true;
    }
  }
Exemple #9
0
    @Override
    public ListModel getSubModel(Object value, int nRows) {

      final String name = value == null ? "" : value.toString().trim();
      if (nRows < 0) nRows = 20;

      ArrayList<ARIESUserModel.Location> ret = new ArrayList<ARIESUserModel.Location>();

      if (name.isEmpty() && defaultValues != null) {
        ret.addAll(defaultValues);
      } else if (!name.isEmpty()) {
        try {
          IQueryResult qr = null;
          try {
            qr = Geospace.get().lookupFeature(name);
          } catch (ThinklabInvalidQueryException e) {
            // this will catch query compile errors if users write
            // strange characters or are in between writing complex
            // queries with parentheses
          }
          if (qr != null) {
            for (int i = 0; i < nRows && i < qr.getTotalResultCount(); i++) {

              ARIESUserModel.Location r = new ARIESUserModel.Location();
              r.id = qr.getResultField(i, "id");
              r.label = qr.getResultField(i, "label");
              r.description = qr.getResultField(i, "description");
              ret.add(r);
            }
          }
        } catch (ThinklabException e) {
          throw new ThinklabRuntimeException(e);
        }
      }
      ListModel rt = new SimpleListModel(ret);
      return rt;
    }