| 40,6 → 40,7 |
| import org.postgresql.util.PGobject; |
| |
| import java.sql.Connection; |
| import java.sql.SQLException; |
| import java.sql.Types; |
| import java.util.regex.Matcher; |
| import java.util.regex.Pattern; |
| 115,15 → 116,20 |
| return out; |
| } else if (object instanceof org.postgis.PGboxbase) { |
| return convertBox((org.postgis.PGboxbase) object); |
| } else if (object instanceof PGobject && ((PGobject)object).getType().contains("box")) { |
| PGobject pgo = (PGobject)object; |
| } else if (object instanceof PGobject && ((PGobject) object).getType().contains("box")) { |
| PGobject pgo = (PGobject) object; |
| //try to extract the box object (if available) |
| String boxStr = extractBoxString(pgo); |
| if (boxStr == null) throw new IllegalArgumentException("Can't convert object: " + pgo.getType() + " : " + pgo.getValue()); |
| if (boxStr == null) |
| throw new IllegalArgumentException("Can't convert object: " + pgo.getType() + " : " + pgo.getValue()); |
| String[] pointsStr = boxStr.split(","); |
| Point ll = toPoint(pointsStr[0]); |
| Point ur = toPoint(pointsStr[1]); |
| return cornerPointsToPolygon(ll, ur, false); |
| // The Postgis driver not always registers geography objects |
| } else if (object instanceof PGobject && (((PGobject)object).getType().equals("geometry") || |
| ((PGobject)object).getType().equals("geography"))) { |
| return convertFromPGobject((PGobject) object); |
| } else { |
| throw new IllegalArgumentException("Can't convert object of type " |
| + object.getClass().getCanonicalName()); |
| 132,17 → 138,27 |
| |
| } |
| |
| private Geometry convertFromPGobject(PGobject object) { |
| String value = object.getValue(); |
| try { |
| PGgeometry pg = new PGgeometry(value); |
| return convert2JTS(pg); |
| } catch (SQLException e) { |
| throw new IllegalArgumentException("Can't convert PGobject of type " + object.getType()); |
| } |
| } |
| |
| private Point toPoint(String s) { |
| String[] coords = s.split("\\s"); |
| double x = Double.parseDouble(coords[0]); |
| double y = Double.parseDouble(coords[1]); |
| return new Point(x,y); |
| return new Point(x, y); |
| } |
| |
| private String extractBoxString(PGobject pgo) { |
| String boxStr = null; |
| Matcher m = boxPattern.matcher(pgo.getValue()); |
| if (m.matches() && m.groupCount() >= 1){ |
| if (m.matches() && m.groupCount() >= 1) { |
| boxStr = m.group(1); |
| } |
| return boxStr; |
| 174,7 → 190,6 |
| } |
| |
| |
| |
| private Geometry convertGeometryCollection(GeometryCollection collection) { |
| org.postgis.Geometry[] geometries = collection.getGeometries(); |
| com.vividsolutions.jts.geom.Geometry[] jtsGeometries = new com.vividsolutions.jts.geom.Geometry[geometries.length]; |