本文整理汇总了Java中org.geotools.geometry.jts.ReferencedEnvelope.getCoordinateReferenceSystem方法的典型用法代码示例。如果您正苦于以下问题:Java ReferencedEnvelope.getCoordinateReferenceSystem方法的具体用法?Java ReferencedEnvelope.getCoordinateReferenceSystem怎么用?Java ReferencedEnvelope.getCoordinateReferenceSystem使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.geotools.geometry.jts.ReferencedEnvelope
的用法示例。
在下文中一共展示了ReferencedEnvelope.getCoordinateReferenceSystem方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: drawImage
import org.geotools.geometry.jts.ReferencedEnvelope; //导入方法依赖的package包/类
public void drawImage( Graphics2D g2d, ReferencedEnvelope ref, int imageWidth, int imageHeight, double buffer ) {
checkMapContent();
if (buffer > 0.0)
ref.expandBy(buffer, buffer);
Rectangle2D refRect = new Rectangle2D.Double(ref.getMinX(), ref.getMinY(), ref.getWidth(), ref.getHeight());
Rectangle2D imageRect = new Rectangle2D.Double(0, 0, imageWidth, imageHeight);
GeometryUtilities.scaleToRatio(imageRect, refRect, false);
ReferencedEnvelope newRef = new ReferencedEnvelope(refRect, ref.getCoordinateReferenceSystem());
Rectangle imageBounds = new Rectangle(0, 0, imageWidth, imageHeight);
Color white = Color.white;
g2d.setColor(new Color(white.getRed(), white.getGreen(), white.getBlue(), 0));
g2d.fillRect(0, 0, imageWidth, imageHeight);
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
synchronized (renderer) {
content.getViewport().setBounds(newRef);
renderer.paint(g2d, imageBounds, newRef);
}
}
示例2: merge
import org.geotools.geometry.jts.ReferencedEnvelope; //导入方法依赖的package包/类
private Optional<ReferencedEnvelope> merge(final ReferencedEnvelope oldEnv,
final Collection<ReferencedEnvelope> dirtyList) {
final CoordinateReferenceSystem declaredCrs = oldEnv.getCoordinateReferenceSystem();
return dirtyList.stream()
.map(env->{
if(env instanceof ReferencedEnvelope3D) {
return new ReferencedEnvelope(env, CRS.getHorizontalCRS(env.getCoordinateReferenceSystem()));
} else {
return env;
}
})
.map(env->{
try {
return env.transform(declaredCrs, true, 1000);
} catch (TransformException | FactoryException e) {
throw new RuntimeException("Error while merging bounding boxes",e);
}
})
.reduce((env1, env2)->{ReferencedEnvelope x = new ReferencedEnvelope(env1); x.expandToInclude(env2); return x;});
}
示例3: setCrs
import org.geotools.geometry.jts.ReferencedEnvelope; //导入方法依赖的package包/类
public void setCrs(final CoordinateReferenceSystem crs) {
try {
// System.out.println(content.layers().size());
final ReferencedEnvelope rEnv = getDisplayArea();
// System.out.println(rEnv);
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);
// ReferencedEnvelope displayArea =
getDisplayArea();
// System.out.println(displayArea);
} catch (final Exception e) {
e.printStackTrace();
}
}
示例4: exampleReferencedEnvelope
import org.geotools.geometry.jts.ReferencedEnvelope; //导入方法依赖的package包/类
private void exampleReferencedEnvelope() throws Exception {
// exampleReferencedEnvelope start
ReferencedEnvelope envelope = new ReferencedEnvelope(0, 10, 0, 20, DefaultGeographicCRS.WGS84);
double xMin = envelope.getMinX();
double yMin = envelope.getMinY();
double xMax = envelope.getMaxX();
double yMax = envelope.getMaxY();
double width = envelope.getWidth();
double height = envelope.getHeight();
double xCenter = envelope.getMedian(0);
double yCenter = envelope.getMedian(1);
CoordinateReferenceSystem crs = envelope.getCoordinateReferenceSystem();
int dimension = envelope.getDimension();
// Direct access to internal upper and lower positions
DirectPosition lower = envelope.getLowerCorner();
DirectPosition upper = envelope.getUpperCorner();
// expand to include 15, 30
envelope.include(15, 30);
envelope.isEmpty(); // check if storing width and height are 0
envelope.isNull(); // check if "null" (not storing anything)
envelope.setToNull();
// exampleReferencedEnvelope end
}
示例5: calculateBounds
import org.geotools.geometry.jts.ReferencedEnvelope; //导入方法依赖的package包/类
/**
* 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) {
Unit<?> unit = CRSUtilities
.getUnit(bounds.getCoordinateReferenceSystem().getCoordinateSystem());
double width;
double height;
if (unit == NonSI.DEGREE_ANGLE) {
width = (bounds.getWidth() < BOUNDINGBOX_BUFFER_THRESHOLD_ANGLE)
? BOUNDINGBOX_BUFFER_MIN_ANGLE
: (bounds.getWidth() * BOUNDINGBOX_BUFFER_ANGLE);
height = (bounds.getHeight() < BOUNDINGBOX_BUFFER_THRESHOLD_ANGLE)
? BOUNDINGBOX_BUFFER_MIN_ANGLE
: (bounds.getHeight() * BOUNDINGBOX_BUFFER_ANGLE);
} else {
width = (bounds.getWidth() < BOUNDINGBOX_BUFFER_THRESHOLD_LINEAR)
? BOUNDINGBOX_BUFFER_MIN_LINEAR
: (bounds.getWidth() * BOUNDINGBOX_BUFFER_LINEAR);
height = (bounds.getHeight() < BOUNDINGBOX_BUFFER_THRESHOLD_LINEAR)
? BOUNDINGBOX_BUFFER_MIN_LINEAR
: (bounds.getHeight() * BOUNDINGBOX_BUFFER_LINEAR);
}
bounds.expandBy(width, height);
}
} catch (IOException e) {
ConsoleManager.getInstance().exception(this, e);
}
return bounds;
}
示例6: initalize
import org.geotools.geometry.jts.ReferencedEnvelope; //导入方法依赖的package包/类
public GeoHashGrid initalize(ReferencedEnvelope srcEnvelope, SimpleFeatureCollection features) throws NoSuchAuthorityCodeException, TransformException, FactoryException {
this.buckets = readFeatures(features);
final String firstGeohash = buckets.isEmpty() ? null : (String) buckets.get(0).get("key");
final int precision;
if (firstGeohash == null || !isValid(firstGeohash)) {
LOGGER.fine("No aggregations found or missing/invalid geohash key");
precision = DEFAULT_PRECISION;
} else {
precision = ((String) buckets.get(0).get("key")).length();
}
cellWidth = GeoHash.widthDegrees(precision);
cellHeight = GeoHash.heightDegrees(precision);
if (srcEnvelope.getCoordinateReferenceSystem() != null) {
srcEnvelope = srcEnvelope.transform(DefaultGeographicCRS.WGS84,false);
}
computeMinLonOffset(srcEnvelope);
envelope = computeEnvelope(srcEnvelope, precision);
boundingBox = new ReferencedEnvelope(envelope.getMinX()-cellWidth/2.0, envelope.getMaxX()+cellWidth/2.0,
envelope.getMinY()-cellHeight/2.0, envelope.getMaxY()+cellHeight/2.0, DefaultGeographicCRS.WGS84);
final int numCol = (int) Math.round((envelope.getMaxX()-envelope.getMinX())/cellWidth+1);
final int numRow = (int) Math.round((envelope.getMaxY()-envelope.getMinY())/cellHeight+1);
grid = new float[numRow][numCol];
LOGGER.fine("Created grid with size (" + numCol + ", " + numRow + ")");
if (emptyCellValue != 0) {
for (float[] row: grid)
Arrays.fill(row, emptyCellValue);
}
List<GridCell> cells = new ArrayList<>();
buckets.stream().forEach(bucket -> {
Number rasterValue = computeCellValue(bucket);
cells.add(new GridCell((String) bucket.get("key"), rasterValue));
scale.prepareScale(rasterValue.floatValue());
});
cells.stream().forEach(cell -> updateGrid(cell.getGeohash(), cell.getValue()));
LOGGER.fine("Read " + cells.size() + " aggregation buckets");
return this;
}
示例7: envelope2Sector
import org.geotools.geometry.jts.ReferencedEnvelope; //导入方法依赖的package包/类
public static Sector envelope2Sector( ReferencedEnvelope env ) throws Exception {
CoordinateReferenceSystem sourceCRS = env.getCoordinateReferenceSystem();
CoordinateReferenceSystem targetCRS = GPS_CRS;
MathTransform transform = CRS.findMathTransform(sourceCRS, targetCRS);
Envelope envLL = JTS.transform(env, transform);
ReferencedEnvelope llEnv = new ReferencedEnvelope(envLL, targetCRS);
Sector sector = Sector.fromDegrees(llEnv.getMinY(), llEnv.getMaxY(), llEnv.getMinX(), llEnv.getMaxX());
return sector;
}
示例8: workaround
import org.geotools.geometry.jts.ReferencedEnvelope; //导入方法依赖的package包/类
public static ReferencedEnvelope workaround(ReferencedEnvelope env){
return new ReferencedEnvelope(-89,89,-89,89,
env.getCoordinateReferenceSystem());
}
示例9: process
import org.geotools.geometry.jts.ReferencedEnvelope; //导入方法依赖的package包/类
@Execute
public void process() throws Exception {
checkNull(inROI, outFolder);
SimpleFeatureCollection boundsVector = OmsVectorReader.readVector(inROI);
ReferencedEnvelope bounds = boundsVector.getBounds();
// bounds.expandBy(50.0);
OmsTmsGenerator gen = new OmsTmsGenerator();
if (inRaster1 != null || inRaster2 != null) {
List<String> inRasters = new ArrayList<String>();
if (inRaster1 != null)
inRasters.add(inRaster1);
if (inRaster2 != null)
inRasters.add(inRaster2);
gen.inRasterFile = FileUtilities.stringListAsTmpFile(inRasters).getAbsolutePath();
}
if (inVector1 != null || inVector2 != null || inVector3 != null || inVector4 != null || inVector5 != null) {
List<String> inVectors = new ArrayList<String>();
if (inVector1 != null)
inVectors.add(inVector1);
if (inVector2 != null)
inVectors.add(inVector2);
if (inVector3 != null)
inVectors.add(inVector3);
if (inVector4 != null)
inVectors.add(inVector4);
if (inVector5 != null)
inVectors.add(inVector5);
gen.inVectorFile = FileUtilities.stringListAsTmpFile(inVectors).getAbsolutePath();
}
gen.pMinzoom = pMinZoom;
gen.pMaxzoom = pMaxZoom;
gen.pName = pName;
gen.inPath = outFolder;
gen.pWest = bounds.getMinX();
gen.pEast = bounds.getMaxX();
gen.pNorth = bounds.getMaxY();
gen.pSouth = bounds.getMinY();
// gen.pEpsg = "EPSG:32632";
gen.dataCrs = bounds.getCoordinateReferenceSystem();
gen.doMbtiles = true;
gen.inZoomLimitVector = inZoomLimitROI;
gen.pZoomLimit = pZoomLimit;
switch( pImageType ) {
case "jpg":
gen.pImagetype = 1;
break;
case "png":
default:
gen.pImagetype = 0;
break;
}
gen.pm = pm;
gen.process();
}
示例10: process
import org.geotools.geometry.jts.ReferencedEnvelope; //导入方法依赖的package包/类
@Execute
public void process() throws Exception {
checkNull(inVector, inRaster);
boolean hasUserTotalMean = false;
if (pTotalMean != null) {
hasUserTotalMean = true;
tm_usertm_tactivecells[1] = pTotalMean;
}
ReferencedEnvelope bounds = inVector.getBounds();
CoordinateReferenceSystem crs = bounds.getCoordinateReferenceSystem();
SimpleFeatureBuilder featureBuilder = createFeatureBuilder(crs, hasUserTotalMean);
outVector = new DefaultFeatureCollection();
List<Geometry> geometriesList = FeatureUtilities.featureCollectionToGeometriesList(inVector, true, null);
// pm.message("" + readEnvelope);
GridGeometry2D gridGeometry = inRaster.getGridGeometry();
RandomIter readIter = CoverageUtilities.getRandomIterator(inRaster);
pm.beginTask("Processing polygons...", geometriesList.size());
for( Geometry geometry : geometriesList ) {
double[] polygonStats = polygonStats(geometry, gridGeometry, readIter, hasUserTotalMean, tm_usertm_tactivecells,
pPercentageThres, pm);
if (polygonStats == null) {
continue;
}
Object[] values;
if (!hasUserTotalMean) {
values = new Object[]{geometry, //
polygonStats[0], //
polygonStats[1], //
polygonStats[2], //
polygonStats[3], //
polygonStats[4], //
(int) polygonStats[5], //
(int) polygonStats[6] //
};
} else {
values = new Object[]{geometry, //
polygonStats[0], //
polygonStats[1], //
polygonStats[2], //
polygonStats[3], //
polygonStats[4], //
polygonStats[5], //
(int) polygonStats[6], //
(int) polygonStats[7] //
};
}
featureBuilder.addAll(values);
SimpleFeature feature = featureBuilder.buildFeature(null);
((DefaultFeatureCollection) outVector).add(feature);
pm.worked(1);
}
pm.done();
if (!hasUserTotalMean) {
tm_usertm_tactivecells[0] = tm_usertm_tactivecells[0] / tm_usertm_tactivecells[2];
pm.message("Total mean: " + tm_usertm_tactivecells[0]);
}
}
示例11: clipImageToFeatureSource
import org.geotools.geometry.jts.ReferencedEnvelope; //导入方法依赖的package包/类
private Coverage clipImageToFeatureSource(RenderedImage image, ReferencedEnvelope bounds,
FeatureSource<SimpleFeatureType, SimpleFeature> featureSource) throws IOException, FactoryException,
MismatchedDimensionException, TransformException {
FeatureCollection<SimpleFeatureType, SimpleFeature> collection = featureSource.getFeatures();
CoordinateReferenceSystem crsFeatures = featureSource.getSchema().getCoordinateReferenceSystem();
CoordinateReferenceSystem crsMap = bounds.getCoordinateReferenceSystem();
boolean needsReproject = !CRS.equalsIgnoreMetadata(crsFeatures, crsMap);
MathTransform transform = CRS.findMathTransform(crsFeatures, crsMap, true);
FeatureIterator<SimpleFeature> iterator = collection.features();
List<Geometry> all = new ArrayList<Geometry>();
try {
while (iterator.hasNext()) {
SimpleFeature feature = iterator.next();
Geometry geometry = (Geometry) feature.getDefaultGeometry();
if (geometry == null)
continue;
if (!geometry.isSimple())
continue;
if (needsReproject) {
geometry = JTS.transform(geometry, transform);
System.out.println("Reprojected a geometry. Result is " + geometry.toString());
}
Geometry intersection = geometry.intersection(JTS.toGeometry(bounds));
if (intersection.isEmpty()) {
continue;
}
// String name = (String) feature.getAttribute("NAME");
// if (name == null)
// name = (String) feature.getAttribute("CNTRY_NAME");
if (intersection instanceof MultiPolygon) {
MultiPolygon mp = (MultiPolygon) intersection;
for (int i = 0; i < mp.getNumGeometries(); i++) {
com.vividsolutions.jts.geom.Polygon g = (com.vividsolutions.jts.geom.Polygon) mp.getGeometryN(i);
Geometry gIntersection = IntersectUtils.intersection(g, JTS.toGeometry(bounds));
if (gIntersection.isEmpty()) {
continue;
}
all.add(g);
}
} else if (intersection instanceof Polygon)
all.add(intersection);
else
continue;
}
} finally {
if (iterator != null) {
iterator.close();
}
}
GridCoverageFactory gridCoverageFactory = new GridCoverageFactory();
Coverage coverage = gridCoverageFactory.create("Raster", image, bounds);
Coverage clippedCoverage = null;
if (all.size() > 0) {
CoverageProcessor processor = new CoverageProcessor();
ParameterValueGroup params = processor.getOperation("CoverageCrop").getParameters();
params.parameter("Source").setValue(coverage);
GeometryFactory factory = JTSFactoryFinder.getGeometryFactory(null);
Geometry[] a = all.toArray(new Geometry[0]);
GeometryCollection c = new GeometryCollection(a, factory);
// params.parameter("ENVELOPE").setValue(bounds);
params.parameter("ROI").setValue(c);
params.parameter("ForceMosaic").setValue(true);
clippedCoverage = processor.doOperation(params);
}
if (all.size() == 0) {
logger.info("Crop by shapefile requested but no simple features matched extent!");
}
return clippedCoverage;
}
示例12: invertQuery
import org.geotools.geometry.jts.ReferencedEnvelope; //导入方法依赖的package包/类
public Query invertQuery(
@DescribeParameter(name = "outputBBOX", description = "Georeferenced bounding box of the output") ReferencedEnvelope envelope,
Query targetQuery, GridGeometry targetGridGeometry
) throws ProcessException {
final BBOXRemovingFilterVisitor visitor = new BBOXRemovingFilterVisitor();
Filter filter = (Filter) targetQuery.getFilter().accept(visitor, null);
final String geometryName = visitor.getGeometryPropertyName();
if (geometryName != null) {
final BBOX bbox;
try {
if (envelope.getCoordinateReferenceSystem() != null) {
envelope = envelope.transform(DefaultGeographicCRS.WGS84,false);
}
bbox = FILTER_FACTORY.bbox(geometryName, envelope.getMinX(), envelope.getMinY(), envelope.getMaxX(), envelope.getMaxY(), "EPSG:4326");
} catch (Exception e) {
throw new ProcessException("Unable to create bbox filter for feature source", e);
}
filter = (Filter) FILTER_FACTORY.and(filter, bbox).accept(new SimplifyingFilterVisitor(), null);
targetQuery.setFilter(filter);
}
final List<PropertyName> properties = new ArrayList<>();
properties.add(FILTER_FACTORY.property("_aggregation"));
targetQuery.setProperties(properties);
return targetQuery;
}