本文整理汇总了Java中org.geotools.geometry.jts.JTS.toGeometry方法的典型用法代码示例。如果您正苦于以下问题:Java JTS.toGeometry方法的具体用法?Java JTS.toGeometry怎么用?Java JTS.toGeometry使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.geotools.geometry.jts.JTS
的用法示例。
在下文中一共展示了JTS.toGeometry方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: call
import org.geotools.geometry.jts.JTS; //导入方法依赖的package包/类
public Object call(Properties bindings, Object[] args) {
if(args.length==2){
String lat = args[0].toString();
String lng = args[1].toString();
double[] latlng = {
Double.parseDouble(lat),
Double.parseDouble(lng)
};
GeometryBuilder builder = new GeometryBuilder(DefaultGeographicCRS.WGS84);
return JTS.toGeometry(builder.createPoint(latlng).getDirectPosition());
}
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects 2 arguments");
}
示例2: clipTile
import org.geotools.geometry.jts.JTS; //导入方法依赖的package包/类
/**
* 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);
}
示例3: buildBoundsViewparam
import org.geotools.geometry.jts.JTS; //导入方法依赖的package包/类
private String buildBoundsViewparam(ReferencedEnvelope bbox) throws UnsupportedEncodingException {
Polygon poly = JTS.toGeometry(bbox);
String boundsWKT = "bounds:'"+ poly.toText()+"';";
boundsWKT = boundsWKT.replaceAll(", ", "|");
boundsWKT = URLEncoder.encode(boundsWKT, "UTF-8");
return boundsWKT;
}
示例4: testEpsg
import org.geotools.geometry.jts.JTS; //导入方法依赖的package包/类
@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));
}
示例5: CrsTransformImpl
import org.geotools.geometry.jts.JTS; //导入方法依赖的package包/类
/**
* 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);
}
}
示例6: clipToWorld
import org.geotools.geometry.jts.JTS; //导入方法依赖的package包/类
private Literal clipToWorld(Literal geometry) {
if(geometry != null) {
Geometry g = geometry.evaluate(null, Geometry.class);
if(g != null) {
Envelope env = g.getEnvelopeInternal();
// first, limit to world
if(!WORLD.contains(env)) {
g = sanitizePolygons(g.intersection(JTS.toGeometry(WORLD)));
}
// second, postgis will always use the shortest distance between two
// points, if an arc is longer than 180 degrees the opposite will
// be used instead, so we have to slice the geometry in parts
env = g.getEnvelopeInternal();
if(Math.sqrt(env.getWidth() * env.getWidth() + env.getHeight() * env.getHeight()) >= 180) {
// slice in 90x90 degrees quadrants, none of them has a diagonal longer than 180
final List<Polygon> polygons = new ArrayList<Polygon>();
for(double lon = Math.floor(env.getMinX()); lon < env.getMaxX(); lon+= 90) {
for (double lat = Math.floor(env.getMinY()); lat < env.getMaxY(); lat += 90) {
Geometry quadrant = JTS.toGeometry(new Envelope(lon, lon + 90, lat, lat + 90));
Geometry cut = sanitizePolygons(g.intersection(quadrant));
if(!cut.isEmpty()) {
if(cut instanceof Polygon) {
polygons.add((Polygon) cut);
} else {
for (int i = 0; i < cut.getNumGeometries(); i++) {
polygons.add((Polygon) cut.getGeometryN(i));
}
}
}
}
}
g = toPolygon(g.getFactory(), polygons);
}
geometry = CommonFactoryFinder.getFilterFactory(null).literal(g);
}
}
return geometry;
}
示例7: getTransformableGeometry
import org.geotools.geometry.jts.JTS; //导入方法依赖的package包/类
@Override
public Geometry getTransformableGeometry() {
return JTS.toGeometry(getTransformableEnvelope());
}
示例8: VectorTileEncoder
import org.geotools.geometry.jts.JTS; //导入方法依赖的package包/类
/**
* Create a {@link VectorTileEncoder} with the given extent value.
* <p>
* The extent value control how detailed the coordinates are encoded in the
* vector tile. 4096 is a good default, 256 can be used to reduce density.
* <p>
* The polygon clip buffer value control how large the clipping area is
* outside of the tile for polygons. 0 means that the clipping is done at
* the tile border. 8 is a good default.
*
* @param extent a int with extent value. 4096 is a good value.
* @param targetBbox the bbox defined for the target tile
* @param simplificationFactor the factor for simplification
* @param smallGeometryThreshold defines the threshold in length / area when geometries should be skipped in output. 0 or negative means all geoms are included
*/
public VectorTileEncoder(int extent, Envelope targetBbox, double simplificationFactor, double smallGeometryThreshold) {
this.autoScale = true;
this.extent = extent;
this.clipGeometry = JTS.toGeometry(targetBbox);
this.simplificationFactor = simplificationFactor;
this.smallGeometryThreshold = smallGeometryThreshold;
}