Package com.vividsolutions.jts.geom

Examples of com.vividsolutions.jts.geom.Geometry


    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


    return new CrsTransformImpl(key, source, target, mathTransform, crsTransformInfo.getTransformableArea());
  }

  private static Geometry createEmptyGeometryForClass(Class<? extends Geometry> geomClass) {
    Geometry empty = EMPTY_GEOMETRIES.get(geomClass);
    if (empty == null) {
      empty = EMPTY_GEOMETRIES.get(Geometry.class);
    }
    return empty;
  }
View Full Code Here

  /** @{inheritDoc} */
  @edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "REC_CATCH_EXCEPTION")
  public Geometry transform(Geometry source, CrsTransform crsTransform) {
    try {
      if (crsTransform.isTransforming()) {
        Geometry transformableArea = crsTransform.getTransformableGeometry();
        if (null != transformableArea) {
          source = source.intersection(transformableArea);
        }
        return JTS.transform(source, crsTransform);
      } else {
View Full Code Here

    return transform(source, crsTransform);
  }

  /** @{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

    // base is the max bounds of the layer
    Envelope maxBounds = converterService.toInternal(layerInfo.getMaxExtent());
    PrecisionModel precisionModel = new PrecisionModel(PrecisionModel.FLOATING);
    int srid = geoService.getSridFromCrs(layer.getLayerInfo().getCrs());
    GeometryFactory geometryFactory = new GeometryFactory(precisionModel, srid);
    Geometry geometry = geometryFactory.toGeometry(maxBounds);

    // limit based on authorizations
    for (Authentication authentication : authentications) {
      for (BaseAuthorization authorization : authentication.getAuthorizations()) {
        if (authorization instanceof AreaAuthorization) {
          geometry = geometry.intersection(areaGetter.get((AreaAuthorization) authorization));
        }
      }
    }
    geometry.setSRID(srid); // force srid, even when not set correctly by security service
    return geometry;
  }
View Full Code Here

  @DirtiesContext // changing security context
  public void testNotAuthenticatedVisibleArea() throws Exception {
    SecurityContextImpl securityContext = (SecurityContextImpl)this.securityContext;
    securityContext.setAuthentications(null, null);
    Assert.assertFalse(securityContext.isLayerVisible(LAYER_ID));
    Geometry geometry = securityContext.getVisibleArea(LAYER_ID);
    Assert.assertNull(geometry);
    securityContext.setAuthentications(null, null);
  }
View Full Code Here

    List<Authentication> authentications = new ArrayList<Authentication>();
    Authentication auth1 = getBaseAuthentication();
    authentications.add(auth1);
    securityContext.setAuthentications("token", authentications);
    Assert.assertTrue(securityContext.isLayerVisible(LAYER_ID));
    Geometry geometry = securityContext.getVisibleArea(LAYER_ID);
    Assert.assertNotNull(geometry);
    PrecisionModel precisionModel  = new PrecisionModel(PrecisionModel.FLOATING);
    GeometryFactory geometryFactory = new GeometryFactory(precisionModel, LAYER_SRID);
    Coordinate coordinate = new Coordinate();

    coordinate.x = coordinate.y = -86;
    Assert.assertFalse(geometry.contains(geometryFactory.createPoint(coordinate)));
    coordinate.x = -85.05;
    coordinate.y = -85.05;
    Assert.assertTrue(geometry.contains(geometryFactory.createPoint(coordinate)));
    coordinate.x = -85.05;
    coordinate.y = 85.05;
    Assert.assertTrue(geometry.contains(geometryFactory.createPoint(coordinate)));
    coordinate.x = 85.05;
    coordinate.y = -85.05;
    Assert.assertTrue(geometry.contains(geometryFactory.createPoint(coordinate)));
    coordinate.x = 85.05;
    coordinate.y = 85.05;
    Assert.assertTrue(geometry.contains(geometryFactory.createPoint(coordinate)));
    coordinate.x = coordinate.y = 86;
    Assert.assertFalse(geometry.contains(geometryFactory.createPoint(coordinate)));

    Assert.assertFalse(securityContext.isPartlyVisibleSufficient(LAYER_ID));
  }
View Full Code Here

    Authentication auth2 = getAreaAuthentication(1);
    authentications.add(auth1);
    authentications.add(auth2);
    securityContext.setAuthentications("token", authentications);

    Geometry geometry = securityContext.getVisibleArea(LAYER_ID);
    Assert.assertNotNull(geometry);
    PrecisionModel precisionModel  = new PrecisionModel(PrecisionModel.FLOATING);
    GeometryFactory geometryFactory = new GeometryFactory(precisionModel, LAYER_SRID);
    Coordinate coordinate = new Coordinate();
    coordinate.x = coordinate.y = 0.5;
    Assert.assertFalse(geometry.contains(geometryFactory.createPoint(coordinate)));
    coordinate.x = coordinate.y = 1.5;
    Assert.assertTrue(geometry.contains(geometryFactory.createPoint(coordinate)));
    coordinate.x = coordinate.y = 2.5;
    Assert.assertTrue(geometry.contains(geometryFactory.createPoint(coordinate)));
    coordinate.x = coordinate.y = 3.5;
    Assert.assertFalse(geometry.contains(geometryFactory.createPoint(coordinate)));
    coordinate.x = coordinate.y = 4.5;
    Assert.assertFalse(geometry.contains(geometryFactory.createPoint(coordinate)));

    Assert.assertFalse(securityContext.isPartlyVisibleSufficient(LAYER_ID));
  }
View Full Code Here

    Authentication auth2 = getAreaAuthentication(2);
    authentications.add(auth1);
    authentications.add(auth2);
    securityContext.setAuthentications("token", authentications);

    Geometry geometry = securityContext.getVisibleArea(LAYER_ID);
    Assert.assertNotNull(geometry);
    PrecisionModel precisionModel  = new PrecisionModel(PrecisionModel.FLOATING);
    GeometryFactory geometryFactory = new GeometryFactory(precisionModel, LAYER_SRID);
    Coordinate coordinate = new Coordinate();
    coordinate.x = coordinate.y = 0.5;
    Assert.assertFalse(geometry.contains(geometryFactory.createPoint(coordinate)));
    coordinate.x = coordinate.y = 1.5;
    Assert.assertFalse(geometry.contains(geometryFactory.createPoint(coordinate)));
    coordinate.x = coordinate.y = 2.5;
    Assert.assertTrue(geometry.contains(geometryFactory.createPoint(coordinate)));
    coordinate.x = coordinate.y = 3.5;
    Assert.assertFalse(geometry.contains(geometryFactory.createPoint(coordinate)));
    coordinate.x = coordinate.y = 4.5;
    Assert.assertFalse(geometry.contains(geometryFactory.createPoint(coordinate)));

    Assert.assertFalse(securityContext.isPartlyVisibleSufficient(LAYER_ID));
  }
View Full Code Here

    String crsCode = request.getCrs();
    if (null == crsCode) {
      throw new GeomajasException(ExceptionCode.PARAMETER_MISSING, "crs");
    }
    String[] layerIds = request.getLayerIds();
    Geometry location = converter.toInternal(request.getLocation());
    int queryType = request.getQueryType();
    double ratio = request.getRatio();
    int searchType = request.getSearchType();
    Crs crs = geoService.getCrs2(request.getCrs());

    // Check if a buffer should be added around the location:
    Geometry geometry = location;
    if (request.getBuffer() > 0) {
      geometry = location.buffer(request.getBuffer());
    }
    log.debug("search by location " + geometry);

    if (layerIds != null && layerIds.length > 0) {
      for (String layerId : layerIds) {
        if (securityContext.isLayerVisible(layerId)) {
          VectorLayer vectorLayer = configurationService.getVectorLayer(layerId);
          if (vectorLayer != null) {
            String geomName = vectorLayer.getLayerInfo().getFeatureInfo().getGeometryType().getName();

            // Transform geometry to layer CRS:
            Geometry layerGeometry = geoService.transform(geometry, crs, vectorLayer.getCrs());
            log.trace("on layer " + layerId + " use " + layerGeometry);

            // Create the correct Filter object:
            Filter f = null;
            switch (queryType) {
              case SearchByLocationRequest.QUERY_INTERSECTS:
                f = filterCreator.createIntersectsFilter(layerGeometry, geomName);
                break;
              case SearchByLocationRequest.QUERY_CONTAINS:
                f = filterCreator.createContainsFilter(layerGeometry, geomName);
                break;
              case SearchByLocationRequest.QUERY_TOUCHES:
                f = filterCreator.createTouchesFilter(layerGeometry, geomName);
                break;
              case SearchByLocationRequest.QUERY_WITHIN:
                f = filterCreator.createWithinFilter(layerGeometry, geomName);
                break;
            }
            //Set the per layer filter
            if (null != request.getFilter(layerId)) {
              if (null == f) {
                f = filterCreator.parseFilter(request.getFilter(layerId));
              } else {
                f = filterCreator.createAndFilter(
                    filterCreator.parseFilter(request.getFilter(layerId)), f);
              }
            }
            //Set the global filter
            if (null != request.getFilter()) {
              if (null == f) {
                f = filterCreator.parseFilter(request.getFilter());
              } else {
                f = filterCreator.createAndFilter(filterCreator.parseFilter(request.getFilter()), f);
              }
            }

            // Get the features:
            List<InternalFeature> temp = layerService.getFeatures(layerId, crs, f, null, request
                .getFeatureIncludes());
            if (temp.size() > 0) {
              List<Feature> features = new ArrayList<Feature>();

              // Calculate overlap ratio in case of intersects:
              if (queryType == SearchByLocationRequest.QUERY_INTERSECTS && ratio >= 0 && ratio < 1) {
                for (InternalFeature feature : temp) {
                  double minimalOverlap = feature.getGeometry().getArea() * ratio;
                  Geometry overlap = location.intersection(feature.getGeometry());
                  double effectiveOverlap = overlap.getArea();
                  if (minimalOverlap <= effectiveOverlap) {
                    log.trace("found " + feature);
                    Feature dto = converter.toDto(feature);
                    dto.setCrs(crsCode);
                    features.add(dto);
View Full Code Here

TOP

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

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.