本文整理汇总了Java中org.geotools.geojson.geom.GeometryJSON类的典型用法代码示例。如果您正苦于以下问题:Java GeometryJSON类的具体用法?Java GeometryJSON怎么用?Java GeometryJSON使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
GeometryJSON类属于org.geotools.geojson.geom包,在下文中一共展示了GeometryJSON类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: visitLiteralGeometry
import org.geotools.geojson.geom.GeometryJSON; //导入依赖的package包/类
protected void visitLiteralGeometry(Literal expression) throws IOException {
// evaluate the literal and store it for later
currentGeometry = (Geometry) evaluateLiteral(expression, Geometry.class);
if ( currentGeometry instanceof LinearRing ) {
// convert LinearRing to LineString
final GeometryFactory factory = currentGeometry.getFactory();
final LinearRing linearRing = (LinearRing) currentGeometry;
final CoordinateSequence coordinates;
coordinates = linearRing.getCoordinateSequence();
currentGeometry = factory.createLineString(coordinates);
}
final String geoJson = new GeometryJSON().toString(currentGeometry);
currentShapeBuilder = mapReader.readValue(geoJson);
}
示例2: handleCoordinatesJson
import org.geotools.geojson.geom.GeometryJSON; //导入依赖的package包/类
/**
* Handle GeoJSON representation of a coordinates processing.
* @param data
* @param idprovided
* @param request
* @param response
* @return
*/
@RequestMapping(value="/coordinates.json", method={RequestMethod.GET,RequestMethod.POST},params="!callback")
@ResponseBody
public String handleCoordinatesJson(@RequestParam String data, @RequestParam(required=false) Boolean idprovided, HttpServletRequest request, HttpServletResponse response){
CoordinateAPIResponse apiResponse;
String returnString;
//make sure the answer is set as UTF-8
response.setCharacterEncoding("UTF-8");
apiResponse = generateCoordinateAPIResponse(data,idprovided);
StringWriter sw = new StringWriter();
try {
GeometryJSON gjson = new GeometryJSON(JSON_NUMBER_DECIMALS);
org.geotools.geojson.feature.FeatureJSON fj = new FeatureJSON(gjson);
fj.writeFeatureCollection(buildSimpleFeatureCollection(apiResponse), sw);
LOGGER.info("Coordinate|{}|{}|{}", request.getMethod(), request.getRequestURI(), request.getRemoteAddr());
} catch (IOException e) {
e.printStackTrace();
}
returnString= sw.toString();
return returnString;
}
示例3: getGeoJsonPoint
import org.geotools.geojson.geom.GeometryJSON; //导入依赖的package包/类
/**
* Get GeometryJSON point.
*
* @param longitude the longitude.
* @param latitude the latitude.
* @return the GeoJSON representation of the given point.
*/
public static Point getGeoJsonPoint( double longitude, double latitude )
throws IOException
{
Point point = null;
GeometryJSON gtjson = new GeometryJSON();
point = gtjson.readPoint( new StringReader( "{\"type\":\"Point\", \"coordinates\":[" + longitude + ","
+ latitude + "]}" ) );
return point;
}
示例4: checkPointWithMultiPolygon
import org.geotools.geojson.geom.GeometryJSON; //导入依赖的package包/类
/**
* Check if the point coordinate falls within the polygon/MultiPolygon Shape
*
* @param longitude the longitude.
* @param latitude the latitude.
* @param multiPolygonJson the GeoJSON coordinates of the MultiPolygon
* @param featureType the featureType of the MultiPolygon.
*/
public static boolean checkPointWithMultiPolygon( double longitude, double latitude,
String multiPolygonJson, FeatureType featureType )
{
try
{
boolean contains = false;
GeometryJSON gtjson = new GeometryJSON();
Point point = getGeoJsonPoint( longitude, latitude );
if ( point != null && point.isValid() )
{
if ( featureType == FeatureType.POLYGON )
{
Polygon polygon = gtjson.readPolygon( new StringReader(
"{\"type\":\"Polygon\", \"coordinates\":" + multiPolygonJson + "}" ) );
contains = polygon.contains( point );
}
else if ( featureType == FeatureType.MULTI_POLYGON )
{
MultiPolygon multiPolygon = gtjson.readMultiPolygon( new StringReader(
"{\"type\":\"MultiPolygon\", \"coordinates\":" + multiPolygonJson + "}" ) );
contains = multiPolygon.contains( point );
}
}
return contains;
}
catch ( Exception ex )
{
return false;
}
}
示例5: write
import org.geotools.geojson.geom.GeometryJSON; //导入依赖的package包/类
protected void write(DefaultFeatureCollection features, OutputStream out) throws IOException {
final FeatureJSON json = new FeatureJSON(new GeometryJSON(7));
boolean geometryless = features.getSchema().getGeometryDescriptor() == null;
json.setEncodeFeatureCollectionBounds(!geometryless);
json.setEncodeFeatureCollectionCRS(!geometryless);
json.writeFeatureCollection(features, out);
}
示例6: RandomGeometryBuilder
import org.geotools.geojson.geom.GeometryJSON; //导入依赖的package包/类
public RandomGeometryBuilder() {
geometryFactory = new GeometryFactory();
random = new Random(123456789l);
decimals = 4;
numPoints = 10;
numGeometries = 2;
geometryJson = new GeometryJSON(decimals);
}
示例7: createGeometry
import org.geotools.geojson.geom.GeometryJSON; //导入依赖的package包/类
public static Geometry createGeometry(String str) {
GeometryJSON j = new GeometryJSON();
try {
return j.read(str.replace("'", "\""));
} catch (IOException e) {
throw new RuntimeException("Failed to create a geometry from given str " + str, e);
}
}
示例8: call
import org.geotools.geojson.geom.GeometryJSON; //导入依赖的package包/类
public Object call(Properties bindings, Object[] args) {
if(args.length==1){
GeometryJSON gjson = new GeometryJSON();
String json = args[0].toString();
Reader reader = new StringReader(json);
try {
return gjson.read(reader);
}
catch (java.io.IOException e) {
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + ": " + e.getMessage());
}
}
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects 1 argument");
}
示例9: testEpsg
import org.geotools.geojson.geom.GeometryJSON; //导入依赖的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));
}
示例10: handleJSONP
import org.geotools.geojson.geom.GeometryJSON; //导入依赖的package包/类
/**
* Handle JSONP representation of a coordinates processing.
* We are not returning any Object to avoid confusion with any MessageConverter.
* MappingJackson2HttpMessageConverter is not supporting JSONP and custom implementation
* seems to conflict with ContentNegotiatingViewResolver (we want application/x-javascript and ask it with .json).
* @param data
* @param idprovided
* @param callback
* @param request
* @param response
*/
@RequestMapping(value="/coordinates.json", method={RequestMethod.GET},params="callback")
public void handleJSONP(@RequestParam String data, @RequestParam(required=false) Boolean idprovided, @RequestParam String callback,
HttpServletRequest request, HttpServletResponse response){
//make sure the answer is set as UTF-8
response.setCharacterEncoding("UTF-8");
response.setContentType(APIControllerHelper.JSONP_CONTENT_TYPE);
if(APIControllerHelper.JSONP_ACCEPTED_CHAR_PATTERN.matcher(callback).matches()){
CoordinateAPIResponse apiResponse = generateCoordinateAPIResponse(data,idprovided);
StringWriter sw = new StringWriter();
try {
GeometryJSON gjson = new GeometryJSON(7);
org.geotools.geojson.feature.FeatureJSON a = new FeatureJSON(gjson);
a.writeFeatureCollection(buildSimpleFeatureCollection(apiResponse), sw);
String responseTxt = callback + "("+sw.toString()+");";
response.getWriter().print(responseTxt);
response.setContentLength(responseTxt.length());
response.getWriter().close();
LOGGER.info("Coordinate(jsonp)|{}|{}|{}", request.getMethod(), request.getRequestURI(), request.getRemoteAddr());
} catch (IOException e) {
e.printStackTrace();
}
}
else{
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
}
}
示例11: getGeoJSONGeometryForSubject
import org.geotools.geojson.geom.GeometryJSON; //导入依赖的package包/类
private String getGeoJSONGeometryForSubject(Subject subject) {
return (new GeometryJSON()).toString(subject.getShape());
}
示例12: shareUAZSnapshot
import org.geotools.geojson.geom.GeometryJSON; //导入依赖的package包/类
/**
* Upload features.
*
* @param features
* the features
* @param userId
* the user id
* @param project
* @return the string
* @throws IOException
* Signals that an I/O exception has occurred.
* @throws DataStoreCreationException
* the data store creation exception
* @throws MiddlewarePersistentException
*/
private String shareUAZSnapshot(final SimpleFeatureCollection features,
final String userId, final WifProject project) throws IOException,
DataStoreCreationException, MiddlewarePersistentException {
// TODO the following chunk of code is from Mohammed, we should have these
// in a shared library
final int decimals = WifKeys.GEOJSON_PRECISION;
final GeometryJSON gjson = new GeometryJSON(decimals);
final FeatureJSON featureJSON = new FeatureJSON(gjson);
featureJSON.setEncodeFeatureCollectionBounds(true);
featureJSON.setEncodeFeatureCollectionCRS(true);
featureJSON.setEncodeNullValues(true);
final String uuid = UUID.randomUUID().toString();
// Get the temporary directory and print it.
final String tempDir = System.getProperty("java.io.tmpdir");
final File tmpFile = new File(tempDir + "/" + uuid + ".json");
if (!tmpFile.exists()) {
tmpFile.createNewFile();
LOGGER.info(tmpFile.getAbsolutePath() + " has been created");
}
final OutputStream output = new BufferedOutputStream(new FileOutputStream(
tmpFile));
// TODO end the chunk code from Mohammed
// FIXME the following operation tthrow a
// org.geotools.data.postgis.PostGISDialect getOptimizedBounds
// WARNING: Failed to use ST_Estimated_Extent, falling back on envelope
// aggregation
// org.postgresql.util.PSQLException: ERROR: LWGEOM_estimated_extent:
// couldn't locate table within current schema
// Nonetheless, this a known issue of geotools when working with psotgis of
// earlier versions of 1.5
featureJSON.writeFeatureCollection(features, output);// output
LOGGER.info("done writing feature collection..." + tmpFile.length() / 1024
/ 1024 + " MB.");
final Map<String, Object> item = aurinServiceClient.shareAurinProject(
tmpFile, userId, project);
LOGGER.debug("response " + item.get("result"));
return (String) item.get("result");
}
示例13: startQueryResult
import org.geotools.geojson.geom.GeometryJSON; //导入依赖的package包/类
@Override
public void startQueryResult(List<String> bindingNames) throws TupleQueryResultHandlerException {
fjson = new FeatureJSON(new GeometryJSON(jts.getPrecision()));
fjson.setEncodeFeatureCRS(true);
}
示例14: LayerPublisher
import org.geotools.geojson.geom.GeometryJSON; //导入依赖的package包/类
public LayerPublisher(String layers)
{
this.layers = layers;
this.gjson = new GeometryJSON(8);
}