Package com.vividsolutions.jts.geom

Examples of com.vividsolutions.jts.geom.Coordinate


  }

  @Test
  public void extendPointTest() throws Exception {
    CoordinateReferenceSystem crs;
    Coordinate coordinate;
    Envelope envelope;

    crs = geoService.getCrs("EPSG:900913");
    coordinate = new Coordinate(0, 0);
    envelope = geocoderUtilService.extendPoint(coordinate, crs, 200, 100);
    Assert.assertEquals(-100.00000376900834, envelope.getMinX(), DELTA);
    Assert.assertEquals(-50.33697512339748, envelope.getMinY(), DELTA);
    Assert.assertEquals(100.00000376900834, envelope.getMaxX(), DELTA);
    Assert.assertEquals(50.33697512339748, envelope.getMaxY(), DELTA);

    coordinate = new Coordinate(10000, 10000);
    envelope = geocoderUtilService.extendPoint(coordinate, crs, 200, 100);
    Assert.assertEquals(9899.999874146251, envelope.getMinX(), DELTA);
    Assert.assertEquals(9949.6629648107, envelope.getMinY(), DELTA);
    Assert.assertEquals(10100.000125853749, envelope.getMaxX(), DELTA);
    Assert.assertEquals(10050.3370351893, envelope.getMaxY(), DELTA);

    crs = geoService.getCrs("EPSG:4326");
    coordinate = new Coordinate(0, 0);
    envelope = geocoderUtilService.extendPoint(coordinate, crs, 200, 100);
    Assert.assertEquals(-8.983152841199021E-4, envelope.getMinX(), DELTA);
    Assert.assertEquals(-4.5218473391466234E-4, envelope.getMinY(), DELTA);
    Assert.assertEquals(8.983152841199021E-4, envelope.getMaxX(), DELTA);
    Assert.assertEquals(4.5218473391466234E-4, envelope.getMaxY(), DELTA);

    coordinate = new Coordinate(100, 50);
    envelope = geocoderUtilService.extendPoint(coordinate, crs, 200, 100);
    Assert.assertEquals(99.99860521715158, envelope.getMinX(), DELTA);
    Assert.assertEquals(49.99955048109636, envelope.getMinY(), DELTA);
    Assert.assertEquals(100.00139478284842, envelope.getMaxX(), DELTA);
    Assert.assertEquals(50.00044951890364, envelope.getMaxY(), DELTA);
View Full Code Here


  private Coordinate[] getCoordinates(List<CoordTypeInfo> coords) {
    Coordinate[] result = new Coordinate[coords.size()];
    int i = 0;
    for (CoordTypeInfo coordinate : coords) {
      result[i++] = new Coordinate(coordinate.getX().doubleValue(), coordinate.getY().doubleValue());
    }
    return result;
  }
View Full Code Here

        Pattern.quote(coords.getCs()) + "|" + Pattern.quote(coords.getTs()));
    Coordinate[] result = new Coordinate[coordinates.length / 2];
    for (int i = 0; i < coordinates.length; i += 2) {
      double x = Double.parseDouble(coordinates[i].replace(coords.getDecimal(), "."));
      double y = Double.parseDouble(coordinates[i + 1].replace(coords.getDecimal(), "."));
      result[i / 2] = new Coordinate(x, y);
    }
    return result;
  }
View Full Code Here

      if (bounds.isNull()) {
        return new ArrayList<RasterTile>();
      }

      // find the center of the map in map coordinates (positive y-axis)
      Coordinate boundsCenter = new Coordinate((bounds.getMinX() + bounds.getMaxX()) / 2,
          (bounds.getMinY() + bounds.getMaxY()) / 2);

      // find zoomlevel
      // scale in pix/m should just above the given scale so we have at least one
      // screen pixel per google pixel ! (otherwise text unreadable)
      int zoomLevel = getBestZoomLevelForScaleInPixPerMeter(tileServiceState, mapToLayer, boundsCenter, scale);
      log.debug("zoomLevel={}", zoomLevel);

      // find the google indices for the center
      // google indices determine the row and column of the 256x256 image
      // in the big google square for the given zoom zoomLevel
      // the resulting indices are floating point values as the center
      // is not coincident with an image corner !!!!
      Coordinate indicesCenter;
      indicesCenter = getTileIndicesFromMap(mapToLayer, boundsCenter, zoomLevel);

      // Calculate the width in map units of the image that contains the
      // center
      Coordinate indicesUpperLeft = new Coordinate(Math.floor(indicesCenter.x), Math.floor(indicesCenter.y));
      Coordinate indicesLowerRight = new Coordinate(indicesUpperLeft.x + 1, indicesUpperLeft.y + 1);
      Coordinate mapUpperLeft = getMapFromTileIndices(layerToMap, indicesUpperLeft, zoomLevel);
      Coordinate mapLowerRight =
          getMapFromTileIndices(layerToMap, indicesLowerRight, zoomLevel);
      double width = Math.abs(mapLowerRight.x - mapUpperLeft.x);
      if (0 == width) {
        width = 1.0;
      }
      double height = Math.abs(mapLowerRight.y - mapUpperLeft.y);
      if (0 == height) {
        height = 1.0;
      }

      // Calculate the position and indexes of the center image corner
      // in map space
      double xCenter = boundsCenter.x - (indicesCenter.x - indicesUpperLeft.x) * width;
      double yCenter = boundsCenter.y + (indicesCenter.y - indicesUpperLeft.y) * height;
      int iCenter = (int) indicesUpperLeft.x;
      int jCenter = (int) indicesUpperLeft.y;

      // Calculate the position and indexes of the upper left image corner
      // that just falls off the screen
      double xMin = xCenter;
      int iMin = iCenter;
      while (xMin > bounds.getMinX() && iMin > 0) {
        xMin -= width;
        iMin--;
      }
      double yMax = yCenter;
      int jMin = jCenter;
      while (yMax < bounds.getMaxY() && jMin > 0) {
        yMax += height;
        jMin--;
      }
      // Calculate the indexes of the lower right corner
      // that just falls off the screen
      int levelMax = POWERS_OF_TWO[zoomLevel] - 1;
      double xMax = xCenter;
      int iMax = iCenter;
      while (xMax < bounds.getMaxX() && iMax <= levelMax) {
        xMax += width;
        iMax++;
      }
      double yMin = yCenter;
      int jMax = jCenter;
      while (yMin > bounds.getMinY() && jMax <= levelMax) {
        yMin -= height;
        jMax++;
      }
      Coordinate upperLeft = new Coordinate(xMin, yMax);

      // calculate the images
      List<RasterTile> result = new ArrayList<RasterTile>();
      if (log.isDebugEnabled()) {
        log.debug("bounds =" + bounds);
View Full Code Here

  private int getBestZoomLevelForScaleInPixPerMeter(TiledRasterLayerServiceState tileServiceState,
      CrsTransform layerToGoogle, Coordinate mapPosition,
      double scale) {
    double scaleRatio = MAP_UNIT_PER_GOOGLE_METER_DEFAULT;
    try {
      Coordinate mercatorCenter = JTS.transform(mapPosition, new Coordinate(), layerToGoogle);
      Coordinate dx = JTS.transform(new Coordinate(mapPosition.x + 1, mapPosition.y), new Coordinate(),
          layerToGoogle);
      scaleRatio = 1.0 / (dx.x - mercatorCenter.x);
    } catch (TransformException e) {
      log.warn("calculateMapUnitPerGoogleMeter() : transformation failed", e);
    }
View Full Code Here

  private Coordinate getMapFromTileIndices(CrsTransform mapToLayer, Coordinate indices, int zoomLevel)
      throws TransformException {
    double xMeter = EQUATOR_IN_METERS * indices.x / POWERS_OF_TWO[zoomLevel] - HALF_EQUATOR_IN_METERS;
    double yMeter = -EQUATOR_IN_METERS * indices.y / POWERS_OF_TWO[zoomLevel] + HALF_EQUATOR_IN_METERS;
    return JTS.transform(new Coordinate(xMeter, yMeter), new Coordinate(), mapToLayer);
  }
View Full Code Here

    return JTS.transform(new Coordinate(xMeter, yMeter), new Coordinate(), mapToLayer);
  }

  private Coordinate getTileIndicesFromMap(CrsTransform mapToLayer, Coordinate centerMapCoor, int zoomLevel)
      throws TransformException {
    Coordinate centerLayerCoor = JTS.transform(centerMapCoor, new Coordinate(), mapToLayer);
    double xIndex = (centerLayerCoor.x + HALF_EQUATOR_IN_METERS) * POWERS_OF_TWO[zoomLevel] / EQUATOR_IN_METERS;
    double yIndex = (-centerLayerCoor.y + HALF_EQUATOR_IN_METERS) * POWERS_OF_TWO[zoomLevel] / EQUATOR_IN_METERS;
    return new Coordinate(xIndex, yIndex);
  }
View Full Code Here

    newFeatures = new ArrayList<InternalFeature>();
    feature = converterService.toInternal(new Feature());
    feature.setId("4");
    feature.setLayer(beanLayer);
    // feature needs a geometry or exceptions all over
    geometry = geometryFactory.createPoint(new Coordinate(1.5, 1.5));
    feature.setGeometry(geometry);   
    newFeatures.add(feature);
    try {
      layerService.saveOrUpdate(LAYER_ID, crs, oldFeatures, newFeatures);
      Assert.fail("create should have failed");
    } catch (GeomajasSecurityException gse) {
      Assert.assertEquals(ExceptionCode.FEATURE_CREATE_PROHIBITED, gse.getExceptionCode());
    }
    filter = filterService.createFidFilter(new String[]{"4"});
    oldFeatures = layerService.getFeatures(LAYER_ID,
        crs, filter, null, VectorLayerService.FEATURE_INCLUDE_ATTRIBUTES);
    Assert.assertEquals(0, oldFeatures.size());

    login("luc");
    oldFeatures = new ArrayList<InternalFeature>();
    newFeatures = new ArrayList<InternalFeature>();
    feature = converterService.toInternal(new Feature());
    feature.setId("4");
    feature.setLayer(beanLayer);
    // feature needs a geometry or exceptions all over
    geometry = geometryFactory.createPoint(new Coordinate(1.5, 1.5));
    feature.setGeometry(geometry);
    newFeatures.add(feature);
    layerService.saveOrUpdate(LAYER_ID, crs, oldFeatures, newFeatures);
    filter = filterService.createFidFilter(new String[]{"4"});
    oldFeatures = layerService.getFeatures(LAYER_ID,
View Full Code Here

    newFeatures = new ArrayList<InternalFeature>();
    feature = converterService.toInternal(new Feature());
    feature.setId("4");
    feature.setLayer(beanLayer);
    // feature needs a geometry or exceptions all over
    geometry = geometryFactory.createPoint(new Coordinate(5.5, 5.5));
    feature.setGeometry(geometry);
    newFeatures.add(feature);
    try {
      layerService.saveOrUpdate(LAYER_ID, crs, oldFeatures, newFeatures);
      Assert.fail("create area not checked");
    } catch (GeomajasSecurityException gse) {
      Assert.assertEquals(ExceptionCode.FEATURE_CREATE_PROHIBITED, gse.getExceptionCode());
    }
    filter = filterService.createFidFilter(new String[]{"4"});
    oldFeatures = layerService.getFeatures(LAYER_ID,
        crs, filter, null, VectorLayerService.FEATURE_INCLUDE_ATTRIBUTES);
    Assert.assertEquals(0, oldFeatures.size());
    // verify success
    oldFeatures = new ArrayList<InternalFeature>();
    newFeatures = new ArrayList<InternalFeature>();
    feature = converterService.toInternal(new Feature());
    feature.setId("4");
    feature.setLayer(beanLayer);
    // feature needs a geometry or exceptions all over
    geometry = geometryFactory.createPoint(new Coordinate(1.5, 1.5));
    feature.setGeometry(geometry);
    newFeatures.add(feature);
    layerService.saveOrUpdate(LAYER_ID, crs, oldFeatures, newFeatures);
    filter = filterService.createFidFilter(new String[]{"4"});
    oldFeatures = layerService.getFeatures(LAYER_ID,
View Full Code Here

    featureModel = layer.getFeatureModel();

    feature1 = ExtendedHibernateTestFeature.getDefaultInstance1(new Long(1));
    feature2 = ExtendedHibernateTestFeature.getDefaultInstance2(new Long(2));

    feature1.setGeometry(geometryFactory.createPoint(new Coordinate(3, 42)));
    feature2.setGeometry(geometryFactory.createPoint(new Coordinate(0, 0)));
  }
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.