/** Estimate an array of "fat" Points */ private int estimateMultiPoint(MultiPoint geom) { // int size int result = 4; if (geom.getNumGeometries() > 0) { // We can shortcut here, compared to estimateGeometryArray, as all // subgeoms have the same fixed size result += geom.getNumGeometries() * estimateBytes(geom.getGeometryN(0)); } return result; }
protected Geometry transformMultiPoint(MultiPoint geom, Geometry parent) { List transGeomList = new ArrayList(); for (int i = 0; i < geom.getNumGeometries(); i++) { Geometry transformGeom = transformPoint((Point) geom.getGeometryN(i), geom); if (transformGeom == null) continue; if (transformGeom.isEmpty()) continue; transGeomList.add(transformGeom); } return factory.buildGeometry(transGeomList); }
private static IBoundedGeometry2D<? extends IFinite2DBounds<?>> createEuclidMultiPoint( final GeometryAttribute geometryAttribute, final GProjection projection) { final com.vividsolutions.jts.geom.MultiPoint multipoint = (com.vividsolutions.jts.geom.MultiPoint) geometryAttribute.getValue(); if (multipoint.getNumGeometries() == 1) { final com.vividsolutions.jts.geom.Point jtsPoint = (com.vividsolutions.jts.geom.Point) multipoint.getGeometryN(0); return createPoint(jtsPoint.getCoordinate(), projection); } final IVector2[] euclidPoints = new IVector2[multipoint.getNumGeometries()]; for (int i = 0; i < euclidPoints.length; i++) { final com.vividsolutions.jts.geom.Point jtsPoint = (com.vividsolutions.jts.geom.Point) multipoint.getGeometryN(i); euclidPoints[i] = createPoint(jtsPoint.getCoordinate(), projection); } return new GMultiGeometry2D<IVector2>(euclidPoints); }
// Multipoint private String transformMultiPointToJsonMultiPoint(MultiPoint multipoint) { LOGGER.info("Transforming multipoint to json multipoint"); /* Multipoints are like this: * {"points":[[-122.63,45.51],[-122.56,45.51],[-122.56,45.55]],"spatialReference":({" wkid":4326 })} * (1) {"points":[ * (2) [coords],[coords],[coords], * (4) ] * (5) "spatialReference":{" wkid":4326 } * (6) } * */ // Get CRS in this form: "spatialReference":{" wkid":4326 } String wkid; try { wkid = crsToJsonSpatialReference(multipoint); } catch (IOException e) { wkid = "\"spatialReference\":{\"wkid\":0000}"; } LOGGER.debug("Point's CRS: " + wkid); // Step (1) String jsonString = "{\"points\":["; // Step (2) boolean firstElement = true; for (int i = 0; i < multipoint.getNumGeometries(); i++) { /* Treat one point of the multipoint: */ Point point = (Point) multipoint.getGeometryN(i); String onePointString = "["; // Get coordinates Coordinate coordinatePair = point.getCoordinate(); double x = coordinatePair.x; double y = coordinatePair.y; LOGGER.info("Point's coordinates: " + x + ", " + y); // Define which one is east-west and which one is north-soutn // TODO There should not be this difference!! I think the error is that // x and y were wrongly given to GML input! double eastwest; double northsouth; if (isShapefile) { // In GTVectorBindings made of shapefiles, // the x seems to stand for north-south // and the y seems to stand for east-west eastwest = x; northsouth = y; } else { // In GML content (without given CRS) // the y seems to stand for north-south // and the x seems to stand for east-west northsouth = x; eastwest = y; } /* In JSONGEOMETRY, x stands for EAST/WEST coordinate, y for NORTH/SOUTH. * Lines are like this [eastwest, northsouth] */ onePointString = onePointString.concat(eastwest + "," + northsouth + "]"); if (firstElement) { jsonString = jsonString.concat(onePointString); firstElement = false; } else { jsonString = jsonString.concat("," + onePointString); } } // Step (3), (4), (5) jsonString = jsonString.concat("], " + wkid + "}"); return jsonString; }
/** * Transform a feature to a JSON string * * <p>The feature that is passed to this method is transformed to a JSON string according to this * site (http://help.arcgis.com/en/webapi/javascript/arcgis/help/jsapi_start.htm). * * @param geom * @return * @throws IOException */ private String transformOneFeature(Geometry geom) throws IOException { // Depending on geometry's type, transform to json geometry String jsonString = ""; // simple geometries: if (geom instanceof Point) { jsonString = transformPointToJsonPoint((Point) geom); } else if (geom instanceof LineString) { jsonString = transformLineStringToJsonLineString((LineString) geom); } else if (geom instanceof Polygon) { jsonString = transformPolygonToJsonPolygon((Polygon) geom); } // multipoint else if (geom instanceof MultiPoint) { MultiPoint multipoint = (MultiPoint) geom; // if only one point inside, make normal point out of it if (multipoint.getNumGeometries() == 1) { Point point = (Point) multipoint.getGeometryN(0); jsonString = transformPointToJsonPoint(point); } else { jsonString = transformMultiPointToJsonMultiPoint(multipoint); } // multilinestring } else if (geom instanceof MultiLineString) { MultiLineString multiline = (MultiLineString) geom; // if only one linestring inside, make normal linestring out of it if (multiline.getNumGeometries() == 1) { LineString line = (LineString) multiline.getGeometryN(0); jsonString = transformLineStringToJsonLineString(line); } // real multilinestring else { if (multiGeometriesToArray) { jsonString = transformMultiLineStringToJsonLineStringArray(multiline); } else { jsonString = transformMultiLineStringToJsonLineString(multiline); } } // multipolygon } else if (geom instanceof MultiPolygon) { MultiPolygon multipoly = (MultiPolygon) geom; // if only one polygon inside, make normal polygon out of it if (multipoly.getNumGeometries() == 1) { Polygon poly = (Polygon) multipoly.getGeometryN(0); jsonString = transformPolygonToJsonPolygon(poly); } // real multi polygon else { if (multiGeometriesToArray) { jsonString = transformMultiPolygonToJsonPolygonArray(multipoly); } else { jsonString = transformMultiPolygonToJsonPolygon(multipoly); } } } else { LOGGER.error("Feature has no recognized geometry type"); } return jsonString; }
/** * Return an image of the world with a shape drawn on it. Flags control the rendering mode. * Default is a hollow shape in red outline, touching the borders of the image. * * @param shape * @param width * @param height * @param flags * @return * @throws ThinklabException */ public BufferedImage getImagery( Envelope envelope, ShapeValue shape, int width, int height, int flags) throws ThinklabException { BufferedImage ret = getImagery(envelope, width, height); GeometryFactory geoFactory = new GeometryFactory(); double edgeBuffer = 0.0; if (ret == null) { ret = getSatelliteImage( envelope, width, height, null, null, HAlignment.MIDDLE, VAlignment.MIDDLE); } /* * draw shape boundaries. */ Geometry geometry = shape.getGeometry(); double x = envelope.getMinX() - edgeBuffer; double y = envelope.getMinY() - edgeBuffer; double w = envelope.getWidth() + edgeBuffer * 2; double h = envelope.getHeight() + edgeBuffer * 2; java.awt.geom.Rectangle2D.Double bounds = new java.awt.geom.Rectangle2D.Double(x, y, w, h); Graphics graphics = ret.getGraphics(); if ((flags & GREEN_SHAPES) != 0) { graphics.setColor(Color.green); } else { graphics.setColor(Color.red); } graphics.setPaintMode(); if (geometry.getClass().equals(MultiPolygon.class) || geometry.getClass().equals(Polygon.class)) { for (int i = 0; i < geometry.getNumGeometries(); i++) { com.vividsolutions.jts.geom.Polygon poly = (com.vividsolutions.jts.geom.Polygon) geometry.getGeometryN(i); LinearRing lr = geoFactory.createLinearRing(poly.getExteriorRing().getCoordinates()); com.vividsolutions.jts.geom.Polygon part = geoFactory.createPolygon(lr, null); drawGeometry(part, bounds, graphics, width, height, flags); for (int j = 0; j < poly.getNumInteriorRing(); j++) { lr = geoFactory.createLinearRing(poly.getInteriorRingN(j).getCoordinates()); part = geoFactory.createPolygon(lr, null); drawGeometry(part, bounds, graphics, width, height, flags); } } } else if (geometry.getClass().equals(MultiLineString.class)) { MultiLineString mp = (MultiLineString) geometry; for (int n = 0; n < mp.getNumGeometries(); n++) { drawGeometry(mp.getGeometryN(n), bounds, graphics, width, height, flags); } } else if (geometry.getClass().equals(MultiPoint.class)) { MultiPoint mp = (MultiPoint) geometry; for (int n = 0; n < mp.getNumGeometries(); n++) { drawGeometry(mp.getGeometryN(n), bounds, graphics, width, height, flags); } } else { drawGeometry(geometry, bounds, graphics, width, height, flags); } return ret; }