Раскрасить мою коллекцию геометрических объектов?
Привет, я пытаюсь нарисовать свою особенность (коллекцию геометрии с определенным цветом), но я получаю эту ошибку: это проблема с массивом, который должен быть приведен, но я не знаю, как это исправить PLZ, помогите мне заранее спасибо
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException:
java.util.ArrayList нельзя преобразовать в com.vividsolutions.jts.geom.GeometryCollection в com.vividsolutions.jump.workbench.ui.plugin.specific.SearchPropertiesPlugin$3.actionPerformed(SearchPropertiesPlugin.java:205) в javax.sw " DefaultButtonModel.java:242) в javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236) в java.awt.Component.processMouseEvent(Component.java:6297) в javax.swent.Jom.java:3275) на java.awt.Component.processEvent(Component.java:6062) на java.awt.Container.processEvent(Container.java:2039) на java.awt.Component.dispatchEventImpl(Component.java:4660). в java.awt.Container.dispatchEventImpl(Container.java:2097) в java.awt.Component.dispatchEvent(Component.java:4488) в java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4575) в java.awt.LightweightDispatcher.processMouseEvent(Container.java:4236) в java.awt.LightweightDispatcher.vent java:4166) в java.awt.Container.dispatchEventImpl(Container.java:2083) в java.awt.Window.dispatchEventImpl(Window.java:2489) в java.awt.Component.dispatchEvent(Component.java:4488) в java.awt.EventQueue.dispatchEventImpl(EventQueue.java:668) в java.awt.EventQueue.access$400(EventQueue.java:81) в java.awt.EventQueue$2.run(EventQueue.java:627) в java.awt.EventQueue$2.run(EventQueue.java:625) в java.security.AccessController.doPrivileged(Native Method) в java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87) в java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:98) в java.awt.EventQueue$3.run(EventQueue.java:641) в java.awt.EventQueue$3.run(EventQueue.java:639) в java.s ecurity.AccessController..java:269) в java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184) в java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174) в java.awpisThread.Ed в java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161) в java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
вот где он получает исключение:
Viewport viewport = new Viewport(context.getLayerViewPanel());
Paint fillPaint = null;
Color color = Color.yellow;
Stroke stroke =new BasicStroke(5, BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND);
final Graphics2D graphics = (Graphics2D) context.getLayerViewPanel().getGraphics();
// в этой строке:
paintGeometryCollection((GeometryCollection) selectedFeatures(),
graphics, viewport, true,
stroke,fillPaint, true,
stroke, color);
и вот другие методы, которые ему нужны:
public Collection selectedFeatures() {
ArrayList selectedFeatures = new ArrayList();
for(BasicFeature basicFeature : TitreList) {
selectedFeatures.add(search().getGeometry());
// search() is a BasicFeature
}
return selectedFeatures;
}
private static void paintGeometryCollection(GeometryCollection collection,
Graphics2D g, Viewport viewport, boolean renderingFill,
Stroke fillStroke, Paint fillPaint, boolean renderingLine,
Stroke lineStroke, Color lineColor)
throws NoninvertibleTransformException {
//For GeometryCollections, render each element separately. Otherwise,
//for example, if you pass in a GeometryCollection containing a ring and a
// disk, you cannot render them as such: if you use Graphics.fill, you'll get
//two disks, and if you use Graphics.draw, you'll get two rings. [Jon Aquino]
for (int i = 0; i < collection.getNumGeometries(); i++) {
paint(collection.getGeometryN(i), g, viewport, renderingFill,
fillStroke, fillPaint, renderingLine, lineStroke, lineColor);
}
}
public static void paint(Geometry geometry, Graphics2D g,
Viewport viewport, boolean renderingFill, Stroke fillStroke,
Paint fillPaint, boolean renderingLine, Stroke lineStroke,
Color lineColor) throws NoninvertibleTransformException {
if (geometry instanceof GeometryCollection) {
paintGeometryCollection((GeometryCollection) geometry, g, viewport,
renderingFill, fillStroke, fillPaint, renderingLine,
lineStroke, lineColor);
return;
}
Shape shape = toShape(geometry, viewport);
if (!(shape instanceof GeneralPath) && renderingFill) {
g.setStroke(fillStroke);
g.setPaint(fillPaint);
g.fill(shape);
}
if (renderingLine) {
g.setStroke(lineStroke);
g.setColor(lineColor);
g.draw(shape);
}
}
private static Shape toShape(Geometry geometry, Viewport viewport)
throws NoninvertibleTransformException {
//At high magnifications, Java rendering can be sped up by clipping
//the Geometry to only that portion visible inside the viewport.
//Hence the code below. [Jon Aquino]
Envelope bufferedEnvelope = EnvelopeUtil.bufferByFraction(viewport.getEnvelopeInModelCoordinates(),
0.05);
Geometry actualGeometry = geometry;
Envelope geomEnv = actualGeometry.getEnvelopeInternal();
if (! bufferedEnvelope.contains(geomEnv)) {
/**
* MD - letting Java2D do more clipping actually seems to be slower!
* So don't use following "optimization"
*/
//if (isRatioLarge(bufferedEnvelope, geomEnv, 2)) {
if (!((geometry instanceof LineString) || (geometry instanceof MultiLineString)))
actualGeometry = clipGeometry(geometry, bufferedEnvelope);
//System.out.println("cl");
//}
}
return viewport.getJava2DConverter().toShape(actualGeometry);
}
private static Geometry clipGeometry(Geometry geom, Envelope env)
{
try {
Geometry clipGeom = EnvelopeUtil.toGeometry(env)
.intersection(geom);
return clipGeom;
} catch (Exception e) {
//Can get a TopologyException if the Geometry is invalid. Eat it. [Jon Aquino]
//Can get an AssertionFailedException (unable to assign hole to a shell)
//at high magnifications. Eat it. [Jon Aquino]
//Alvaro Zabala reports that we can get here with an
//IllegalArgumentException (points must form a closed linestring)
//for bad geometries. Eat it. [Jon Aquino]
}
return geom;
}
1 ответ
public Collection selectedFeatures()
возвращается Colecction
но вы бросили его GeometryCollection
, Для меня это проблема.
Линия paintGeometryCollection((GeometryCollection) selectedFeatures(),