@Override
 public MultiLineString apply(LineString object) throws UnconvertibleObjectException {
   final MultiLineString geom =
       object.getFactory().createMultiLineString(new LineString[] {object});
   geom.setSRID(object.getSRID());
   geom.setUserData(object.getUserData());
   return geom;
 }
Esempio n. 2
0
  /**
   * Adds an Edge, DirectedEdges, and Nodes for the given LineString representation of an edge.
   * Snaps all vertices according to GraphParams.GLOBAL_SNAP_DIST
   *
   * @param lineString
   * @param id : the id coming out of OSM
   */
  public void addLineString(
      LineString lineString, int id, short envType, short cykType, double groenM) {

    distancesCalculated = false;

    if (lineString.isEmpty()) {
      return;
    }
    if (lineString.getCoordinates().length < 2) {
      System.exit(1);
    }

    Coordinate[] coordinates = lineString.getCoordinates();
    modifyEnvelope(coordinates);

    if (GraphParams.getInstance().getSnap()) {
      double sd = GraphParams.getInstance().getSnapDistance();
      for (Coordinate c : coordinates) {
        c.x = c.x - (c.x % sd);
        c.y = c.y - (c.y % sd);
      }
    }

    Edge edge = getLineMergeGraphH4cked().addEdge(lineString);
    edgeId__edge.put(id, edge);
    if (edge != null) { // edge might not have been added because of coinciding coordinates
      if (lineString.getUserData() == null) lineString.setUserData(new HashMap<String, Object>(3));
      @SuppressWarnings("unchecked")
      HashMap<String, Object> userdata = (HashMap<String, Object>) lineString.getUserData();
      // HashMap<String, Object> hm = new HashMap<String, Object>();

      userdata.put("id", id);
      userdata.put("et", envType);
      userdata.put("ct", cykType);
      userdata.put("gm", groenM); // groenM
      userdata.put("geom", lineString);
      edge.setData(userdata);

      // add edge data to the spatial index

    }
  }
  /**
   * Create a new instance of the builder giving the split line, the feature list and the CRS which
   * the operation will be based on.
   *
   * @param featureList A non empty list of features.
   * @param splitLine The split line.
   * @param desiredCRS the crs where the split operation is done it
   * @return a new instance of the builder.
   */
  public static SplitFeatureBuilder newInstance(
      final List<SimpleFeature> featureList,
      final LineString splitLine,
      final CoordinateReferenceSystem desiredCRS)
      throws SplitFeatureBuilderFailException {

    if (featureList == null)
      throw new NullPointerException("The source feature list is required"); // $NON-NLS-1$
    if (splitLine == null)
      throw new NullPointerException("The split line is required"); // $NON-NLS-1$
    if (desiredCRS == null)
      throw new NullPointerException("The desired crs is required, i.e: map crs"); // $NON-NLS-1$
    if (!(splitLine.getUserData() instanceof CoordinateReferenceSystem))
      throw new IllegalArgumentException(
          "Set the crs of the line before calling newInstance (splitLine.setUserData(CoordinateReferenceSystem))"); //$NON-NLS-1$

    LOGGER.fine("featureList parameter:" + prettyPrint(featureList)); // $NON-NLS-1$
    LOGGER.fine("splitLine parameter:" + splitLine.toText()); // $NON-NLS-1$
    LOGGER.fine(((CoordinateReferenceSystem) splitLine.getUserData()).toWKT());

    try {
      LineString splitReprojected =
          (LineString)
              GeoToolsUtils.reproject(
                  splitLine, (CoordinateReferenceSystem) splitLine.getUserData(), desiredCRS);
      SplitFeatureBuilder sfb = new SplitFeatureBuilder();
      sfb.splitLine = splitReprojected;
      sfb.splitStrategy = new SplitStrategy(splitLine);
      sfb.splitResultList = null;
      sfb.originalGeometryList = new LinkedList<Geometry>();
      sfb.featuresThatSufferedSplit = new LinkedList<SimpleFeature>();
      sfb.featureList = featureList;
      sfb.desiredCRS = desiredCRS;

      return sfb;

    } catch (Exception e) {
      throw makeFailException(e);
    }
  }
  @DescribeResult(name = "result", description = "The contours feature collection")
  public SimpleFeatureCollection execute(
      @DescribeParameter(name = "data", description = "The raster to be used as the source")
          GridCoverage2D gc2d,
      @DescribeParameter(
              name = "band",
              description = "The source image band to process",
              min = 0,
              max = 1)
          Integer band,
      @DescribeParameter(name = "levels", description = "Values for which to generate contours")
          double[] levels,
      @DescribeParameter(
              name = "interval",
              description = "Interval between contour values (ignored if levels arg is supplied)",
              min = 0)
          Double interval,
      @DescribeParameter(
              name = "simplify",
              description = "Values for which to generate contours",
              min = 0)
          Boolean simplify,
      @DescribeParameter(
              name = "smooth",
              description = "Values for which to generate contours",
              min = 0)
          Boolean smooth,
      @DescribeParameter(
              name = "roi",
              description = "The geometry used to delineate the area of interest in model space",
              min = 0)
          Geometry roi,
      ProgressListener progressListener)
      throws ProcessException {

    //
    // initial checks
    //
    if (gc2d == null) {
      throw new ProcessException("Invalid input, source grid coverage should be not null");
    }
    if (band != null && (band < 0 || band >= gc2d.getNumSampleDimensions())) {
      throw new ProcessException("Invalid input, invalid band number:" + band);
    }
    boolean hasValues = !(levels == null || levels.length == 0);
    if (!hasValues && interval == null) {
      throw new ProcessException("One between interval and values must be valid");
    }

    // switch to geophisics if necessary
    gc2d = gc2d.view(ViewType.GEOPHYSICS);

    //
    // GRID TO WORLD preparation
    //
    final AffineTransform mt2D =
        (AffineTransform) gc2d.getGridGeometry().getGridToCRS2D(PixelOrientation.CENTER);

    // get the list of nodata, if any
    List<Object> noDataList = new ArrayList<Object>();
    for (GridSampleDimension sd : gc2d.getSampleDimensions()) {
      // grab all the explicit nodata
      final double[] sdNoData = sd.getNoDataValues();
      if (sdNoData != null) {
        for (double nodata : sdNoData) {
          noDataList.add(nodata);
        }
      }

      // handle also readers setting up nodata in a category with a specific name
      if (sd.getCategories() != null) {
        for (Category cat : sd.getCategories()) {
          if (cat.getName().equals(NO_DATA)) {
            final NumberRange<? extends Number> catRange = cat.getRange();
            if (catRange.getMinimum() == catRange.getMaximum()) {
              noDataList.add(catRange.getMinimum());
            } else {
              Range<Double> noData =
                  new Range<Double>(
                      catRange.getMinimum(),
                      catRange.isMinIncluded(),
                      catRange.getMaximum(),
                      catRange.isMaxIncluded());
              noDataList.add(noData);
            }
          }
        }
      }
    }

    // get the rendered image
    final RenderedImage raster = gc2d.getRenderedImage();

    // perform jai operation
    ParameterBlockJAI pb = new ParameterBlockJAI("Contour");
    pb.setSource("source0", raster);

    if (roi != null) {
      pb.setParameter("roi", CoverageUtilities.prepareROI(roi, mt2D));
    }
    if (band != null) {
      pb.setParameter("band", band);
    }
    if (interval != null) {
      pb.setParameter("interval", interval);
    } else {
      final ArrayList<Double> elements = new ArrayList<Double>(levels.length);
      for (double level : levels) elements.add(level);
      pb.setParameter("levels", elements);
    }
    if (simplify != null) {
      pb.setParameter("simplify", simplify);
    }
    if (smooth != null) {
      pb.setParameter("smooth", smooth);
    }
    if (noDataList != null) {
      pb.setParameter("nodata", noDataList);
    }

    final RenderedOp dest = JAI.create("Contour", pb);
    @SuppressWarnings("unchecked")
    final Collection<LineString> prop =
        (Collection<LineString>) dest.getProperty(ContourDescriptor.CONTOUR_PROPERTY_NAME);

    // wrap as a feature collection and return
    final SimpleFeatureType schema = CoverageUtilities.createFeatureType(gc2d, LineString.class);
    final SimpleFeatureBuilder builder = new SimpleFeatureBuilder(schema);
    int i = 0;
    final ListFeatureCollection featureCollection = new ListFeatureCollection(schema);
    final AffineTransformation jtsTransformation =
        new AffineTransformation(
            mt2D.getScaleX(),
            mt2D.getShearX(),
            mt2D.getTranslateX(),
            mt2D.getShearY(),
            mt2D.getScaleY(),
            mt2D.getTranslateY());
    for (LineString line : prop) {

      // get value
      Double value = (Double) line.getUserData();
      line.setUserData(null);
      // filter coordinates in place
      line.apply(jtsTransformation);

      // create feature and add to list
      builder.set("the_geom", line);
      builder.set("value", value);

      featureCollection.add(builder.buildFeature(String.valueOf(i++)));
    }

    // return value

    return featureCollection;
  }