[Jts-topo-suite-user] Issue with GeometryFactory.createMultiPoint(CoordinateSequence)
Brought to you by:
dr_jts
From: Felix O. <obe@IVV-AACHEN.DE> - 2012-12-03 09:36:13
|
Hello I just noticed a small issue with creating MultiPoints from a coordinate sequence that has a dimension greater than three: public void testMultiPointDim4() { GeometryFactory gf = new GeometryFactory(new PackedCoordinateSequenceFactory()); CoordinateSequence mpSeq = gf.getCoordinateSequenceFactory().create(1, 4); mpSeq.setOrdinate(0, 0, 50); mpSeq.setOrdinate(0, 1, -2); mpSeq.setOrdinate(0, 2, 10); mpSeq.setOrdinate(0, 3, 20); MultiPoint mp = gf.createMultiPoint(mpSeq); CoordinateSequence pSeq = ((Point)mp.getGeometryN(0)).getCoordinateSequence(); assertEquals(4, pSeq.getDimension()); for (int i = 0; i < 4; i++) assertEquals(mpSeq.getOrdinate(0, i), pSeq.getOrdinate(0, i)); } The issue can be resolved by changing GeometryFactory's createMultiPoint function to this: /** * Creates a MultiPoint using the given CoordinateSequence. * A a null or empty CoordinateSequence will create an empty MultiPoint. * * @param coordinates a CoordinateSequence (possibly empty), or <code>null</code> * @return a MultiPoint object */ public MultiPoint createMultiPoint(CoordinateSequence coordinates) { if (coordinates == null) { return createMultiPoint(new Point[0]); } Point[] points = new Point[coordinates.size()]; for (int i = 0; i < coordinates.size(); i++) { CoordinateSequence seq = coordinateSequenceFactory.create(1, coordinates.getDimension()); CoordinateSequences.copy(coordinates, 0, seq, i, 1); points[i] = createPoint(seq); } return createMultiPoint(points); Hth FObermaier |