Java Code Examples for org.geotools.geometry.jts.JTS#toGeometry()

The following examples show how to use org.geotools.geometry.jts.JTS#toGeometry() . 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: TiledFeatureService.java    From geomajas-project-server with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Apply clipping to the features in a tile. The tile and its features should already be in map space.
 *
 * @param tile
 *            tile to put features in
 * @param scale
 *            scale
 * @param panOrigin
 *            When panning on the client, only this parameter changes. So we need to be aware of it as we calculate
 *            the maxScreenEnvelope.
 * @throws GeomajasException oops
 */
public void clipTile(InternalTile tile, double scale, Coordinate panOrigin) throws GeomajasException {
	log.debug("clipTile before {}", tile);
	List<InternalFeature> orgFeatures = tile.getFeatures();
	tile.setFeatures(new ArrayList<InternalFeature>());
	Geometry maxScreenBbox = null; // The tile's maximum bounds in screen space. Used for clipping.
	for (InternalFeature feature : orgFeatures) {
		// clip feature if necessary
		if (exceedsScreenDimensions(feature, scale)) {
			log.debug("feature {} exceeds screen dimensions", feature);
			InternalFeatureImpl vectorFeature = (InternalFeatureImpl) feature.clone();
			tile.setClipped(true);
			vectorFeature.setClipped(true);
			if (null == maxScreenBbox) {
				maxScreenBbox = JTS.toGeometry(getMaxScreenEnvelope(tile, panOrigin));
			}
			Geometry clipped = maxScreenBbox.intersection(feature.getGeometry());
			vectorFeature.setClippedGeometry(clipped);
			tile.addFeature(vectorFeature);
		} else {
			tile.addFeature(feature);
		}
	}
	log.debug("clipTile after {}", tile);
}
 
Example 2
Source File: RDDUtils.java    From geowave with Apache License 2.0 5 votes vote down vote up
public static InsertionIds trimIndexIds(
    final InsertionIds rawIds,
    final Geometry geom,
    final NumericIndexStrategy index) {
  for (final SinglePartitionInsertionIds insertionId : rawIds.getPartitionKeys()) {
    final byte[] partitionKey = insertionId.getPartitionKey();
    final int size = insertionId.getSortKeys().size();
    if (size > 3) {
      final Iterator<byte[]> it = insertionId.getSortKeys().iterator();
      while (it.hasNext()) {
        final byte[] sortKey = it.next();
        final MultiDimensionalNumericData keyTile = index.getRangeForId(partitionKey, sortKey);
        final Envelope other = new Envelope();
        other.init(
            keyTile.getMinValuesPerDimension()[0],
            keyTile.getMaxValuesPerDimension()[0],
            keyTile.getMinValuesPerDimension()[1],
            keyTile.getMaxValuesPerDimension()[1]);
        final Polygon rect = JTS.toGeometry(other);
        if (!RectangleIntersects.intersects(rect, geom)) {
          it.remove();
        }
      }
    }
  }
  return rawIds;
}
 
Example 3
Source File: RestControllerTest.java    From geomajas-project-server with GNU Affero General Public License v3.0 5 votes vote down vote up
@Test
public void testEpsg() throws Exception {
	MockHttpServletRequest request = new MockHttpServletRequest();
	request.setRequestURI("/rest/beans");
	request.setMethod("GET");
	MockHttpServletResponse response = new MockHttpServletResponse();
	// check attribute equality
	request.setParameter("queryable", "stringAttr");
	request.setParameter("stringAttr_eq", "bean1");
	request.setParameter("epsg", "900913");
	ModelAndView mav = adapter.handle(request, response, restController);
	view.render(mav.getModel(), request, response);
	response.flushBuffer();
	Object json = new JSONParser().parse(response.getContentAsString());
	Assert.assertTrue(json instanceof JSONObject);
	JSONObject jsonObject = (JSONObject) json;
	JSONArray features = (JSONArray) jsonObject.get("features");
	JSONObject feature = (JSONObject) features.get(0);
	JSONObject geometry = (JSONObject) feature.get("geometry");
	GeometryJSON g = new GeometryJSON(0);
	Geometry m = g.read(geometry.toJSONString());
	Envelope envelope = new Envelope(0, 1, 0, 1);
	Geometry orig = JTS.toGeometry(envelope);
	Geometry m2 = geoservice.transform(orig, "EPSG:4326", "EPSG:900913");
	// equality check on buffer, JTS equals does not do the trick !
	Assert.assertTrue(m.buffer(0.01).contains(m2));
	Assert.assertTrue(m2.buffer(0.01).contains(m));
}
 
Example 4
Source File: CrsTransformImpl.java    From geomajas-project-server with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Constructor.
 *
 * @param id id
 * @param source source CRS
 * @param target target CRS
 * @param mathTransform transformation
 * @param transformableBbox bounding bow of transformable area
 */
public CrsTransformImpl(String id, Crs source, Crs target, MathTransform mathTransform,
		Bbox transformableBbox) {
	this(id, source, target, mathTransform);
	if (null != transformableBbox) {
		this.transformableBbox = transformableBbox;
		this.transformableEnvelope =
				new Envelope(transformableBbox.getX(), transformableBbox.getMaxX(), transformableBbox.getY(),
						transformableBbox.getMaxY());
		this.transformableGeometry = JTS.toGeometry(transformableEnvelope);
	}
}
 
Example 5
Source File: CrsTransformImpl.java    From geomajas-project-server with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Constructor.
 *
 * @param id id
 * @param source source CRS
 * @param target target CRS
 * @param mathTransform transformation
 * @param transformableEnvelope bounding bow of transformable area
 */
public CrsTransformImpl(String id, Crs source, Crs target, MathTransform mathTransform,
		Envelope transformableEnvelope) {
	this(id, source, target, mathTransform);
	if (null != transformableEnvelope) {
		this.transformableEnvelope = transformableEnvelope;
		this.transformableBbox = new Bbox(transformableEnvelope.getMinX(), transformableEnvelope.getMinY(),
				transformableEnvelope.getMaxX(), transformableEnvelope.getMaxY());
		this.transformableGeometry = JTS.toGeometry(transformableEnvelope);
	}
}
 
Example 6
Source File: GeoServiceTest.java    From geomajas-project-server with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public Geometry getTransformableGeometry() {
	return JTS.toGeometry(getTransformableEnvelope());
}