private static boolean intersects(
      Envelope requestEnv, String requestCrs, Envelope regionEnv, String regionCrs)
      throws CRSException, GeometryException, CRSTransformationException, UnknownCRSException {
    Surface request = GeometryFactory.createSurface(requestEnv, CRSFactory.create(requestCrs));
    Surface region = GeometryFactory.createSurface(regionEnv, CRSFactory.create(regionCrs));

    if (!requestCrs.equalsIgnoreCase(regionCrs)) {
      GeoTransformer gt = new GeoTransformer(requestCrs);
      region = (Surface) gt.transform(region);
    }

    return request.intersects(region);
  }
  /**
   * zooms the current map by a factor and recenters it to the point the user has clicked to.
   *
   * @throws PortalException
   * @throws ContextException
   */
  void zoom() throws PortalException, ContextException {

    ViewContext vc = getCurrentViewContext(portlet.getID());
    MapModelAccess mma = new DefaultMapModelAccess(vc);

    String tmp = parameter.get(PARAM_FACTOR);
    if (tmp == null) {
      throw new PortalException("FACTOR must be set for zoom operation!");
    }
    double factor = Double.parseDouble(tmp);

    tmp = parameter.get(PARAM_CLICKPOINT);
    if (tmp != null) {
      // zoom by pixel coordinates
      double coords[] = StringTools.toArrayDouble(tmp, ",");
      java.awt.Point point = new java.awt.Point((int) coords[0], (int) coords[1]);
      vc = mma.zoom(point, factor);
    } else {
      // zoom by map coordinates
      tmp = parameter.get(PARAM_MAPPOINT);
      if (tmp == null) {
        throw new PortalException(
            "at least a CLICKPOINT or a MAPPOINT must be defined for zoom operation!");
      }
      double coords[] = StringTools.toArrayDouble(tmp, ",");
      Point point = GeometryFactory.createPoint(coords[0], coords[1], null);
      vc = mma.zoom(point, factor);
    }
    setCurrentMapContext(vc, portlet.getID());
  }
 /**
  * Parse Layer Bounding Boxes
  *
  * @param nl
  * @return LayerBoundingBox[]
  * @throws XMLParsingException
  */
 protected LayerBoundingBox[] parseLayerBoundingBoxes(List nl) throws XMLParsingException {
   LOG.entering();
   LayerBoundingBox[] llBoxes = new LayerBoundingBox[nl.size()];
   for (int i = 0; i < llBoxes.length; i++) {
     double minx = XMLTools.getRequiredNodeAsDouble((Node) nl.get(i), "./@minx", nsContext);
     double maxx = XMLTools.getRequiredNodeAsDouble((Node) nl.get(i), "./@maxx", nsContext);
     double miny = XMLTools.getRequiredNodeAsDouble((Node) nl.get(i), "./@miny", nsContext);
     double maxy = XMLTools.getRequiredNodeAsDouble((Node) nl.get(i), "./@maxy", nsContext);
     double resx = XMLTools.getNodeAsDouble((Node) nl.get(i), "./@resx", nsContext, -1);
     double resy = XMLTools.getNodeAsDouble((Node) nl.get(i), "./@resx", nsContext, -1);
     String srs = XMLTools.getRequiredNodeAsString((Node) nl.get(i), "./@SRS", nsContext);
     Position min = GeometryFactory.createPosition(minx, miny);
     Position max = GeometryFactory.createPosition(maxx, maxy);
     llBoxes[i] = new LayerBoundingBox(min, max, srs, resx, resy);
   }
   LOG.exiting();
   return llBoxes;
 }
  /**
   * This creates a MultiPoint object.
   *
   * @see org.deegree.io.shpapi.shape_new.Shape#getGeometry()
   */
  public Geometry getGeometry() throws ShapeGeometryException {
    if (points == null) {
      return null;
    }
    Point[] ps = new Point[points.length];

    for (int i = 0; i < ps.length; ++i) {
      ps[i] = (Point) points[i].getGeometry();
    }

    return GeometryFactory.createMultiPoint(ps, crs);
  }
예제 #5
0
  /** updates geometry with current ({@link #spArcRadius}) radius */
  private void applyRadius() {
    List<Point> points = drawingPane.getDrawObjectsAsGeoPoints();
    if (points.size() > 2) {
      // calculate new end point for first vector
      double[] lineParam =
          LineUtils.getLineFromPoints(
              points.get(0).getX(), points.get(0).getY(),
              points.get(1).getX(), points.get(1).getY());
      Pair<Position, Position> pair1 =
          LineUtils.getSymmetricPoints(
              points.get(0).getX(), points.get(0).getY(), lineParam[0], getRadius());

      // calculate new end point for second vector
      lineParam =
          LineUtils.getLineFromPoints(
              points.get(0).getX(), points.get(0).getY(),
              points.get(2).getX(), points.get(2).getY());
      Pair<Position, Position> pair2 =
          LineUtils.getSymmetricPoints(
              points.get(0).getX(), points.get(0).getY(), lineParam[0], getRadius());
      // must check to ensure correct direction
      if (points.get(1).getX() >= points.get(0).getX()) {
        points.set(
            1, GeometryFactory.createPoint(pair1.first, points.get(0).getCoordinateSystem()));
      } else {
        points.set(
            1, GeometryFactory.createPoint(pair1.second, points.get(0).getCoordinateSystem()));
      }
      if (points.get(2).getX() >= points.get(0).getX()) {
        points.set(
            2, GeometryFactory.createPoint(pair2.first, points.get(0).getCoordinateSystem()));
      } else {
        points.set(
            2, GeometryFactory.createPoint(pair2.second, points.get(0).getCoordinateSystem()));
      }
      digitizerModule.getMapModule().update();
    }
  }
  /**
   * Parse Lat Lon Bounding Box
   *
   * @param llBox
   * @return Envelope
   * @throws XMLParsingException
   * @throws UnknownCRSException
   */
  protected Envelope parseLatLonBoundingBox(Element llBox)
      throws XMLParsingException, UnknownCRSException {
    LOG.entering();

    double minx = XMLTools.getRequiredNodeAsDouble(llBox, "./@minx", nsContext);
    double maxx = XMLTools.getRequiredNodeAsDouble(llBox, "./@maxx", nsContext);
    double miny = XMLTools.getRequiredNodeAsDouble(llBox, "./@miny", nsContext);
    double maxy = XMLTools.getRequiredNodeAsDouble(llBox, "./@maxy", nsContext);
    /** default crs = EPSG:4326 */
    CoordinateSystem crs = CRSFactory.create("EPSG:4326");
    Envelope env = GeometryFactory.createEnvelope(minx, miny, maxx, maxy, crs);

    LOG.exiting();
    return env;
  }
  private static boolean intersects(
      Envelope envelope, Code reqCRS, Envelope[] envs, LonLatEnvelope llEnv)
      throws UnknownCRSException {

    boolean res = false;
    String reqCRSCode = reqCRS.getCode();

    try {
      if (envs == null || envs.length == 0) {
        Envelope latlonEnv =
            GeometryFactory.createEnvelope(
                llEnv.getMin().getX(),
                llEnv.getMin().getY(),
                llEnv.getMax().getX(),
                llEnv.getMax().getY(),
                CRSFactory.create("EPSG:4326"));

        if (!"EPSG:4326".equals(reqCRSCode)) {
          res = intersects(envelope, reqCRSCode, latlonEnv, "EPSG:4326");
        } else {
          res = envelope.intersects(latlonEnv);
        }
      } else {
        for (int i = 0; i < envs.length && !res; i++) {
          if (intersects(
              envelope, reqCRSCode, envs[i], envs[i].getCoordinateSystem().getPrefixedName())) {
            res = true;
            break;
          }
        }
      }
    } catch (GeometryException ex) {
      LOG.logWarning("intersection test; translation into surface failed", ex);
    } catch (CRSException ex) {
      LOG.logWarning(
          "intersection test; transformation of reqeust envelope/valid area impossible", ex);
    } catch (CRSTransformationException ex) {
      LOG.logWarning("intersection test; transformation of reqeust envelope/valid area failed", ex);
    }
    return res;
  }
  /** return the LonLatEnvelope of the entire image in "EPSG:4326" */
  private Envelope getLLEAsEnvelope() {
    String code = getNativeSRSCode();
    LonLatEnvelope lle = description.getLonLatEnvelope();
    Envelope tmp =
        GeometryFactory.createEnvelope(
            lle.getMin().getX(),
            lle.getMin().getY(),
            lle.getMax().getX(),
            lle.getMax().getY(),
            null);
    try {
      if (!code.equals("EPSG:4326")) {
        GeoTransformer trans = new GeoTransformer(code);
        tmp = trans.transform(tmp, "EPSG:4326");
      }
    } catch (Exception e) {
      LOGGER.logError(StringTools.stackTraceToString(e));
    }

    return tmp;
  }
예제 #9
0
    public void run() {
      Container container = getContentPane();
      container.removeAll();
      container.setLayout(new GridLayout(3, 1));

      int features = shapeFile.getRecordNum();
      container.add(new JLabel("Indexing..."));
      JProgressBar progressBar = new JProgressBar(1, features);
      progressBar.setStringPainted(true);
      container.add(progressBar);
      cancel = new JButton("Cancel");
      cancel.addActionListener(frame);
      container.add(cancel);
      pack();

      boolean geometry = false;
      DBaseIndex[] index = new DBaseIndex[properties.length];
      RTree rtree = null;

      try {
        String[] dataTypes = shapeFile.getDataTypes();
        int[] lengths = shapeFile.getDataLengths();

        if (geometryCheckBox.isSelected() && !hasGeometry) {
          geometry = true;
          rtree = new RTree(2, 11, fileName + ".rti");
        }

        boolean indexes = false;
        for (int i = 0; i < index.length; i++) {
          if (checkboxes[i].isSelected() && !hasIndex[i]) {
            index[i] =
                DBaseIndex.createIndex(
                    fileName + "$" + properties[i],
                    properties[i],
                    lengths[i],
                    uniqueBoxes[i].isSelected(),
                    (dataTypes[i].equalsIgnoreCase("N")
                        || dataTypes[i].equalsIgnoreCase("I")
                        || dataTypes[i].equalsIgnoreCase("F")));
            indexes = true;
          } else index[i] = null;
        }

        if (geometry || indexes) {
          for (int i = 1; i < features + 1; i++) {
            Feature feature = shapeFile.getFeatureByRecNo(i);

            if (geometry) {
              Geometry[] geometries = feature.getGeometryPropertyValues();
              if (geometries.length == 0) {
                LOG.logInfo("no geometries at recno" + i);
                continue;
              }
              Envelope envelope = null;
              // TODO: deal with more than one geometry; handle geometry=null (allowed
              // in shapefile)
              envelope = (feature.getDefaultGeometryPropertyValue()).getEnvelope();
              if (envelope == null) { // assume a Point-geometry
                Point pnt = (Point) geometries[0];
                envelope =
                    GeometryFactory.createEnvelope(
                        pnt.getX(), pnt.getY(), pnt.getX(), pnt.getY(), null);
              }
              HyperBoundingBox box =
                  new HyperBoundingBox(
                      new HyperPoint(envelope.getMin().getAsArray()),
                      new HyperPoint(envelope.getMax().getAsArray()));
              rtree.insert(new Integer(i), box);
            }

            for (int j = 0; j < index.length; j++) {
              if (index[j] != null) {
                QualifiedName qn = new QualifiedName(properties[j]);
                index[j].addKey((Comparable) feature.getDefaultProperty(qn), i);
              }
            }

            progressBar.setValue(i);

            synchronized (this) {
              if (stop) {
                shapeFile.close();
                if (geometry) {
                  rtree.close();
                  new File(fileName + ".rti").delete();
                }
                for (int j = 0; j < index.length; j++) {
                  if (index[j] != null) {
                    index[j].close();
                    new File(fileName + "$" + properties[j] + ".ndx").delete();
                  }
                }
                System.exit(3);
              }
            }
          }
        }

        try {
          if (geometry) {
            rtree.close();
          }
          shapeFile.close();

          for (int i = 0; i < index.length; i++) if (index[i] != null) index[i].close();
        } catch (Exception e) {
          e.printStackTrace();
          JOptionPane.showMessageDialog(frame, e);
          System.exit(1);
        }

        if (!geometryCheckBox.isSelected() && hasGeometry) {
          new File(fileName + ".rti").delete();
        }

        for (int i = 0; i < index.length; i++) {
          if (!checkboxes[i].isSelected() && hasIndex[i]) {
            new File(fileName + "$" + properties[i] + ".ndx").delete();
          }
        }

        System.exit(0);
      } catch (Exception ex) {
        ex.printStackTrace();
        JOptionPane.showMessageDialog(frame, ex);
        System.exit(1);
      }
    }
  /**
   * returns the layers offered by the WMPS
   *
   * @param layerElem
   * @param parent
   * @return Layer
   * @throws XMLParsingException
   * @throws UnknownCRSException
   */
  protected Layer parseLayers(Element layerElem, Layer parent)
      throws XMLParsingException, UnknownCRSException {
    LOG.entering();

    boolean queryable = XMLTools.getNodeAsBoolean(layerElem, "./@queryable", nsContext, false);

    int cascaded = XMLTools.getNodeAsInt(layerElem, "./@cascaded", nsContext, 0);
    boolean opaque = XMLTools.getNodeAsBoolean(layerElem, "./@opaque", nsContext, false);
    boolean noSubsets = XMLTools.getNodeAsBoolean(layerElem, "./@noSubsets", nsContext, false);
    int fixedWidth = XMLTools.getNodeAsInt(layerElem, "./@fixedWidth", nsContext, 0);
    int fixedHeight = XMLTools.getNodeAsInt(layerElem, "./@fixedHeight", nsContext, 0);
    String name = XMLTools.getNodeAsString(layerElem, "./Name", nsContext, null);
    String title = XMLTools.getRequiredNodeAsString(layerElem, "./Title", nsContext);
    String layerAbstract = XMLTools.getNodeAsString(layerElem, "./Abstract", nsContext, null);
    String[] keywords = XMLTools.getNodesAsStrings(layerElem, "./KeywordList/Keyword", nsContext);
    String[] srs = XMLTools.getNodesAsStrings(layerElem, "./SRS", nsContext);

    List nl = XMLTools.getNodes(layerElem, "./BoundingBox", nsContext);
    // TODO substitue with Envelope
    LayerBoundingBox[] bboxes = null;
    if (nl.size() == 0 && parent != null) {
      // inherit BoundingBoxes from parent layer
      bboxes = parent.getBoundingBoxes();
    } else {
      bboxes = parseLayerBoundingBoxes(nl);
    }

    Element llBox = (Element) XMLTools.getNode(layerElem, "./LatLonBoundingBox", nsContext);
    Envelope llBoundingBox = null;

    if (llBox == null && parent != null) {
      // inherit LatLonBoundingBox parent layer
      llBoundingBox = parent.getLatLonBoundingBox();
    } else if (llBox != null) {
      llBoundingBox = parseLatLonBoundingBox(llBox);
    } else {
      /** Default crs = EPSG:4326 */
      CoordinateSystem crs = CRSFactory.create("EPSG:4326");
      llBoundingBox = GeometryFactory.createEnvelope(-180, -90, 180, 90, crs);
    }

    Dimension[] dimensions = parseDimensions(layerElem);

    Extent[] extents = parseExtents(layerElem);

    Attribution attribution = parseAttribution(layerElem);

    AuthorityURL[] authorityURLs = parseAuthorityURLs(layerElem);

    MetadataURL[] metadataURLs = parseMetadataURLs(layerElem);

    DataURL[] dataURLs = parseDataURL(layerElem);

    Identifier[] identifiers = parseIdentifiers(layerElem);

    FeatureListURL[] featureListURLs = parseFeatureListURL(layerElem);

    Style[] styles = parseStyles(layerElem);

    ScaleHint scaleHint = parseScaleHint(layerElem);

    Layer layer =
        new Layer(
            queryable,
            cascaded,
            opaque,
            noSubsets,
            fixedWidth,
            fixedHeight,
            name,
            title,
            layerAbstract,
            llBoundingBox,
            attribution,
            scaleHint,
            keywords,
            srs,
            bboxes,
            dimensions,
            extents,
            authorityURLs,
            identifiers,
            metadataURLs,
            dataURLs,
            featureListURLs,
            styles,
            null,
            null,
            parent);

    // get Child layers
    nl = XMLTools.getNodes(layerElem, "./Layer", nsContext);
    Layer[] layers = new Layer[nl.size()];
    for (int i = 0; i < layers.length; i++) {
      layers[i] = parseLayers((Element) nl.get(i), layer);
    }

    // set child layers
    layer.setLayer(layers);

    LOG.exiting();
    return layer;
  }