示例#1
0
  private GraphicStrokeType getJAXBType() {
    GraphicStrokeType s = new GraphicStrokeType();

    this.setJAXBProperties(s);

    if (getOwnUom() != null) {
      s.setUom(getOwnUom().toURN());
    }

    if (graphic != null) {
      s.setGraphic(graphic.getJAXBElement());
    }

    if (length != null) {
      s.setLength(length.getJAXBParameterValueType());
    }

    if (orientation != null) {
      s.setRelativeOrientation(orientation.getJAXBType());
    }

    if (relativePosition != null) {
      s.setRelativePosition(relativePosition.getJAXBParameterValueType());
    }
    return s;
  }
示例#2
0
  @Override
  public JAXBElement<AreaSymbolizerType> getJAXBElement() {
    ObjectFactory of = new ObjectFactory();
    AreaSymbolizerType s = of.createAreaSymbolizerType();

    this.setJAXBProperty(s);

    if (this.getGeometryAttribute() != null) {
      s.setGeometry(getGeometryAttribute().getJAXBGeometryType());
    }

    if (getUom() != null) {
      s.setUom(this.getUom().toURN());
    }

    if (getTranslate() != null) {
      s.setDisplacement(getTranslate().getJAXBType());
    }

    if (this.perpendicularOffset != null) {
      s.setPerpendicularOffset(perpendicularOffset.getJAXBParameterValueType());
    }

    if (fill != null) {
      s.setFill(fill.getJAXBElement());
    }

    if (stroke != null) {
      s.setStroke(stroke.getJAXBElement());
    }

    return of.createAreaSymbolizer(s);
  }
示例#3
0
  @Override
  public Double getNaturalLength(Map<String, Object> map, Shape shp, MapTransform mt)
      throws ParameterException, IOException {
    double naturalLength;

    if (length != null) {
      double lineLength = ShapeHelper.getLineLength(shp);
      Double value = length.getValue(map);
      if (value != null) {
        naturalLength =
            Uom.toPixel(value, getUom(), mt.getDpi(), mt.getScaleDenominator(), lineLength);
        // if (naturalLength <= GraphicStroke.MIN_LENGTH || naturalLength > lineLength) {
        if (naturalLength < 1e-5 || Double.isInfinite(naturalLength)) {
          return Double.POSITIVE_INFINITY;
        }

        if (naturalLength > lineLength) {
          naturalLength = lineLength;
        }

        return naturalLength;
      }
    }

    return getGraphicWidth(map, mt);
  }
示例#4
0
  /**
   * @param g2
   * @param rs
   * @param fid
   * @throws ParameterException
   * @throws IOException error while accessing external resource
   * @throws java.sql.SQLException
   */
  @Override
  public void draw(
      Graphics2D g2, ResultSet rs, long fid, boolean selected, MapTransform mt, Geometry the_geom)
      throws ParameterException, IOException, SQLException {

    List<Shape> shapes = new LinkedList<Shape>();
    shapes.add(mt.getShape(the_geom, true));
    Map<String, Object> map = getFeaturesMap(rs, fid);
    for (Shape shp : shapes) {
      if (this.getTranslate() != null) {
        shp =
            getTranslate()
                .getAffineTransform(
                    map, getUom(), mt, (double) mt.getWidth(), (double) mt.getHeight())
                .createTransformedShape(shp);
      }
      if (shp != null) {
        if (fill != null) {
          fill.draw(g2, map, shp, selected, mt);
        }

        if (stroke != null) {
          double offset = 0.0;
          if (perpendicularOffset != null) {
            offset =
                Uom.toPixel(
                    perpendicularOffset.getValue(rs, fid),
                    getUom(),
                    mt.getDpi(),
                    mt.getScaleDenominator(),
                    null);
          }
          stroke.draw(g2, map, shp, selected, mt, offset);
        }
      }
    }
  }
示例#5
0
  @Override
  public void draw(
      Graphics2D g2,
      Map<String, Object> map,
      Shape shape,
      boolean selected,
      MapTransform mt,
      double offset)
      throws ParameterException, IOException {

    List<Shape> shapes;

    if (!this.isOffsetRapport() && Math.abs(offset) > 0.0) {
      shapes = ShapeHelper.perpendicularOffset(shape, offset);
      // Setting offset to 0.0 let be sure the offset will never been applied twice!
      offset = 0.0;
    } else {
      shapes = new ArrayList<Shape>();
      // TODO : Extract holes as separate shape !
      shapes.add(shape);
    }

    double gWidth = getGraphicWidth(map, mt);
    for (Shape shp : shapes) {
      double segLength = getNaturalLength(map, shp, mt);
      double lineLength = ShapeHelper.getLineLength(shp);

      if (segLength > lineLength) {
        segLength = lineLength;
      }

      RelativeOrientation rOrient = this.getRelativeOrientation();
      List<Shape> segments = null;

      double nbSegments;

      // int nbToDraw;

      if (this.isLengthRapport()) {
        nbSegments = (int) ((lineLength / segLength) + 0.5);
        segments = ShapeHelper.splitLine(shp, (int) nbSegments);
        // segLength = lineLength / nbSegments;
        // nbToDraw = (int) nbSegments;
      } else {
        nbSegments = lineLength / segLength;
        if (nbSegments == 0 && getParent() instanceof StrokeElement) {
          nbSegments = 1;
        }
        if (nbSegments > 0) {
          // TODO remove half of extra space at the beginning of the line
          // shp = ShapeHelper.splitLine(shp, (nbSegments - nbToDraw)/2.0).get(1);
          segments = ShapeHelper.splitLineInSeg(shp, segLength);
        }
      }

      if (segments != null) {
        for (Shape seg : segments) {
          List<Shape> oSegs;
          if (this.isOffsetRapport() && Math.abs(offset) > 0.0) {
            oSegs = ShapeHelper.perpendicularOffset(seg, offset);
          } else {
            oSegs = new ArrayList<Shape>();
            oSegs.add(seg);
          }

          for (Shape oSeg : oSegs) {
            if (oSeg != null) {
              double realSegLength = ShapeHelper.getLineLength(oSeg);
              // Is there enough space on the real segment ?  otherwise is the graphic part of a
              // compound stroke ?
              if (realSegLength > 0.9 * segLength
                  || (getParent() instanceof StrokeElement && segLength == 0.0)) {
                Point2D.Double pt;
                double relativePos = 0.5;

                if (relativePosition != null) {
                  relativePos = relativePosition.getValue(map);
                }

                if (segLength < MIN_LENGTH) {
                  pt = ShapeHelper.getPointAt(oSeg, 0);
                } else {
                  // TODO Replace with relative position !
                  pt = ShapeHelper.getPointAt(oSeg, realSegLength * relativePos);
                }
                AffineTransform at = AffineTransform.getTranslateInstance(pt.x, pt.y);

                if (rOrient != RelativeOrientation.PORTRAYAL) {
                  Point2D.Double ptA;
                  Point2D.Double ptB;

                  if (segLength < MIN_LENGTH) {
                    ptA = pt;
                    ptB = ShapeHelper.getPointAt(oSeg, gWidth);
                  } else {
                    ptA =
                        ShapeHelper.getPointAt(oSeg, relativePos * realSegLength - (gWidth * 0.5));
                    ptB =
                        ShapeHelper.getPointAt(oSeg, relativePos * realSegLength + (gWidth * 0.5));
                  }

                  double theta = Math.atan2(ptB.y - ptA.y, ptB.x - ptA.x);
                  switch (rOrient) {
                    case LINE:
                      theta += 0.5 * Math.PI;
                      break;
                    case NORMAL_UP:
                      if (theta < -Math.PI / 2 || theta > Math.PI / 2) {
                        theta += Math.PI;
                      }
                      break;
                  }
                  at.concatenate(AffineTransform.getRotateInstance(theta));
                }

                graphic.draw(g2, map, selected, mt, at);
              }
            }
          }
        }
      }
    }
  }