From 94ae08701bbd7585a0b7e5a92d1975965a503c03 Mon Sep 17 00:00:00 2001 From: Dennis Kao <ulysseskao@gmail.com> Date: Wed, 15 Jan 2014 11:28:52 +0800 Subject: [PATCH] Merge branch 'origin/2.1.x' --- xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/util/postjts/JtsGeometry.java | 72 ++++++++++++------------------------ 1 files changed, 24 insertions(+), 48 deletions(-) diff --git a/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/util/postjts/JtsGeometry.java b/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/util/postjts/JtsGeometry.java index 18a6295..74ed0c9 100644 --- a/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/util/postjts/JtsGeometry.java +++ b/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/util/postjts/JtsGeometry.java @@ -45,8 +45,7 @@ * @author Markus Schaber */ -public class JtsGeometry extends PGobject -{ +public class JtsGeometry extends PGobject { /* JDK 1.5 Serialization */ private static final long serialVersionUID = 0x100; @@ -67,44 +66,35 @@ /** * Constructor called by JDBC drivers */ - public JtsGeometry() - { + public JtsGeometry() { setType("geometry"); } - public JtsGeometry(Geometry geom) - { + public JtsGeometry(Geometry geom) { this(); this.geom = geom; } - public JtsGeometry(String value) throws SQLException - { + public JtsGeometry(String value) throws SQLException { this(); setValue(value); } - public void setValue(String value) throws SQLException - { + public void setValue(String value) throws SQLException { geom = geomFromString(value); } - public static Geometry geomFromString(String value) throws SQLException - { - try - { + public static Geometry geomFromString(String value) throws SQLException { + try { value = value.trim(); - if (value.startsWith("00") || value.startsWith("01")) - { + if (value.startsWith("00") || value.startsWith("01")) { return bp.parse(value); - } else - { + } else { Geometry result; // no srid := 0 in JTS world int srid = 0; // break up geometry into srid and wkt - if (value.startsWith("SRID=")) - { + if (value.startsWith("SRID=")) { String[] temp = value.split(";"); value = temp[1].trim(); srid = Integer.parseInt(temp[0].substring(5)); @@ -114,8 +104,7 @@ setSridRecurse(result, srid); return result; } - } catch (Exception E) - { + } catch (Exception E) { E.printStackTrace(); throw new SQLException("Error parsing SQL data:" + E); } @@ -124,61 +113,48 @@ /** * Recursively set a srid for the geometry and all subgeometries */ - public static void setSridRecurse(final Geometry geom, final int srid) - { + public static void setSridRecurse(final Geometry geom, final int srid) { geom.setSRID(srid); - if (geom instanceof GeometryCollection) - { + if (geom instanceof GeometryCollection) { final int subcnt = geom.getNumGeometries(); - for (int i = 0; i < subcnt; i++) - { + for (int i = 0; i < subcnt; i++) { setSridRecurse(geom.getGeometryN(i), srid); } - } else if (geom instanceof Polygon) - { + } else if (geom instanceof Polygon) { Polygon poly = (Polygon) geom; poly.getExteriorRing().setSRID(srid); final int subcnt = poly.getNumInteriorRing(); - for (int i = 0; i < subcnt; i++) - { + for (int i = 0; i < subcnt; i++) { poly.getInteriorRingN(i).setSRID(srid); } } } - public Geometry getGeometry() - { + public Geometry getGeometry() { return geom; } - public String toString() - { + public String toString() { return geom.toString(); } - public String getValue() - { + public String getValue() { return bw.writeHexed(getGeometry()); } - public Object clone() - { + public Object clone() { JtsGeometry obj = new JtsGeometry(geom); obj.setType(type); return obj; } - public boolean equals(Object obj) - { - if ((obj != null) && (obj instanceof JtsGeometry)) - { + public boolean equals(Object obj) { + if ((obj != null) && (obj instanceof JtsGeometry)) { Geometry other = ((JtsGeometry) obj).geom; - if (this.geom == other) - { // handles identity as well as both + if (this.geom == other) { // handles identity as well as both // ==null return true; - } else if (this.geom != null && other != null) - { + } else if (this.geom != null && other != null) { return other.equals(this.geom); } } -- Gitblit v0.0.0-SNAPSHOT