Java Code Examples for org.geotools.geometry.jts.ReferencedEnvelope

The following examples show how to use org.geotools.geometry.jts.ReferencedEnvelope. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: sldeditor   Source File: RenderPanelImpl.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * Calculate bounds.
 *
 * @return the referenced envelope
 */
private ReferencedEnvelope calculateBounds() {
    ReferencedEnvelope bounds = null;

    try {
        bounds = featureList.getBounds();

        if (bounds == null) {
            // It could be that the above call was too costly!
            bounds = featureList.getFeatures().getBounds();
        }

        if (bounds.getCoordinateReferenceSystem() == null) {
            // We need a coordinate reference system set otherwise
            // transformations fail to render
            bounds = ReferencedEnvelope.create(bounds, DefaultGeographicCRS.WGS84);
        }

        if (bounds != null) {
            expandEnvelope(bounds);
        }
    } catch (IOException e) {
        ConsoleManager.getInstance().exception(this, e);
    }
    return bounds;
}
 
Example 2
private RasterizingContainer callPipeline(ClientMapInfo clientMapInfo, PipelineContext context, String pipelineKey)
		throws GeomajasException {
	DefaultMapContext mapContext = new DefaultMapContext();
	mapContext.setCoordinateReferenceSystem(geoService.getCrs2(clientMapInfo.getCrs()));
	MapRasterizingInfo mapInfo = (MapRasterizingInfo) clientMapInfo.getWidgetInfo(MapRasterizingInfo.WIDGET_KEY);
	mapContext.setAreaOfInterest(new ReferencedEnvelope(dtoConverterService.toInternal(mapInfo.getBounds()),
			mapContext.getCoordinateReferenceSystem()));
	RenderingHints renderingHints = new Hints();
	renderingHints.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
	RasterizingContainer response = new RasterizingContainer();
	context.put(RasterizingPipelineCode.CLIENT_MAP_INFO_KEY, clientMapInfo);
	context.put(RasterizingPipelineCode.RENDERING_HINTS, renderingHints);
	Map<Object, Object> rendererHints = new HashMap<Object, Object>();
	if (mapInfo.getDpi() > 0) {
		rendererHints.put(StreamingRenderer.DPI_KEY, mapInfo.getDpi());
	}
	context.put(RasterizingPipelineCode.RENDERER_HINTS, rendererHints);
	context.put(RasterizingPipelineCode.MAP_CONTEXT_KEY, mapContext);
	pipelineService.execute(pipelineKey, null, context, response);
	mapContext.dispose();
	return response;
}
 
Example 3
Source Project: snap-desktop   Source File: FeatureLayer.java    License: GNU General Public License v3.0 6 votes vote down vote up
public FeatureLayer(LayerType layerType, final FeatureCollection<SimpleFeatureType, SimpleFeature> fc,
                    PropertySet configuration) {
    super(layerType, configuration);
    crs = fc.getSchema().getGeometryDescriptor().getCoordinateReferenceSystem();
    if (crs == null) {
        // todo - check me! Why can this happen??? (nf)
        crs = DefaultGeographicCRS.WGS84;
    }
    final ReferencedEnvelope envelope = new ReferencedEnvelope(fc.getBounds(), crs);
    modelBounds = new Rectangle2D.Double(envelope.getMinX(), envelope.getMinY(),
                                         envelope.getWidth(), envelope.getHeight());
    mapContext = new DefaultMapContext(crs);
    final Style style = (Style) configuration.getValue(FeatureLayerType.PROPERTY_NAME_SLD_STYLE);
    mapContext.addLayer(fc, style);
    renderer = new StreamingRenderer();
    workaroundLabelCacheBug();
    style.accept(new RetrievingStyleVisitor());
    renderer.setContext(mapContext);

}
 
Example 4
/**
 * Populate field.
 *
 * @param value the value
 */
@Override
public void populateField(ReferencedEnvelope value) {
    xMinTextField.setText(Double.toString(value.getMinX()));
    xMaxTextField.setText(Double.toString(value.getMaxX()));
    yMinTextField.setText(Double.toString(value.getMinY()));
    yMaxTextField.setText(Double.toString(value.getMaxY()));

    String key = CoordManager.getInstance().getCRSCode(value.getCoordinateReferenceSystem());

    crsComboBox.setSelectValueKey(key);

    if (!FieldConfigBoundingBox.this.isSuppressUndoEvents()) {
        UndoManager.getInstance()
                .addUndoEvent(new UndoEvent(this, getFieldId(), oldValueObj, value));
        oldValueObj = value;
    }
}
 
Example 5
Source Project: hortonmachine   Source File: DaoGpsLog.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * Get the current data envelope.
 * 
 * @param connection the db connection.
 * @return the envelope.
 * @throws Exception
 */
public static ReferencedEnvelope getEnvelope( IHMConnection connection ) throws Exception {
    String query = "SELECT min(" + //
            GpsLogsDataTableFields.COLUMN_DATA_LON.getFieldName() + "), max(" + //
            GpsLogsDataTableFields.COLUMN_DATA_LON.getFieldName() + "), min(" + //
            GpsLogsDataTableFields.COLUMN_DATA_LAT.getFieldName() + "), max(" + //
            GpsLogsDataTableFields.COLUMN_DATA_LAT.getFieldName() + ") " + //
            " FROM " + TABLE_GPSLOG_DATA;
    try (IHMStatement statement = connection.createStatement(); IHMResultSet rs = statement.executeQuery(query);) {
        if (rs.next()) {
            double minX = rs.getDouble(1);
            double maxX = rs.getDouble(2);
            double minY = rs.getDouble(3);
            double maxY = rs.getDouble(4);

            ReferencedEnvelope env = new ReferencedEnvelope(minX, maxX, minY, maxY, DefaultGeographicCRS.WGS84);
            return env;
        }
    }

    return null;
}
 
Example 6
Source Project: geowave   Source File: RasterUtils.java    License: Apache License 2.0 6 votes vote down vote up
public static ReferencedEnvelope getReferenceEnvelope(
    final GridCoverage gridCoverage,
    final CoordinateReferenceSystem targetCrs) {
  final CoordinateReferenceSystem sourceCrs = gridCoverage.getCoordinateReferenceSystem();
  final Envelope sampleEnvelope = gridCoverage.getEnvelope();

  final ReferencedEnvelope sampleReferencedEnvelope =
      new ReferencedEnvelope(
          new org.locationtech.jts.geom.Envelope(
              sampleEnvelope.getMinimum(0),
              sampleEnvelope.getMaximum(0),
              sampleEnvelope.getMinimum(1),
              sampleEnvelope.getMaximum(1)),
          gridCoverage.getCoordinateReferenceSystem());

  ReferencedEnvelope projectedReferenceEnvelope = sampleReferencedEnvelope;
  if ((targetCrs != null) && !targetCrs.equals(sourceCrs)) {
    try {
      projectedReferenceEnvelope = sampleReferencedEnvelope.transform(targetCrs, true);
    } catch (TransformException | FactoryException e) {
      LOGGER.warn("Unable to transform envelope of grid coverage to " + targetCrs.getName(), e);
    }
  }
  return projectedReferenceEnvelope;
}
 
Example 7
/**
 * Test method for {@link
 * com.sldeditor.filter.v2.envvar.EnvironmentVariableManager#setWMSEnvVarValues(com.sldeditor.filter.v2.envvar.WMSEnvVarValues)}.
 */
@Test
public void testSetWMSEnvVarValues() {
    EnvironmentVariableManager.getInstance().setWMSEnvVarValues(null);

    WMSEnvVarValues wmsEnvVar = new WMSEnvVarValues();

    wmsEnvVar.setImageHeight(42);
    wmsEnvVar.setImageWidth(454);
    Envelope envelope = new Envelope(1.0, 2.0, 50.0, 51.1);
    ReferencedEnvelope mapBounds =
            ReferencedEnvelope.create(envelope, CoordManager.getInstance().getWGS84());
    wmsEnvVar.setMapBounds(mapBounds);

    EnvironmentVariableManager.getInstance().setWMSEnvVarValues(wmsEnvVar);

    // Update the values again
    WMSEnvVarValues wmsEnvVar2 = new WMSEnvVarValues();
    wmsEnvVar2.setImageHeight(69);
    wmsEnvVar2.setImageWidth(123);
    Envelope envelope2 = new Envelope(-1.0, -2.0, 50.0, 51.1);
    ReferencedEnvelope mapBounds2 =
            ReferencedEnvelope.create(envelope2, CoordManager.getInstance().getWGS84());
    wmsEnvVar2.setMapBounds(mapBounds2);
    EnvironmentVariableManager.getInstance().setWMSEnvVarValues(wmsEnvVar2);
}
 
Example 8
public Layer createLayer(MapContext mapContext, ClientLayerInfo clientLayerInfo) throws GeomajasException {
	if (!(clientLayerInfo instanceof ClientRasterLayerInfo)) {
		throw new IllegalArgumentException(
				"RasterLayerFactory.createLayer() should only be called using ClientRasterLayerInfo");
	}
	ClientRasterLayerInfo rasterInfo = (ClientRasterLayerInfo) clientLayerInfo;
	RasterLayerRasterizingInfo extraInfo = (RasterLayerRasterizingInfo) rasterInfo
			.getWidgetInfo(RasterLayerRasterizingInfo.WIDGET_KEY);
	ReferencedEnvelope areaOfInterest = mapContext.getAreaOfInterest();
	final RasterLayer layer = configurationService.getRasterLayer(clientLayerInfo.getServerLayerId());
	MapViewport port = mapContext.getViewport();
	double rasterScale = port.getScreenArea().getWidth() / port.getBounds().getWidth();
	List<RasterTile> tiles = rasterLayerService.getTiles(clientLayerInfo.getServerLayerId(),
			areaOfInterest.getCoordinateReferenceSystem(), areaOfInterest, rasterScale);
	RasterDirectLayer rasterLayer = new RasterDirectLayer(imageThreadPool, new UrlDownLoader() {

		@Override
		public InputStream getStream(String url) throws IOException {
			return httpService.getStream(url, layer);
		}
	}, tiles, layer.getLayerInfo().getTileWidth(), layer.getLayerInfo().getTileHeight(), extraInfo.getCssStyle());
	rasterLayer.setTitle(clientLayerInfo.getLabel());
	rasterLayer.getUserData().put(USERDATA_KEY_LAYER_ID, layer.getId());
	rasterLayer.getUserData().put(USERDATA_KEY_SHOWING, extraInfo.isShowing());
	return rasterLayer;
}
 
Example 9
Source Project: hortonmachine   Source File: MainController.java    License: GNU General Public License v3.0 6 votes vote down vote up
private void zoomToSubItems() {
    if (currentFeaturesList != null) {
        int size = currentFeaturesList.size();
        if (currentFeatureIndex < 0) {
            currentFeatureIndex = 0;
        } else if (currentFeatureIndex > size - 1) {
            currentFeatureIndex = size - 1;
        }

        SimpleFeature simpleFeature = currentFeaturesList.get(currentFeatureIndex);
        Envelope env = ((Geometry) simpleFeature.getDefaultGeometry()).getEnvelopeInternal();
        if (env.getWidth() == 0) {
            env.expandBy(0.1);
        } else {
            env.expandBy(env.getWidth() * 0.05);
        }

        mapPane.setDisplayArea(new ReferencedEnvelope(env, simpleFeature.getFeatureType().getCoordinateReferenceSystem()));
    }

}
 
Example 10
Source Project: gama   Source File: SwtMapPane.java    License: GNU General Public License v3.0 6 votes vote down vote up
public void setCrs(final CoordinateReferenceSystem crs) {
	try {
		final ReferencedEnvelope rEnv = getDisplayArea();

		final CoordinateReferenceSystem sourceCRS = rEnv.getCoordinateReferenceSystem();
		final CoordinateReferenceSystem targetCRS = crs;

		final MathTransform transform = CRS.findMathTransform(sourceCRS, targetCRS);
		final com.vividsolutions.jts.geom.Envelope newJtsEnv = JTS.transform(rEnv, transform);

		final ReferencedEnvelope newEnvelope = new ReferencedEnvelope(newJtsEnv, targetCRS);
		content.getViewport().setBounds(newEnvelope);
		fullExtent = null;
		doSetDisplayArea(newEnvelope);

	} catch (final Exception e) {
		e.printStackTrace();
	}
}
 
Example 11
Source Project: geowave   Source File: GeoWaveEmptyTransaction.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void add(final String fid, final SimpleFeature feature) throws IOException {
  feature.getUserData().put(Hints.USE_PROVIDED_FID, true);
  if (feature.getUserData().containsKey(Hints.PROVIDED_FID)) {
    final String providedFid = (String) feature.getUserData().get(Hints.PROVIDED_FID);
    feature.getUserData().put(Hints.PROVIDED_FID, providedFid);
  } else {
    feature.getUserData().put(Hints.PROVIDED_FID, feature.getID());
  }
  components.writeCommit(feature, this);

  components.getGTstore().getListenerManager().fireFeaturesAdded(
      components.getAdapter().getFeatureType().getTypeName(),
      Transaction.AUTO_COMMIT,
      ReferencedEnvelope.reference(feature.getBounds()),
      true);
}
 
Example 12
Source Project: geowave   Source File: GeoWaveFeatureCollection.java    License: Apache License 2.0 6 votes vote down vote up
private Geometry getBBox(final Query query, final ReferencedEnvelope envelope) {
  if (envelope != null) {
    return new GeometryFactory().toGeometry(envelope);
  }
  final String geomAtrributeName =
      reader.getComponents().getAdapter().getFeatureType().getGeometryDescriptor().getLocalName();
  final ExtractGeometryFilterVisitorResult geoAndCompareOp =
      ExtractGeometryFilterVisitor.getConstraints(
          query.getFilter(),
          reader.getComponents().getAdapter().getFeatureType().getCoordinateReferenceSystem(),
          geomAtrributeName);
  if (geoAndCompareOp == null) {
    return reader.clipIndexedBBOXConstraints(null);
  } else {
    return reader.clipIndexedBBOXConstraints(geoAndCompareOp.getGeometry());
  }
}
 
Example 13
Source Project: geowave   Source File: GeoWaveEmptyTransaction.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Record a modification to the indicated fid
 *
 * @param fid
 * @param original the original feature(prior state)
 * @param updated the update feature replacement feature; null to indicate remove
 */
@Override
public void modify(final String fid, final SimpleFeature original, final SimpleFeature updated)
    throws IOException {
  // point move?
  if (!updated.getBounds().equals(original.getBounds())) {
    components.remove(original, this);
    components.writeCommit(updated, new GeoWaveEmptyTransaction(components));
  } else {
    components.writeCommit(updated, new GeoWaveEmptyTransaction(components));
  }

  final ReferencedEnvelope bounds = new ReferencedEnvelope();
  bounds.include(updated.getBounds());
  bounds.include(original.getBounds());
  components.getGTstore().getListenerManager().fireFeaturesChanged(
      updated.getFeatureType().getTypeName(),
      Transaction.AUTO_COMMIT,
      bounds,
      true);
}
 
Example 14
@Override
public synchronized ReferencedEnvelope getOverallEnvelope() throws Exception {
    if (referencedEnvelope2D == null) {
        checkOpen();

        List<LasSource> lasSources = LasSourcesTable.getLasSources(spatialDb);
        ReferencedEnvelope total = new ReferencedEnvelope(crs);
        for( LasSource lasSource : lasSources ) {
            Envelope envelopeInternal = lasSource.polygon.getEnvelopeInternal();
            total.expandToInclude(envelopeInternal);
        }
        referencedEnvelope2D = total;
        referencedEnvelope2DList.add(referencedEnvelope2D);
    }
    return referencedEnvelope2D;
}
 
Example 15
Source Project: geowave   Source File: DecimationProcess.java    License: Apache License 2.0 6 votes vote down vote up
@DescribeResult(
    name = "result",
    description = "This is just a pass-through, the key is to provide enough information within invertQuery to perform a map to screen transform")
public SimpleFeatureCollection execute(
    @DescribeParameter(
        name = "data",
        description = "Feature collection containing the data") final SimpleFeatureCollection features,
    @DescribeParameter(
        name = "outputBBOX",
        description = "Georeferenced bounding box of the output") final ReferencedEnvelope argOutputEnv,
    @DescribeParameter(
        name = "outputWidth",
        description = "Width of the output raster") final Integer argOutputWidth,
    @DescribeParameter(
        name = "outputHeight",
        description = "Height of the output raster") final Integer argOutputHeight,
    @DescribeParameter(
        name = "pixelSize",
        description = "The pixel size to decimate by") final Double pixelSize)
    throws ProcessException {
  // vector-to-vector render transform that is just a pass through - the
  // key is to add map to screen transform within invertQuery
  return features;
}
 
Example 16
private void createBboxGeometry( CoordinateReferenceSystem crs, File lasFile, SimpleFeatureCollection outGeodata )
        throws Exception {
    final ReferencedEnvelope3D envelope = lasReader.getHeader().getDataEnvelope();
    ReferencedEnvelope env2d = new ReferencedEnvelope(envelope);
    final Polygon polygon = FeatureUtilities.envelopeToPolygon(new Envelope2D(env2d));

    final SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
    b.setName("lasdataenvelope");
    b.setCRS(crs);
    b.add("the_geom", Polygon.class);
    b.add("id", String.class);
    final SimpleFeatureType type = b.buildFeatureType();

    final SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type);
    final Object[] values = new Object[]{polygon, lasFile.getName()};
    builder.addAll(values);
    final SimpleFeature feature = builder.buildFeature(null);
    ((DefaultFeatureCollection) outGeodata).add(feature);
    OmsVectorWriter.writeVector(outFile, outGeodata);
}
 
Example 17
Source Project: elasticgeo   Source File: GeoHashGridTest.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testGeoHashGrid() throws Exception {
    features = TestUtil.createAggregationFeatures(ImmutableList.of(
            ImmutableMap.of("_aggregation", mapper.writeValueAsBytes(ImmutableMap.of("key",GeoHash.encodeHash(new LatLong(-89.9,-179.9),1),"doc_count",10)))
            ));
    ReferencedEnvelope envelope = new ReferencedEnvelope(-180,180,-90,90,DefaultGeographicCRS.WGS84);
    geohashGrid.initalize(envelope, features);
    assertEquals(GeoHash.widthDegrees(1), geohashGrid.getCellWidth(), 1e-10);
    assertEquals(GeoHash.heightDegrees(1), geohashGrid.getCellHeight(), 1e-10);
    assertEquals(new Envelope(-180+GeoHash.widthDegrees(1)/2.,180-GeoHash.widthDegrees(1)/2.,-90+GeoHash.heightDegrees(1)/2.,90-GeoHash.heightDegrees(1)/2.), geohashGrid.getEnvelope());
    int ny = (int) Math.round(180/geohashGrid.getCellHeight());
    int nx = (int) Math.round(360/GeoHash.widthDegrees(1));
    float[][] expected = new float[ny][nx];
    expected[ny-1][0] = 10;
    assertEquals(ny, geohashGrid.getGrid().length);
    assertEquals(nx, geohashGrid.getGrid()[0].length);
    IntStream.range(0, ny).forEach(i-> assertArrayEquals(expected[i], geohashGrid.getGrid()[i], 0.0f));
}
 
Example 18
public static void main( String[] args ) throws Exception {
    String lasPath = "/media/hydrologis/LESTOPLUS/test_lidar_spatialite/las_aurina/uni_bz_44.las";
    String outPath = "/home/hydrologis/TMP/tops_2m.asc";
    OmsPointCloudMaximaFinderStream s = new OmsPointCloudMaximaFinderStream();

    List<LasRecord> dotList = new ArrayList<>();
    try (ALasReader reader = ALasReader.getReader(new File(lasPath), null)) {
        reader.open();
        while( reader.hasNextPoint() ) {
            LasRecord dot = (LasRecord) reader.getNextPoint();
            dotList.add(dot);
        }
        s.inLas = dotList;
        ReferencedEnvelope3D dataEnvelope = reader.getHeader().getDataEnvelope();
        s.aoi = new ReferencedEnvelope(dataEnvelope);
        s.pBaseGridResolution = 0.5;
        s.pMaxRadius = 2;
        s.process();

        OmsRasterWriter.writeRaster(outPath, s.outCoverage);
    }

}
 
Example 19
public ImageMosaicNwwLayer( File imageMosaicShpFile, Integer tileSize, GeneralParameterValue[] gp,
        boolean removeSameColorImages ) throws Exception {
    super(makeLevels(imageMosaicShpFile, getRenderer(imageMosaicShpFile, gp), tileSize, removeSameColorImages));
    this.layerName = FileUtilities.getNameWithoutExtention(imageMosaicShpFile);

    ReferencedEnvelope envelope = OmsVectorReader.readEnvelope(imageMosaicShpFile.getAbsolutePath());
    ReferencedEnvelope envelopeLL = envelope.transform(DefaultGeographicCRS.WGS84, true);

    double w = envelopeLL.getMinX();
    double s = envelopeLL.getMinY();
    double e = envelopeLL.getMaxX();
    double n = envelopeLL.getMaxY();

    double centerX = w + (e - w) / 2.0;
    double centerY = s + (n - s) / 2.0;

    centerCoordinate = new Coordinate(centerX, centerY);

    this.setUseTransparentTextures(true);

}
 
Example 20
Source Project: elasticgeo   Source File: GeohashUtilTest.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testComputePrecision() {
    assertEquals(1, GeohashUtil.computePrecision(new ReferencedEnvelope(-180,180,-90,90,null), 32, 0.9));
    assertEquals(2, GeohashUtil.computePrecision(new ReferencedEnvelope(-180,180,-90,90,null), 1024, 0.9));
    assertEquals(3, GeohashUtil.computePrecision(new ReferencedEnvelope(-180,180,-90,90,null), 32768, 0.9));

    assertEquals(2, GeohashUtil.computePrecision(new ReferencedEnvelope(-180,180,-90,90,null), 1000, 0.9));
    assertEquals(3, GeohashUtil.computePrecision(new ReferencedEnvelope(-180,180,-90,90,null), 1500, 0.9));

    assertEquals(1, GeohashUtil.computePrecision(new ReferencedEnvelope(EVERYTHING.getMinX(),EVERYTHING.getMaxX(),EVERYTHING.getMinY(),EVERYTHING.getMaxY(),null), 32, 0.9));

    assertEquals(1, GeohashUtil.computePrecision(new ReferencedEnvelope(-1,1,-1,1,null), 0, 0.9));
    assertEquals(6, GeohashUtil.computePrecision(new ReferencedEnvelope(-180,180,-90,90,null), (long) 1e9, 0.9));
    assertEquals(6, GeohashUtil.computePrecision(new ReferencedEnvelope(-180,180,-90,90,null), 1, 1e9));
    assertEquals(1, GeohashUtil.computePrecision(new ReferencedEnvelope(-180,180,-90,90,null), 1, -1e9));
}
 
Example 21
Source Project: geowave   Source File: GeometryUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static SpatialOperator geometryToSpatialOperator(
    final Geometry jtsGeom,
    final String geometryAttributeName) {
  final FilterFactory2 factory = CommonFactoryFinder.getFilterFactory2();
  if (jtsGeom.equalsTopo(jtsGeom.getEnvelope())) {
    return factory.bbox(
        factory.property(geometryAttributeName),
        new ReferencedEnvelope(jtsGeom.getEnvelopeInternal(), GeometryUtils.getDefaultCRS()));
  }
  // there apparently is no way to associate a CRS with a poly
  // intersection operation so it will have to assume the same CRS as the
  // feature type
  return factory.intersects(factory.property(geometryAttributeName), factory.literal(jtsGeom));
}
 
Example 22
Source Project: sldeditor   Source File: RenderPanelImpl.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Render vector map.
 *
 * @param features the results
 * @param imageSize the image size
 * @param style the style
 * @param dpi the dpi
 */
private void renderVectorMap(
        FeatureSource<SimpleFeatureType, SimpleFeature> features,
        Rectangle imageSize,
        Style style,
        int dpi) {
    List<Layer> layerList = new ArrayList<>();
    if (style != null) {
        FeatureLayer featureLayer = new FeatureLayer(features, style);
        layerList.add(featureLayer);
    }

    boolean hasGeometry = false;
    ReferencedEnvelope bounds = null;

    if (features != null) {
        bounds = calculateBounds();

        wmsEnvVarValues.setMapBounds(bounds);

        EnvironmentVariableManager.getInstance().setWMSEnvVarValues(wmsEnvVarValues);

        if (features.getSchema() != null) {
            hasGeometry = (features.getSchema().getGeometryDescriptor() != null);
        }
    }

    internalRenderMap(layerList, bounds, imageSize, hasGeometry, dpi);
}
 
Example 23
/**
 * Populate expression.
 *
 * @param objValue the obj value
 */
/*
 * (non-Javadoc)
 *
 * @see com.sldeditor.ui.detail.config.FieldConfigBase#populateExpression(java.lang.Object)
 */
@Override
public void populateExpression(Object objValue) {
    if (objValue instanceof ReferencedEnvelope) {
        populateField((ReferencedEnvelope) objValue);

        valueUpdated();
    }
}
 
Example 24
@Override
public CrsTransform getCrsTransform(Crs sourceCrs, Crs targetCrs) throws GeomajasException {
	String key = getTransformKey(sourceCrs, targetCrs);
	CrsTransform transform = transformCache.get(key);
	if (null == transform) {
		MathTransform mathTransform = getBaseMathTransform(sourceCrs, targetCrs);

		// as there was no transformable area configured, try to build it instead
		Envelope transformableArea = null;
		try {
			org.opengis.geometry.Envelope ogEnvelope = CRS.getEnvelope(targetCrs);
			if (null != ogEnvelope) {
				Envelope envelope = new Envelope(ogEnvelope.getLowerCorner().getCoordinate()[0], ogEnvelope
						.getUpperCorner().getCoordinate()[0], ogEnvelope.getLowerCorner().getCoordinate()[1],
						ogEnvelope.getUpperCorner().getCoordinate()[1]);
				log.debug("CRS " + targetCrs.getId() + " envelope " + envelope);
				ReferencedEnvelope refEnvelope = new ReferencedEnvelope(envelope, targetCrs);
				transformableArea = refEnvelope.transform(sourceCrs, true);
				log.debug("transformable area for " + key + " is " + transformableArea);
			}
		} catch (MismatchedDimensionException mde) {
			log.warn(WARN_TRANSFORMABLE_AREA, new Object[] {sourceCrs.getId(), targetCrs.getId(),
					mde.getMessage()});
		} catch (TransformException te) {
			log.warn(WARN_TRANSFORMABLE_AREA, new Object[] {sourceCrs.getId(), targetCrs.getId(),
					te.getMessage()});
		} catch (FactoryException fe) {
			log.warn(WARN_TRANSFORMABLE_AREA, new Object[] {sourceCrs.getId(), targetCrs.getId(),
					fe.getMessage()});
		}

		transform = new CrsTransformImpl(key, sourceCrs, targetCrs, mathTransform, transformableArea);
		transformCache.put(key, transform);
	}
	return transform;
}
 
Example 25
/**
 * Redo action.
 *
 * @param undoRedoObject the undo/redo object
 */
@Override
public void redoAction(UndoInterface undoRedoObject) {
    if (undoRedoObject != null) {
        if (undoRedoObject.getNewValue() instanceof ReferencedEnvelope) {
            ReferencedEnvelope oldValue = (ReferencedEnvelope) undoRedoObject.getNewValue();

            populateField(oldValue);
        }
    }
}
 
Example 26
/**
 * Sets the test value.
 *
 * @param fieldId the field id
 * @param testValue the test value
 */
@Override
public void setTestValue(FieldIdEnum fieldId, ReferencedEnvelope testValue) {
    populateField(testValue);

    valueUpdated();
}
 
Example 27
Source Project: snap-desktop   Source File: MaskFormActions.java    License: GNU General Public License v3.0 5 votes vote down vote up
private static Rectangle2D handleVectorMask(Mask mask) {
    VectorDataNode vectorData = Mask.VectorDataType.getVectorData(mask);
    ReferencedEnvelope envelope = vectorData.getEnvelope();
    if (!envelope.isEmpty()) {
        return new Rectangle2D.Double(envelope.getMinX(), envelope.getMinY(),
                                      envelope.getWidth(), envelope.getHeight());
    }
    return null;
}
 
Example 28
Source Project: hortonmachine   Source File: DaoNotes.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Get the current data envelope.
 * 
 * @param connection the db connection.
 * @param noteTypeName if <code>null</code>, simple notes are handled. Else this 
 *          is taken as name for the note type.
 * @return the envelope.
 * @throws Exception
 */
public static ReferencedEnvelope getEnvelope( IHMConnection connection, String noteTypeName ) throws Exception {
    String query = "SELECT min(" + //
            NotesTableFields.COLUMN_LON.getFieldName() + "), max(" + //
            NotesTableFields.COLUMN_LON.getFieldName() + "), min(" + //
            NotesTableFields.COLUMN_LAT.getFieldName() + "), max(" + //
            NotesTableFields.COLUMN_LAT.getFieldName() + ") " + //
            " FROM " + TABLE_NOTES;

    if (noteTypeName != null) {
        query += " where " + NotesTableFields.COLUMN_TEXT.getFieldName() + "='" + noteTypeName + "'";
    } else {
        String formFN = NotesTableFields.COLUMN_FORM.getFieldName();
        query += " where " + formFN + " is null OR " + formFN + "=''";
    }

    try (IHMStatement statement = connection.createStatement(); IHMResultSet rs = statement.executeQuery(query);) {
        if (rs.next()) {
            double minX = rs.getDouble(1);
            double maxX = rs.getDouble(2);
            double minY = rs.getDouble(3);
            double maxY = rs.getDouble(4);

            ReferencedEnvelope env = new ReferencedEnvelope(minX, maxX, minY, maxY, DefaultGeographicCRS.WGS84);
            return env;
        }
    } catch (Exception e) {
        // print trace but return null
        e.printStackTrace();
    }

    return null;
}
 
Example 29
protected void showInMapFrame( boolean withLayers, SimpleFeatureCollection[] fcs, Style[] styles ) {
    if (mapFrame == null || !mapFrame.isVisible()) {
        Class<DatabaseController> class1 = DatabaseController.class;
        ImageIcon icon = new ImageIcon(class1.getResource("/org/hortonmachine/images/hm150.png"));
        mapFrame = new HMMapframe("Geometries Viewer");
        mapFrame.setIconImage(icon.getImage());
        mapFrame.enableToolBar(true);
        mapFrame.enableStatusBar(false);
        mapFrame.enableLayerTable(withLayers);
        mapFrame.enableTool(Tool.PAN, Tool.ZOOM, Tool.RESET);
        mapFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        if (withLayers) {
            mapFrame.setSize(900, 600);
        } else {
            mapFrame.setSize(600, 600);
        }
        mapFrame.setVisible(true);

    }
    ReferencedEnvelope renv = null;
    for( int i = 0; i < fcs.length; i++ ) {
        SimpleFeatureCollection fc = fcs[i];
        if (styles != null) {
            mapFrame.addLayer(fc, styles[i]);
        } else {
            mapFrame.addLayer(fc);
        }
        ReferencedEnvelope bounds = fc.getBounds();
        if (renv == null) {
            renv = bounds;
        } else {
            renv.expandToInclude(bounds);
        }
    }

    mapFrame.getMapPane().setDisplayArea(renv);
}
 
Example 30
@Override
public Coordinate getCenter() {
    try {
        ReferencedEnvelope bounds = getfeatureCollection().getBounds();
        return bounds.centre();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return new Coordinate(0, 0);
}