Hi,
I send two new patches which implements what have been discussed in the
previous mails.
Resume:
Type = geography -> 2D, because ST_AsEWKB don't support geographic type.
(http://postgis.refractions.net/documentation/manual-svn/ST_AsEWKB.html)
No hint -> 3D
hints.put(FEATURE_2D, false) -> 3D
hints.put(FEATURE_2D, true) -> 2D
Regards,
Nuno Oliveira
2012/5/4 Andrea Aime <[email protected]>
> On Fri, May 4, 2012 at 5:13 PM, Justin Deoliveira <[email protected]>wrote:
>
>>
>> Hum,
>>
>>> the original intended behavior for the hint was to return 3D geometries
>>> any time the hint was not explicitly
>>> set, that's how we got 3d geometries in GML and KML output even if those
>>> do not explicitly set any hints,
>>> while on the other side the renderer manually forces the hint in.
>>>
>>
>> Sorry, i am not sure if you are saying my reasoning is in error? I think
>> we are saying the same thing? My interpretation is:
>>
>> //no hint -> 3D
>> hints.put(FEATURE_2D, false) -> 3D
>> hints.put(FEATURE_2D, true) -> 2D
>>
>
> Ah ok, then we are on the same page, must have misread your previous mail
>
>
>>
>>
>>> Do you know of other code paths, besides the renderer, that would break
>>> when facing 3D data?
>>>
>>
>> Hmmm... can't think of any. Martin is currently looking at the wfs
>> pipeline, gml 2/3 and geojson and it seems they just happily will
>> drop/ignore the third coordinate if its there.
>>
>
> Cool
>
> Cheers
> Andrea
>
> --
> Ing. Andrea Aime
> GeoSolutions S.A.S.
> Tech lead
>
> Via Poggio alle Viti 1187
> 55054 Massarosa (LU)
> Italy
>
> phone: +39 0584 962313
> fax: +39 0584 962313
> mob: +39 339 8844549
>
> http://www.geo-solutions.it
> http://geo-solutions.blogspot.com/
> http://www.youtube.com/user/GeoSolutionsIT
> http://www.linkedin.com/in/andreaaime
> http://twitter.com/geowolf
>
>
From e1dc60ed3f418d1fd70054581f2bb8962d6e9a98 Mon Sep 17 00:00:00 2001
From: nuno <[email protected]>
Date: Mon, 7 May 2012 11:47:58 +0100
Subject: [PATCH] Add 3D coordinates support to PostGIS.
---
.../main/java/org/geotools/jdbc/JDBCDataStore.java | 2 +-
.../main/java/org/geotools/jdbc/SQLDialect.java | 38 ++++++++++++++++++++
.../org/geotools/data/postgis/PostGISDialect.java | 35 ++++++++++++++++++
3 files changed, 74 insertions(+), 1 deletions(-)
diff --git a/modules/library/jdbc/src/main/java/org/geotools/jdbc/JDBCDataStore.java b/modules/library/jdbc/src/main/java/org/geotools/jdbc/JDBCDataStore.java
index 9776158..7cc4636 100644
--- a/modules/library/jdbc/src/main/java/org/geotools/jdbc/JDBCDataStore.java
+++ b/modules/library/jdbc/src/main/java/org/geotools/jdbc/JDBCDataStore.java
@@ -4384,7 +4384,7 @@ public final class JDBCDataStore extends ContentDataStore
return;
}
- dialect.encodeGeometryColumn(gatt,prefix,srid, sql);
+ dialect.encodeGeometryColumn(gatt,prefix,srid, sql, hints);
}
/**
diff --git a/modules/library/jdbc/src/main/java/org/geotools/jdbc/SQLDialect.java b/modules/library/jdbc/src/main/java/org/geotools/jdbc/SQLDialect.java
index 0c0c68a..a298649 100644
--- a/modules/library/jdbc/src/main/java/org/geotools/jdbc/SQLDialect.java
+++ b/modules/library/jdbc/src/main/java/org/geotools/jdbc/SQLDialect.java
@@ -705,10 +705,48 @@ public abstract class SQLDialect {
* This default implementation simply uses the column name without any
* wrapping function, subclasses must override.
* </p>
+ *
+ * @deprecated use {@link #encodeGeometryColumn(GeometryDescriptor, String, int, StringBuffer, Hints)}
*/
public void encodeGeometryColumn(GeometryDescriptor gatt, String prefix, int srid, StringBuffer sql) {
encodeColumnName(prefix, gatt.getLocalName(), sql);
}
+
+ /**
+ * Encodes the name of a geometry column in a SELECT statement.
+ * <p>
+ * This method should wrap the column name in any functions that are used to
+ * retrieve its value. For instance, often it is necessary to use the
+ * function <code>asText</code>, or <code>asWKB</code> when fetching a
+ * geometry.
+ * </p>
+ * <p>
+ * This method must also be sure to properly encode the name of the column
+ * with the {@link #encodeColumnName(String, String, StringBuffer)}
+ * function.
+ * </p>
+ * <p>
+ * Example:
+ * </p>
+ *
+ * <pre>
+ * <code>
+ * sql.append( "asText(" );
+ * column( gatt.getLocalName(), sql );
+ * sql.append( ")" );
+ * </code>
+ * </pre>
+ *
+ * </p>
+ * <p>
+ * This default implementation simply uses the column name without any
+ * wrapping function, subclasses must override.
+ * </p>
+ */
+ public void encodeGeometryColumn(GeometryDescriptor gatt, String prefix,
+ int srid, StringBuffer sql, Hints hints) {
+ encodeColumnName(prefix, gatt.getLocalName(), sql);
+ }
/**
* Encodes a generalized geometry using a DB provided SQL function if available
diff --git a/modules/plugin/jdbc/jdbc-postgis/src/main/java/org/geotools/data/postgis/PostGISDialect.java b/modules/plugin/jdbc/jdbc-postgis/src/main/java/org/geotools/data/postgis/PostGISDialect.java
index 1f68d35..6cce869 100644
--- a/modules/plugin/jdbc/jdbc-postgis/src/main/java/org/geotools/data/postgis/PostGISDialect.java
+++ b/modules/plugin/jdbc/jdbc-postgis/src/main/java/org/geotools/data/postgis/PostGISDialect.java
@@ -33,6 +33,7 @@ import java.util.UUID;
import java.util.logging.Level;
import org.geotools.data.jdbc.FilterToSQL;
+import org.geotools.factory.Hints;
import org.geotools.geometry.jts.ReferencedEnvelope;
import org.geotools.jdbc.BasicSQLDialect;
import org.geotools.jdbc.ColumnMetadata;
@@ -206,6 +207,40 @@ public class PostGISDialect extends BasicSQLDialect {
}
sql.append("),'base64')");
}
+
+ @Override
+ public void encodeGeometryColumn(GeometryDescriptor gatt, String prefix,
+ int srid, StringBuffer sql, Hints hints) {
+
+ boolean geography = "geography".equals(gatt.getUserData().get(
+ JDBCDataStore.JDBC_NATIVE_TYPENAME));
+
+ if(geography) {
+ sql.append("encode(ST_AsBinary(");
+ encodeColumnName(prefix, gatt.getLocalName(), sql);
+ sql.append("),'base64')");
+ }
+
+ else {
+ boolean force2D = false;
+ if (hints.containsKey(Hints.FEATURE_2D)) {
+ if (hints.get(Hints.FEATURE_2D) == Boolean.TRUE) {
+ force2D = true;
+ }
+ }
+
+ if(force2D) {
+ sql.append("encode(ST_AsBinary(ST_Force_2D(");
+ encodeColumnName(prefix, gatt.getLocalName(), sql);
+ sql.append(")),'base64')");
+ }
+ else {
+ sql.append("encode(ST_AsEWKB(");
+ encodeColumnName(prefix, gatt.getLocalName(), sql);
+ sql.append("),'base64')");
+ }
+ }
+ }
@Override
public void encodeGeometryEnvelope(String tableName, String geometryColumn,
--
1.7.1
From b910e1bcc9505c78d5d4cbbfe64f16891a44e772 Mon Sep 17 00:00:00 2001
From: nuno <[email protected]>
Date: Mon, 7 May 2012 12:00:10 +0100
Subject: [PATCH] Add PostGIS 3D tests.
---
.../org/geotools/data/postgis/PostGIS3DTest.java | 52 ++++++++++++
.../geotools/data/postgis/PostGIS3DTestSetup.java | 85 ++++++++++++++++++++
2 files changed, 137 insertions(+), 0 deletions(-)
create mode 100644 modules/plugin/jdbc/jdbc-postgis/src/test/java/org/geotools/data/postgis/PostGIS3DTest.java
create mode 100644 modules/plugin/jdbc/jdbc-postgis/src/test/java/org/geotools/data/postgis/PostGIS3DTestSetup.java
diff --git a/modules/plugin/jdbc/jdbc-postgis/src/test/java/org/geotools/data/postgis/PostGIS3DTest.java b/modules/plugin/jdbc/jdbc-postgis/src/test/java/org/geotools/data/postgis/PostGIS3DTest.java
new file mode 100644
index 0000000..3294f40
--- /dev/null
+++ b/modules/plugin/jdbc/jdbc-postgis/src/test/java/org/geotools/data/postgis/PostGIS3DTest.java
@@ -0,0 +1,52 @@
+/*
+ * GeoTools - The Open Source Java GIS Toolkit
+ * http://geotools.org
+ *
+ * (C) 2002-2008, Open Source Geospatial Foundation (OSGeo)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ */
+package org.geotools.data.postgis;
+
+import java.util.HashSet;
+import java.util.List;
+
+import org.geotools.data.DataUtilities;
+import org.geotools.data.Query;
+import org.geotools.data.Transaction;
+import org.geotools.data.simple.SimpleFeatureCollection;
+import org.geotools.data.simple.SimpleFeatureIterator;
+import org.geotools.data.simple.SimpleFeatureStore;
+import org.geotools.factory.Hints;
+import org.geotools.feature.simple.SimpleFeatureBuilder;
+import org.geotools.jdbc.JDBC3DTest;
+import org.geotools.jdbc.JDBC3DTestSetup;
+import org.opengis.feature.simple.SimpleFeature;
+import org.opengis.filter.identity.FeatureId;
+
+import com.vividsolutions.jts.geom.Coordinate;
+import com.vividsolutions.jts.geom.Geometry;
+import com.vividsolutions.jts.geom.GeometryFactory;
+import com.vividsolutions.jts.geom.LineString;
+
+/**
+ *
+ *
+ * @source $URL$
+ */
+public class PostGIS3DTest extends JDBC3DTest {
+
+ @Override
+ protected JDBC3DTestSetup createTestSetup() {
+ return new PostGIS3DTestSetup();
+ }
+
+}
diff --git a/modules/plugin/jdbc/jdbc-postgis/src/test/java/org/geotools/data/postgis/PostGIS3DTestSetup.java b/modules/plugin/jdbc/jdbc-postgis/src/test/java/org/geotools/data/postgis/PostGIS3DTestSetup.java
new file mode 100644
index 0000000..da3fac9
--- /dev/null
+++ b/modules/plugin/jdbc/jdbc-postgis/src/test/java/org/geotools/data/postgis/PostGIS3DTestSetup.java
@@ -0,0 +1,85 @@
+/*
+ * GeoTools - The Open Source Java GIS Toolkit
+ * http://geotools.org
+ *
+ * (C) 2002-2008, Open Source Geospatial Foundation (OSGeo)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ */
+package org.geotools.data.postgis;
+
+import org.geotools.jdbc.JDBC3DTestSetup;
+
+/**
+ *
+ *
+ * @source $URL$
+ */
+public class PostGIS3DTestSetup extends JDBC3DTestSetup {
+
+ protected PostGIS3DTestSetup() {
+ super(new PostGISTestSetup());
+
+ }
+
+ @Override
+ protected void createLine3DTable() throws Exception {
+ // setup table
+ run("CREATE TABLE \"line3d\"(\"fid\" serial PRIMARY KEY, \"id\" int, "
+ + "\"geom\" geometry, \"name\" varchar )");
+ run("INSERT INTO GEOMETRY_COLUMNS VALUES('', 'public', 'line3d', 'geom', 3, '4326', 'LINESTRING')");
+ run("CREATE INDEX line3d_GEOM_IDX ON \"line3d\" USING GIST (\"geom\") ");
+
+ // insert data
+ run("INSERT INTO \"line3d\" (\"id\",\"geom\",\"name\") VALUES (0,"
+ + "GeomFromText('LINESTRING(1 1 0, 2 2 0, 4 2 1, 5 1 1)', 4326),"
+ + "'l1')");
+ run("INSERT INTO \"line3d\" (\"id\",\"geom\",\"name\") VALUES (1,"
+ + "GeomFromText('LINESTRING(3 0 1, 3 2 2, 3 3 3, 3 4 5)', 4326),"
+ + "'l2')");
+ }
+
+ @Override
+ protected void createPoint3DTable() throws Exception {
+ // setup table
+ run("CREATE TABLE \"point3d\"(\"fid\" serial PRIMARY KEY, \"id\" int, "
+ + "\"geom\" geometry, \"name\" varchar )");
+ run("INSERT INTO GEOMETRY_COLUMNS VALUES('', 'public', 'point3d', 'geom', 3, '4326', 'POINT')");
+ run("CREATE INDEX POINT3D_GEOM_IDX ON \"point3d\" USING GIST (\"geom\") ");
+
+ // insert data
+ run("INSERT INTO \"point3d\" (\"id\",\"geom\",\"name\") VALUES (0,"
+ + "GeomFromText('POINT(1 1 1)', 4326),"
+ + "'p1')");
+ run("INSERT INTO \"point3d\" (\"id\",\"geom\",\"name\") VALUES (1,"
+ + "GeomFromText('POINT(3 0 1)', 4326),"
+ + "'p2')");
+ }
+
+ @Override
+ protected void dropLine3DTable() throws Exception {
+ run("DELETE FROM GEOMETRY_COLUMNS WHERE F_TABLE_NAME = 'line3d'");
+ run("DROP TABLE \"line3d\"");
+ }
+
+ @Override
+ protected void dropPoly3DTable() throws Exception {
+ run("DELETE FROM GEOMETRY_COLUMNS WHERE F_TABLE_NAME = 'poly3d'");
+ run("DROP TABLE \"poly3d\"");
+ }
+
+ @Override
+ protected void dropPoint3DTable() throws Exception {
+ run("DELETE FROM GEOMETRY_COLUMNS WHERE F_TABLE_NAME = 'point3d'");
+ run("DROP TABLE \"point3d\"");
+ }
+
+}
--
1.7.1
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Geoserver-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geoserver-devel