Package org.geotools.geometry.jts

Examples of org.geotools.geometry.jts.ReferencedEnvelope


                        // try getting an envelope out of the crs
                        org.opengis.geometry.Envelope envelope = CRS.getEnvelope(crs);

                        if (envelope != null) {
                            bounds = new ReferencedEnvelope(envelope.getLowerCorner()
                                    .getOrdinate(0), envelope.getUpperCorner().getOrdinate(0),
                                    envelope.getLowerCorner().getOrdinate(1), envelope
                                            .getUpperCorner().getOrdinate(1), crs);
                        } else {
                            // TODO: perhaps access a preference which indicates
                            // whether to do a full table scan
                            // bounds = new ReferencedEnvelope(new Envelope(),crs);
                            // as a last resort do the full scan
                            bounds = new ReferencedEnvelope(new Envelope(), crs);
                            FeatureIterator<SimpleFeature> iter = source.getFeatures().features();
                            try {
                                while( iter.hasNext() ) {
                                    SimpleFeature element = iter.next();
                                    if (bounds.isNull())
                                        bounds.init(element.getBounds());
                                    else
                                        bounds.include(element.getBounds());
                                }
                            } finally {
                                iter.close();
                            }
                        }
                    }
                } catch (DataSourceException e) {
                    MySQLPlugin.log("Exception while generating MySQLGeoResource.", e); //$NON-NLS-1$
                } catch (Exception e) {
                    CatalogPlugin
                            .getDefault()
                            .getLog()
                            .log(
                                    new org.eclipse.core.runtime.Status(
                                            IStatus.WARNING,
                                            "org.locationtech.udig.catalog", 0, Messages.MySQLGeoResource_error_layer_bounds, e)); //$NON-NLS-1$
                    bounds = new ReferencedEnvelope(new Envelope(), null);
                }

            }
            return super.getBounds();
        }
View Full Code Here


    class SetZoomToMapToolAction extends Action {
        public SetZoomToMapToolAction() {
            super("Zoom to Map"); //$NON-NLS-1$
        }
        public void run() {
            ReferencedEnvelope bounds = getMap().getBounds(new NullProgressMonitor());
            getMap().sendCommandASync(new SetViewportBBoxCommand(bounds));
        }
View Full Code Here

    public ReferencedEnvelope getBounds(IProgressMonitor monitor, CoordinateReferenceSystem crs) {
        if (crs == null) {
            crs = getCRS();
        }
        ReferencedEnvelope result;

        if (bounds == null) {
            result = obtainBoundsFromResources(monitor);
        } else {
            result = bounds;
        }

        if (result != null && !result.isNull()) {
            DefaultEngineeringCRS generic2d = DefaultEngineeringCRS.GENERIC_2D;
            if (crs != null && result.getCoordinateReferenceSystem() != generic2d) {
                try {
                    result = result.transform(crs, true);
                } catch (Exception fe) {
                    ProjectPlugin.log("failure to transform layer bounds", fe); //$NON-NLS-1$
                }
            }
        } else {
            return new ReferencedEnvelope(new Envelope(), null);
        }

        return result;

    }
View Full Code Here

        return result;

    }

    private ReferencedEnvelope obtainBoundsFromResources(IProgressMonitor monitor) {
        ReferencedEnvelope result = null;
        for (IGeoResource resource : getGeoResources()) {
            //IGeoResourceInfo info = resource.getInfo(monitor);
            IGeoResourceInfo info = getInfo(resource, monitor);
            Envelope tmp = null;
            if (info != null)
                tmp = info.getBounds();

            if (tmp instanceof ReferencedEnvelope
                    && ((ReferencedEnvelope) tmp).getCoordinateReferenceSystem() != null) {
                result = (ReferencedEnvelope) tmp;
            } else {
                result = new ReferencedEnvelope(tmp.getMinX(), tmp.getMaxX(), tmp.getMinY(),
                        tmp.getMaxY(), getCRS());
            }

            if (result != null) {
                break;
View Full Code Here

    @Override
    protected Control createContents( Composite parent ) {
        final Layer layer = (Layer) getElement();
        final CoordinateReferenceSystem layerCRS = layer.getCRS();
        ReferencedEnvelope bounds = layer.getBounds(ProgressManager.instance().get(), layerCRS);
       
        final List<SummaryData> data=new ArrayList<SummaryData>();
        String name = layer.getName();
        nameData=new SummaryData(Messages.LayerSummary_name, name==null?"":name); //$NON-NLS-1$
        nameData.setModifier(new NameModifier());
View Full Code Here

    if(oldScaleDenom<=0 || Double.isInfinite(oldScaleDenom) || Double.isNaN(oldScaleDenom)){
      return currentBounds;
    }
    double ratio = newScaleDenominator / oldScaleDenom;
    double newWidth = currentBounds.getWidth() * ratio;
    ReferencedEnvelope newExtent = calculateBounds(newWidth, displaySize,
        currentBounds);
    double calculatedScale = calculateScaleDenominator(newExtent,
        displaySize, dpi);
    if (Math.abs(calculatedScale - newScaleDenominator) > ACCURACY
        && iterations < MAX_ITERATIONS && calculatedScale>0) {
View Full Code Here

        .getCoordinateReferenceSystem();
    double minx = center.x - width / 2;
    double maxx = center.x + width / 2;
    double miny = center.y - height / 2;
    double maxy = center.y + height / 2;
    return new ReferencedEnvelope(minx, maxx, miny, maxy, crs);
  }
View Full Code Here

    return new ReferencedEnvelope(minx, maxx, miny, maxy, crs);
  }

  private static double distancePerPixel(Dimension displaySize,
      ReferencedEnvelope currentBounds) {
    ReferencedEnvelope referencePixel = toValidPixelBoundsClosestToCenter(
        displaySize, currentBounds);
    try {
      ReferencedEnvelope referencePixelLatLong = referencePixel
          .transform(DefaultGeographicCRS.WGS84, true);
      double minX = referencePixelLatLong.getMinX();
      double maxX = referencePixelLatLong.getMaxX();
      double scale = 1;

      if (referencePixelLatLong.getWidth() > 360) {
        scale = referencePixelLatLong.getWidth() / 18;
        minX = 0;
        maxX = 180;
      }
      GeodeticCalculator calc = new GeodeticCalculator();
      double centerY = centeredYWithinWorld(referencePixelLatLong);
View Full Code Here

    Coordinate centre = currentBounds.centre();
    Point referencePixel = nearestPixel(centre.x, centre.y, currentBounds,
        displaySize);

    ReferencedEnvelope pixelBounds = pixelBounds(referencePixel.x,
        referencePixel.y, currentBounds, displaySize);

    return shiftToWorld(pixelBounds);
  }
View Full Code Here

    return shiftToWorld(pixelBounds);
  }

  static ReferencedEnvelope shiftToWorld(ReferencedEnvelope pixelBounds) {
    DefaultGeographicCRS wgs84 = DefaultGeographicCRS.WGS84;
    ReferencedEnvelope latLong;
    try {
      latLong = pixelBounds.transform(wgs84, true);

      if (WORLD.contains(latLong)) {
        return pixelBounds;
      }

      double deltax = 0, deltay = 0;
      if (latLong.getWidth() < WORLD.getWidth()) {
        if (latLong.getMinX() < WORLD.getMinX()) {
          deltax = WORLD.getMinX() - latLong.getMinX();
        }
        if (latLong.getMaxX() > WORLD.getMaxX()) {
          deltax = WORLD.getMaxX() - latLong.getMaxX();
        }
      }

      if (latLong.getHeight() < WORLD.getHeight()) {
        if (latLong.getMinY() < WORLD.getMinY()) {
          deltay = WORLD.getMinY() - latLong.getMinY();
        }
        if (latLong.getMaxY() > WORLD.getMaxY()) {
          deltay = WORLD.getMaxX() - latLong.getMaxY();
        }
      }

      latLong.translate(deltax, deltay);

      return latLong.transform(
          pixelBounds.getCoordinateReferenceSystem(), true);
    } catch (TransformException e) {
      ProjectPlugin.log("", e);
    } catch (FactoryException e) {
      ProjectPlugin.log("", e);
View Full Code Here

TOP

Related Classes of org.geotools.geometry.jts.ReferencedEnvelope

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.