コード例 #1
0
  GmlResult handleRequest(GetGmlObject request) {
    if (!config.hasUniquePrefixMapping()) {
      return new GmlResult(
          request, new InconsistentRequestException(get("WFS_CONF_FT_PREFICES_NOT_UNIQUE2")));
    }
    String objectId = request.getObjectId();
    MappedFeatureType type = config.getFeatureType(objectId);

    if (type == null) {
      LOG.logDebug("The GML type could not be determined for the incoming GMLObjectID");
      return new GmlResult(
          request,
          new InvalidParameterValueException("getgmlobject", get("WFS_NO_SUCH_FEATURE", objectId)));
    }

    if (type.isAbstract()) {
      String msg = Messages.getMessage("WFS_FEATURE_TYPE_ABSTRACT", type.getName());
      return new GmlResult(request, new OGCWebServiceException("getgmlobject", msg));
    }
    if (!type.isVisible()) {
      String msg = Messages.getMessage("WFS_FEATURE_TYPE_INVISIBLE", type.getName());
      return new GmlResult(request, new OGCWebServiceException("getgmlobject", msg));
    }

    int idx = objectId.indexOf("_GEOM_");
    int geom = -1;
    if (idx > 0) {
      try {
        geom = parseInt(objectId.substring(idx + 6));
      } catch (NumberFormatException e) {
        LOG.logDebug("Stack trace: ", e);
        return new GmlResult(
            request,
            new InvalidParameterValueException(
                "getgmlobject", get("WFS_NO_SUCH_FEATURE", request.getObjectId())));
      }
      objectId = objectId.substring(0, idx);
      LOG.logDebug("Trying to find geometry object number " + geom);
    }

    LOG.logDebug("Feature ID: ", objectId);

    Set<FeatureId> set = singleton(new FeatureId(objectId));
    Filter filter = new FeatureFilter(new ArrayList<FeatureId>(set));

    Datastore ds = type.getGMLSchema().getDatastore();

    Query q =
        new Query(
            null,
            null,
            null,
            null,
            null,
            new QualifiedName[] {type.getName()},
            null,
            null,
            filter,
            null,
            -1,
            -1);
    try {
      FeatureCollection col = ds.performQuery(q, new MappedFeatureType[] {type});
      if (col.size() == 0) {
        return new GmlResult(
            request,
            new InvalidParameterValueException(
                "getgmlobject", get("WFS_NO_SUCH_FEATURE", request.getObjectId())));
      }
      Feature feature = col.getFeature(0);

      // different formats are not supported anyway, so just use the first one
      FormatType format =
          config.getFeatureTypeList().getFeatureType(type.getName()).getOutputFormats()[0];

      if (geom > -1) {
        try {
          return new GmlResult(request, feature.getGeometryPropertyValues()[geom], format);
        } catch (ArrayIndexOutOfBoundsException e) {
          return new GmlResult(
              request,
              new InvalidParameterValueException(
                  "getgmlobject", get("WFS_NO_SUCH_FEATURE", request.getObjectId())));
        }
      }

      return new GmlResult(request, feature, format);
    } catch (DatastoreException e) {
      LOG.logDebug("Stack trace: ", e);
      return new GmlResult(request, new OGCWebServiceException("getgmlobject", e.getMessage()));
    } catch (UnknownCRSException e) {
      LOG.logDebug("Stack trace: ", e);
      return new GmlResult(request, new OGCWebServiceException("getgmlobject", e.getMessage()));
    }
  }
コード例 #2
0
ファイル: IndexFrame.java プロジェクト: camptocamp/secureOWS
    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);
      }
    }