Package com.vividsolutions.jts.geom

Examples of com.vividsolutions.jts.geom.Coordinate


  private MapComponentImpl createMap() {
    MapComponentImpl map = createInstance(MapComponentImpl.class);
    map.getConstraint().setMarginX(20);
    map.getConstraint().setMarginY(20);
    map.setLocation(new Coordinate());
    map.setPpUnit(1.0f);
    map.setTag(PrintTemplate.MAP);
    return map;
  }
View Full Code Here


    Bbox mapBounds = request.getMapBounds();
    if (null == mapBounds) {
      throw new GeomajasException(ExceptionCode.PARAMETER_MISSING, "mapBounds");
    }

    Coordinate coordinate = new Coordinate(requestLocation.getX(), requestLocation.getY());
    Crs crs = geoService.getCrs2(request.getCrs());
    boolean searchFirstLayerOnly;
    switch (request.getSearchType()) {
      case SearchByPointRequest.SEARCH_FIRST_LAYER:
        searchFirstLayerOnly = true;
        break;
      case SearchByPointRequest.SEARCH_ALL_LAYERS:
        searchFirstLayerOnly = false;
        break;
      default:
        throw new IllegalArgumentException("Invalid value for searchType");
    }

    log.debug("search by location {}", coordinate);

    if (layerIds.length > 0) {
      for (String layerId : layerIds) {
        if (securityContext.isLayerVisible(layerId)) {
          Layer<?> layer = configurationService.getLayer(layerId);
          if (layer instanceof LayerFeatureInfoSupport &&
              ((LayerFeatureInfoSupport) layer).isEnableFeatureInfoSupport()) {
            Crs layerCrs = layerService.getCrs(layer);
            double layerScale = calculateLayerScale(crs, layerCrs, mapBounds, request.getScale());
            Coordinate layerCoordinate = geoService.transform(coordinate, crs, layerCrs);
            List<Feature> features = ((LayerFeatureInfoSupport) layer).getFeaturesByLocation(
                layerCoordinate, layerScale, request.getPixelTolerance());
            if (features != null && features.size() > 0) {
              response.addLayer(layerId, features);
              if (searchFirstLayerOnly) {
View Full Code Here

  protected LiteShape2 createShape(Symbolizer symbolizer, double w, double h) {
    try {
      if (symbolizer instanceof LineSymbolizer) {
        if (line == null) {
          List<Coordinate> coords = new ArrayList<Coordinate>();
          coords.add(new Coordinate(0, 0));
          coords.add(new Coordinate(0.75 * w, 0.25 * h));
          coords.add(new Coordinate(0.25 * w, 0.75 * h));
          coords.add(new Coordinate(w, h));
          LineString linestring = geometryFactory.createLineString(
              coords.toArray(new Coordinate[coords.size()]));
          line = new LiteShape2(linestring, null, null, false);
        }
        return line;
      } else if (symbolizer instanceof PolygonSymbolizer) {
        if (polygon == null) {
          List<Coordinate> coords = new ArrayList<Coordinate>();
          coords.add(new Coordinate(0, 0));
          coords.add(new Coordinate(w, 0));
          coords.add(new Coordinate(w, h));
          coords.add(new Coordinate(0, h));
          coords.add(new Coordinate(0, 0));
          LinearRing ring = geometryFactory.createLinearRing(coords.toArray(new Coordinate[coords.size()]));
          Polygon p = geometryFactory.createPolygon(ring, null);
          polygon = new LiteShape2(p, null, null, false);
        }
        return polygon;
      } else if (symbolizer instanceof PointSymbolizer) {
        if (point == null) {
          Coordinate coord = new Coordinate(w / 2, h / 2);
          Point p = geometryFactory.createPoint(coord);
          point = new LiteShape2(p, null, null, false);
        }
        return point;
      } else {
View Full Code Here

  private VectorLayer layer;

  @Before
  public void setupBeans() throws LayerException {
    GeometryFactory factory = new GeometryFactory(new PrecisionModel(PrecisionModel.FLOATING), 4329);
    LinearRing shell = factory.createLinearRing(new Coordinate[] { new Coordinate(0, 0), new Coordinate(1, 0),
        new Coordinate(1, 1), new Coordinate(0, 1), new Coordinate(0, 0), });
    Polygon p = factory.createPolygon(shell, null);
    MultiPolygon expected = factory.createMultiPolygon(new Polygon[] { p });
    CustomBean cb = new CustomBean();
    cb.setId(1);
    cb.setGeometry(expected);
View Full Code Here

  }

  @Test
  public void readGeometry() throws LayerException {
    GeometryFactory factory = new GeometryFactory(new PrecisionModel(), 4326);
    LinearRing shell = factory.createLinearRing(new Coordinate[] { new Coordinate(0, 0), new Coordinate(1, 0),
        new Coordinate(1, 1), new Coordinate(0, 1), new Coordinate(0, 0), });
    Polygon p = factory.createPolygon(shell, null);
    MultiPolygon expected = factory.createMultiPolygon(new Polygon[] { p });
    Assert.assertTrue(((CustomBean) layer.read("1")).getGeometry().equalsExact(expected));
  }
View Full Code Here

  @Test
  public void readGeometry() throws LayerException {
    Object bean = layer.read("1");
    GeometryFactory factory = new GeometryFactory(new PrecisionModel(), 4326);
    LinearRing shell = factory.createLinearRing(new Coordinate[] { new Coordinate(0, 0), new Coordinate(1, 0),
        new Coordinate(1, 1), new Coordinate(0, 1), new Coordinate(0, 0), });
    Polygon p = factory.createPolygon(shell, null);
    MultiPolygon expected =factory.createMultiPolygon(new Polygon[]{p});
    Geometry g = layer.getFeatureModel().getGeometry(bean);
    Assert.assertTrue(expected.equalsExact(g, 0.00001));
  }
View Full Code Here

    StringWriter writer = new StringWriter();
    GraphicsDocument document = new DefaultSvgDocument(writer, false);
    document.writeElement("path", false);
    document.writeAttributeStart("points");
    Coordinate[] coordinates = new Coordinate[2];
    coordinates[0] = new Coordinate(1.23456789, 9.87654321);
    coordinates[1] = new Coordinate(9.876, 1.234);
    document.writePathContent(coordinates);
    document.writeAttributeEnd();
    document.closeElement();
    Assert.assertEquals("<path points=\"M1.23457 9.87654l8.64143 -8.64254 \"/>", writer.getBuffer().toString());
  }
View Full Code Here

  public Coordinate transform(Coordinate source, CrsTransform crsTransform) {
    try {
      if (crsTransform.isTransforming()) {
        Envelope transformableArea = crsTransform.getTransformableEnvelope();
        if (null == transformableArea || transformableArea.contains(source)) {
          return JTS.transform(source, new Coordinate(), crsTransform);
        }
        return null;
      } else {
        return source;
      }
View Full Code Here

  }

  /** @{inheritDoc} */
  public Coordinate calcDefaultLabelPosition(InternalFeature feature) {
    Geometry geometry = feature.getGeometry();
    Coordinate labelPoint = null;
    if (geometry != null && !geometry.isEmpty() && geometry.isValid()) {
      if (geometry instanceof Polygon || geometry instanceof MultiPolygon) {
        try {
          InteriorPointArea ipa = new InteriorPointArea(geometry);
          labelPoint = ipa.getInteriorPoint();
        } catch (Throwable t) { // NOPMD
          // BUG in JTS for some valid geometries ? fall back to centroid
          log.warn("getInteriorPoint() failed", t);
        }
      } else if (geometry instanceof LineString || geometry instanceof MultiLineString) {
        InteriorPointLine ipa = new InteriorPointLine(geometry);
        labelPoint = ipa.getInteriorPoint();
      } else {
        labelPoint = geometry.getCentroid().getCoordinate();
      }
    }
    if (null == labelPoint && null != geometry) {
      Point centroid = geometry.getCentroid();
      if (null != centroid) {
        labelPoint = centroid.getCoordinate();
      }
    }
    if (null != labelPoint && (Double.isNaN(labelPoint.x) || Double.isNaN(labelPoint.y))) {
      labelPoint = new Coordinate(geometry.getCoordinate());
    }
    return null == labelPoint ? null : new Coordinate(labelPoint);
  }
View Full Code Here

    Coordinate[] coords = new Coordinate[nrPoints + 1];
    for (int i = 0; i < nrPoints; i++) {
      double angle = ((double) i / (double) nrPoints) * Math.PI * 2.0;
      double dx = Math.cos(angle) * radius;
      double dy = Math.sin(angle) * radius;
      coords[i] = new Coordinate(x + dx, y + dy);
    }
    coords[nrPoints] = coords[0];

    LinearRing ring = point.getFactory().createLinearRing(coords);
    return point.getFactory().createPolygon(ring, null);
View Full Code Here

TOP

Related Classes of com.vividsolutions.jts.geom.Coordinate

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.