Hi Justin,

I'm really sorry about the patch i haven't seen the formatting trick (sorry
for the waste of time).
I send in annex two patchs one who makes the changes in the existing
classes and another to add the PostGIS 3D tests.

I hope i did it well this time.

Regards,

Nuno Oliveira




2012/5/3 Justin Deoliveira <jdeol...@opengeo.org>

> Hi Nuno,
>
> The changes make sense, unfortunately the patch still has issues. The
> patch contains largely formatting changes. Looks like spaces were converted
> to tabs at some point. This unfortunately makes it nearly impossible to
> figure out what actually changed in that class. Seems to be mostly
> the PostGISDialect class, but also the test classes contain misformatting
> in terms of tabs vs spaces.
>
> Not sure what IDE you are using but if you are using eclipse there are
> existing formatting templates that will help with this. See this for more
> details.
>
>   http://docs.geotools.org/latest/developer/conventions/code/style.html
>
> Again, to reiterate, for any patches that are proposed it is imperative
> that they only contain relevant changes, and no formatting changes.
>
> -Justin
>
>
> On Wed, May 2, 2012 at 8:22 AM, Nuno Miguel Carvalho Oliveira <
> nmco51...@gmail.com> wrote:
>
>> Hi,
>>
>> (Sorry for the late reply, i had a very very busy week).
>>
>> First, thank you for your very complete answer.
>> I create a new patch based on your advices (in annex).
>> Basically to read 3D coordinates from a PostGIS data
>> base we need to put a hint in the query:
>>
>>   Hints hints = query.getHints();
>>   hints.put(Hints.FEATURE_2D, Boolean.FALSE);
>>   query.setHints(hints);
>>
>> This hint will remove 'ST_Force_2D' from the final querry
>> and set the encode to 'ST_AsEWKB' instead of 'ST_AsBinary'.
>>
>> I run the tests and all works fine (PostGIS3DTest).
>>
>> To resume what i have changed:
>>
>>     - SQLDialect.java and PostGISDialect.java: I extend the
>>       'encodeGeometryColumn' function to take also the 'Hints'
>>       as a parameter.
>>     - JDBCDataStore.java: I give the 'Hints' as a parameter
>>       to the 'encodeGeometryColumn' function.
>>     - PostGIS3DTest and PostGIS3DTestSetup: I add 3D tests
>>       to PostGIS.
>>
>>
>> Any suggestions are very welcome.
>>
>> Regards,
>>
>> Nuno Oliveira
>>
>>
>> 2012/4/21 Andrea Aime <andrea.a...@geo-solutions.it>
>>
>>> On Thu, Apr 19, 2012 at 7:01 AM, Nuno Miguel Carvalho Oliveira <
>>> nmco51...@gmail.com> wrote:
>>>
>>>> Hi,
>>>>
>>>> Follows in anexe two patchs, one to integrate W3DS as a community
>>>> module in GeoServer and another to GeoTools who  permits the acess of 3D
>>>> data from a PostGIS data base. Related to the acess of 3D data in GeoTools
>>>> maybe it exists a better way to do this, any idea is welcome.
>>>>
>>>>
>>> Hi,
>>> let's start discussing the Geotools patch, since it's really short.
>>> The patch is almost correct, but it's mis-using the hints somehow.
>>>
>>> Hints are used in the query as a way to tell the store that we'd
>>> like the returned objects to have some particular property, such as being
>>> built with a particular geometry factory, or being flat (2D).
>>> The geometry column user data is instead used to carry some extra info
>>> that describes it, such as the fact the column is a "geography" instead
>>> of a
>>> "geometry".
>>>
>>> Query hints are created per request and can vary over time, for example
>>> WMS will always ask for 2D geometries, whilst W3DS or WFS won't.
>>> Geometry descriptor attributes instead are structural, once set they
>>> describe
>>> something about the geometry column "forever".
>>>
>>> As such you should not mix them, otherwise one request can force the
>>> geometry to be 2d by attaching the hint and the next request looking for
>>> 3d data won't get it (because the hint is already in place).
>>> To do what you want is better to extend the encodeGeometryColumn in
>>> SQLDialect  to take also the Hints as a parameter: it is an API break
>>> that
>>> I believe we can take on trunk (Justin, thoughts?).
>>>
>>> The other thing that's missing is a test.
>>> The JDBC testing framework is shared between all the databases and is
>>> setup so that there is a base abstract class which needs to be subclasses
>>> and return a "test setup" object that knows how to setup the expected
>>> spatial tables with the DDL specific of that particular database.
>>> You can extend JDBC3DTest and JDBC3DTestSetup, which are
>>> now implemented only for Oracle and DB2, and create an implementation
>>> for PostGIS.
>>>
>>> I'll try to have a look at the W3DS community module too, but as long as
>>> it's a
>>> community module you don't really need to pass any review.
>>> One thing is important tough, in order for GeoServer to include your
>>> module
>>> in the future you, or the company/authority/adminstration that employs
>>> you
>>> have to sign and send a "copyright assignment" contract that gives
>>> Openplans,
>>> the no-profit managing GeoServer, rights on the source code that you
>>> created.
>>> This is necessary to keep the ownership in one place and defend
>>> GeoServer in
>>> court should a license violation arise.
>>>
>>> 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
>>>
>>> -------------------------------------------------------
>>>
>>
>>
>
>
> --
> Justin Deoliveira
> OpenGeo - http://opengeo.org
> Enterprise support for open source geospatial.
>
>
From bb385fa78801c1e378de1f3231d859048f70dd1f Mon Sep 17 00:00:00 2001
From: nuno <nmco51...@gmail.com>
Date: Thu, 3 May 2012 17:51:41 +0100
Subject: [PATCH] Permit obtain 3D coordinates froma PostGIS data base.

---
 .../main/java/org/geotools/jdbc/JDBCDataStore.java |    2 +-
 .../main/java/org/geotools/jdbc/SQLDialect.java    |   32 +++++++++++++++++++
 .../org/geotools/data/postgis/PostGISDialect.java  |   33 ++++++++++++++++++++
 3 files changed, 66 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..5bae90e 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..d514160 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
@@ -709,6 +709,38 @@ public abstract class SQLDialect {
     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..2efd322 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,38 @@ 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));
+
+        sql.append("encode(");
+
+        boolean is3D = false;
+
+        if (hints.containsKey(Hints.FEATURE_2D)) {
+            if (hints.get(Hints.FEATURE_2D) == Boolean.FALSE) {
+                sql.append("ST_AsEWKB(");
+                is3D = true;
+                geography = true;
+            }
+        }
+        if (!is3D) {
+            sql.append("ST_AsBinary(");
+            if (!geography) {
+                sql.append("ST_Force_2D(");
+            }
+        }
+
+        encodeColumnName(prefix, gatt.getLocalName(), sql);
+        if (!geography) {
+            sql.append(")");
+        }
+        sql.append("),'base64')");
+    }
 
     @Override
     public void encodeGeometryEnvelope(String tableName, String geometryColumn,
-- 
1.7.1

From dc441731ca550e6502b91e75604bf7995b4c7781 Mon Sep 17 00:00:00 2001
From: nuno <nmco51...@gmail.com>
Date: Thu, 3 May 2012 18:53:18 +0100
Subject: [PATCH] Add PostGIS 3D Tests.

---
 .../org/geotools/data/postgis/PostGIS3DTest.java   |   73 +++++++++++++++++
 .../geotools/data/postgis/PostGIS3DTestSetup.java  |   85 ++++++++++++++++++++
 2 files changed, 158 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..386782f
--- /dev/null
+++ b/modules/plugin/jdbc/jdbc-postgis/src/test/java/org/geotools/data/postgis/PostGIS3DTest.java
@@ -0,0 +1,73 @@
+/*
+ *    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();
+    }
+    
+    @Override
+    public void testReadLine() throws Exception {
+    	Query query = new Query(Query.ALL);
+    	
+    	Hints hints = query.getHints();
+		hints.put(Hints.FEATURE_2D, Boolean.FALSE);
+		query.setHints(hints);
+		
+    	SimpleFeatureCollection fc = dataStore.getFeatureSource(tname(LINE3D)).getFeatures(query);
+        SimpleFeatureIterator fr = fc.features();
+        assertTrue(fr.hasNext());
+        LineString ls = (LineString) fr.next().getDefaultGeometry();
+        // 1 1 0, 2 2 0, 4 2 1, 5 1 1
+        assertEquals(4, ls.getCoordinates().length);
+        assertTrue(new Coordinate(1, 1, 0).equals3D(ls.getCoordinateN(0)));
+        assertTrue(new Coordinate(2, 2, 0).equals3D(ls.getCoordinateN(1)));
+        assertTrue(new Coordinate(4, 2, 1).equals3D(ls.getCoordinateN(2)));
+        assertTrue(new Coordinate(5, 1, 1).equals3D(ls.getCoordinateN(3)));
+        fr.close();
+    }
+    
+}
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
Geoserver-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geoserver-devel

Reply via email to