[postgis-users] Bug in org.postgis.LineString concat() from Java API 1.3.3

Innerebner Markus markus.innerebner at inf.unibz.it
Thu Jan 26 02:20:13 PST 2012


Hi all,

for me this looks like an error:

postgis.jdbc.LineString method concat (line70)

WRONG:
int count = points.length + points.length - (cutPoint ? 1 : 0);

CORRECT:
int count = points.length + opoints.length - (cutPoint ? 1 : 0);

can you check this please?

thanks Markus

I am using the version 1.3.3 from the maven repository

<dependency>
	<groupId>org.postgis</groupId>
	<artifactId>postgis-jdbc</artifactId>
	<version>1.3.3</version>
</dependency>


/************** corrected ***/

public LineString concat(LineString other) {
        Point[] points = this.getPoints();
        Point[] opoints = other.getPoints();

        boolean cutPoint = this.getLastPoint() == null
                || this.getLastPoint().equals(other.getFirstPoint());
        int count = points.length + opoints.length - (cutPoint ? 1 : 0);
        Point[] p = new Point[count];

        // Maybe we should use System.arrayCopy here?
        int i, j;
        for (i = 0; i < points.length; i++) {
            p[i] = points[i];
        }
        if (!cutPoint) {
            p[i++] = other.getFirstPoint();
        }
        for (j = 1; j < opoints.length; j++, i++) {
            p[i] = opoints[j];
        }
        return new LineString(p);
    }




More information about the postgis-users mailing list