当前位置: 首页>>代码示例>>Java>>正文


Java DirectPosition2D类代码示例

本文整理汇总了Java中org.geotools.geometry.DirectPosition2D的典型用法代码示例。如果您正苦于以下问题:Java DirectPosition2D类的具体用法?Java DirectPosition2D怎么用?Java DirectPosition2D使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


DirectPosition2D类属于org.geotools.geometry包,在下文中一共展示了DirectPosition2D类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createSearchEnv

import org.geotools.geometry.DirectPosition2D; //导入依赖的package包/类
private ReferencedEnvelope createSearchEnv(final DirectPosition2D pos, final double radius) {
	final CoordinateReferenceSystem contextCRS = getMapContent().getCoordinateReferenceSystem();
	ReferencedEnvelope env = new ReferencedEnvelope(pos.x - radius, pos.x + radius, pos.y - radius, pos.y + radius,
			contextCRS);
	if (isTransformRequired()) {
		final Layer layer = layerRef.get();
		if (layer != null) {
			final CoordinateReferenceSystem layerCRS = layer.getFeatureSource().getSchema()
					.getCoordinateReferenceSystem();
			try {
				env = env.transform(layerCRS, true);
			} catch (final Exception ex) {
				throw new IllegalStateException(ex);
			}
		}
	}

	return env;
}
 
开发者ID:gama-platform,项目名称:gama,代码行数:20,代码来源:VectorLayerHelper.java

示例2: onMouseClicked

import org.geotools.geometry.DirectPosition2D; //导入依赖的package包/类
/**
 * Zoom out by the currently set increment, with the map
 * centred at the location (in world coords) of the mouse
 * click
 *
 * @param ev the mouse event
 */
@Override
public void onMouseClicked(final MapMouseEvent ev) {

	if ( !isTriggerMouseButton(ev) ) { return; }

	final Rectangle paneArea = getMapPane().getBounds();
	final DirectPosition2D mapPos = ev.getMapPosition();

	final double scale = getMapPane().getWorldToScreenTransform().getScaleX();
	final double newScale = scale / zoom;

	final DirectPosition2D corner = new DirectPosition2D(mapPos.getX() - 0.5d * paneArea.width / newScale,
		mapPos.getY() + 0.5d * paneArea.height / newScale);

	final Envelope2D newMapArea = new Envelope2D();
	newMapArea.setFrameFromCenter(mapPos, corner);
	getMapPane().setDisplayArea(newMapArea);
}
 
开发者ID:gama-platform,项目名称:gama,代码行数:26,代码来源:ZoomOutTool.java

示例3: onMouseReleased

import org.geotools.geometry.DirectPosition2D; //导入依赖的package包/类
/**
 * If the mouse was dragged, determines the bounds of the
 * box that the user defined and passes this to the mapPane's
 * {@link org.geotools.swing.JMapPane#setDisplayArea(org.opengis.geometry.Envelope) }
 * method
 *
 * @param ev the mouse event
 */
@Override
public void onMouseReleased(final MapMouseEvent ev) {

	if ( !isTriggerMouseButton(ev) ) { return; }

	if ( dragged ) {
		final Envelope2D env = new Envelope2D();
		env.setFrameFromDiagonal(startDragPos, ev.getMapPosition());
		dragged = false;
		getMapPane().setDisplayArea(env);
	} else {
		final Rectangle paneArea = getMapPane().getVisibleRect();

		final double scale = getMapPane().getWorldToScreenTransform().getScaleX();
		final double newScale = scale * zoom;

		final DirectPosition2D corner = new DirectPosition2D(startDragPos.getX() - 0.5d * paneArea.width / newScale,
			startDragPos.getY() + 0.5d * paneArea.height / newScale);

		final Envelope2D newMapArea = new Envelope2D();
		newMapArea.setFrameFromCenter(startDragPos, corner);
		getMapPane().setDisplayArea(newMapArea);
	}

}
 
开发者ID:gama-platform,项目名称:gama,代码行数:34,代码来源:ZoomInTool.java

示例4: getInfo

import org.geotools.geometry.DirectPosition2D; //导入依赖的package包/类
/**
 * Get band values at the given position
 *
 * @param pos
 *            the location to query
 *
 * @param params
 *            not used at present
 *
 * @return a {@code List} of band values; will be empty if {@code pos} was
 *         outside the coverage bounds
 *
 * @throws Exception
 *             if the grid coverage could not be queried
 */
@Override
public List<Number> getInfo(final DirectPosition2D pos, final Object... params) throws Exception {

	final List<Number> list = new ArrayList<Number>();

	if (isValid()) {
		final GridCoverage2D cov = covRef.get();
		if (cov != null) {
			final ReferencedEnvelope env = new ReferencedEnvelope(cov.getEnvelope2D());
			final DirectPosition2D trPos = getTransformed(pos);
			if (env.contains(trPos)) {
				final Object objArray = cov.evaluate(trPos);
				final Number[] bandValues = asNumberArray(objArray);
				if (bandValues != null) {
					for (final Number value : bandValues) {
						list.add(value);
					}
				}
			}
		}
	}

	return list;
}
 
开发者ID:gama-platform,项目名称:gama,代码行数:40,代码来源:GridLayerHelper.java

示例5: getTransformed

import org.geotools.geometry.DirectPosition2D; //导入依赖的package包/类
/**
 * Transform the query position into the coordinate reference system of the
 * data (if different to that of the {@code MapContext}).
 *
 * @param pos
 *            query position in {@code MapContext} coordinates
 *
 * @return query position in data ({@code MapLayer}) coordinates
 */
private DirectPosition2D getTransformed(final DirectPosition2D pos) {
	if (isTransformRequired()) {
		final MathTransform tr = getTransform();
		if (tr == null) {
			throw new IllegalStateException("MathTransform should not be null");
		}

		try {
			return (DirectPosition2D) tr.transform(pos, null);
		} catch (final Exception ex) {
			throw new IllegalStateException(ex);
		}
	}

	return pos;
}
 
开发者ID:gama-platform,项目名称:gama,代码行数:26,代码来源:GridLayerHelper.java

示例6: afterImageMove

import org.geotools.geometry.DirectPosition2D; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:gama-platform,项目名称:gama,代码行数:25,代码来源:SwtMapPane.java

示例7: getPixelSize

import org.geotools.geometry.DirectPosition2D; //导入依赖的package包/类
/**
 * Utility methods
 */

private double[] getPixelSize(GeoCoding sourceGeoCoding, CoordinateReferenceSystem targetCRS) {
    double[] size = null;
    try {
        size = new double[2];
        DirectPosition geoPos1 = sourceGeoCoding.getImageToMapTransform()
                .transform(new DirectPosition2D(0, 0), null);
        Coordinate c1 = new Coordinate(geoPos1.getOrdinate(0), geoPos1.getOrdinate(1));
        DirectPosition geoPos2 = sourceGeoCoding.getImageToMapTransform()
                .transform(new DirectPosition2D(0, 1), null);
        Coordinate c2 = new Coordinate(geoPos2.getOrdinate(0), geoPos2.getOrdinate(1));
        DirectPosition geoPos3 = sourceGeoCoding.getImageToMapTransform()
                .transform(new DirectPosition2D(1, 0), null);
        Coordinate c3 = new Coordinate(geoPos3.getOrdinate(0), geoPos3.getOrdinate(1));
        final CoordinateReferenceSystem sourceCRS = sourceGeoCoding.getMapCRS();
        size[0] = distance(sourceCRS, targetCRS, c3, c1);
        size[1] = distance(sourceCRS, targetCRS, c2, c1);
    } catch (TransformException tex) {
        tex.printStackTrace();
    }
    return size;
}
 
开发者ID:senbox-org,项目名称:s2tbx,代码行数:26,代码来源:S2tbxMosaicOp.java

示例8: exampleGridCoverageDirect

import org.geotools.geometry.DirectPosition2D; //导入依赖的package包/类
void exampleGridCoverageDirect() throws Exception {
    double x =0;
    double y = 0;
    CoordinateReferenceSystem crs = null;
    
    File file = new File("test.tiff");
    AbstractGridFormat format = GridFormatFinder.findFormat(file);
    GridCoverage2DReader reader = format.getReader(file);
    // exampleGridCoverageDirect start
    GridCoverage2D coverage = reader.read(null);
    
    // direct access
    DirectPosition position = new DirectPosition2D( crs, x, y);
    
    double[] sample = (double[]) coverage.evaluate( position ); // assume double
    
    // resample with the same array
    sample = coverage.evaluate( position, sample );
    // exampleGridCoverageDirect end
}
 
开发者ID:ianturton,项目名称:geotools-cookbook,代码行数:21,代码来源:CoverageExamples.java

示例9: transformJTSGeometry

import org.geotools.geometry.DirectPosition2D; //导入依赖的package包/类
protected Geometry transformJTSGeometry(Geometry geom, final CoordinateReferenceSystem sourceCRS, final CoordinateReferenceSystem crs) throws Exception {
	final MathTransform transform = CRS.findMathTransform(sourceCRS, crs, true);
	final Mutable<Boolean> anyChanged = new Mutable<Boolean>(false);
	
	geom = (Geometry) geom.clone();
	geom.apply(new CoordinateFilter() {
		@Override
		public void filter(Coordinate c) {
			DirectPosition dpFrom = new DirectPosition2D(sourceCRS, c.x, c.y);
			DirectPosition dpTo = new DirectPosition2D();
			try {
				transform.transform(dpFrom, dpTo);
				c.x = dpTo.getOrdinate(0);
				c.y = dpTo.getOrdinate(1);
				anyChanged.set(true);
			} catch (TransformException e) {
				LOG.warn("Failed to transform point " + c, e);
			}
		}
	});
	if (anyChanged.get()) {
		geom.geometryChanged();
	}
	return geom;
}
 
开发者ID:opengeospatial,项目名称:geopackager,代码行数:26,代码来源:AbstractFeatureHarvester.java

示例10: distanceInCrs

import org.geotools.geometry.DirectPosition2D; //导入依赖的package包/类
private double distanceInCrs(double inMeters,
        double[] refXY,
        CoordinateReferenceSystem crs) throws TransformException {
    double dist = 0;

    // calculate the distance in meters of 0.01 * refY in the ref CRS
    double[] sp = {refXY[0], refXY[1]};
    double[] dp = {refXY[0], refXY[1] * 1.01};

    GeodeticCalculator gc = new GeodeticCalculator(crs);

    gc.setStartingPosition(new DirectPosition2D(crs, sp[0], sp[1]));
    gc.setDestinationPosition(new DirectPosition2D(crs, dp[0], dp[1]));

    double refY01InMeters = gc.getOrthodromicDistance();

    // now, calculate the CRS distance as a proportional of 0.01 * refY
    dist = inMeters * (refXY[1] * 0.01) / refY01InMeters;

    return dist;
}
 
开发者ID:geobeyond,项目名称:fluxomajic,代码行数:22,代码来源:FluxoFilterFunction.java

示例11: getUnitLength

import org.geotools.geometry.DirectPosition2D; //导入依赖的package包/类
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);
	}
}
 
开发者ID:geomajas,项目名称:geomajas-project-server,代码行数:17,代码来源:ConfigurationDtoPostProcessor.java

示例12: fetchElevation

import org.geotools.geometry.DirectPosition2D; //导入依赖的package包/类
/**
 * Gets elevation for a coordinate giving (lat,lon). Note that latitude
 * corresponds to the 'x' member of each coordinate, despite any unfortunate
 * clash with the use of x for horizontal cartesian coordinates.
 * @param l
 * @return
 * @throws DataUnavailableException If a non-recoverable error stops the data
 *  from being accessed. Less serious errors simply result in null elevations
 *  being returned.
 * @throws
 */
@Override
public Double fetchElevation(Coordinate point) throws DataUnavailableException {
	if( wrap ) {
		// Convert coordinates to valid lat=(-90,90], lon=[-180,180)
		point = ProjectionTools.wrapCoordinate(point);
	} else {
		if( point.x <= -90 || 90 < point.x ||
				point.y < -180 || 180 <= point.y ) {
			// Coordinates off the map
			return null;
		}
	}
	GridCoverage2D grid = loadGrid(point);
	// Change from (lat,lon) convention to (x,y)
	DirectPosition pos = new DirectPosition2D(point.y,point.x);
	double elev = grid.evaluate(pos,(double[])null)[0];
	return elev;
}
 
开发者ID:sbliven,项目名称:earthcraft,代码行数:30,代码来源:GridCoverageElevationProvider.java

示例13: testPopulateWKTSegmentList

import org.geotools.geometry.DirectPosition2D; //导入依赖的package包/类
/**
 * 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);
}
 
开发者ID:robward-scisys,项目名称:sldeditor,代码行数:40,代码来源:WKTPointModelTest.java

示例14: testWKTPointDirectPosition

import org.geotools.geometry.DirectPosition2D; //导入依赖的package包/类
/**
 * 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)}.
 */
@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());
}
 
开发者ID:robward-scisys,项目名称:sldeditor,代码行数:48,代码来源:WKTPointTest.java

示例15: process

import org.geotools.geometry.DirectPosition2D; //导入依赖的package包/类
@Override
public void process(NodeContainer nodec) {
    Node node = nodec.getEntity();
    double lat = node.getLatitude();
    double lon = node.getLongitude();

    // Transform to EPSG:3067
    DirectPosition2D ptDst = new DirectPosition2D(targetCRS);
    try {
        transform.transform(new DirectPosition2D(sourceCRS, lon, lat), ptDst);

        String tm35MapSheet = TM35Utils.reverseGeocode(ptDst.x, ptDst.y, TM35Scale.SCALE_10000);

        GridCoverage2D gc = ready.get(tm35MapSheet);

        if (gc != null) {
            // Do the computation
            processReady(gc, ptDst, node);
        } else {
            // Download tiff async

            processing.compute(tm35MapSheet, (sheetKey, currentSet) -> {
                if (currentSet == null)
                    currentSet = new HashSet<>();

                currentSet.add(new TranslatedNode(node, ptDst));
                return currentSet;
            });
            submitTiffQuerying(tm35MapSheet);
        }
        processReadyItems();

    } catch (MismatchedDimensionException | TransformException e) {
        LOGGER.log(Level.WARNING,
                "Could not transform lat=" + lat + ", lon=" + lon + " from " + sourceCRS + " to " + targetCRS, e);
    }
}
 
开发者ID:jsimomaa,项目名称:osmosis-nls-dem,代码行数:38,代码来源:NLSDEMTask.java


注:本文中的org.geotools.geometry.DirectPosition2D类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。