/**
   * @param pointNode the point node from which the x or y value will be extracted. For example,
   *     node is <gml:Point srsName="EPSG:31466"> <gml:coordinates cs="," decimal="." ts="
   *     ">0.0,0.0</gml:coordinates> </gml:Point>
   * @param coordIndex the coordenate index indicated whether to extract from x (index = 0)
   *     otherwise from y
   * @return the String representation of the x or y value
   * @throws GeometryException
   */
  private static String getPointXorY(Node pointNode, int coordIndex) throws GeometryException {
    String value = "";

    if (pointNode != null) {

      Geometry geometry = GMLGeometryAdapter.wrap((Element) pointNode, null);
      if (geometry instanceof Point) {
        Point p = (Point) geometry;
        double d = coordIndex == 0 ? p.getX() : p.getY();
        value = Double.toString(d);
      }
    }

    return value;
  }
  /**
   * renders one point to the submitted graphic context considering the also submitted projection
   *
   * @param g
   * @param point
   * @param projection
   * @param image
   * @param dis displacement
   */
  private void drawPoint(
      Graphics2D g, Point point, GeoTransform projection, Image image, double[] dis) {
    Envelope destSize = projection.getDestRect();
    Position source = point.getPosition();
    int x = (int) Math.round(projection.getDestX(source.getX()) + 0.5 + dis[0]);
    int y = (int) Math.round(projection.getDestY(source.getY()) + 0.5 + dis[1]);

    int x_ = x - (image.getWidth(null) >> 1);
    int y_ = y - (image.getHeight(null) >> 1);

    int dx = Math.min(image.getWidth(null), (int) destSize.getWidth() - x_);
    int dy = Math.min(image.getHeight(null), (int) destSize.getHeight() - y_);
    int tx = Math.min((int) destSize.getWidth(), x_ + image.getWidth(null));
    int ty = Math.min((int) destSize.getHeight(), y_ + image.getHeight(null));

    g.drawImage(image, x_, y_, tx, ty, 0, 0, dx, dy, null);
  }
Exemplo n.º 3
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);
      }
    }