Пример #1
0
  /**
   * API Method: getURL
   *
   * @return url create the url of a tile based on bounds
   */
  @Override
  public String getUrl(Envelope bounds) {
    bounds = this.adjustBoundsByGutter(bounds);
    // Util.printDebugMessage("@...AgsTiled.getUrl() is called here with bounds:" + bounds.toBBOX()
    // + "...");
    double res = this.map.getResolution();
    String path = null;
    String url = null;

    if (this.tileFullExtent.intersects(bounds) == true) {
      int col;
      if (this.tileOrigin.x <= bounds.getMinX()) {
        col =
            (int)
                Math.round(
                    (bounds.getMinX() - this.tileOrigin.x) / (res * this.tileSize.getWidth()));
      } else if (this.tileOrigin.x >= bounds.getMaxX()) {
        col =
            (int)
                Math.round(
                    (this.tileOrigin.x - bounds.getMaxX()) / (res * this.tileSize.getWidth()));
      } else {
        Util.printErrorMessage("...invalid tileOrigin...");
        return getTransparentTileUrl();
      }
      int row;
      if (this.tileOrigin.y >= bounds.getMaxY()) {
        row =
            (int)
                Math.round(
                    (this.tileOrigin.y - bounds.getMaxY()) / (res * this.tileSize.getHeight()));
      } else if (this.tileOrigin.y <= bounds.getMinY()) {
        row =
            (int)
                Math.round(
                    (bounds.getMinY() - this.tileOrigin.y) / (res * this.tileSize.getHeight()));
      } else {
        // Util.printDebugMessage("...invalid tileOrigin...");
        return getTransparentTileUrl();
      }
      int zoom = this.map.getZoom();
      if (this.mimeType.equalsIgnoreCase("") == true) {
        path = zoom + "/" + row + "/" + col;
      } else {
        path = zoom + "/" + row + "/" + col + "." + this.mimeType;
      }
      url = this.url;

      return url + path;
    } else {
      // area outside of tiles' full extent
      return getTransparentTileUrl();
    }
  }
Пример #2
0
  public static void getRelationsInfo(List<Geometry> aGeometryList) {

    int numVar = aGeometryList.size();
    int[] numRel = new int[8];
    int sum = 0;
    for (int i1 = 0; i1 < numVar; i1++) {
      Geometry a1 = aGeometryList.get(i1);
      Envelope a1m = a1.getEnvelopeInternal();
      double[] m1 = new double[4];
      m1[0] = a1m.getMinX();
      m1[1] = a1m.getMaxX();
      m1[2] = a1m.getMinY();
      m1[3] = a1m.getMaxY();
      for (int j1 = i1 + 1; j1 < numVar; j1++) {

        Geometry a2 = aGeometryList.get(j1);
        Envelope a2m = a2.getEnvelopeInternal();
        double[] m2 = new double[4];
        m2[0] = a2m.getMinX();
        m2[1] = a2m.getMaxX();
        m2[2] = a2m.getMinY();
        m2[3] = a2m.getMaxY();
        boolean[] relationAB = new boolean[8];
        // assume relation table is indexed by i*n+j for each pair (i,j), i<j
        relationAB = GeometryRelated.computeRCC8RelationMBR(a1, a2, m1, m2);
        if (GeometryRelated.rectangleIntersect(m1, m2)) {
          sum += 2;
        }
        for (int k = 0; k < 8; k++) {
          // we already know relation is basic
          if (relationAB[k]) {
            numRel[k]++;
            break;
          }
        }
      }
    }

    System.out.println("DC number:" + numRel[0]);
    System.out.println("EC number:" + numRel[1]);
    System.out.println("PO number:" + numRel[2]);
    System.out.println("NTPP number:" + numRel[3]);
    System.out.println("TPP number:" + numRel[4]);
    System.out.println("NTPPi number:" + numRel[5]);
    System.out.println("TPPi number:" + numRel[6]);
    System.out.println("EQ number:" + numRel[7]);
    System.out.println("Average Intersection Degree: " + ((double) sum / ((double) numVar)));
  }
 private EXGeographicBoundingBox getGeographicBoundingBox(Envelope env, String epsgCode) {
   Envelope newEnvelope;
   if ("EPSG:4326".equals(epsgCode)) {
     newEnvelope = env;
   } else {
     try {
       GeometryFactory gf = new GeometryFactory();
       Polygon poly = (Polygon) gf.toGeometry(env);
       ST_Transform transformFunction = new ST_Transform();
       CoordinateReferenceSystem inputCRS = DataSourceFactory.getCRSFactory().getCRS(epsgCode);
       Value val =
           transformFunction.evaluate(
               null,
               ValueFactory.createValue(poly, inputCRS),
               ValueFactory.createValue("EPSG:4326"));
       newEnvelope = val.getAsGeometry().getEnvelopeInternal();
     } catch (FunctionException fe) {
       return getDummyGeographic();
     } catch (CRSException ex) {
       return getDummyGeographic();
     }
   }
   EXGeographicBoundingBox ret = new EXGeographicBoundingBox();
   ret.setEastBoundLongitude(newEnvelope.getMaxX());
   ret.setWestBoundLongitude(newEnvelope.getMinX());
   ret.setNorthBoundLatitude(newEnvelope.getMaxY());
   ret.setSouthBoundLatitude(newEnvelope.getMinY());
   return ret;
 }
Пример #4
0
  /**
   * Utility method to create a ReferencedEnvelope from an JTS Envelope class, supporting 2d as well
   * as 3d envelopes (returning the right class).
   *
   * @param env The JTS Envelope object
   * @return ReferencedEnvelope, ReferencedEnvelope3D if it is 3d,<br>
   *     results in a null/an empty envelope, if input envelope was a null/an empty envelope
   */
  public static ReferencedEnvelope create(Envelope env, CoordinateReferenceSystem crs) {
    if (env == null) {
      return null;
    }
    if (crs.getCoordinateSystem().getDimension() >= 3) {
      if (env.isNull()) {
        return new ReferencedEnvelope3D(crs);
      } else {
        return new ReferencedEnvelope3D(
            env.getMinX(),
            env.getMaxX(),
            env.getMinY(),
            env.getMaxY(),
            Double.NaN,
            Double.NaN,
            crs);
      }
    }

    if (env.isNull()) {
      return new ReferencedEnvelope(crs);
    } else {
      return new ReferencedEnvelope(env, crs);
    }
  }
Пример #5
0
  /*
   * Adds a feature layer to the geopackage.
   */
  void addFeatureLayer(
      GeoPackage geopkg, FeatureLayer layer, MapLayerInfo mapLayer, WMSMapContent map)
      throws IOException {

    FeatureEntry e = new FeatureEntry();
    initEntry(e, layer, mapLayer, map);

    Filter filter = layer.getQuery().getFilter();
    GeometryDescriptor gd = mapLayer.getFeature().getFeatureType().getGeometryDescriptor();
    if (gd != null) {
      Envelope bnds = bounds(map);
      BBOX bboxFilter =
          filterFactory.bbox(
              gd.getLocalName(),
              bnds.getMinX(),
              bnds.getMinY(),
              bnds.getMaxX(),
              bnds.getMaxY(),
              map.getRequest().getSRS());
      filter = filterFactory.and(filter, bboxFilter);
    }

    LOGGER.fine("Creating feature entry" + e.getTableName());
    geopkg.add(e, layer.getSimpleFeatureSource(), filter);
  }
 private void addEnv(@Nullable Bounded node) {
   if (node == null) {
     return;
   }
   Envelope env = envBuff;
   env.setToNull();
   node.expand(env);
   if (env.isNull()) {
     return;
   }
   if (isPoint(env)) {
     points.add(env.getMinX(), env.getMinY());
   } else if (isOrthoLine(env)) {
     // handle the case where the envelope is given by an orthogonal line so we don't add a
     // zero area polygon
     double width = env.getWidth();
     GrowableCoordinateSequence cs = new GrowableCoordinateSequence();
     if (width == 0D) {
       cs.add(env.getMinX(), env.getMinY());
       cs.add(env.getMinX(), env.getMaxY());
     } else {
       cs.add(env.getMinX(), env.getMinY());
       cs.add(env.getMaxX(), env.getMinY());
     }
     nonPoints.add(GEOM_FACTORY.createLineString(cs));
   } else {
     nonPoints.add(JTS.toGeometry(env, GEOM_FACTORY));
   }
 }
Пример #7
0
 public Node(Envelope env, int level) {
   // this.parent = parent;
   this.env = env;
   this.level = level;
   centrex = (env.getMinX() + env.getMaxX()) / 2;
   centrey = (env.getMinY() + env.getMaxY()) / 2;
 }
  private void renderGridCoverage(
      Graphics2D graphics,
      Envelope bounds,
      Dimension dimension,
      ReferencedEnvelope requestBBox,
      BufferedImage image)
      throws Exception {
    CoordinateReferenceSystem destinationCRS = getContext().getCRS();

    Envelope envelope = bounds;
    if (envelope == null || envelope.isNull()) {
      // get the bounds from the context
      envelope = getContext().getImageBounds();
    }
    Point upperLeft =
        getContext().worldToPixel(new Coordinate(envelope.getMinX(), envelope.getMinY()));
    Point bottomRight =
        getContext().worldToPixel(new Coordinate(envelope.getMaxX(), envelope.getMaxY()));
    Rectangle screenSize = new Rectangle(upperLeft);
    screenSize.add(bottomRight);

    GridCoverage2D coverage = convertImageToGridCoverage(requestBBox, image);

    AffineTransform worldToScreen =
        RendererUtilities.worldToScreenTransform(envelope, screenSize, destinationCRS);
    GridCoverageRenderer paint =
        new GridCoverageRenderer(destinationCRS, envelope, screenSize, worldToScreen);

    RasterSymbolizer symbolizer =
        CommonFactoryFinder.getStyleFactory(null).createRasterSymbolizer();

    paint.paint(graphics, coverage, symbolizer);
  }
Пример #9
0
 /**
  * Turns an envelope into an array [minX,minY,maxX,maxY]
  *
  * @param env envelope representing bounding box
  * @return this
  */
 protected JSONBuilder writeBoundingBox(Envelope env) {
   this.key("bbox");
   this.array();
   if (axisOrder == CRS.AxisOrder.NORTH_EAST) {
     roundedValue(env.getMinY());
     roundedValue(env.getMinX());
     roundedValue(env.getMaxY());
     roundedValue(env.getMaxX());
   } else {
     roundedValue(env.getMinX());
     roundedValue(env.getMinY());
     roundedValue(env.getMaxX());
     roundedValue(env.getMaxY());
   }
   return this.endArray();
 }
Пример #10
0
  /**
   * Fits screen to specified geometry bounds.
   *
   * @param aArea A geometry in geo coordinates space.
   * @throws Exception
   */
  public void fit(Geometry aArea) throws Exception {

    Geometry bounds = aArea.getBoundary();
    Envelope envBounds = bounds.getEnvelopeInternal();
    Point2D.Double leftUpCorner = new Point2D.Double(envBounds.getMinX(), envBounds.getMinY());
    Point2D.Double rightBottomCorner = new Point2D.Double(envBounds.getMaxX(), envBounds.getMaxY());
    Point2D.Double cartlu = geo2Cartesian(leftUpCorner);
    Point2D.Double cartrb = geo2Cartesian(rightBottomCorner);
    double destWidth = Math.abs(cartrb.getX() - cartlu.getX());
    double destHeight = Math.abs(cartrb.getY() - cartlu.getY());
    Coordinate centre =
        new Coordinate((cartrb.getX() + cartlu.getX()) / 2, (cartrb.getY() + cartlu.getY()) / 2);

    Dimension size = getSize();
    Point2D.Double screenLT = awtScreen2Cartesian(new Point(0, 0));
    Point2D.Double screenBR = awtScreen2Cartesian(new Point(size.width, size.height));

    double srcWidth = screenBR.x - screenLT.x;
    double srcHeight = screenBR.y - screenLT.y;
    double sx = srcWidth / destWidth;
    double sy = srcHeight / destHeight;
    double coef = Math.min(sx, sy);
    coef = snapScale(coef);
    scaleView(coef, coef, false);

    Point2D.Double projectedScreenCenter = screen2Cartesian(new Point(0, 0));
    translateView(projectedScreenCenter.x - centre.x, projectedScreenCenter.y - centre.y, true);
    repaint();
  }
Пример #11
0
 @Test
 public void testBounds() throws Exception {
   Envelope bounds = ws.get("states").bounds();
   assertEquals(-124.73, bounds.getMinX(), 0.01);
   assertEquals(24.96, bounds.getMinY(), 0.01);
   assertEquals(-66.97, bounds.getMaxX(), 0.01);
   assertEquals(49.37, bounds.getMaxY(), 0.01);
 }
Пример #12
0
  protected Shape getShape() {
    if (zoomBoxEnd == null) return null;

    Envelope envModel = getEnvelope();

    Point2D base = toView(new Coordinate(envModel.getMinX(), envModel.getMaxY()));
    double width = toView(envModel.getWidth());
    double height = toView(envModel.getHeight());
    return new Rectangle2D.Double(base.getX(), base.getY(), width, height);
  }
Пример #13
0
  /*
   * returns a two element array, where each element is list.
   * the first list represents x-coordinates of vertical grid lines, and
   * the second list represents y coordinates of horizintal grid lines.
   */
  private List<Double>[] chooseGridLines(Envelope bounds) {
    double[] gridSizeChoices = {
      1, 2, 5, 10, 25, 50, 100, 500, 1000, 5000, 10000, 50000, 100000, 500000, 1000000
    };
    int preferredNumberOfGridLines = 2; // approximately, but +/- a couple is okay

    double xSizeGuess = (bounds.getMaxX() - bounds.getMinX()) / preferredNumberOfGridLines;
    double xSize = findClosest(gridSizeChoices, xSizeGuess);

    double ySizeGuess = (bounds.getMaxY() - bounds.getMinY()) / preferredNumberOfGridLines;
    double ySize = findClosest(gridSizeChoices, ySizeGuess);

    double max = Math.max(xSize, ySize);
    xSize = max;
    ySize = max;

    // make list of all the x-coordinates (vertical grid lines)
    double firstX = Math.round(bounds.getMinX() / xSize) * xSize;
    if (firstX > bounds.getMinX()) {
      firstX -= xSize;
    }
    List xList = new ArrayList();
    double xCoord = firstX;
    while (xCoord < bounds.getMaxX() + xSize) {
      xList.add(xCoord);
      xCoord += xSize;
    }

    // make list of all the y-coordinates (hortizontal grid lines)
    double firstY = Math.round(bounds.getMaxY() / ySize) * ySize;
    if (firstY < bounds.getMaxY()) {
      firstY += ySize;
    }
    List yList = new ArrayList();
    double yCoord = firstY;
    while (yCoord > bounds.getMinY() - ySize) {
      yList.add(yCoord);
      yCoord -= ySize;
    }

    List[] result = {xList, yList};
    return result;
  }
Пример #14
0
  /**
   * @param envelope
   * @param width
   * @param height
   * @return
   * @throws ThinklabResourceNotFoundException
   */
  private BufferedImage getWMSImage(Envelope envelope, int width, int height)
      throws ThinklabResourceNotFoundException {

    BufferedImage ret = null;
    initializeWms();

    String sig = envelope.toString() + "," + width + "," + height;

    if (_cache.containsKey(sig)) return ImageUtil.clone(_cache.get(sig));

    if (_wms != null) {

      GetMapRequest request = _wms.createGetMapRequest();
      request.setFormat("image/png");
      request.setDimensions("" + width, "" + height);
      request.setTransparent(true);

      // FIXME this assumes the envelope is in lat/lon
      request.setSRS("EPSG:4326");

      String bbox =
          (float) envelope.getMinX()
              + ","
              + (float) envelope.getMinY()
              + ","
              + (float) envelope.getMaxX()
              + ","
              + (float) envelope.getMaxY();

      request.setBBox(bbox);

      for (Layer layer : getWMSLayers()) {
        request.addLayer(layer);
      }

      GetMapResponse response = null;
      try {

        System.out.println(request.getFinalURL());

        response = (GetMapResponse) _wms.issueRequest(request);
        ret = ImageIO.read(response.getInputStream());
      } catch (Exception e) {
        Geospace.get().logger().warn("cannot get WFS imagery: " + e.getLocalizedMessage());
        return null;
      }

      /*
       * FIXME this obviously must have a limit
       */
      if (ret != null) _cache.put(sig, ImageUtil.clone(ret));
    }

    return ret;
  }
Пример #15
0
  /**
   * Computes the distance between this and another <code>Envelope</code>. The distance between
   * overlapping Envelopes is 0. Otherwise, the distance is the Euclidean distance between the
   * closest points.
   */
  @Override
  public double distance(final Envelope env) {
    if (intersects(env)) {
      return 0;
    }

    double dx = 0.0;
    if (getMaxX() < env.getMinX()) {
      dx = env.getMinX() - getMaxX();
    } else if (getMinX() > env.getMaxX()) {
      dx = getMinX() - env.getMaxX();
    }

    double dy = 0.0;
    if (getMaxY() < env.getMinY()) {
      dy = env.getMinY() - getMaxY();
    } else if (getMinY() > env.getMaxY()) {
      dy = getMinY() - env.getMaxY();
    }

    double dz = 0.0;
    double otherMinZ = getMinZOf(env);
    double otherMaxZ = getMaxZOf(env);
    if (maxz < otherMinZ) {
      dz = otherMinZ - maxz;
    } else if (minz > otherMaxZ) {
      dz = minz - otherMaxZ;
    }

    // if either is zero, the envelopes overlap either vertically or
    // horizontally
    if (dx == 0.0 && dz == 0.0) {
      return dy;
    }
    if (dy == 0.0 && dz == 0.0) {
      return dx;
    }
    if (dx == 0.0 && dy == 0.0) {
      return dz;
    }
    return Math.sqrt(dx * dx + dy * dy + dz * dz);
  }
 boolean tooSmallOnScreen(Envelope env) {
   double[] d = new double[] {env.getMinX(), env.getMinY(), env.getMaxX(), env.getMaxY()};
   getMap().getViewportModel().worldToScreenTransform().transform(d, 0, d, 0, 2);
   Rectangle r =
       new Rectangle(
           (int) d[0], (int) d[1], (int) Math.abs(d[2] - d[0]), (int) Math.abs(d[3] - d[1]));
   return (double) r.getWidth()
           < getMap().getRenderManager().getMapDisplay().getWidth() / (double) 16
       && (double) r.getHeight()
           < getMap().getRenderManager().getMapDisplay().getHeight() / (double) 16;
 }
Пример #17
0
  /**
   * Getes the coordinates for the rectangle starting with the lower left point. The coordinates are
   * oriented CW.
   *
   * @return the coordinates for the rectangle
   */
  protected List getCoordinatesOfEnvelope() {
    Envelope env = getEnvelope();

    List coords = new ArrayList();
    coords.add(new Coordinate(env.getMinX(), env.getMinY()));
    coords.add(new Coordinate(env.getMinX(), env.getMaxY()));
    coords.add(new Coordinate(env.getMaxX(), env.getMaxY()));
    coords.add(new Coordinate(env.getMaxX(), env.getMinY()));
    coords.add(new Coordinate(env.getMinX(), env.getMinY()));
    return coords;
  }
Пример #18
0
  /**
   * Step 2 of the bootstrapping process.
   *
   * <p>Calculating the the extent for each image level (original + pyramids). This calculation is
   * only done if the extent info in the master table is SQL NULL. After calculation the meta table
   * is updated with the result to avoid this operation in the future.
   *
   * @param coverageName The coverage name in the sql meta table
   * @param con JDBC connection
   * @throws SQLException
   * @throws IOException
   */
  void calculateExtentsFromDB(String coverageName, Connection con)
      throws SQLException, IOException {
    PreparedStatement stmt = con.prepareStatement(config.getSqlUpdateMosaicStatement());

    List<ImageLevelInfo> toBeRemoved = new ArrayList<ImageLevelInfo>();

    for (ImageLevelInfo li : levelInfos) {
      if (li.getCoverageName().equals(coverageName) == false) {
        continue;
      }

      if (li.calculateExtentsNeeded() == false) {
        continue;
      }

      Date start = new Date();
      if (LOGGER.isLoggable(Level.INFO)) LOGGER.info("Calculate extent for " + li.toString());

      Envelope env = getExtent(li, con);

      if (env == null) {
        if (LOGGER.isLoggable(Level.WARNING))
          LOGGER.log(Level.WARNING, "No extent, removing this level");
        toBeRemoved.add(li);

        continue;
      }

      li.setExtentMaxX(new Double(env.getMaxX()));
      li.setExtentMaxY(new Double(env.getMaxY()));
      li.setExtentMinX(new Double(env.getMinX()));
      li.setExtentMinY(new Double(env.getMinY()));

      stmt.setDouble(1, li.getExtentMaxX().doubleValue());
      stmt.setDouble(2, li.getExtentMaxY().doubleValue());
      stmt.setDouble(3, li.getExtentMinX().doubleValue());
      stmt.setDouble(4, li.getExtentMinY().doubleValue());
      stmt.setString(5, li.getCoverageName());
      stmt.setString(6, li.getTileTableName());
      stmt.setString(7, li.getSpatialTableName());
      stmt.execute();

      long msecs = (new Date()).getTime() - start.getTime();

      if (LOGGER.isLoggable(Level.INFO))
        LOGGER.info("Calculate extent for " + li.toString() + " finished in " + msecs + " ms ");
    }

    levelInfos.removeAll(toBeRemoved);

    if (stmt != null) {
      stmt.close();
    }
  }
Пример #19
0
    /**
     * Returns a {@link CoordinateSequence} for the {@code coordinates} property so its handled by a
     * {@link GMLCoordinatesTypeBinding} at encoding time as {@code gml:coordinates} that Ionic
     * understands
     */
    @Override
    public Object getProperty(Object object, QName name) throws Exception {
      Envelope e = (Envelope) object;
      if (GML.coordinates.equals(name)) {
        double[] seq = {e.getMinX(), e.getMinY(), e.getMaxX(), e.getMaxY()};
        CoordinateSequence coords = new PackedCoordinateSequence.Double(seq, 2);
        return coords;
      }

      return null;
    }
Пример #20
0
  @Override
  public Number[] getScope(int dimension) throws DriverException {
    if (cachedScope == null) {
      boolean open = isOpen();
      if (!open) {
        open();
      }
      for (int i = 0; i < getRowCount(); i++) {
        Metadata m = getMetadata();
        for (int j = 0; j < m.getFieldCount(); j++) {
          int typeCode = m.getFieldType(j).getTypeCode();
          Envelope r = null;
          if ((typeCode & Type.GEOMETRY) != 0) {
            Value v = getFieldValue(i, j);
            if ((v != null) && (!v.isNull())) {
              r = v.getAsGeometry().getEnvelopeInternal();
            }
          } else if (typeCode == Type.RASTER) {
            Value v = getFieldValue(i, j);
            if ((v != null) && (!v.isNull())) {
              r = v.getAsRaster().getMetadata().getEnvelope();
            }
          } else if (typeCode == Type.STREAM) {
            Value v = getFieldValue(i, j);
            if ((v != null) && (!v.isNull())) {
              r = v.getAsStream().getEnvelope();
            }
          }
          if (r != null) {
            if (cachedScope == null) {
              cachedScope = new Envelope(r);
            } else {
              cachedScope.expandToInclude(r);
            }
          }
        }
      }
      if (!open) {
        close();
      }
    }

    if (cachedScope == null) {
      return new Number[] {0, 0};
    } else {
      if (dimension == DataSet.X) {
        return new Number[] {cachedScope.getMinX(), cachedScope.getMaxX()};
      } else if (dimension == DataSet.Y) {
        return new Number[] {cachedScope.getMinY(), cachedScope.getMaxY()};
      } else {
        throw new UnsupportedOperationException("Not yet implemented");
      }
    }
  }
Пример #21
0
  public boolean onToolTouchEvent(MotionEvent event) {
    if (mapView == null || mapView.isClickable()) {
      return false;
    }
    Projection pj = editingViewProjection;

    // handle drawing
    currentX = event.getX();
    currentY = event.getY();

    int action = event.getAction();
    switch (action) {
      case MotionEvent.ACTION_DOWN:
        startGeoPoint = pj.fromPixels(round(currentX), round(currentY));
        pj.toPixels(startGeoPoint, startP);
        endP.set(startP.x, startP.y);

        drawingPath.reset();
        drawingPath.moveTo(startP.x, startP.y);

        lastX = currentX;
        lastY = currentY;
        break;
      case MotionEvent.ACTION_MOVE:
        float dx = currentX - lastX;
        float dy = currentY - lastY;
        if (abs(dx) < 1 && abs(dy) < 1) {
          lastX = currentX;
          lastY = currentY;
          return true;
        }
        GeoPoint currentGeoPoint = pj.fromPixels(round(currentX), round(currentY));
        pj.toPixels(currentGeoPoint, tmpP);
        drawingPath.lineTo(tmpP.x, tmpP.y);
        endP.set(tmpP.x, tmpP.y);

        EditManager.INSTANCE.invalidateEditingView();
        break;
      case MotionEvent.ACTION_UP:
        GeoPoint endGeoPoint = pj.fromPixels(round(currentX), round(currentY));
        GeometryFactory gf = new GeometryFactory();
        Coordinate startCoord =
            new Coordinate(startGeoPoint.getLongitude(), startGeoPoint.getLatitude());
        com.vividsolutions.jts.geom.Point startPoint = gf.createPoint(startCoord);
        Coordinate endCoord = new Coordinate(endGeoPoint.getLongitude(), endGeoPoint.getLatitude());
        com.vividsolutions.jts.geom.Point endPoint = gf.createPoint(endCoord);
        Envelope env = new Envelope(startCoord, endCoord);
        select(env.getMaxY(), env.getMinX(), env.getMinY(), env.getMaxX(), startPoint, endPoint);
        //            EditManager.INSTANCE.invalidateEditingView();
        break;
    }

    return true;
  }
Пример #22
0
  @Test
  public void toGeometry_BoundingBox() {
    BoundingBox bbox = new ReferencedEnvelope(-10, 10, -5, 5, null);
    Geometry geom = JTS.toGeometry(bbox);
    assertTrue(geom instanceof com.vividsolutions.jts.geom.Polygon);

    Envelope geomEnv = geom.getEnvelopeInternal();
    assertEquals(-10.0, geomEnv.getMinX(), TOL);
    assertEquals(10.0, geomEnv.getMaxX(), TOL);
    assertEquals(-5.0, geomEnv.getMinY(), TOL);
    assertEquals(5.0, geomEnv.getMaxY(), TOL);
  }
Пример #23
0
  /**
   * Transforms an envelope in map units to image units
   *
   * @param geographicEnvelope The {@link Envelope} in map units.
   * @return Rectangle2DDouble The envelope in image units as a {@link Rectangle2DDouble}.
   */
  public Rectangle2DDouble toPixel(Envelope geographicEnvelope) {
    final Point2D lowerRight =
        new Point2D.Double(geographicEnvelope.getMaxX(), geographicEnvelope.getMinY());
    final Point2D upperLeft =
        new Point2D.Double(geographicEnvelope.getMinX(), geographicEnvelope.getMaxY());

    final Point2D ul = trans.transform(upperLeft, null);
    final Point2D lr = trans.transform(lowerRight, null);

    return new Rectangle2DDouble(
        ul.getX(), ul.getY(), lr.getX() - ul.getX(), lr.getY() - ul.getY());
  }
Пример #24
0
  @Test
  public void toGeometry_ReferencedEnvelope() {
    ReferencedEnvelope refEnv = new ReferencedEnvelope(-10, 10, -5, 5, DefaultGeographicCRS.WGS84);
    Geometry geom = JTS.toGeometry(refEnv);
    assertTrue(geom instanceof com.vividsolutions.jts.geom.Polygon);

    Envelope geomEnv = geom.getEnvelopeInternal();
    assertEquals(-10.0, geomEnv.getMinX(), TOL);
    assertEquals(10.0, geomEnv.getMaxX(), TOL);
    assertEquals(-5.0, geomEnv.getMinY(), TOL);
    assertEquals(5.0, geomEnv.getMaxY(), TOL);
  }
Пример #25
0
  @Test
  public void toGeometry_Envelope() {
    Envelope refEnv = new Envelope(-10, 10, -5, 5);
    Geometry geom = JTS.toGeometry(refEnv);
    assertTrue(geom instanceof com.vividsolutions.jts.geom.Polygon);

    Envelope geomEnv = geom.getEnvelopeInternal();
    assertEquals(-10.0, geomEnv.getMinX(), TOL);
    assertEquals(10.0, geomEnv.getMaxX(), TOL);
    assertEquals(-5.0, geomEnv.getMinY(), TOL);
    assertEquals(5.0, geomEnv.getMaxY(), TOL);
  }
  /**
   * Creates a rectangular {@link Polygon}.
   *
   * @return a rectangular Polygon
   */
  public Polygon createRectangle() {
    int i;
    int ipt = 0;
    int nSide = nPts / 4;
    if (nSide < 1) nSide = 1;
    double XsegLen = dim.getEnvelope().getWidth() / nSide;
    double YsegLen = dim.getEnvelope().getHeight() / nSide;

    Coordinate[] pts = new Coordinate[4 * nSide + 1];
    Envelope env = dim.getEnvelope();

    double maxx = env.getMinX() + nSide * XsegLen;
    double maxy = env.getMinY() + nSide * XsegLen;

    for (i = 0; i < nSide; i++) {
      double x = env.getMinX() + i * XsegLen;
      double y = env.getMinY();
      pts[ipt++] = new Coordinate(x, y);
    }
    for (i = 0; i < nSide; i++) {
      double x = env.getMaxX();
      double y = env.getMinY() + i * YsegLen;
      pts[ipt++] = new Coordinate(x, y);
    }
    for (i = 0; i < nSide; i++) {
      double x = env.getMaxX() - i * XsegLen;
      double y = env.getMaxY();
      pts[ipt++] = new Coordinate(x, y);
    }
    for (i = 0; i < nSide; i++) {
      double x = env.getMinX();
      double y = env.getMaxY() - i * YsegLen;
      pts[ipt++] = new Coordinate(x, y);
    }
    pts[ipt++] = new Coordinate(pts[0]);

    LinearRing ring = geomFact.createLinearRing(pts);
    Polygon poly = geomFact.createPolygon(ring, null);
    return poly;
  }
Пример #27
0
  /**
   * Write the headers for this shapefile including the bounds, shape type, the number of geometries
   * and the total fileLength (in actual bytes, NOT 16 bit words).
   */
  public void writeHeaders(
      final Envelope bounds,
      final ShapeType type,
      final int numberOfGeometries,
      final int fileLength)
      throws IOException {

    try {
      handler = type.getShapeHandler(true);
    } catch (DataStoreException se) {
      throw new RuntimeException("unexpected Exception", se);
    }
    if (shapeBuffer == null) allocateBuffers();

    ShapefileHeader.write(
        shapeBuffer,
        type,
        fileLength / 2,
        bounds.getMinX(),
        bounds.getMinY(),
        bounds.getMaxX(),
        bounds.getMaxY());

    shx.moveToHeaderStart();
    shx.writeHeader(
        type,
        50 + 4 * numberOfGeometries,
        bounds.getMinX(),
        bounds.getMinY(),
        bounds.getMaxX(),
        bounds.getMaxY());

    offset = 50;
    this.type = type;
    cnt = 0;

    shpChannel.position(0);
    drain();
  }
Пример #28
0
 /**
  * Computes the intersection of two {@link Envelope}s.
  *
  * @param env the envelope to intersect with
  * @return a new Envelope representing the intersection of the envelopes (this will be the null
  *     envelope if either argument is null, or they do not intersect
  */
 @Override
 public Envelope3D intersection(final Envelope env) {
   if (isNull() || env.isNull() || !intersects(env)) {
     return new Envelope3D();
   }
   Envelope xyInt = super.intersection(env);
   double otherMinZ = getMinZOf(env);
   double intMinZ = minz > otherMinZ ? minz : otherMinZ;
   double otherMaxZ = getMaxZOf(env);
   double intMaxZ = maxz < otherMaxZ ? maxz : otherMaxZ;
   return new Envelope3D(
       xyInt.getMinX(), xyInt.getMaxX(), xyInt.getMinY(), xyInt.getMaxY(), intMinZ, intMaxZ);
 }
Пример #29
0
 /**
  * insert an item which is known to be contained in the tree rooted at the given QuadNode root.
  * Lower levels of the tree will be created if necessary to hold the item.
  */
 private void insertContained(ExitEarlyNode tree, Envelope itemEnv, Object item) {
   Assert.isTrue(tree.getEnvelope().contains(itemEnv));
   /**
    * Do NOT create a new quad for zero-area envelopes - this would lead to infinite recursion.
    * Instead, use a heuristic of simply returning the smallest existing quad containing the query
    */
   boolean isZeroX = IntervalSize.isZeroWidth(itemEnv.getMinX(), itemEnv.getMaxX());
   boolean isZeroY = IntervalSize.isZeroWidth(itemEnv.getMinY(), itemEnv.getMaxY());
   ExitEarlyNodeBase node;
   if (isZeroX || isZeroY) node = tree.find(itemEnv);
   else node = tree.getNode(itemEnv);
   node.add(item);
 }
Пример #30
0
 /**
  * Writes an Envelope instance as GeoJSON returning the result as a string.
  *
  * @param e The envelope
  * @return The envelope encoded as GeoJSON
  */
 public String toString(Envelope e) {
   return new StringBuffer()
       .append("[")
       .append(e.getMinX())
       .append(",")
       .append(e.getMinY())
       .append(",")
       .append(e.getMaxX())
       .append(",")
       .append(e.getMaxY())
       .append("]")
       .toString();
 }