Ejemplo n.º 1
0
 public void createArc() {
   List<Point> points = drawingPane.getDrawObjectsAsGeoPoints();
   ApplicationContainer<?> appCont = digitizerModule.getApplicationContainer();
   if (points.size() >= 3) {
     try {
       Curve curve =
           GeometryUtils.calcCircleCoordinates(
               points.get(0).getPosition(),
               getRadius(),
               getNoOfVertices(),
               points.get(1).getPosition(),
               points.get(2).getPosition(),
               points.get(1).getCoordinateSystem());
       MapModel mapModel = appCont.getMapModel(null);
       Layer layer = mapModel.getLayersSelectedForAction(MapModel.SELECTION_EDITING).get(0);
       FeatureAdapter featureAdapter = (FeatureAdapter) layer.getDataAccess().get(0);
       FeatureType ft = featureAdapter.getSchema();
       Feature feat = featureAdapter.getDefaultFeature(ft.getName());
       feat = feat.cloneDeep();
       QualifiedName geomProperty = ft.getGeometryProperties()[0].getName();
       feat.getProperties(geomProperty)[0].setValue(curve);
       Command cmd = new InsertFeatureCommand(featureAdapter, feat);
       appCont.getCommandProcessor().executeSychronously(cmd, true);
     } catch (Exception ex) {
       LOG.logError(ex);
       DialogFactory.openErrorDialog(
           appCont.getViewPlatform(),
           DrawArcDialog.this,
           Messages.getMessage(getLocale(), "$MD11628"),
           Messages.getMessage(getLocale(), "$MD11629"),
           ex);
     }
   }
 }
Ejemplo n.º 2
0
  /**
   * Method getNames
   *
   * @param rootfeat feature where starting the search
   * @param name name of the feature to search for
   * @return ArrayList<String>
   */
  private Feature findFeature(Feature rootfeat, String name) {
    Object[] fp = rootfeat.getProperties();

    // find out subcollections
    for (int i = 0; i < fp.length; i++) {
      Object o = fp[i];

      if (o instanceof FeatureCollection) {
        FeatureCollection fc = (FeatureCollection) o;
        Feature[] feats = fc.getAllFeatures();

        for (int j = 0; j < feats.length; j++) // foreach feature in the collection
        {
          if (feats[j].getFeatureType().getProperty(name) != null) // if it's ok, return it
          {
            return feats[j];
          }

          // else perform a subsearch
          Feature find = findFeature(feats[j], name);

          if (find != null) {
            return find;
          }
        }
      }
    }

    return null;
  }
Ejemplo n.º 3
0
  /**
   * Method getProperty
   *
   * @param feature a Feature
   * @param value a String
   * @return an Object
   */
  private Object getProperty(Feature feature, String value) throws FilterEvaluationException {
    if (feature.getFeatureType().getProperty(value) != null) {
      return feature.getProperty(value);
    }

    Feature found = findFeature(feature, value);
    System.out.println("Feature" + found); // MMDEBUG

    if (found != null) {
      return found.getProperty(value);
    } else {
      throw new FilterEvaluationException(
          "FeatureType '"
              + feature.getFeatureType().getName()
              + "' has no property with name '"
              + value
              + "'!");
    }
  }
Ejemplo n.º 4
0
  private boolean isTargetCRS(Feature feature, CoordinateSystem targetCRS)
      throws CRSTransformationException, GeometryException {

    FeatureProperty[] fp = feature.getProperties();
    for (int i = 0; i < fp.length; i++) {

      if (fp[i].getValue() instanceof Geometry) {
        Geometry geom = (Geometry) fp[i].getValue();
        if (!targetCRS.equals(geom.getCoordinateSystem())) {
          LOG.logInfo(geom.getCoordinateSystem().getIdentifier());
          LOG.logInfo(" - " + targetCRS.getIdentifier());
          return false;
        }
      } else if (fp[i].getValue() instanceof Feature) {
        if (!isTargetCRS((Feature) fp[i].getValue(), targetCRS)) {
          return false;
        }
      }
    }

    return true;
  }
Ejemplo n.º 5
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()));
    }
  }
Ejemplo n.º 6
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);
      }
    }