org.geotools.geometry.DirectPosition2D Java Examples
The following examples show how to use
org.geotools.geometry.DirectPosition2D.
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 check out the related API usage on the sidebar.
Example #1
Source File: RasterUtils.java From geowave with Apache License 2.0 | 6 votes |
private static Coordinate[] getWorldCoordinates( final double minX, final double minY, final double maxX, final double maxY, final int numPointsPerSegment, final MathTransform gridToCRS) throws MismatchedDimensionException, TransformException { final Point2D[] gridCoordinates = getGridCoordinates(minX, minY, maxX, maxY, numPointsPerSegment); final Coordinate[] worldCoordinates = new Coordinate[gridCoordinates.length]; for (int i = 0; i < gridCoordinates.length; i++) { final DirectPosition2D worldPt = new DirectPosition2D(); final DirectPosition2D dp = new DirectPosition2D(gridCoordinates[i]); gridToCRS.transform(dp, worldPt); worldCoordinates[i] = new Coordinate(worldPt.getX(), worldPt.getY()); } return worldCoordinates; }
Example #2
Source File: ConfigurationDtoPostProcessor.java From geomajas-project-server with GNU Affero General Public License v3.0 | 6 votes |
private double getUnitLength(String mapCrsKey, Bbox mapBounds) throws LayerException { try { if (null == mapBounds) { throw new LayerException(ExceptionCode.MAP_MAX_EXTENT_MISSING); } Crs crs = geoService.getCrs2(mapCrsKey); GeodeticCalculator calculator = new GeodeticCalculator(crs); Coordinate center = new Coordinate(0.5 * (mapBounds.getX() + mapBounds.getMaxX()), 0.5 * (mapBounds.getY() + mapBounds.getMaxY())); calculator.setStartingPosition(new DirectPosition2D(crs, center.getX(), center.getY())); calculator.setDestinationPosition(new DirectPosition2D(crs, center.getX() + 1, center.getY())); return calculator.getOrthodromicDistance(); } catch (TransformException e) { throw new LayerException(e, ExceptionCode.TRANSFORMER_CREATE_LAYER_TO_MAP_FAILED); } }
Example #3
Source File: WKTPointModelTest.java From sldeditor with GNU General Public License v3.0 | 5 votes |
/** * Test method for {@link * com.sldeditor.ui.detail.vendor.geoserver.marker.wkt.WKTPointModel#setWKTType(com.sldeditor.ui.detail.vendor.geoserver.marker.wkt.WKTType)}. * Test method for {@link * com.sldeditor.ui.detail.vendor.geoserver.marker.wkt.WKTPointModel#populate(com.sldeditor.ui.detail.vendor.geoserver.marker.wkt.WKTSegmentList)}. */ @Test public void testPopulateWKTSegmentList() { WKTSegmentList segmentList = new WKTSegmentList(); DirectPosition pos1 = new DirectPosition2D(1.0, 1.0); DirectPosition pos2 = new DirectPosition2D(2.0, 2.0); DirectPosition pos3 = new DirectPosition2D(3.0, 3.0); DirectPosition pos4 = new DirectPosition2D(4.0, 4.0); segmentList.addPoint(new WKTPoint(pos1)); segmentList.addPoint(new WKTPoint(pos2)); segmentList.addPoint(new WKTPoint(pos3)); segmentList.addPoint(new WKTPoint(pos4)); WKTPointModel model = new WKTPointModel(); WKTType wktType = new WKTType("name", false, 5, "", false, false); model.setWKTType(wktType); model.populate(null); assertTrue(model.getRowCount() == 0); model.populate(segmentList); assertTrue(model.getRowCount() == 4); model.populate(segmentList); assertTrue(model.getRowCount() == 4); segmentList.addPoint(new WKTPoint(pos1)); assertTrue(model.getRowCount() == 5); // Set WKTType to null is the same as first and last points flag = false model.setWKTType(null); model.populate(segmentList); assertTrue(model.getRowCount() == 5); }
Example #4
Source File: WKTPointTest.java From sldeditor with GNU General Public License v3.0 | 5 votes |
/** * Test method for {@link * com.sldeditor.ui.detail.vendor.geoserver.marker.wkt.WKTPoint#WKTPoint(org.opengis.geometry.DirectPosition)}. * Test method for {@link * com.sldeditor.ui.detail.vendor.geoserver.marker.wkt.WKTPoint#WKTPoint()}. Test method for * {@link com.sldeditor.ui.detail.vendor.geoserver.marker.wkt.WKTPoint#getX()}. Test method for * {@link com.sldeditor.ui.detail.vendor.geoserver.marker.wkt.WKTPoint#getY()}. Test method for * {@link com.sldeditor.ui.detail.vendor.geoserver.marker.wkt.WKTPoint#setX(double)}. Test * method for {@link com.sldeditor.ui.detail.vendor.geoserver.marker.wkt.WKTPoint#setY(double)}. * Test method for {@link * com.sldeditor.ui.detail.vendor.geoserver.marker.wkt.WKTPoint#equals(java.lang.Object)}. */ @SuppressWarnings("unlikely-arg-type") @Test public void testWKTPointDirectPosition() { WKTPoint point = new WKTPoint(); assertTrue(Math.abs(point.getX() - 0.0) < 0.001); assertTrue(Math.abs(point.getY() - 0.0) < 0.001); point = new WKTPoint(null); assertTrue(Math.abs(point.getX() - 0.0) < 0.001); assertTrue(Math.abs(point.getY() - 0.0) < 0.001); double x = 45.2; double y = -3.1; DirectPosition pos = new DirectPosition2D(x, y); point = new WKTPoint(pos); assertTrue(Math.abs(point.getX() - x) < 0.001); assertTrue(Math.abs(point.getY() - y) < 0.001); x = 42.0; point.setX(x); assertTrue(Math.abs(point.getX() - x) < 0.001); y = 42.0; point.setY(y); assertTrue(Math.abs(point.getY() - y) < 0.001); DirectPosition pos2 = new DirectPosition2D(x, y); WKTPoint point2 = new WKTPoint(pos2); assertTrue(point.equals(point2)); point2.setX(3.14); assertFalse(point.equals(point2)); assertFalse(point.equals(null)); assertFalse(point.equals(pos2)); assertTrue(point.equals(point)); assertTrue(point.hashCode() != point2.hashCode()); }
Example #5
Source File: SwtMapPane.java From gama with GNU General Public License v3.0 | 5 votes |
/** * Called after the base image has been dragged. Sets the new map area and transforms * * @param env * the display area (world coordinates) prior to the image being moved * @param paintArea * the current drawing area (screen units) */ private void afterImageMove() { final ReferencedEnvelope env = content.getViewport().getBounds(); if (env == null) { return; } final int dx = imageOrigin.x; final int dy = imageOrigin.y; final DirectPosition2D newPos = new DirectPosition2D(dx, dy); screenToWorld.transform(newPos, newPos); env.translate(env.getMinimum(0) - newPos.x, env.getMaximum(1) - newPos.y); doSetDisplayArea(env); imageOrigin.setLocation(0, 0); redrawBaseImage = true; }
Example #6
Source File: OmsRasterCatToFeatureAttribute.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
private double getRasterValue( Coordinate c ) throws TransformException { double value; GridCoordinates2D gridCoord = gridGeometry.worldToGrid(new DirectPosition2D(c.x, c.y)); value = inIter.getSampleDouble(gridCoord.x, gridCoord.y, 0); // TODO make this better if (isNovalue(value) || value >= Float.MAX_VALUE || value <= -Float.MAX_VALUE) { value = -9999.0; } return value; }
Example #7
Source File: CoverageUtilities.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
/** * Calculates the profile of a raster map between given {@link Coordinate coordinates}. * * <p>Note that novalues and points outside of the given raster region are * added to the list with a {@link HMConstants#doubleNovalue novalue} elevation. * * @param mapIter the {@link RandomIter map iterator}. * @param gridGeometry the gridgeometry of the map. * @param coordinates the {@link Coordinate}s to create the profile on. * @return the list of {@link ProfilePoint}s. * @throws TransformException */ public static List<ProfilePoint> doProfile( RandomIter mapIter, GridGeometry2D gridGeometry, Coordinate... coordinates ) throws TransformException { List<ProfilePoint> profilePointsList = new ArrayList<ProfilePoint>(); GridEnvelope2D gridRange = gridGeometry.getGridRange2D(); int rows = gridRange.height; int cols = gridRange.width; AffineTransform gridToCRS = (AffineTransform) gridGeometry.getGridToCRS(); double xres = XAffineTransform.getScaleX0(gridToCRS); double yres = XAffineTransform.getScaleY0(gridToCRS); double step = Math.min(xres, yres); LineString line = GeometryUtilities.gf().createLineString(coordinates); double lineLength = line.getLength(); LengthIndexedLine indexedLine = new LengthIndexedLine(line); double progressive = 0.0; GridCoordinates2D gridCoords; while( progressive < lineLength + step ) { // run over by a step to make sure we get the // last coord back from the extractor Coordinate c = indexedLine.extractPoint(progressive); gridCoords = gridGeometry.worldToGrid(new DirectPosition2D(c.x, c.y)); double value = HMConstants.doubleNovalue; if (// envelope2d.contains(c.x, c.y) && isInside(cols - 1, rows - 1, gridCoords)) { value = mapIter.getSampleDouble(gridCoords.x, gridCoords.y, 0); } ProfilePoint profilePoint = new ProfilePoint(progressive, value, c.x, c.y); profilePointsList.add(profilePoint); progressive = progressive + step; } return profilePointsList; }
Example #8
Source File: SceneFeatureIteratorTest.java From geowave with Apache License 2.0 | 5 votes |
@Test public void testIterate() throws IOException, CQLException { final boolean onlyScenesSinceLastRun = false; final boolean useCachedScenes = true; final boolean nBestScenesByPathRow = false; final int nBestScenes = 1; final Filter cqlFilter = CQL.toFilter("BBOX(shape,-76.6,42.34,-76.4,42.54) and band='BQA'"); final String workspaceDir = Tests.WORKSPACE_DIR; final List<SimpleFeature> features = new ArrayList<>(); try (SceneFeatureIterator iterator = new SceneFeatureIterator( onlyScenesSinceLastRun, useCachedScenes, nBestScenesByPathRow, nBestScenes, cqlFilter, workspaceDir)) { while (iterator.hasNext()) { features.add(iterator.next()); } } assertEquals(features.size(), 1); assertThat( features, everyItem( allOf( hasProperties(), inBounds( new Envelope2D( new DirectPosition2D(-76.6, 42.34), new DirectPosition2D(-76.4, 42.54)))))); }
Example #9
Source File: WKTSegmentListTest.java From sldeditor with GNU General Public License v3.0 | 4 votes |
/** * Test method for {@link * com.sldeditor.ui.detail.vendor.geoserver.marker.wkt.WKTSegmentList#getWktPointList(boolean)}. * Test method for {@link * com.sldeditor.ui.detail.vendor.geoserver.marker.wkt.WKTSegmentList#setWktPointList(java.util.List)}. * Test method for {@link * com.sldeditor.ui.detail.vendor.geoserver.marker.wkt.WKTSegmentList#addPoint(com.sldeditor.ui.detail.vendor.geoserver.marker.wkt.WKTPoint)}. * Test method for {@link * com.sldeditor.ui.detail.vendor.geoserver.marker.wkt.WKTSegmentList#getWKTString()}. Test * method for {@link * com.sldeditor.ui.detail.vendor.geoserver.marker.wkt.WKTSegmentList#getWKTString(boolean)}. */ @Test public void testGetWktPointList() { WKTSegmentList segmentList = new WKTSegmentList(); DirectPosition pos1 = new DirectPosition2D(1.0, 1.0); segmentList.addPoint(new WKTPoint(pos1)); String actualValue = segmentList.getWKTString(); assertTrue(actualValue.compareTo("(1 1)") == 0); List<WKTPoint> ptList = new ArrayList<WKTPoint>(); ptList.add(new WKTPoint(pos1)); DirectPosition pos2 = new DirectPosition2D(2.0, 2.0); DirectPosition pos3 = new DirectPosition2D(3.0, 3.0); DirectPosition pos4 = new DirectPosition2D(4.0, 4.0); ptList.add(new WKTPoint(pos2)); ptList.add(new WKTPoint(pos3)); ptList.add(new WKTPoint(pos4)); segmentList.setWktPointList(ptList); actualValue = segmentList.getWKTString(); assertTrue(actualValue.compareTo("(1 1, 2 2, 3 3, 4 4)") == 0); actualValue = segmentList.getWKTString(false, false); assertTrue(actualValue.compareTo("1 1, 2 2, 3 3, 4 4") == 0); actualValue = segmentList.getWKTString(false, true); assertTrue(actualValue.compareTo("1 1, 2 2, 3 3, 4 4, 1 1") == 0); ptList.add(new WKTPoint(pos1)); segmentList.setWktPointList(ptList); assertTrue(segmentList.getWktPointList(false).size() == ptList.size()); assertTrue((segmentList.getWktPointList(true).size() + 1) == ptList.size()); ptList.clear(); ptList.add(new WKTPoint(pos1)); assertTrue(segmentList.getWktPointList(false).size() == ptList.size()); assertTrue(segmentList.getWktPointList(true).size() == ptList.size()); segmentList.addPoint(new WKTPoint(pos2)); assertTrue(segmentList.getWktPointList(false).size() == ptList.size()); assertTrue(segmentList.getWktPointList(true).size() == ptList.size()); }
Example #10
Source File: OmsPointsRasterizer.java From hortonmachine with GNU General Public License v3.0 | 4 votes |
@Execute public void process() throws Exception { checkNull(inGrid, inVector); SimpleFeatureType schema = inVector.getSchema(); if (!EGeometryType.isPoint(schema.getGeometryDescriptor())) { throw new ModelsRuntimeException("The module works only with point vectors.", this); } RegionMap regionMap = CoverageUtilities.gridGeometry2RegionParamsMap(inGrid); double n = regionMap.getNorth(); double s = regionMap.getSouth(); double e = regionMap.getEast(); double w = regionMap.getWest(); WritableRaster outWR = CoverageUtilities.createWritableRaster(regionMap.getCols(), regionMap.getRows(), null, null, HMConstants.doubleNovalue); WritableRandomIter outIter = RandomIterFactory.createWritable(outWR, null); List<FeatureMate> matesList = FeatureUtilities.featureCollectionToMatesList(inVector); double value = 0; pm.beginTask("Rasterizing points...", matesList.size()); for( FeatureMate featureMate : matesList ) { Geometry geometry = featureMate.getGeometry(); if (fCat == null) { Double cat = featureMate.getAttribute(fCat, Double.class); if (cat != null) { value = cat; } } Coordinate[] coordinates = geometry.getCoordinates(); for( Coordinate coordinate : coordinates ) { if (!NumericsUtilities.isBetween(coordinate.x, w, e) || !NumericsUtilities.isBetween(coordinate.y, s, n)) { continue; } GridCoordinates2D onGrid = inGrid.worldToGrid(new DirectPosition2D(coordinate.x, coordinate.y)); outIter.setSample(onGrid.x, onGrid.y, 0, value); } pm.worked(1); } pm.done(); outRaster = CoverageUtilities.buildCoverage("pointsraster", outWR, regionMap, inVector.getSchema() .getCoordinateReferenceSystem()); }
Example #11
Source File: OmsLinesRasterizer.java From hortonmachine with GNU General Public License v3.0 | 4 votes |
@Execute public void process() throws Exception { checkNull(inVector); if (pNorth == null || pSouth == null || pWest == null || pEast == null || pRows == null || pCols == null) { throw new ModelsIllegalargumentException( "It is necessary to supply all the information about the processing region. Did you set the boundaries and rows/cols?", this, pm); } SimpleFeatureType schema = inVector.getSchema(); CoordinateReferenceSystem crs = schema.getCoordinateReferenceSystem(); GridGeometry2D inGrid = gridGeometryFromRegionValues(pNorth, pSouth, pEast, pWest, pCols, pRows, crs); if (!EGeometryType.isLine(schema.getGeometryDescriptor())) { throw new ModelsRuntimeException("The module works only with line vectors.", this); } RegionMap regionMap = CoverageUtilities.gridGeometry2RegionParamsMap(inGrid); double n = regionMap.getNorth(); double s = regionMap.getSouth(); double e = regionMap.getEast(); double w = regionMap.getWest(); double xRes = regionMap.getXres(); double yRes = regionMap.getYres(); double step = Math.min(xRes, yRes); WritableRaster outWR = CoverageUtilities.createWritableRaster(regionMap.getCols(), regionMap.getRows(), null, null, HMConstants.doubleNovalue); WritableRandomIter outIter = RandomIterFactory.createWritable(outWR, null); List<FeatureMate> matesList = FeatureUtilities.featureCollectionToMatesList(inVector); pm.beginTask("Rasterizing lines...", matesList.size()); String fCatChecked = null; for( FeatureMate featureMate : matesList ) { Geometry geometry = featureMate.getGeometry(); for( int i = 0; i < geometry.getNumGeometries(); i++ ) { Geometry geometryN = geometry.getGeometryN(i); List<Coordinate> lineCoordinatesAtStep = GeometryUtilities.getCoordinatesAtInterval((LineString) geometryN, step, true, -1, -1); double cat; if (fCat == null) { cat = pCat; } else { if (fCatChecked == null) { fCatChecked = FeatureUtilities.findAttributeName(featureMate.getFeature().getFeatureType(), fCat); if (fCatChecked == null) { throw new ModelsIllegalargumentException("Could not find an attribute named: " + fCat, this, pm); } } cat = featureMate.getAttribute(fCat, Double.class); } for( Coordinate lineCoordinate : lineCoordinatesAtStep ) { if (!NumericsUtilities.isBetween(lineCoordinate.x, w, e) || !NumericsUtilities.isBetween(lineCoordinate.y, s, n)) { continue; } GridCoordinates2D onGrid = inGrid.worldToGrid(new DirectPosition2D(lineCoordinate.x, lineCoordinate.y)); outIter.setSample(onGrid.x, onGrid.y, 0, cat); } } pm.worked(1); } pm.done(); outRaster = CoverageUtilities.buildCoverage("pointsraster", outWR, regionMap, inVector.getSchema() .getCoordinateReferenceSystem()); }
Example #12
Source File: PixelInfoViewModelUpdater.java From snap-desktop with GNU General Public License v3.0 | 4 votes |
private void updatePositionValues() { final boolean availableInRaster = pixelPosValidInRaster && coordinatesAreInRasterBounds(currentRaster, pixelX, pixelY, rasterLevel); final boolean availableInScene = isSampleValueAvailableInScene(); final double offset = 0.5 + (pixelInfoView.getShowPixelPosOffset1() ? 1.0 : 0.0); final double pX = levelZeroRasterX + offset; final double pY = levelZeroRasterY + offset; String tix, tiy, tsx, tsy, tmx, tmy, tgx, tgy; tix = tiy = tsx = tsy = tmx = tmy = tgx = tgy = INVALID_POS_TEXT; GeoCoding geoCoding = currentRaster.getGeoCoding(); if (availableInRaster) { if (pixelInfoView.getShowPixelPosDecimal()) { tix = String.valueOf(pX); tiy = String.valueOf(pY); } else { tix = String.valueOf((int) Math.floor(pX)); tiy = String.valueOf((int) Math.floor(pY)); } } if (getCurrentProduct().isMultiSize()) { if (!availableInScene) { tsx = PixelInfoViewModelUpdater.INVALID_POS_TEXT; tsy = PixelInfoViewModelUpdater.INVALID_POS_TEXT; } else { double sX = levelZeroSceneX + offset; double sY = levelZeroSceneY + offset; if (pixelInfoView.getShowPixelPosDecimal()) { tsx = String.valueOf(sX); tsy = String.valueOf(sY); } else { tsx = String.valueOf((int) Math.floor(sX)); tsy = String.valueOf((int) Math.floor(sY)); } } } if (availableInRaster && geoCoding != null) { PixelPos pixelPos = new PixelPos(pX, pY); GeoPos geoPos = geoCoding.getGeoPos(pixelPos, null); if (pixelInfoView.getShowGeoPosDecimals()) { tgx = String.format("%.6f", geoPos.getLon()); tgy = String.format("%.6f", geoPos.getLat()); } else { tgx = geoPos.getLonString(); tgy = geoPos.getLatString(); } if (geoCoding instanceof MapGeoCoding) { final MapGeoCoding mapGeoCoding = (MapGeoCoding) geoCoding; final MapTransform mapTransform = mapGeoCoding.getMapInfo().getMapProjection().getMapTransform(); Point2D mapPoint = mapTransform.forward(geoPos, null); tmx = String.valueOf(MathUtils.round(mapPoint.getX(), 10000.0)); tmy = String.valueOf(MathUtils.round(mapPoint.getY(), 10000.0)); } else if (geoCoding instanceof CrsGeoCoding) { MathTransform transform = geoCoding.getImageToMapTransform(); try { DirectPosition position = transform.transform(new DirectPosition2D(pX, pY), null); double[] coordinate = position.getCoordinate(); tmx = String.valueOf(coordinate[0]); tmy = String.valueOf(coordinate[1]); } catch (TransformException ignore) { } } } int rowCount = 0; positionModel.updateValue(tix, rowCount++); positionModel.updateValue(tiy, rowCount++); if (getCurrentProduct().isMultiSize()) { positionModel.updateValue(tsx, rowCount++); positionModel.updateValue(tsy, rowCount++); } if (geoCoding != null) { positionModel.updateValue(tgx, rowCount++); positionModel.updateValue(tgy, rowCount++); if (geoCoding instanceof MapGeoCoding || geoCoding instanceof CrsGeoCoding) { positionModel.updateValue(tmx, rowCount++); positionModel.updateValue(tmy, rowCount); } } }
Example #13
Source File: SceneFeatureIteratorTest.java From geowave with Apache License 2.0 | 4 votes |
public void testIterate(final String providerName) throws IOException, CQLException, ParseException, NoSuchAuthorityCodeException, FactoryException, MalformedURLException, GeneralSecurityException { final Sentinel2ImageryProvider provider = Sentinel2ImageryProvider.getProvider(providerName); if (provider == null) { throw new RuntimeException("Unable to find '" + providerName + "' Sentinel2 provider"); } final String collection = provider.collections()[0]; final String platform = ""; final String location = "T30TWM"; final Date startDate = DateUtilities.parseISO("2018-01-28T00:00:00Z"); final Date endDate = DateUtilities.parseISO("2018-01-30T00:00:00Z"); final int orbitNumber = 0; final int relativeOrbitNumber = 0; final Filter cqlFilter = CQL.toFilter("BBOX(shape,-1.8274,42.3253,-1.6256,42.4735)"); final String workspaceDir = Tests.WORKSPACE_DIR; final List<SimpleFeature> features = new ArrayList<>(); try (SceneFeatureIterator iterator = new SceneFeatureIterator( providerName, collection, platform, location, startDate, endDate, orbitNumber, relativeOrbitNumber, cqlFilter, workspaceDir)) { while (iterator.hasNext()) { features.add(iterator.next()); } } assertEquals(features.size(), 1); assertThat( features, everyItem( allOf( hasProperties(), inBounds( new Envelope2D( new DirectPosition2D(-1.828, 42.325), new DirectPosition2D(-1.624, 42.474)))))); }