You can subscribe to this list here.
2001 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(39) |
Dec
(70) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2002 |
Jan
(52) |
Feb
(168) |
Mar
(248) |
Apr
(143) |
May
(418) |
Jun
(558) |
Jul
(702) |
Aug
(311) |
Sep
(141) |
Oct
(350) |
Nov
(172) |
Dec
(182) |
2003 |
Jan
(320) |
Feb
(362) |
Mar
(356) |
Apr
(218) |
May
(447) |
Jun
(203) |
Jul
(745) |
Aug
(494) |
Sep
(175) |
Oct
(422) |
Nov
(554) |
Dec
(162) |
2004 |
Jan
(217) |
Feb
(353) |
Mar
(228) |
Apr
(407) |
May
(211) |
Jun
(270) |
Jul
(264) |
Aug
(198) |
Sep
(268) |
Oct
(227) |
Nov
(118) |
Dec
(47) |
2005 |
Jan
(207) |
Feb
(243) |
Mar
(297) |
Apr
(197) |
May
(281) |
Jun
(166) |
Jul
(164) |
Aug
(92) |
Sep
(155) |
Oct
(196) |
Nov
(189) |
Dec
(114) |
2006 |
Jan
(129) |
Feb
(219) |
Mar
(274) |
Apr
(213) |
May
(245) |
Jun
(220) |
Jul
(376) |
Aug
(347) |
Sep
(179) |
Oct
(493) |
Nov
(448) |
Dec
(339) |
2007 |
Jan
(304) |
Feb
(273) |
Mar
(237) |
Apr
(186) |
May
(215) |
Jun
(320) |
Jul
(229) |
Aug
(313) |
Sep
(331) |
Oct
(279) |
Nov
(347) |
Dec
(266) |
2008 |
Jan
(332) |
Feb
(280) |
Mar
(203) |
Apr
(277) |
May
(301) |
Jun
(356) |
Jul
(292) |
Aug
(203) |
Sep
(277) |
Oct
(142) |
Nov
(210) |
Dec
(239) |
2009 |
Jan
(250) |
Feb
(193) |
Mar
(174) |
Apr
(183) |
May
(342) |
Jun
(230) |
Jul
(292) |
Aug
(161) |
Sep
(204) |
Oct
(280) |
Nov
(281) |
Dec
(175) |
2010 |
Jan
(113) |
Feb
(106) |
Mar
(199) |
Apr
(166) |
May
(298) |
Jun
(147) |
Jul
(175) |
Aug
(192) |
Sep
(71) |
Oct
(79) |
Nov
(58) |
Dec
(55) |
2011 |
Jan
(83) |
Feb
(169) |
Mar
(142) |
Apr
(207) |
May
(311) |
Jun
(183) |
Jul
(218) |
Aug
(190) |
Sep
(158) |
Oct
(197) |
Nov
(93) |
Dec
(74) |
2012 |
Jan
(92) |
Feb
(50) |
Mar
(64) |
Apr
(45) |
May
(100) |
Jun
(70) |
Jul
(3) |
Aug
(1) |
Sep
(2) |
Oct
(5) |
Nov
(7) |
Dec
(4) |
2013 |
Jan
(6) |
Feb
(2) |
Mar
(2) |
Apr
(4) |
May
(3) |
Jun
|
Jul
(2) |
Aug
|
Sep
|
Oct
(1) |
Nov
(1) |
Dec
|
2014 |
Jan
(2) |
Feb
(2) |
Mar
(2) |
Apr
(3) |
May
(3) |
Jun
(1) |
Jul
|
Aug
(4) |
Sep
|
Oct
(1) |
Nov
(1) |
Dec
|
2015 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(1) |
Jul
|
Aug
(1) |
Sep
|
Oct
|
Nov
(1) |
Dec
(1) |
2016 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(1) |
Jun
(1) |
Jul
|
Aug
(3) |
Sep
|
Oct
|
Nov
(1) |
Dec
|
2017 |
Jan
(1) |
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: <svn...@os...> - 2012-04-30 14:22:29
|
Author: aaime Date: 2012-04-30 07:22:21 -0700 (Mon, 30 Apr 2012) New Revision: 38696 Modified: branches/2.7.x/modules/plugin/jdbc/jdbc-oracle/src/main/java/org/geotools/data/oracle/OracleFilterToSQL.java branches/2.7.x/modules/plugin/jdbc/jdbc-oracle/src/test/java/org/geotools/data/oracle/OracleSpatialFiltersTest.java branches/2.7.x/modules/plugin/jdbc/jdbc-postgis/src/main/java/org/geotools/data/postgis/FilterToSqlHelper.java branches/2.7.x/modules/plugin/jdbc/jdbc-postgis/src/test/java/org/geotools/data/postgis/PostgisGeographyTest.java Log: [GEOT-4121] DWithin filter does not work from GeoServer when passing units parameter Modified: branches/2.7.x/modules/plugin/jdbc/jdbc-oracle/src/main/java/org/geotools/data/oracle/OracleFilterToSQL.java =================================================================== --- branches/2.7.x/modules/plugin/jdbc/jdbc-oracle/src/main/java/org/geotools/data/oracle/OracleFilterToSQL.java 2012-04-30 14:19:05 UTC (rev 38695) +++ branches/2.7.x/modules/plugin/jdbc/jdbc-oracle/src/main/java/org/geotools/data/oracle/OracleFilterToSQL.java 2012-04-30 14:22:21 UTC (rev 38696) @@ -265,7 +265,8 @@ protected void doSDODistance(BinarySpatialOperator filter, PropertyName property, Literal geometry, Object extraData) throws IOException { double distance = ((DistanceBufferOperator) filter).getDistance(); - String unit = ((DistanceBufferOperator) filter).getDistanceUnits(); + String unit = getSDOUnitFromOGCUnit(((DistanceBufferOperator) filter).getDistanceUnits()); + String within = filter instanceof DWithin ? "TRUE" : "FALSE"; out.write("SDO_WITHIN_DISTANCE("); @@ -279,5 +280,28 @@ else out.write(",'distance=" + distance + "') = '" + within + "' "); } - + + /** + * The mapping between OGC filter units and Oracle Units. + * The full list of Oracle Units can be obtained by issuing + * "select * from MDSYS.SDO_DIST_UNITS WHERE SDO_UNIT IS NOT NULL order by SDO_UNIT;" + */ + private static final Map<String, String> UNITS_MAP = new HashMap<String, String>() { + { + put("metre", "m"); + put("meters", "m"); + put("kilometers", "km"); + put("mi", "Mile"); + put("miles", "Mile"); + put("NM", "naut_mile"); + put("feet", "foot"); + put("ft", "foot"); + put("in", "inch"); + } + }; + + private static String getSDOUnitFromOGCUnit(String ogcUnit) { + Object sdoUnit = UNITS_MAP.get(ogcUnit); + return sdoUnit != null ? sdoUnit.toString() : ogcUnit; + } } Modified: branches/2.7.x/modules/plugin/jdbc/jdbc-oracle/src/test/java/org/geotools/data/oracle/OracleSpatialFiltersTest.java =================================================================== --- branches/2.7.x/modules/plugin/jdbc/jdbc-oracle/src/test/java/org/geotools/data/oracle/OracleSpatialFiltersTest.java 2012-04-30 14:19:05 UTC (rev 38695) +++ branches/2.7.x/modules/plugin/jdbc/jdbc-oracle/src/test/java/org/geotools/data/oracle/OracleSpatialFiltersTest.java 2012-04-30 14:22:21 UTC (rev 38696) @@ -16,13 +16,25 @@ */ package org.geotools.data.oracle; +import org.geotools.data.Query; +import org.geotools.data.simple.SimpleFeatureCollection; import org.geotools.factory.CommonFactoryFinder; import org.geotools.feature.FeatureCollection; import org.geotools.jdbc.JDBCDataStoreAPITestSetup; import org.geotools.jdbc.JDBCSpatialFiltersTest; import org.opengis.filter.FilterFactory; +import org.opengis.filter.FilterFactory2; +import org.opengis.filter.expression.Literal; +import org.opengis.filter.expression.PropertyName; import org.opengis.filter.spatial.BBOX; +import org.opengis.filter.spatial.DWithin; +import com.vividsolutions.jts.geom.Coordinate; +import com.vividsolutions.jts.geom.Geometry; +import com.vividsolutions.jts.geom.GeometryCollection; +import com.vividsolutions.jts.geom.GeometryFactory; +import com.vividsolutions.jts.geom.Point; + public class OracleSpatialFiltersTest extends JDBCSpatialFiltersTest { @Override @@ -39,4 +51,45 @@ FeatureCollection features = dataStore.getFeatureSource(tname("road")).getFeatures(bbox); checkSingleResult(features, "r2"); } + + // As reported in GEOS-4384 (http://jira.codehaus.org/browse/GEOS-4384) + public void testSDODWithinOGCUnits() throws Exception { + // express the same distance in different ways and check results + validateOGCUnitUsage(10, "kilometers"); + validateOGCUnitUsage(10, "km"); + validateOGCUnitUsage(10, "kilometer"); + // this one does not work... not sure why + // validateOGCUnitUsage(10000 * 1000, "mm"); + validateOGCUnitUsage(10000, "m"); + validateOGCUnitUsage(10000, "metre"); + validateOGCUnitUsage(10000, "meters"); + validateOGCUnitUsage(10000 / 0.0254, "in"); + validateOGCUnitUsage(10000 / 0.3048, "feet"); + validateOGCUnitUsage(10000 / 0.3048, "foot"); + validateOGCUnitUsage(10000 / 0.3048, "ft"); + validateOGCUnitUsage(10000 / 1609.344, "mi"); + validateOGCUnitUsage(10000 / 1609.344, "mile"); + validateOGCUnitUsage(10000 / 1609.344, "miles"); + validateOGCUnitUsage(10000 / 1852, "NM"); + } + + private void validateOGCUnitUsage(double distance, String unit) throws Exception { + Coordinate coordinate = new Coordinate(3.031, 2.754); + GeometryFactory factory = new GeometryFactory(); + Point point = factory.createPoint(coordinate); + Geometry[] geometries = {point}; + GeometryCollection geometry = new GeometryCollection(geometries, factory ); + + FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2(null); + + PropertyName geomName = ff.property(aname("geom")); + Literal lit = ff.literal(geometry); + + DWithin dwithinGeomFilter = ((FilterFactory2) ff).dwithin(geomName, lit, distance, unit); + Query query = new Query(tname("road"), dwithinGeomFilter); + SimpleFeatureCollection features = dataStore.getFeatureSource(tname("road")).getFeatures(query); + assertEquals(1, features.size()); + checkSingleResult(features, "r2"); + } + } Modified: branches/2.7.x/modules/plugin/jdbc/jdbc-postgis/src/main/java/org/geotools/data/postgis/FilterToSqlHelper.java =================================================================== --- branches/2.7.x/modules/plugin/jdbc/jdbc-postgis/src/main/java/org/geotools/data/postgis/FilterToSqlHelper.java 2012-04-30 14:19:05 UTC (rev 38695) +++ branches/2.7.x/modules/plugin/jdbc/jdbc-postgis/src/main/java/org/geotools/data/postgis/FilterToSqlHelper.java 2012-04-30 14:22:21 UTC (rev 38696) @@ -19,7 +19,9 @@ import java.io.IOException; import java.io.Writer; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import org.geotools.data.jdbc.FilterToSQL; import org.geotools.factory.CommonFactoryFinder; @@ -55,6 +57,24 @@ protected static final String IO_ERROR = "io problem writing filter"; + /** + * Conversion factor from common units to meter + */ + private static final Map<String, Double> UNITS_MAP = new HashMap<String, Double>() { + { + put("kilometers", 1000.0); + put("kilometer", 1000.0); + put("mm", 0.001); + put("millimeter", 0.001); + put("mi", 1609.344); + put("miles", 1609.344); + put("NM", 1852d); + put("feet", 0.3048); + put("ft", 0.3048); + put("in", 0.0254); + } + }; + private static final Envelope WORLD = new Envelope(-180, 180, -90, 90); FilterToSQL delegate; @@ -112,7 +132,7 @@ out.write(","); geometry.accept(delegate, extraData); out.write(","); - out.write(Double.toString(filter.getDistance())); + out.write(toMeters(filter.getDistance(), filter.getDistanceUnits())); out.write(")"); } if ((filter instanceof DWithin && swapped) @@ -126,6 +146,19 @@ } } + private String toMeters(double distance, String unit) { + // only geography uses metric units + if(isCurrentGeography()) { + Double conversion = UNITS_MAP.get(unit); + if(conversion != null) { + return String.valueOf(distance * conversion); + } + } + + // in case unknown unit or not geography, use as-is + return String.valueOf(distance); + } + void visitComparisonSpatialOperator(BinarySpatialOperator filter, PropertyName property, Literal geometry, boolean swapped, Object extraData) throws IOException { Modified: branches/2.7.x/modules/plugin/jdbc/jdbc-postgis/src/test/java/org/geotools/data/postgis/PostgisGeographyTest.java =================================================================== --- branches/2.7.x/modules/plugin/jdbc/jdbc-postgis/src/test/java/org/geotools/data/postgis/PostgisGeographyTest.java 2012-04-30 14:19:05 UTC (rev 38695) +++ branches/2.7.x/modules/plugin/jdbc/jdbc-postgis/src/test/java/org/geotools/data/postgis/PostgisGeographyTest.java 2012-04-30 14:22:21 UTC (rev 38696) @@ -16,11 +16,27 @@ */ package org.geotools.data.postgis; +import org.geotools.data.Query; +import org.geotools.data.simple.SimpleFeatureCollection; +import org.geotools.factory.CommonFactoryFinder; +import org.geotools.feature.FeatureCollection; +import org.geotools.feature.FeatureIterator; import org.geotools.jdbc.JDBCDataStore; import org.geotools.jdbc.JDBCGeographyTest; import org.geotools.jdbc.JDBCGeographyTestSetup; +import org.opengis.feature.simple.SimpleFeature; import org.opengis.feature.simple.SimpleFeatureType; +import org.opengis.filter.FilterFactory2; +import org.opengis.filter.expression.Literal; +import org.opengis.filter.expression.PropertyName; +import org.opengis.filter.spatial.DWithin; +import com.vividsolutions.jts.geom.Coordinate; +import com.vividsolutions.jts.geom.Geometry; +import com.vividsolutions.jts.geom.GeometryCollection; +import com.vividsolutions.jts.geom.GeometryFactory; +import com.vividsolutions.jts.geom.Point; + public class PostgisGeographyTest extends JDBCGeographyTest { @Override @@ -40,4 +56,53 @@ SimpleFeatureType ft = dataStore.getFeatureSource(tname("geopoint")).getSchema(); assertEquals("geography", ft.getGeometryDescriptor().getUserData().get(JDBCDataStore.JDBC_NATIVE_TYPENAME)); } + + // As reported in GEOS-4384 (http://jira.codehaus.org/browse/GEOS-4384) + public void testDWithinOGCUnits() throws Exception { + validateOGCUnitUsage(10000, "m"); + validateOGCUnitUsage(10000, "metre"); + validateOGCUnitUsage(10000, "meters"); + validateOGCUnitUsage(10000 * 1000, "mm"); + validateOGCUnitUsage(10, "kilometers"); + validateOGCUnitUsage(10, "km"); + validateOGCUnitUsage(10, "kilometer"); + validateOGCUnitUsage(10000 / 0.0254, "in"); + validateOGCUnitUsage(10000 / 0.3048, "feet"); + validateOGCUnitUsage(10000 / 0.3048, "foot"); + validateOGCUnitUsage(10000 / 0.3048, "ft"); + validateOGCUnitUsage(10000 / 1609.344, "mi"); + validateOGCUnitUsage(10000 / 1609.344, "mile"); + validateOGCUnitUsage(10000 / 1609.344, "miles"); + validateOGCUnitUsage(10000 / 1852, "NM"); + } + + private void validateOGCUnitUsage(double distance, String unit) throws Exception { + Coordinate coordinate = new Coordinate(-110, 30); + GeometryFactory factory = new GeometryFactory(); + Point point = factory.createPoint(coordinate); + Geometry[] geometries = {point}; + GeometryCollection geometry = new GeometryCollection(geometries, factory ); + + FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2(null); + + PropertyName geomName = ff.property(aname("geo")); + Literal lit = ff.literal(geometry); + + DWithin dwithinGeomFilter = ((FilterFactory2) ff).dwithin(geomName, lit, distance, unit); + Query query = new Query(tname("geopoint"), dwithinGeomFilter); + SimpleFeatureCollection features = dataStore.getFeatureSource(tname("geopoint")).getFeatures(query); + assertEquals(1, features.size()); + checkSingleResult(features, "Town"); + } + + protected void checkSingleResult(FeatureCollection features, String name) { + assertEquals(1, features.size()); + FeatureIterator fr = features.features(); + assertTrue(fr.hasNext()); + SimpleFeature f = (SimpleFeature) fr.next(); + assertNotNull(f); + assertEquals(name, f.getAttribute(aname("name"))); + assertFalse(fr.hasNext()); + fr.close(); + } } |
From: <svn...@os...> - 2012-04-30 14:19:13
|
Author: aaime Date: 2012-04-30 07:19:05 -0700 (Mon, 30 Apr 2012) New Revision: 38695 Modified: trunk/modules/plugin/jdbc/jdbc-oracle/src/main/java/org/geotools/data/oracle/OracleFilterToSQL.java trunk/modules/plugin/jdbc/jdbc-oracle/src/test/java/org/geotools/data/oracle/OracleSpatialFiltersTest.java trunk/modules/plugin/jdbc/jdbc-postgis/src/main/java/org/geotools/data/postgis/FilterToSqlHelper.java trunk/modules/plugin/jdbc/jdbc-postgis/src/test/java/org/geotools/data/postgis/PostgisGeographyTest.java Log: [GEOT-4121] DWithin filter does not work from GeoServer when passing units parameter Modified: trunk/modules/plugin/jdbc/jdbc-oracle/src/main/java/org/geotools/data/oracle/OracleFilterToSQL.java =================================================================== --- trunk/modules/plugin/jdbc/jdbc-oracle/src/main/java/org/geotools/data/oracle/OracleFilterToSQL.java 2012-04-29 10:15:03 UTC (rev 38694) +++ trunk/modules/plugin/jdbc/jdbc-oracle/src/main/java/org/geotools/data/oracle/OracleFilterToSQL.java 2012-04-30 14:19:05 UTC (rev 38695) @@ -308,7 +308,8 @@ protected void doSDODistance(BinarySpatialOperator filter, Expression e1, Expression e2, Object extraData) throws IOException { double distance = ((DistanceBufferOperator) filter).getDistance(); - String unit = ((DistanceBufferOperator) filter).getDistanceUnits(); + String unit = getSDOUnitFromOGCUnit(((DistanceBufferOperator) filter).getDistanceUnits()); + String within = filter instanceof DWithin ? "TRUE" : "FALSE"; out.write("SDO_WITHIN_DISTANCE("); @@ -322,5 +323,28 @@ else out.write(",'distance=" + distance + "') = '" + within + "' "); } - + + /** + * The mapping between OGC filter units and Oracle Units. + * The full list of Oracle Units can be obtained by issuing + * "select * from MDSYS.SDO_DIST_UNITS WHERE SDO_UNIT IS NOT NULL order by SDO_UNIT;" + */ + private static final Map<String, String> UNITS_MAP = new HashMap<String, String>() { + { + put("metre", "m"); + put("meters", "m"); + put("kilometers", "km"); + put("mi", "Mile"); + put("miles", "Mile"); + put("NM", "naut_mile"); + put("feet", "foot"); + put("ft", "foot"); + put("in", "inch"); + } + }; + + private static String getSDOUnitFromOGCUnit(String ogcUnit) { + Object sdoUnit = UNITS_MAP.get(ogcUnit); + return sdoUnit != null ? sdoUnit.toString() : ogcUnit; + } } Modified: trunk/modules/plugin/jdbc/jdbc-oracle/src/test/java/org/geotools/data/oracle/OracleSpatialFiltersTest.java =================================================================== --- trunk/modules/plugin/jdbc/jdbc-oracle/src/test/java/org/geotools/data/oracle/OracleSpatialFiltersTest.java 2012-04-29 10:15:03 UTC (rev 38694) +++ trunk/modules/plugin/jdbc/jdbc-oracle/src/test/java/org/geotools/data/oracle/OracleSpatialFiltersTest.java 2012-04-30 14:19:05 UTC (rev 38695) @@ -16,13 +16,25 @@ */ package org.geotools.data.oracle; +import org.geotools.data.Query; +import org.geotools.data.simple.SimpleFeatureCollection; import org.geotools.factory.CommonFactoryFinder; import org.geotools.feature.FeatureCollection; import org.geotools.jdbc.JDBCDataStoreAPITestSetup; import org.geotools.jdbc.JDBCSpatialFiltersTest; import org.opengis.filter.FilterFactory; +import org.opengis.filter.FilterFactory2; +import org.opengis.filter.expression.Literal; +import org.opengis.filter.expression.PropertyName; import org.opengis.filter.spatial.BBOX; +import org.opengis.filter.spatial.DWithin; +import com.vividsolutions.jts.geom.Coordinate; +import com.vividsolutions.jts.geom.Geometry; +import com.vividsolutions.jts.geom.GeometryCollection; +import com.vividsolutions.jts.geom.GeometryFactory; +import com.vividsolutions.jts.geom.Point; + /** * * @@ -44,4 +56,45 @@ FeatureCollection features = dataStore.getFeatureSource(tname("road")).getFeatures(bbox); checkSingleResult(features, "r2"); } + + // As reported in GEOS-4384 (http://jira.codehaus.org/browse/GEOS-4384) + public void testSDODWithinOGCUnits() throws Exception { + // express the same distance in different ways and check results + validateOGCUnitUsage(10, "kilometers"); + validateOGCUnitUsage(10, "km"); + validateOGCUnitUsage(10, "kilometer"); + // this one does not work... not sure why + // validateOGCUnitUsage(10000 * 1000, "mm"); + validateOGCUnitUsage(10000, "m"); + validateOGCUnitUsage(10000, "metre"); + validateOGCUnitUsage(10000, "meters"); + validateOGCUnitUsage(10000 / 0.0254, "in"); + validateOGCUnitUsage(10000 / 0.3048, "feet"); + validateOGCUnitUsage(10000 / 0.3048, "foot"); + validateOGCUnitUsage(10000 / 0.3048, "ft"); + validateOGCUnitUsage(10000 / 1609.344, "mi"); + validateOGCUnitUsage(10000 / 1609.344, "mile"); + validateOGCUnitUsage(10000 / 1609.344, "miles"); + validateOGCUnitUsage(10000 / 1852, "NM"); + } + + private void validateOGCUnitUsage(double distance, String unit) throws Exception { + Coordinate coordinate = new Coordinate(3.031, 2.754); + GeometryFactory factory = new GeometryFactory(); + Point point = factory.createPoint(coordinate); + Geometry[] geometries = {point}; + GeometryCollection geometry = new GeometryCollection(geometries, factory ); + + FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2(null); + + PropertyName geomName = ff.property(aname("geom")); + Literal lit = ff.literal(geometry); + + DWithin dwithinGeomFilter = ((FilterFactory2) ff).dwithin(geomName, lit, distance, unit); + Query query = new Query(tname("road"), dwithinGeomFilter); + SimpleFeatureCollection features = dataStore.getFeatureSource(tname("road")).getFeatures(query); + assertEquals(1, features.size()); + checkSingleResult(features, "r2"); + } + } Modified: trunk/modules/plugin/jdbc/jdbc-postgis/src/main/java/org/geotools/data/postgis/FilterToSqlHelper.java =================================================================== --- trunk/modules/plugin/jdbc/jdbc-postgis/src/main/java/org/geotools/data/postgis/FilterToSqlHelper.java 2012-04-29 10:15:03 UTC (rev 38694) +++ trunk/modules/plugin/jdbc/jdbc-postgis/src/main/java/org/geotools/data/postgis/FilterToSqlHelper.java 2012-04-30 14:19:05 UTC (rev 38695) @@ -24,7 +24,9 @@ import java.sql.Time; import java.sql.Timestamp; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import org.geotools.data.jdbc.FilterToSQL; import org.geotools.factory.CommonFactoryFinder; @@ -90,6 +92,24 @@ protected static final String IO_ERROR = "io problem writing filter"; + /** + * Conversion factor from common units to meter + */ + private static final Map<String, Double> UNITS_MAP = new HashMap<String, Double>() { + { + put("kilometers", 1000.0); + put("kilometer", 1000.0); + put("mm", 0.001); + put("millimeter", 0.001); + put("mi", 1609.344); + put("miles", 1609.344); + put("NM", 1852d); + put("feet", 0.3048); + put("ft", 0.3048); + put("in", 0.0254); + } + }; + private static final Envelope WORLD = new Envelope(-180, 180, -90, 90); FilterToSQL delegate; @@ -193,7 +213,7 @@ out.write(","); geometry.accept(delegate, extraData); out.write(","); - out.write(Double.toString(filter.getDistance())); + out.write(toMeters(filter.getDistance(), filter.getDistanceUnits())); out.write(")"); } if ((filter instanceof DWithin && swapped) @@ -207,6 +227,19 @@ } } + private String toMeters(double distance, String unit) { + // only geography uses metric units + if(isCurrentGeography()) { + Double conversion = UNITS_MAP.get(unit); + if(conversion != null) { + return String.valueOf(distance * conversion); + } + } + + // in case unknown unit or not geography, use as-is + return String.valueOf(distance); + } + void visitComparisonSpatialOperator(BinarySpatialOperator filter, PropertyName property, Literal geometry, boolean swapped, Object extraData) throws IOException { Modified: trunk/modules/plugin/jdbc/jdbc-postgis/src/test/java/org/geotools/data/postgis/PostgisGeographyTest.java =================================================================== --- trunk/modules/plugin/jdbc/jdbc-postgis/src/test/java/org/geotools/data/postgis/PostgisGeographyTest.java 2012-04-29 10:15:03 UTC (rev 38694) +++ trunk/modules/plugin/jdbc/jdbc-postgis/src/test/java/org/geotools/data/postgis/PostgisGeographyTest.java 2012-04-30 14:19:05 UTC (rev 38695) @@ -16,11 +16,27 @@ */ package org.geotools.data.postgis; +import org.geotools.data.Query; +import org.geotools.data.simple.SimpleFeatureCollection; +import org.geotools.factory.CommonFactoryFinder; +import org.geotools.feature.FeatureCollection; +import org.geotools.feature.FeatureIterator; import org.geotools.jdbc.JDBCDataStore; import org.geotools.jdbc.JDBCGeographyTest; import org.geotools.jdbc.JDBCGeographyTestSetup; +import org.opengis.feature.simple.SimpleFeature; import org.opengis.feature.simple.SimpleFeatureType; +import org.opengis.filter.FilterFactory2; +import org.opengis.filter.expression.Literal; +import org.opengis.filter.expression.PropertyName; +import org.opengis.filter.spatial.DWithin; +import com.vividsolutions.jts.geom.Coordinate; +import com.vividsolutions.jts.geom.Geometry; +import com.vividsolutions.jts.geom.GeometryCollection; +import com.vividsolutions.jts.geom.GeometryFactory; +import com.vividsolutions.jts.geom.Point; + /** * * @@ -45,4 +61,53 @@ SimpleFeatureType ft = dataStore.getFeatureSource(tname("geopoint")).getSchema(); assertEquals("geography", ft.getGeometryDescriptor().getUserData().get(JDBCDataStore.JDBC_NATIVE_TYPENAME)); } + + // As reported in GEOS-4384 (http://jira.codehaus.org/browse/GEOS-4384) + public void testDWithinOGCUnits() throws Exception { + validateOGCUnitUsage(10000, "m"); + validateOGCUnitUsage(10000, "metre"); + validateOGCUnitUsage(10000, "meters"); + validateOGCUnitUsage(10000 * 1000, "mm"); + validateOGCUnitUsage(10, "kilometers"); + validateOGCUnitUsage(10, "km"); + validateOGCUnitUsage(10, "kilometer"); + validateOGCUnitUsage(10000 / 0.0254, "in"); + validateOGCUnitUsage(10000 / 0.3048, "feet"); + validateOGCUnitUsage(10000 / 0.3048, "foot"); + validateOGCUnitUsage(10000 / 0.3048, "ft"); + validateOGCUnitUsage(10000 / 1609.344, "mi"); + validateOGCUnitUsage(10000 / 1609.344, "mile"); + validateOGCUnitUsage(10000 / 1609.344, "miles"); + validateOGCUnitUsage(10000 / 1852, "NM"); + } + + private void validateOGCUnitUsage(double distance, String unit) throws Exception { + Coordinate coordinate = new Coordinate(-110, 30); + GeometryFactory factory = new GeometryFactory(); + Point point = factory.createPoint(coordinate); + Geometry[] geometries = {point}; + GeometryCollection geometry = new GeometryCollection(geometries, factory ); + + FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2(null); + + PropertyName geomName = ff.property(aname("geo")); + Literal lit = ff.literal(geometry); + + DWithin dwithinGeomFilter = ((FilterFactory2) ff).dwithin(geomName, lit, distance, unit); + Query query = new Query(tname("geopoint"), dwithinGeomFilter); + SimpleFeatureCollection features = dataStore.getFeatureSource(tname("geopoint")).getFeatures(query); + assertEquals(1, features.size()); + checkSingleResult(features, "Town"); + } + + protected void checkSingleResult(FeatureCollection features, String name) { + assertEquals(1, features.size()); + FeatureIterator fr = features.features(); + assertTrue(fr.hasNext()); + SimpleFeature f = (SimpleFeature) fr.next(); + assertNotNull(f); + assertEquals(name, f.getAttribute(aname("name"))); + assertFalse(fr.hasNext()); + fr.close(); + } } |
From: <svn...@os...> - 2012-04-29 10:15:10
|
Author: aaime Date: 2012-04-29 03:15:03 -0700 (Sun, 29 Apr 2012) New Revision: 38694 Added: trunk/modules/library/render/src/test/java/org/geotools/renderer/lite/BufferTestFunction.java trunk/modules/library/render/src/test/resources/org/geotools/renderer/lite/test-data/line/renderingTransform.png trunk/modules/library/render/src/test/resources/org/geotools/renderer/lite/test-data/line_rendering_transform.sld Modified: trunk/modules/library/render/src/main/java/org/geotools/renderer/lite/StreamingRenderer.java trunk/modules/library/render/src/test/java/org/geotools/renderer/lite/LineTest.java trunk/modules/library/render/src/test/resources/META-INF/services/org.opengis.filter.expression.Function Log: [GEOT-4076] Rendering Transforms are applied to all FeatureTypeStyles, patch by Jared Erickson with some testing extras from yours truly Modified: trunk/modules/library/render/src/main/java/org/geotools/renderer/lite/StreamingRenderer.java =================================================================== --- trunk/modules/library/render/src/main/java/org/geotools/renderer/lite/StreamingRenderer.java 2012-04-29 09:32:47 UTC (rev 38693) +++ trunk/modules/library/render/src/main/java/org/geotools/renderer/lite/StreamingRenderer.java 2012-04-29 10:15:03 UTC (rev 38694) @@ -1932,21 +1932,7 @@ applyUnitRescale(lfts); // classify by transformation - List<List<LiteFeatureTypeStyle>> txClassified = new ArrayList<List<LiteFeatureTypeStyle>>(); - txClassified.add(new ArrayList<LiteFeatureTypeStyle>()); - Expression transformation = null; - for (int i = 0; i < lfts.size(); i++) { - LiteFeatureTypeStyle curr = lfts.get(i); - if(i == 0) { - transformation = curr.transformation; - } else if(!(transformation == curr.transformation) - || (transformation != null && curr.transformation != null && - !curr.transformation.equals(transformation))) { - txClassified.add(new ArrayList<LiteFeatureTypeStyle>()); - - } - txClassified.get(txClassified.size() - 1).add(curr); - } + List<List<LiteFeatureTypeStyle>> txClassified = classifyByTransformation(lfts); // render groups by uniform transformation for (List<LiteFeatureTypeStyle> uniform : txClassified) { @@ -1959,11 +1945,11 @@ uniform, mapArea, destinationCrs, sourceCrs, screenSize, geometryAttribute, at); FeatureCollection rawFeatures; - if(transformation != null) { + if(transform != null) { GridEnvelope2D ge = new GridEnvelope2D(screenSize); ReferencedEnvelope re = new ReferencedEnvelope(mapArea, destinationCrs); GridGeometry2D gridGeometry = new GridGeometry2D(ge, re); - rawFeatures = applyRenderingTransformation(transformation, featureSource, query, + rawFeatures = applyRenderingTransformation(transform, featureSource, query, gridGeometry); if(rawFeatures == null) { return; @@ -2008,6 +1994,30 @@ } /** + * Classify a List of LiteFeatureTypeStyle objects by Transformation. + * @param lfts A List of LiteFeatureTypeStyles + * @return A List of List of LiteFeatureTypeStyles + */ + List<List<LiteFeatureTypeStyle>> classifyByTransformation(List<LiteFeatureTypeStyle> lfts) { + List<List<LiteFeatureTypeStyle>> txClassified = new ArrayList<List<LiteFeatureTypeStyle>>(); + txClassified.add(new ArrayList<LiteFeatureTypeStyle>()); + Expression transformation = null; + for (int i = 0; i < lfts.size(); i++) { + LiteFeatureTypeStyle curr = lfts.get(i); + if(i == 0) { + transformation = curr.transformation; + } else if(!(transformation == curr.transformation) + || (transformation != null && curr.transformation != null && + !curr.transformation.equals(transformation))) { + txClassified.add(new ArrayList<LiteFeatureTypeStyle>()); + + } + txClassified.get(txClassified.size() - 1).add(curr); + } + return txClassified; + } + + /** * Checks the attributes in the query (which we got from the SLD) match the * schema, throws an {@link IllegalFilterException} otherwise * @param schema Added: trunk/modules/library/render/src/test/java/org/geotools/renderer/lite/BufferTestFunction.java =================================================================== --- trunk/modules/library/render/src/test/java/org/geotools/renderer/lite/BufferTestFunction.java (rev 0) +++ trunk/modules/library/render/src/test/java/org/geotools/renderer/lite/BufferTestFunction.java 2012-04-29 10:15:03 UTC (rev 38694) @@ -0,0 +1,65 @@ +package org.geotools.renderer.lite; + +import static org.geotools.filter.capability.FunctionNameImpl.*; + +import org.geotools.data.collection.ListFeatureCollection; +import org.geotools.data.simple.SimpleFeatureCollection; +import org.geotools.data.simple.SimpleFeatureIterator; +import org.geotools.feature.simple.SimpleFeatureBuilder; +import org.geotools.feature.simple.SimpleFeatureTypeBuilder; +import org.geotools.filter.FunctionExpressionImpl; +import org.geotools.filter.capability.FunctionNameImpl; +import org.opengis.feature.simple.SimpleFeature; +import org.opengis.feature.simple.SimpleFeatureType; +import org.opengis.feature.type.GeometryDescriptor; +import org.opengis.filter.capability.FunctionName; + +import com.vividsolutions.jts.geom.Geometry; +import com.vividsolutions.jts.geom.Polygon; + +/** + * A test rendering transformation that buffers a feature collection by a given amount + * + * @author Andrea Aime - GeoSolutions + */ +public class BufferTestFunction extends FunctionExpressionImpl { + + public static FunctionName NAME = new FunctionNameImpl("BufferTest", parameter("distance", Double.class)); + + public BufferTestFunction() { + super(NAME); + } + + public Object evaluate(Object object) { + + SimpleFeatureCollection fc = (SimpleFeatureCollection) object; + Double distance = null; + + try { + distance = getExpression(0).evaluate(null, Double.class); + } catch (Exception e) // probably a type error + { + throw new IllegalArgumentException( + "Filter Function problem for test buffer argument #0 - expected type Double"); + } + + // compute the output schema + SimpleFeatureTypeBuilder tb = new SimpleFeatureTypeBuilder(); + GeometryDescriptor gd = fc.getSchema().getGeometryDescriptor(); + tb.add(gd.getName().getLocalPart(), Polygon.class, gd.getCoordinateReferenceSystem()); + tb.setName("bufferedCollection"); + SimpleFeatureType schema = tb.buildFeatureType(); + + // compute the output features + SimpleFeatureBuilder fb = new SimpleFeatureBuilder(schema); + ListFeatureCollection result = new ListFeatureCollection(schema); + SimpleFeatureIterator fi = fc.features(); + while(fi.hasNext()) { + SimpleFeature f = fi.next(); + fb.add(((Geometry) f.getDefaultGeometry()).buffer(distance)); + result.add(fb.buildFeature(null)); + } + + return result; + } +} Modified: trunk/modules/library/render/src/test/java/org/geotools/renderer/lite/LineTest.java =================================================================== --- trunk/modules/library/render/src/test/java/org/geotools/renderer/lite/LineTest.java 2012-04-29 09:32:47 UTC (rev 38693) +++ trunk/modules/library/render/src/test/java/org/geotools/renderer/lite/LineTest.java 2012-04-29 10:15:03 UTC (rev 38694) @@ -7,6 +7,8 @@ import java.awt.image.BufferedImage; import java.io.File; +import javax.imageio.ImageIO; + import junit.framework.TestCase; import org.geotools.data.property.PropertyDataStore; @@ -87,4 +89,18 @@ ImageAssert.assertEquals(file("dotstar"), image, 10); } + public void testRenderingTransform() throws Exception { + Style style = RendererBaseTest.loadStyle(this, "line_rendering_transform.sld"); + + DefaultMapContext mc = new DefaultMapContext(DefaultGeographicCRS.WGS84); + mc.addLayer(fs, style); + + StreamingRenderer renderer = new StreamingRenderer(); + renderer.setContext(mc); + renderer.setJava2DHints(new RenderingHints(KEY_ANTIALIASING, VALUE_ANTIALIAS_ON)); + + BufferedImage image = RendererBaseTest.showRender("Lines with buffer rendering transform", renderer, TIME, bounds); + ImageAssert.assertEquals(file("renderingTransform"), image, 10); + } + } Modified: trunk/modules/library/render/src/test/resources/META-INF/services/org.opengis.filter.expression.Function =================================================================== --- trunk/modules/library/render/src/test/resources/META-INF/services/org.opengis.filter.expression.Function 2012-04-29 09:32:47 UTC (rev 38693) +++ trunk/modules/library/render/src/test/resources/META-INF/services/org.opengis.filter.expression.Function 2012-04-29 10:15:03 UTC (rev 38694) @@ -1 +1,2 @@ -org.geotools.renderer.lite.CoverageCenterFunction \ No newline at end of file +org.geotools.renderer.lite.CoverageCenterFunction +org.geotools.renderer.lite.BufferTestFunction \ No newline at end of file Added: trunk/modules/library/render/src/test/resources/org/geotools/renderer/lite/test-data/line/renderingTransform.png =================================================================== --- trunk/modules/library/render/src/test/resources/org/geotools/renderer/lite/test-data/line/renderingTransform.png (rev 0) +++ trunk/modules/library/render/src/test/resources/org/geotools/renderer/lite/test-data/line/renderingTransform.png 2012-04-29 10:15:03 UTC (rev 38694) @@ -0,0 +1,17 @@ +PNG + + |
From: <svn...@os...> - 2012-04-29 09:32:54
|
Author: aaime Date: 2012-04-29 02:32:47 -0700 (Sun, 29 Apr 2012) New Revision: 38693 Added: branches/2.7.x/modules/plugin/shapefile/src/test/resources/org/geotools/data/shapefile/test-data/lsOnePoint/ branches/2.7.x/modules/plugin/shapefile/src/test/resources/org/geotools/data/shapefile/test-data/lsOnePoint/lsOnePoint.dbf branches/2.7.x/modules/plugin/shapefile/src/test/resources/org/geotools/data/shapefile/test-data/lsOnePoint/lsOnePoint.prj branches/2.7.x/modules/plugin/shapefile/src/test/resources/org/geotools/data/shapefile/test-data/lsOnePoint/lsOnePoint.shp branches/2.7.x/modules/plugin/shapefile/src/test/resources/org/geotools/data/shapefile/test-data/lsOnePoint/lsOnePoint.shx Modified: branches/2.7.x/modules/plugin/shapefile/src/main/java/org/geotools/data/shapefile/shp/MultiLineHandler.java branches/2.7.x/modules/plugin/shapefile/src/test/java/org/geotools/data/shapefile/ShapefileDataStoreTest.java Log: [GEOT-4090] Features missing when importing shapefile Modified: branches/2.7.x/modules/plugin/shapefile/src/main/java/org/geotools/data/shapefile/shp/MultiLineHandler.java =================================================================== --- branches/2.7.x/modules/plugin/shapefile/src/main/java/org/geotools/data/shapefile/shp/MultiLineHandler.java 2012-04-26 16:21:23 UTC (rev 38692) +++ branches/2.7.x/modules/plugin/shapefile/src/main/java/org/geotools/data/shapefile/shp/MultiLineHandler.java 2012-04-29 09:32:47 UTC (rev 38693) @@ -145,6 +145,7 @@ } length = finish - start; + int xyLength = length; if (length == 1) { length = 2; clonePoint = true; @@ -153,9 +154,9 @@ } CoordinateSequence cs = geometryFactory.getCoordinateSequenceFactory().create(length, dimensions); - double[] xy = new double[length * 2]; + double[] xy = new double[xyLength * 2]; doubleBuffer.get(xy); - for (int i = 0; i < length; i++) { + for (int i = 0; i < xyLength; i++) { cs.setOrdinate(i, 0, xy[i * 2]); cs.setOrdinate(i, 1, xy[i * 2 + 1]); } Modified: branches/2.7.x/modules/plugin/shapefile/src/test/java/org/geotools/data/shapefile/ShapefileDataStoreTest.java =================================================================== --- branches/2.7.x/modules/plugin/shapefile/src/test/java/org/geotools/data/shapefile/ShapefileDataStoreTest.java 2012-04-26 16:21:23 UTC (rev 38692) +++ branches/2.7.x/modules/plugin/shapefile/src/test/java/org/geotools/data/shapefile/ShapefileDataStoreTest.java 2012-04-29 09:32:47 UTC (rev 38693) @@ -67,7 +67,9 @@ import com.vividsolutions.jts.geom.Geometry; import com.vividsolutions.jts.geom.GeometryCollection; import com.vividsolutions.jts.geom.GeometryFactory; +import com.vividsolutions.jts.geom.LineString; import com.vividsolutions.jts.geom.LinearRing; +import com.vividsolutions.jts.geom.MultiLineString; import com.vividsolutions.jts.geom.Point; import com.vividsolutions.jts.geom.Polygon; @@ -85,8 +87,7 @@ final static String DANISH = "shapes/danish_point.shp"; final static String CHINESE = "shapes/chinese_poly.shp"; final static String RUSSIAN = "shapes/rus-windows-1251.shp"; - final static FilterFactory2 ff = CommonFactoryFinder - .getFilterFactory2(null); + final static FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2(null); private ShapefileDataStore store; public ShapefileDataStoreTest(String testName) throws IOException { @@ -936,7 +937,40 @@ doTestReadWriteDate("2000-01-01"); } + public void testLinestringOnePoint() throws Exception { + URL u = TestData.url(TestCaseSupport.class, "lsOnePoint/lsOnePoint.shp"); + File f = DataUtilities.urlToFile(u); + assertTrue(f.exists()); + + store = new ShapefileDataStore(u); + SimpleFeatureSource fs = store.getFeatureSource(store.getTypeNames()[0]); + SimpleFeatureCollection fc = fs.getFeatures(); + assertEquals(3, fc.size()); + + int i = 418; + SimpleFeatureIterator it = fc.features(); + while(it.hasNext()) { + SimpleFeature sf = it.next(); + assertEquals("Activity" + i, sf.getAttribute("Name")); + + if(i == 419) { + assertNotNull(sf.getDefaultGeometry()); + assertTrue(sf.getDefaultGeometry() instanceof MultiLineString); + MultiLineString mls = (MultiLineString) sf.getDefaultGeometry(); + assertEquals(1, mls.getNumGeometries()); + LineString ls = (LineString) mls.getGeometryN(0); + assertEquals(2, ls.getNumPoints()); + assertTrue(ls.getStartPoint().equals(ls.getEndPoint())); + } + i++; + } + + assertEquals(421, i); + + assertEquals(3, fc.toArray().length); + } + /** * This is useful to dump a UTF16 character to an UT16 escape sequence, * basically the only way to represent the chars we don't have on the Added: branches/2.7.x/modules/plugin/shapefile/src/test/resources/org/geotools/data/shapefile/test-data/lsOnePoint/lsOnePoint.dbf =================================================================== --- branches/2.7.x/modules/plugin/shapefile/src/test/resources/org/geotools/data/shapefile/test-data/lsOnePoint/lsOnePoint.dbf (rev 0) +++ branches/2.7.x/modules/plugin/shapefile/src/test/resources/org/geotools/data/shapefile/test-data/lsOnePoint/lsOnePoint.dbf 2012-04-29 09:32:47 UTC (rev 38693) @@ -0,0 +1,2 @@ +_ |
Author: aaime Date: 2012-04-26 09:21:23 -0700 (Thu, 26 Apr 2012) New Revision: 38692 Modified: trunk/modules/library/jdbc/src/test/java/org/geotools/jdbc/JDBCJNDIDataSourceTest.java trunk/modules/plugin/jdbc/jdbc-db2/src/test/java/org/geotools/data/db2/DB2JNDIDataSourceTest.java trunk/modules/plugin/jdbc/jdbc-h2/src/main/java/org/geotools/data/h2/H2JNDIDataStoreFactory.java trunk/modules/plugin/jdbc/jdbc-h2/src/test/java/org/geotools/data/h2/H2JNDIDataSourceTest.java trunk/modules/plugin/jdbc/jdbc-mysql/src/main/java/org/geotools/data/mysql/MySQLJNDIDataStoreFactory.java trunk/modules/plugin/jdbc/jdbc-mysql/src/test/java/org/geotools/data/mysql/MySQLJNDIDataSourceTest.java trunk/modules/plugin/jdbc/jdbc-oracle/src/main/java/org/geotools/data/oracle/OracleNGJNDIDataStoreFactory.java trunk/modules/plugin/jdbc/jdbc-oracle/src/main/java/org/geotools/data/oracle/OracleNGOCIDataStoreFactory.java trunk/modules/plugin/jdbc/jdbc-oracle/src/test/java/org/geotools/data/oracle/OracleJNDIDataSourceTest.java trunk/modules/plugin/jdbc/jdbc-postgis/src/main/java/org/geotools/data/postgis/PostgisNGJNDIDataStoreFactory.java trunk/modules/plugin/jdbc/jdbc-postgis/src/test/java/org/geotools/data/postgis/PostgisJNDIDataSourceTest.java trunk/modules/plugin/jdbc/jdbc-spatialite/src/test/java/org/geotools/data/spatialite/SpatiaLiteJNDIDataSourceTest.java trunk/modules/plugin/jdbc/jdbc-sqlserver/src/main/java/org/geotools/data/sqlserver/SQLServerDataStoreFactory.java trunk/modules/plugin/jdbc/jdbc-sqlserver/src/main/java/org/geotools/data/sqlserver/SQLServerJNDIDataStoreFactory.java trunk/modules/plugin/jdbc/jdbc-sqlserver/src/test/java/org/geotools/data/sqlserver/SQLServerJNDIDataSourceTest.java trunk/modules/plugin/jdbc/jdbc-teradata/src/test/java/org/geotools/data/teradata/TeradataJNDIDataSourceTest.java Log: [GEOT-4119] Not all extra params exposed by plain JDBC factories are also exposed by JDNI ones Modified: trunk/modules/library/jdbc/src/test/java/org/geotools/jdbc/JDBCJNDIDataSourceTest.java =================================================================== --- trunk/modules/library/jdbc/src/test/java/org/geotools/jdbc/JDBCJNDIDataSourceTest.java 2012-04-26 16:19:13 UTC (rev 38691) +++ trunk/modules/library/jdbc/src/test/java/org/geotools/jdbc/JDBCJNDIDataSourceTest.java 2012-04-26 16:21:23 UTC (rev 38692) @@ -18,8 +18,11 @@ package org.geotools.jdbc; import java.sql.Connection; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; +import org.geotools.data.DataAccessFactory.Param; import org.geotools.data.DataStoreFinder; /** @@ -56,5 +59,96 @@ dataStore.closeSafe(con); } + + /** + * Make sure the JNDI factory exposes all the extra params that the non JNDI one exposes + */ + public void testExtraParams() { + List<String> baseParams = getBaseParams(); + List<String> standardParams = getParamKeys(getDataStoreFactory()); + standardParams.remove(JDBCDataStoreFactory.VALIDATECONN.key); + standardParams.remove(JDBCDataStoreFactory.MAX_OPEN_PREPARED_STATEMENTS.key); + standardParams.removeAll(baseParams); + List<String> baseJndiParams = getBaseJNDIParams(); + List<String> jndiParams = getParamKeys(getJNDIStoreFactory()); + jndiParams.removeAll(baseJndiParams); + assertEquals(standardParams, jndiParams); + } + protected abstract JDBCJNDIDataStoreFactory getJNDIStoreFactory(); + + protected abstract JDBCDataStoreFactory getDataStoreFactory(); + + /** + * Extracts the base params all non JNDI JDBC factories have + * @return + */ + protected List<String> getBaseParams() { + JDBCDataStoreFactory factory = getBaseFactory(); + + return getParamKeys(factory); + } + + protected JDBCDataStoreFactory getBaseFactory() { + JDBCDataStoreFactory factory = new JDBCDataStoreFactory() { + + @Override + public String getDescription() { + // nothing to do here + return null; + } + + @Override + protected String getValidationQuery() { + // nothing to do here + return null; + } + + @Override + protected String getDriverClassName() { + // nothing to do here + return null; + } + + @Override + protected String getDatabaseID() { + // nothing to do here + return null; + } + + @Override + protected SQLDialect createSQLDialect(JDBCDataStore dataStore) { + // nothing to do here + return null; + } + }; + return factory; + } + + /** + * Extracts the common params all JNDI factories have + * @return + */ + protected List<String> getBaseJNDIParams() { + JDBCJNDIDataStoreFactory factory = new JDBCJNDIDataStoreFactory(getBaseFactory()) { + + }; + return getParamKeys(factory); + } + + /** + * Extracts the set of params available for a given factory + * @param factory + * @return + */ + protected List<String> getParamKeys(JDBCDataStoreFactory factory) { + Param[] params = factory.getParametersInfo(); + List<String> results = new ArrayList<String>(); + for (Param p : params) { + results.add(p.key); + } + + return results; + } + } Modified: trunk/modules/plugin/jdbc/jdbc-db2/src/test/java/org/geotools/data/db2/DB2JNDIDataSourceTest.java =================================================================== --- trunk/modules/plugin/jdbc/jdbc-db2/src/test/java/org/geotools/data/db2/DB2JNDIDataSourceTest.java 2012-04-26 16:19:13 UTC (rev 38691) +++ trunk/modules/plugin/jdbc/jdbc-db2/src/test/java/org/geotools/data/db2/DB2JNDIDataSourceTest.java 2012-04-26 16:21:23 UTC (rev 38692) @@ -17,7 +17,9 @@ package org.geotools.data.db2; +import org.geotools.jdbc.JDBCDataStoreFactory; import org.geotools.jdbc.JDBCJNDIDataSourceTest; +import org.geotools.jdbc.JDBCJNDIDataStoreFactory; import org.geotools.jdbc.JDBCJNDITestSetup; /** @@ -31,4 +33,14 @@ return new JDBCJNDITestSetup(new DB2TestSetup()); } + @Override + protected JDBCJNDIDataStoreFactory getJNDIStoreFactory() { + return new DB2NGJNDIDataStoreFactory(); + } + + @Override + protected JDBCDataStoreFactory getDataStoreFactory() { + return new DB2NGDataStoreFactory(); + } + } Modified: trunk/modules/plugin/jdbc/jdbc-h2/src/main/java/org/geotools/data/h2/H2JNDIDataStoreFactory.java =================================================================== --- trunk/modules/plugin/jdbc/jdbc-h2/src/main/java/org/geotools/data/h2/H2JNDIDataStoreFactory.java 2012-04-26 16:19:13 UTC (rev 38691) +++ trunk/modules/plugin/jdbc/jdbc-h2/src/main/java/org/geotools/data/h2/H2JNDIDataStoreFactory.java 2012-04-26 16:21:23 UTC (rev 38692) @@ -16,7 +16,10 @@ */ package org.geotools.data.h2; +import static org.geotools.data.h2.H2DataStoreFactory.*; + import java.io.File; +import java.util.Map; import org.geotools.jdbc.JDBCJNDIDataStoreFactory; @@ -48,4 +51,10 @@ public File getBaseDirectory() { return ((H2DataStoreFactory)delegate).getBaseDirectory(); } + + @Override + protected void setupParameters(Map parameters) { + super.setupParameters(parameters); + parameters.put(ASSOCIATIONS.key, ASSOCIATIONS); + } } Modified: trunk/modules/plugin/jdbc/jdbc-h2/src/test/java/org/geotools/data/h2/H2JNDIDataSourceTest.java =================================================================== --- trunk/modules/plugin/jdbc/jdbc-h2/src/test/java/org/geotools/data/h2/H2JNDIDataSourceTest.java 2012-04-26 16:19:13 UTC (rev 38691) +++ trunk/modules/plugin/jdbc/jdbc-h2/src/test/java/org/geotools/data/h2/H2JNDIDataSourceTest.java 2012-04-26 16:21:23 UTC (rev 38692) @@ -17,7 +17,9 @@ package org.geotools.data.h2; +import org.geotools.jdbc.JDBCDataStoreFactory; import org.geotools.jdbc.JDBCJNDIDataSourceTest; +import org.geotools.jdbc.JDBCJNDIDataStoreFactory; import org.geotools.jdbc.JDBCJNDITestSetup; /** @@ -31,4 +33,14 @@ return new JDBCJNDITestSetup(new H2TestSetup()); } + @Override + protected JDBCJNDIDataStoreFactory getJNDIStoreFactory() { + return new H2JNDIDataStoreFactory(); + } + + @Override + protected JDBCDataStoreFactory getDataStoreFactory() { + return new H2DataStoreFactory(); + } + } Modified: trunk/modules/plugin/jdbc/jdbc-mysql/src/main/java/org/geotools/data/mysql/MySQLJNDIDataStoreFactory.java =================================================================== --- trunk/modules/plugin/jdbc/jdbc-mysql/src/main/java/org/geotools/data/mysql/MySQLJNDIDataStoreFactory.java 2012-04-26 16:19:13 UTC (rev 38691) +++ trunk/modules/plugin/jdbc/jdbc-mysql/src/main/java/org/geotools/data/mysql/MySQLJNDIDataStoreFactory.java 2012-04-26 16:21:23 UTC (rev 38692) @@ -16,6 +16,10 @@ */ package org.geotools.data.mysql; +import static org.geotools.data.mysql.MySQLDataStoreFactory.*; + +import java.util.Map; + import org.geotools.jdbc.JDBCJNDIDataStoreFactory; /** @@ -33,4 +37,10 @@ public MySQLJNDIDataStoreFactory() { super(new MySQLDataStoreFactory()); } + + @Override + protected void setupParameters(Map parameters) { + super.setupParameters(parameters); + parameters.put(STORAGE_ENGINE.key, STORAGE_ENGINE); + } } Modified: trunk/modules/plugin/jdbc/jdbc-mysql/src/test/java/org/geotools/data/mysql/MySQLJNDIDataSourceTest.java =================================================================== --- trunk/modules/plugin/jdbc/jdbc-mysql/src/test/java/org/geotools/data/mysql/MySQLJNDIDataSourceTest.java 2012-04-26 16:19:13 UTC (rev 38691) +++ trunk/modules/plugin/jdbc/jdbc-mysql/src/test/java/org/geotools/data/mysql/MySQLJNDIDataSourceTest.java 2012-04-26 16:21:23 UTC (rev 38692) @@ -17,7 +17,9 @@ package org.geotools.data.mysql; +import org.geotools.jdbc.JDBCDataStoreFactory; import org.geotools.jdbc.JDBCJNDIDataSourceTest; +import org.geotools.jdbc.JDBCJNDIDataStoreFactory; import org.geotools.jdbc.JDBCJNDITestSetup; /** @@ -31,4 +33,14 @@ return new JDBCJNDITestSetup(new MySQLTestSetup()); } + @Override + protected JDBCJNDIDataStoreFactory getJNDIStoreFactory() { + return new MySQLJNDIDataStoreFactory(); + } + + @Override + protected JDBCDataStoreFactory getDataStoreFactory() { + return new MySQLDataStoreFactory(); + } + } Modified: trunk/modules/plugin/jdbc/jdbc-oracle/src/main/java/org/geotools/data/oracle/OracleNGJNDIDataStoreFactory.java =================================================================== --- trunk/modules/plugin/jdbc/jdbc-oracle/src/main/java/org/geotools/data/oracle/OracleNGJNDIDataStoreFactory.java 2012-04-26 16:19:13 UTC (rev 38691) +++ trunk/modules/plugin/jdbc/jdbc-oracle/src/main/java/org/geotools/data/oracle/OracleNGJNDIDataStoreFactory.java 2012-04-26 16:21:23 UTC (rev 38692) @@ -41,6 +41,7 @@ super.setupParameters(parameters); parameters.put(OracleNGDataStoreFactory.LOOSEBBOX.key, OracleNGDataStoreFactory.LOOSEBBOX); - parameters.put(MAX_OPEN_PREPARED_STATEMENTS.key, MAX_OPEN_PREPARED_STATEMENTS); + parameters.put(OracleNGDataStoreFactory.ESTIMATED_EXTENTS.key, OracleNGDataStoreFactory.ESTIMATED_EXTENTS); + parameters.put(OracleNGDataStoreFactory.GEOMETRY_METADATA_TABLE.key, OracleNGDataStoreFactory.GEOMETRY_METADATA_TABLE); } } Modified: trunk/modules/plugin/jdbc/jdbc-oracle/src/main/java/org/geotools/data/oracle/OracleNGOCIDataStoreFactory.java =================================================================== --- trunk/modules/plugin/jdbc/jdbc-oracle/src/main/java/org/geotools/data/oracle/OracleNGOCIDataStoreFactory.java 2012-04-26 16:19:13 UTC (rev 38691) +++ trunk/modules/plugin/jdbc/jdbc-oracle/src/main/java/org/geotools/data/oracle/OracleNGOCIDataStoreFactory.java 2012-04-26 16:21:23 UTC (rev 38692) @@ -83,8 +83,12 @@ if (getValidationQuery() != null) parameters.put(VALIDATECONN.key, VALIDATECONN); parameters.put(PK_METADATA_TABLE.key, PK_METADATA_TABLE); + + parameters.put(OracleNGDataStoreFactory.LOOSEBBOX.key, OracleNGDataStoreFactory.LOOSEBBOX); + parameters.put(MAX_OPEN_PREPARED_STATEMENTS.key, MAX_OPEN_PREPARED_STATEMENTS); - parameters.put(LOOSEBBOX.key, LOOSEBBOX); - parameters.put(MAX_OPEN_PREPARED_STATEMENTS.key, MAX_OPEN_PREPARED_STATEMENTS); + parameters.put(OracleNGDataStoreFactory.ESTIMATED_EXTENTS.key, OracleNGDataStoreFactory.ESTIMATED_EXTENTS); + parameters.put(OracleNGDataStoreFactory.GEOMETRY_METADATA_TABLE.key, OracleNGDataStoreFactory.GEOMETRY_METADATA_TABLE); + } } Modified: trunk/modules/plugin/jdbc/jdbc-oracle/src/test/java/org/geotools/data/oracle/OracleJNDIDataSourceTest.java =================================================================== --- trunk/modules/plugin/jdbc/jdbc-oracle/src/test/java/org/geotools/data/oracle/OracleJNDIDataSourceTest.java 2012-04-26 16:19:13 UTC (rev 38691) +++ trunk/modules/plugin/jdbc/jdbc-oracle/src/test/java/org/geotools/data/oracle/OracleJNDIDataSourceTest.java 2012-04-26 16:21:23 UTC (rev 38692) @@ -22,13 +22,21 @@ /** * - * + * * @source $URL$ */ -public class OracleJNDIDataSourceTest extends JDBCJNDIDataSourceTest { +public class OracleJNDIDataSourceTest extends JDBCJNDIDataSourceTest { protected JDBCJNDITestSetup createTestSetup() { return new JDBCJNDITestSetup(new OracleTestSetup()); } + protected OracleNGJNDIDataStoreFactory getJNDIStoreFactory() { + return new OracleNGJNDIDataStoreFactory(); + } + + protected OracleNGDataStoreFactory getDataStoreFactory() { + return new OracleNGDataStoreFactory(); + } + } Modified: trunk/modules/plugin/jdbc/jdbc-postgis/src/main/java/org/geotools/data/postgis/PostgisNGJNDIDataStoreFactory.java =================================================================== --- trunk/modules/plugin/jdbc/jdbc-postgis/src/main/java/org/geotools/data/postgis/PostgisNGJNDIDataStoreFactory.java 2012-04-26 16:19:13 UTC (rev 38691) +++ trunk/modules/plugin/jdbc/jdbc-postgis/src/main/java/org/geotools/data/postgis/PostgisNGJNDIDataStoreFactory.java 2012-04-26 16:21:23 UTC (rev 38692) @@ -42,6 +42,7 @@ super.setupParameters(parameters); parameters.put(LOOSEBBOX.key, LOOSEBBOX); + parameters.put(ESTIMATED_EXTENTS.key, ESTIMATED_EXTENTS); parameters.put(PREPARED_STATEMENTS.key, PREPARED_STATEMENTS); parameters.put(MAX_OPEN_PREPARED_STATEMENTS.key, MAX_OPEN_PREPARED_STATEMENTS); parameters.put(ENCODE_FUNCTIONS.key, ENCODE_FUNCTIONS); Modified: trunk/modules/plugin/jdbc/jdbc-postgis/src/test/java/org/geotools/data/postgis/PostgisJNDIDataSourceTest.java =================================================================== --- trunk/modules/plugin/jdbc/jdbc-postgis/src/test/java/org/geotools/data/postgis/PostgisJNDIDataSourceTest.java 2012-04-26 16:19:13 UTC (rev 38691) +++ trunk/modules/plugin/jdbc/jdbc-postgis/src/test/java/org/geotools/data/postgis/PostgisJNDIDataSourceTest.java 2012-04-26 16:21:23 UTC (rev 38692) @@ -17,7 +17,9 @@ package org.geotools.data.postgis; +import org.geotools.jdbc.JDBCDataStoreFactory; import org.geotools.jdbc.JDBCJNDIDataSourceTest; +import org.geotools.jdbc.JDBCJNDIDataStoreFactory; import org.geotools.jdbc.JDBCJNDITestSetup; /** @@ -31,4 +33,14 @@ return new JDBCJNDITestSetup(new PostGISTestSetup()); } + @Override + protected JDBCJNDIDataStoreFactory getJNDIStoreFactory() { + return new PostgisNGJNDIDataStoreFactory(); + } + + @Override + protected JDBCDataStoreFactory getDataStoreFactory() { + return new PostgisNGDataStoreFactory(); + } + } Modified: trunk/modules/plugin/jdbc/jdbc-spatialite/src/test/java/org/geotools/data/spatialite/SpatiaLiteJNDIDataSourceTest.java =================================================================== --- trunk/modules/plugin/jdbc/jdbc-spatialite/src/test/java/org/geotools/data/spatialite/SpatiaLiteJNDIDataSourceTest.java 2012-04-26 16:19:13 UTC (rev 38691) +++ trunk/modules/plugin/jdbc/jdbc-spatialite/src/test/java/org/geotools/data/spatialite/SpatiaLiteJNDIDataSourceTest.java 2012-04-26 16:21:23 UTC (rev 38692) @@ -17,7 +17,9 @@ package org.geotools.data.spatialite; +import org.geotools.jdbc.JDBCDataStoreFactory; import org.geotools.jdbc.JDBCJNDIDataSourceTest; +import org.geotools.jdbc.JDBCJNDIDataStoreFactory; import org.geotools.jdbc.JDBCJNDITestSetup; /** @@ -31,4 +33,16 @@ return new JDBCJNDITestSetup(new SpatiaLiteTestSetup()); } + @Override + protected JDBCJNDIDataStoreFactory getJNDIStoreFactory() { + return new SpatiaLiteJNDIDataStoreFactory(); + } + + @Override + protected JDBCDataStoreFactory getDataStoreFactory() { + return new SpatiaLiteDataStoreFactory(); + } + + + } Modified: trunk/modules/plugin/jdbc/jdbc-sqlserver/src/main/java/org/geotools/data/sqlserver/SQLServerDataStoreFactory.java =================================================================== --- trunk/modules/plugin/jdbc/jdbc-sqlserver/src/main/java/org/geotools/data/sqlserver/SQLServerDataStoreFactory.java 2012-04-26 16:19:13 UTC (rev 38691) +++ trunk/modules/plugin/jdbc/jdbc-sqlserver/src/main/java/org/geotools/data/sqlserver/SQLServerDataStoreFactory.java 2012-04-26 16:21:23 UTC (rev 38692) @@ -37,7 +37,7 @@ /** parameter for database type */ public static final Param DBTYPE = new Param("dbtype", String.class, "Type", true, "sqlserver"); /** parameter for using integrated security, only works on windows, ignores the user and password parameters, the current windows user account is used for login*/ - public static final Param INTSEC = new Param("Integrated Security", Boolean.class, "Login as current windows user account. Works only in windows. Ignores user and password settings.", true, new Boolean(false)); + public static final Param INTSEC = new Param("Integrated Security", Boolean.class, "Login as current windows user account. Works only in windows. Ignores user and password settings.", false, new Boolean(false)); @Override protected SQLDialect createSQLDialect(JDBCDataStore dataStore) { @@ -84,7 +84,7 @@ url = url.substring(0, url.lastIndexOf("/")) + (db != null ? ";DatabaseName="+db : ""); } - if (intsec.booleanValue()) { + if (intsec != null && intsec.booleanValue()) { url = url + ";integratedSecurity=true"; } Modified: trunk/modules/plugin/jdbc/jdbc-sqlserver/src/main/java/org/geotools/data/sqlserver/SQLServerJNDIDataStoreFactory.java =================================================================== --- trunk/modules/plugin/jdbc/jdbc-sqlserver/src/main/java/org/geotools/data/sqlserver/SQLServerJNDIDataStoreFactory.java 2012-04-26 16:19:13 UTC (rev 38691) +++ trunk/modules/plugin/jdbc/jdbc-sqlserver/src/main/java/org/geotools/data/sqlserver/SQLServerJNDIDataStoreFactory.java 2012-04-26 16:21:23 UTC (rev 38692) @@ -16,6 +16,10 @@ */ package org.geotools.data.sqlserver; +import static org.geotools.data.sqlserver.SQLServerDataStoreFactory.*; + +import java.util.Map; + import org.geotools.jdbc.JDBCJNDIDataStoreFactory; /** @@ -33,4 +37,11 @@ public SQLServerJNDIDataStoreFactory() { super(new SQLServerDataStoreFactory()); } + + @SuppressWarnings("unchecked") + @Override + protected void setupParameters(Map parameters) { + super.setupParameters(parameters); + parameters.put(INTSEC.key, INTSEC); + } } Modified: trunk/modules/plugin/jdbc/jdbc-sqlserver/src/test/java/org/geotools/data/sqlserver/SQLServerJNDIDataSourceTest.java =================================================================== --- trunk/modules/plugin/jdbc/jdbc-sqlserver/src/test/java/org/geotools/data/sqlserver/SQLServerJNDIDataSourceTest.java 2012-04-26 16:19:13 UTC (rev 38691) +++ trunk/modules/plugin/jdbc/jdbc-sqlserver/src/test/java/org/geotools/data/sqlserver/SQLServerJNDIDataSourceTest.java 2012-04-26 16:21:23 UTC (rev 38692) @@ -17,7 +17,9 @@ package org.geotools.data.sqlserver; +import org.geotools.jdbc.JDBCDataStoreFactory; import org.geotools.jdbc.JDBCJNDIDataSourceTest; +import org.geotools.jdbc.JDBCJNDIDataStoreFactory; import org.geotools.jdbc.JDBCJNDITestSetup; /** @@ -31,4 +33,14 @@ return new JDBCJNDITestSetup(new SQLServerTestSetup()); } + @Override + protected JDBCJNDIDataStoreFactory getJNDIStoreFactory() { + return new SQLServerJNDIDataStoreFactory(); + } + + @Override + protected JDBCDataStoreFactory getDataStoreFactory() { + return new SQLServerDataStoreFactory(); + } + } Modified: trunk/modules/plugin/jdbc/jdbc-teradata/src/test/java/org/geotools/data/teradata/TeradataJNDIDataSourceTest.java =================================================================== --- trunk/modules/plugin/jdbc/jdbc-teradata/src/test/java/org/geotools/data/teradata/TeradataJNDIDataSourceTest.java 2012-04-26 16:19:13 UTC (rev 38691) +++ trunk/modules/plugin/jdbc/jdbc-teradata/src/test/java/org/geotools/data/teradata/TeradataJNDIDataSourceTest.java 2012-04-26 16:21:23 UTC (rev 38692) @@ -17,7 +17,9 @@ package org.geotools.data.teradata; +import org.geotools.jdbc.JDBCDataStoreFactory; import org.geotools.jdbc.JDBCJNDIDataSourceTest; +import org.geotools.jdbc.JDBCJNDIDataStoreFactory; import org.geotools.jdbc.JDBCJNDITestSetup; /** @@ -31,4 +33,14 @@ return new JDBCJNDITestSetup(new TeradataTestSetup()); } + @Override + protected JDBCJNDIDataStoreFactory getJNDIStoreFactory() { + return new TeradataJNDIDataStoreFactory(); + } + + @Override + protected JDBCDataStoreFactory getDataStoreFactory() { + return new TeradataDataStoreFactory(); + } + } |
Author: aaime Date: 2012-04-26 09:19:13 -0700 (Thu, 26 Apr 2012) New Revision: 38691 Modified: branches/2.7.x/modules/library/jdbc/src/test/java/org/geotools/jdbc/JDBCJNDIDataSourceTest.java branches/2.7.x/modules/plugin/jdbc/jdbc-db2/src/test/java/org/geotools/data/db2/DB2JNDIDataSourceTest.java branches/2.7.x/modules/plugin/jdbc/jdbc-h2/src/main/java/org/geotools/data/h2/H2JNDIDataStoreFactory.java branches/2.7.x/modules/plugin/jdbc/jdbc-h2/src/test/java/org/geotools/data/h2/H2JNDIDataSourceTest.java branches/2.7.x/modules/plugin/jdbc/jdbc-mysql/src/main/java/org/geotools/data/mysql/MySQLJNDIDataStoreFactory.java branches/2.7.x/modules/plugin/jdbc/jdbc-mysql/src/test/java/org/geotools/data/mysql/MySQLJNDIDataSourceTest.java branches/2.7.x/modules/plugin/jdbc/jdbc-oracle/src/main/java/org/geotools/data/oracle/OracleNGJNDIDataStoreFactory.java branches/2.7.x/modules/plugin/jdbc/jdbc-oracle/src/main/java/org/geotools/data/oracle/OracleNGOCIDataStoreFactory.java branches/2.7.x/modules/plugin/jdbc/jdbc-oracle/src/test/java/org/geotools/data/oracle/OracleJNDIDataSourceTest.java branches/2.7.x/modules/plugin/jdbc/jdbc-postgis/src/main/java/org/geotools/data/postgis/PostgisNGJNDIDataStoreFactory.java branches/2.7.x/modules/plugin/jdbc/jdbc-postgis/src/test/java/org/geotools/data/postgis/PostgisJNDIDataSourceTest.java branches/2.7.x/modules/plugin/jdbc/jdbc-spatialite/src/test/java/org/geotools/data/spatialite/SpatiaLiteJNDIDataSourceTest.java branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/main/java/org/geotools/data/sqlserver/SQLServerDataStoreFactory.java branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/main/java/org/geotools/data/sqlserver/SQLServerJNDIDataStoreFactory.java branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/test/java/org/geotools/data/sqlserver/SQLServerJNDIDataSourceTest.java branches/2.7.x/modules/plugin/jdbc/jdbc-teradata/src/test/java/org/geotools/data/teradata/TeradataJNDIDataSourceTest.java Log: [GEOT-4119] Not all extra params exposed by plain JDBC factories are also exposed by JDNI ones Modified: branches/2.7.x/modules/library/jdbc/src/test/java/org/geotools/jdbc/JDBCJNDIDataSourceTest.java =================================================================== --- branches/2.7.x/modules/library/jdbc/src/test/java/org/geotools/jdbc/JDBCJNDIDataSourceTest.java 2012-04-26 12:25:19 UTC (rev 38690) +++ branches/2.7.x/modules/library/jdbc/src/test/java/org/geotools/jdbc/JDBCJNDIDataSourceTest.java 2012-04-26 16:19:13 UTC (rev 38691) @@ -18,8 +18,11 @@ package org.geotools.jdbc; import java.sql.Connection; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; +import org.geotools.data.DataAccessFactory.Param; import org.geotools.data.DataStoreFinder; /** @@ -55,5 +58,91 @@ dataStore.closeSafe(con); } + + /** + * Make sure the JNDI factory exposes all the extra params that the non JNDI one exposes + */ + public void testExtraParams() { + List<String> baseParams = getBaseParams(); + List<String> standardParams = getParamKeys(getDataStoreFactory()); + standardParams.remove(JDBCDataStoreFactory.VALIDATECONN.key); + standardParams.remove(JDBCDataStoreFactory.MAX_OPEN_PREPARED_STATEMENTS.key); + standardParams.removeAll(baseParams); + List<String> baseJndiParams = getBaseJNDIParams(); + List<String> jndiParams = getParamKeys(getJNDIStoreFactory()); + jndiParams.removeAll(baseJndiParams); + assertEquals(standardParams, jndiParams); + } + protected abstract JDBCJNDIDataStoreFactory getJNDIStoreFactory(); + + protected abstract JDBCDataStoreFactory getDataStoreFactory(); + + /** + * Extracts the base params all non JNDI JDBC factories have + * @return + */ + protected List<String> getBaseParams() { + JDBCDataStoreFactory factory = getBaseFactory(); + + return getParamKeys(factory); + } + + protected JDBCDataStoreFactory getBaseFactory() { + JDBCDataStoreFactory factory = new JDBCDataStoreFactory() { + + public String getDescription() { + // nothing to do here + return null; + } + + protected String getValidationQuery() { + // nothing to do here + return null; + } + + protected String getDriverClassName() { + // nothing to do here + return null; + } + + protected String getDatabaseID() { + // nothing to do here + return null; + } + + protected SQLDialect createSQLDialect(JDBCDataStore dataStore) { + // nothing to do here + return null; + } + }; + return factory; + } + + /** + * Extracts the common params all JNDI factories have + * @return + */ + protected List<String> getBaseJNDIParams() { + JDBCJNDIDataStoreFactory factory = new JDBCJNDIDataStoreFactory(getBaseFactory()) { + + }; + return getParamKeys(factory); + } + + /** + * Extracts the set of params available for a given factory + * @param factory + * @return + */ + protected List<String> getParamKeys(JDBCDataStoreFactory factory) { + Param[] params = factory.getParametersInfo(); + List<String> results = new ArrayList<String>(); + for (Param p : params) { + results.add(p.key); + } + + return results; + } + } Modified: branches/2.7.x/modules/plugin/jdbc/jdbc-db2/src/test/java/org/geotools/data/db2/DB2JNDIDataSourceTest.java =================================================================== --- branches/2.7.x/modules/plugin/jdbc/jdbc-db2/src/test/java/org/geotools/data/db2/DB2JNDIDataSourceTest.java 2012-04-26 12:25:19 UTC (rev 38690) +++ branches/2.7.x/modules/plugin/jdbc/jdbc-db2/src/test/java/org/geotools/data/db2/DB2JNDIDataSourceTest.java 2012-04-26 16:19:13 UTC (rev 38691) @@ -17,7 +17,9 @@ package org.geotools.data.db2; +import org.geotools.jdbc.JDBCDataStoreFactory; import org.geotools.jdbc.JDBCJNDIDataSourceTest; +import org.geotools.jdbc.JDBCJNDIDataStoreFactory; import org.geotools.jdbc.JDBCJNDITestSetup; public class DB2JNDIDataSourceTest extends JDBCJNDIDataSourceTest { @@ -26,4 +28,14 @@ return new JDBCJNDITestSetup(new DB2TestSetup()); } + @Override + protected JDBCJNDIDataStoreFactory getJNDIStoreFactory() { + return new DB2NGJNDIDataStoreFactory(); + } + + @Override + protected JDBCDataStoreFactory getDataStoreFactory() { + return new DB2NGDataStoreFactory(); + } + } Modified: branches/2.7.x/modules/plugin/jdbc/jdbc-h2/src/main/java/org/geotools/data/h2/H2JNDIDataStoreFactory.java =================================================================== --- branches/2.7.x/modules/plugin/jdbc/jdbc-h2/src/main/java/org/geotools/data/h2/H2JNDIDataStoreFactory.java 2012-04-26 12:25:19 UTC (rev 38690) +++ branches/2.7.x/modules/plugin/jdbc/jdbc-h2/src/main/java/org/geotools/data/h2/H2JNDIDataStoreFactory.java 2012-04-26 16:19:13 UTC (rev 38691) @@ -16,7 +16,10 @@ */ package org.geotools.data.h2; +import static org.geotools.data.h2.H2DataStoreFactory.*; + import java.io.File; +import java.util.Map; import org.geotools.jdbc.JDBCJNDIDataStoreFactory; @@ -47,4 +50,10 @@ public File getBaseDirectory() { return ((H2DataStoreFactory)delegate).getBaseDirectory(); } + + @Override + protected void setupParameters(Map parameters) { + super.setupParameters(parameters); + parameters.put(ASSOCIATIONS.key, ASSOCIATIONS); + } } Modified: branches/2.7.x/modules/plugin/jdbc/jdbc-h2/src/test/java/org/geotools/data/h2/H2JNDIDataSourceTest.java =================================================================== --- branches/2.7.x/modules/plugin/jdbc/jdbc-h2/src/test/java/org/geotools/data/h2/H2JNDIDataSourceTest.java 2012-04-26 12:25:19 UTC (rev 38690) +++ branches/2.7.x/modules/plugin/jdbc/jdbc-h2/src/test/java/org/geotools/data/h2/H2JNDIDataSourceTest.java 2012-04-26 16:19:13 UTC (rev 38691) @@ -17,7 +17,9 @@ package org.geotools.data.h2; +import org.geotools.jdbc.JDBCDataStoreFactory; import org.geotools.jdbc.JDBCJNDIDataSourceTest; +import org.geotools.jdbc.JDBCJNDIDataStoreFactory; import org.geotools.jdbc.JDBCJNDITestSetup; public class H2JNDIDataSourceTest extends JDBCJNDIDataSourceTest { @@ -26,4 +28,14 @@ return new JDBCJNDITestSetup(new H2TestSetup()); } + @Override + protected JDBCJNDIDataStoreFactory getJNDIStoreFactory() { + return new H2JNDIDataStoreFactory(); + } + + @Override + protected JDBCDataStoreFactory getDataStoreFactory() { + return new H2DataStoreFactory(); + } + } Modified: branches/2.7.x/modules/plugin/jdbc/jdbc-mysql/src/main/java/org/geotools/data/mysql/MySQLJNDIDataStoreFactory.java =================================================================== --- branches/2.7.x/modules/plugin/jdbc/jdbc-mysql/src/main/java/org/geotools/data/mysql/MySQLJNDIDataStoreFactory.java 2012-04-26 12:25:19 UTC (rev 38690) +++ branches/2.7.x/modules/plugin/jdbc/jdbc-mysql/src/main/java/org/geotools/data/mysql/MySQLJNDIDataStoreFactory.java 2012-04-26 16:19:13 UTC (rev 38691) @@ -16,6 +16,10 @@ */ package org.geotools.data.mysql; +import static org.geotools.data.mysql.MySQLDataStoreFactory.*; + +import java.util.Map; + import org.geotools.jdbc.JDBCJNDIDataStoreFactory; /** @@ -32,4 +36,10 @@ public MySQLJNDIDataStoreFactory() { super(new MySQLDataStoreFactory()); } + + @Override + protected void setupParameters(Map parameters) { + super.setupParameters(parameters); + parameters.put(STORAGE_ENGINE.key, STORAGE_ENGINE); + } } Modified: branches/2.7.x/modules/plugin/jdbc/jdbc-mysql/src/test/java/org/geotools/data/mysql/MySQLJNDIDataSourceTest.java =================================================================== --- branches/2.7.x/modules/plugin/jdbc/jdbc-mysql/src/test/java/org/geotools/data/mysql/MySQLJNDIDataSourceTest.java 2012-04-26 12:25:19 UTC (rev 38690) +++ branches/2.7.x/modules/plugin/jdbc/jdbc-mysql/src/test/java/org/geotools/data/mysql/MySQLJNDIDataSourceTest.java 2012-04-26 16:19:13 UTC (rev 38691) @@ -17,7 +17,9 @@ package org.geotools.data.mysql; +import org.geotools.jdbc.JDBCDataStoreFactory; import org.geotools.jdbc.JDBCJNDIDataSourceTest; +import org.geotools.jdbc.JDBCJNDIDataStoreFactory; import org.geotools.jdbc.JDBCJNDITestSetup; public class MySQLJNDIDataSourceTest extends JDBCJNDIDataSourceTest { @@ -26,4 +28,14 @@ return new JDBCJNDITestSetup(new MySQLTestSetup()); } + @Override + protected JDBCJNDIDataStoreFactory getJNDIStoreFactory() { + return new MySQLJNDIDataStoreFactory(); + } + + @Override + protected JDBCDataStoreFactory getDataStoreFactory() { + return new MySQLDataStoreFactory(); + } + } Modified: branches/2.7.x/modules/plugin/jdbc/jdbc-oracle/src/main/java/org/geotools/data/oracle/OracleNGJNDIDataStoreFactory.java =================================================================== --- branches/2.7.x/modules/plugin/jdbc/jdbc-oracle/src/main/java/org/geotools/data/oracle/OracleNGJNDIDataStoreFactory.java 2012-04-26 12:25:19 UTC (rev 38690) +++ branches/2.7.x/modules/plugin/jdbc/jdbc-oracle/src/main/java/org/geotools/data/oracle/OracleNGJNDIDataStoreFactory.java 2012-04-26 16:19:13 UTC (rev 38691) @@ -40,6 +40,7 @@ super.setupParameters(parameters); parameters.put(OracleNGDataStoreFactory.LOOSEBBOX.key, OracleNGDataStoreFactory.LOOSEBBOX); - parameters.put(MAX_OPEN_PREPARED_STATEMENTS.key, MAX_OPEN_PREPARED_STATEMENTS); + parameters.put(OracleNGDataStoreFactory.ESTIMATED_EXTENTS.key, OracleNGDataStoreFactory.ESTIMATED_EXTENTS); + parameters.put(OracleNGDataStoreFactory.GEOMETRY_METADATA_TABLE.key, OracleNGDataStoreFactory.GEOMETRY_METADATA_TABLE); } } Modified: branches/2.7.x/modules/plugin/jdbc/jdbc-oracle/src/main/java/org/geotools/data/oracle/OracleNGOCIDataStoreFactory.java =================================================================== --- branches/2.7.x/modules/plugin/jdbc/jdbc-oracle/src/main/java/org/geotools/data/oracle/OracleNGOCIDataStoreFactory.java 2012-04-26 12:25:19 UTC (rev 38690) +++ branches/2.7.x/modules/plugin/jdbc/jdbc-oracle/src/main/java/org/geotools/data/oracle/OracleNGOCIDataStoreFactory.java 2012-04-26 16:19:13 UTC (rev 38691) @@ -82,8 +82,12 @@ if (getValidationQuery() != null) parameters.put(VALIDATECONN.key, VALIDATECONN); parameters.put(PK_METADATA_TABLE.key, PK_METADATA_TABLE); + + parameters.put(OracleNGDataStoreFactory.LOOSEBBOX.key, OracleNGDataStoreFactory.LOOSEBBOX); + parameters.put(MAX_OPEN_PREPARED_STATEMENTS.key, MAX_OPEN_PREPARED_STATEMENTS); - parameters.put(LOOSEBBOX.key, LOOSEBBOX); - parameters.put(MAX_OPEN_PREPARED_STATEMENTS.key, MAX_OPEN_PREPARED_STATEMENTS); + parameters.put(OracleNGDataStoreFactory.ESTIMATED_EXTENTS.key, OracleNGDataStoreFactory.ESTIMATED_EXTENTS); + parameters.put(OracleNGDataStoreFactory.GEOMETRY_METADATA_TABLE.key, OracleNGDataStoreFactory.GEOMETRY_METADATA_TABLE); + } } Modified: branches/2.7.x/modules/plugin/jdbc/jdbc-oracle/src/test/java/org/geotools/data/oracle/OracleJNDIDataSourceTest.java =================================================================== --- branches/2.7.x/modules/plugin/jdbc/jdbc-oracle/src/test/java/org/geotools/data/oracle/OracleJNDIDataSourceTest.java 2012-04-26 12:25:19 UTC (rev 38690) +++ branches/2.7.x/modules/plugin/jdbc/jdbc-oracle/src/test/java/org/geotools/data/oracle/OracleJNDIDataSourceTest.java 2012-04-26 16:19:13 UTC (rev 38691) @@ -26,4 +26,12 @@ return new JDBCJNDITestSetup(new OracleTestSetup()); } + protected OracleNGJNDIDataStoreFactory getJNDIStoreFactory() { + return new OracleNGJNDIDataStoreFactory(); + } + + protected OracleNGDataStoreFactory getDataStoreFactory() { + return new OracleNGDataStoreFactory(); + } + } Modified: branches/2.7.x/modules/plugin/jdbc/jdbc-postgis/src/main/java/org/geotools/data/postgis/PostgisNGJNDIDataStoreFactory.java =================================================================== --- branches/2.7.x/modules/plugin/jdbc/jdbc-postgis/src/main/java/org/geotools/data/postgis/PostgisNGJNDIDataStoreFactory.java 2012-04-26 12:25:19 UTC (rev 38690) +++ branches/2.7.x/modules/plugin/jdbc/jdbc-postgis/src/main/java/org/geotools/data/postgis/PostgisNGJNDIDataStoreFactory.java 2012-04-26 16:19:13 UTC (rev 38691) @@ -41,7 +41,7 @@ super.setupParameters(parameters); parameters.put(LOOSEBBOX.key, LOOSEBBOX); + parameters.put(ESTIMATED_EXTENTS.key, ESTIMATED_EXTENTS); parameters.put(PREPARED_STATEMENTS.key, PREPARED_STATEMENTS); - parameters.put(MAX_OPEN_PREPARED_STATEMENTS.key, MAX_OPEN_PREPARED_STATEMENTS); } } Modified: branches/2.7.x/modules/plugin/jdbc/jdbc-postgis/src/test/java/org/geotools/data/postgis/PostgisJNDIDataSourceTest.java =================================================================== --- branches/2.7.x/modules/plugin/jdbc/jdbc-postgis/src/test/java/org/geotools/data/postgis/PostgisJNDIDataSourceTest.java 2012-04-26 12:25:19 UTC (rev 38690) +++ branches/2.7.x/modules/plugin/jdbc/jdbc-postgis/src/test/java/org/geotools/data/postgis/PostgisJNDIDataSourceTest.java 2012-04-26 16:19:13 UTC (rev 38691) @@ -17,7 +17,9 @@ package org.geotools.data.postgis; +import org.geotools.jdbc.JDBCDataStoreFactory; import org.geotools.jdbc.JDBCJNDIDataSourceTest; +import org.geotools.jdbc.JDBCJNDIDataStoreFactory; import org.geotools.jdbc.JDBCJNDITestSetup; public class PostgisJNDIDataSourceTest extends JDBCJNDIDataSourceTest { @@ -26,4 +28,14 @@ return new JDBCJNDITestSetup(new PostGISTestSetup()); } + @Override + protected JDBCJNDIDataStoreFactory getJNDIStoreFactory() { + return new PostgisNGJNDIDataStoreFactory(); + } + + @Override + protected JDBCDataStoreFactory getDataStoreFactory() { + return new PostgisNGDataStoreFactory(); + } + } Modified: branches/2.7.x/modules/plugin/jdbc/jdbc-spatialite/src/test/java/org/geotools/data/spatialite/SpatiaLiteJNDIDataSourceTest.java =================================================================== --- branches/2.7.x/modules/plugin/jdbc/jdbc-spatialite/src/test/java/org/geotools/data/spatialite/SpatiaLiteJNDIDataSourceTest.java 2012-04-26 12:25:19 UTC (rev 38690) +++ branches/2.7.x/modules/plugin/jdbc/jdbc-spatialite/src/test/java/org/geotools/data/spatialite/SpatiaLiteJNDIDataSourceTest.java 2012-04-26 16:19:13 UTC (rev 38691) @@ -17,7 +17,9 @@ package org.geotools.data.spatialite; +import org.geotools.jdbc.JDBCDataStoreFactory; import org.geotools.jdbc.JDBCJNDIDataSourceTest; +import org.geotools.jdbc.JDBCJNDIDataStoreFactory; import org.geotools.jdbc.JDBCJNDITestSetup; public class SpatiaLiteJNDIDataSourceTest extends JDBCJNDIDataSourceTest { @@ -26,4 +28,16 @@ return new JDBCJNDITestSetup(new SpatiaLiteTestSetup()); } + @Override + protected JDBCJNDIDataStoreFactory getJNDIStoreFactory() { + return new SpatiaLiteJNDIDataStoreFactory(); + } + + @Override + protected JDBCDataStoreFactory getDataStoreFactory() { + return new SpatiaLiteDataStoreFactory(); + } + + + } Modified: branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/main/java/org/geotools/data/sqlserver/SQLServerDataStoreFactory.java =================================================================== --- branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/main/java/org/geotools/data/sqlserver/SQLServerDataStoreFactory.java 2012-04-26 12:25:19 UTC (rev 38690) +++ branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/main/java/org/geotools/data/sqlserver/SQLServerDataStoreFactory.java 2012-04-26 16:19:13 UTC (rev 38691) @@ -36,7 +36,7 @@ /** parameter for database type */ public static final Param DBTYPE = new Param("dbtype", String.class, "Type", true, "sqlserver"); /** parameter for using integrated security, only works on windows, ignores the user and password parameters, the current windows user account is used for login*/ - public static final Param INTSEC = new Param("Integrated Security", Boolean.class, "Login as current windows user account. Works only in windows. Ignores user and password settings.", true, new Boolean(false)); + public static final Param INTSEC = new Param("Integrated Security", Boolean.class, "Login as current windows user account. Works only in windows. Ignores user and password settings.", false, new Boolean(false)); @Override protected SQLDialect createSQLDialect(JDBCDataStore dataStore) { @@ -83,7 +83,7 @@ url = url.substring(0, url.lastIndexOf("/")) + (db != null ? ";DatabaseName="+db : ""); } - if (intsec.booleanValue()) { + if (intsec != null && intsec.booleanValue()) { url = url + ";integratedSecurity=true"; } Modified: branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/main/java/org/geotools/data/sqlserver/SQLServerJNDIDataStoreFactory.java =================================================================== --- branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/main/java/org/geotools/data/sqlserver/SQLServerJNDIDataStoreFactory.java 2012-04-26 12:25:19 UTC (rev 38690) +++ branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/main/java/org/geotools/data/sqlserver/SQLServerJNDIDataStoreFactory.java 2012-04-26 16:19:13 UTC (rev 38691) @@ -16,6 +16,10 @@ */ package org.geotools.data.sqlserver; +import static org.geotools.data.sqlserver.SQLServerDataStoreFactory.*; + +import java.util.Map; + import org.geotools.jdbc.JDBCJNDIDataStoreFactory; /** @@ -32,4 +36,11 @@ public SQLServerJNDIDataStoreFactory() { super(new SQLServerDataStoreFactory()); } + + @SuppressWarnings("unchecked") + @Override + protected void setupParameters(Map parameters) { + super.setupParameters(parameters); + parameters.put(INTSEC.key, INTSEC); + } } Modified: branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/test/java/org/geotools/data/sqlserver/SQLServerJNDIDataSourceTest.java =================================================================== --- branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/test/java/org/geotools/data/sqlserver/SQLServerJNDIDataSourceTest.java 2012-04-26 12:25:19 UTC (rev 38690) +++ branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/test/java/org/geotools/data/sqlserver/SQLServerJNDIDataSourceTest.java 2012-04-26 16:19:13 UTC (rev 38691) @@ -17,7 +17,9 @@ package org.geotools.data.sqlserver; +import org.geotools.jdbc.JDBCDataStoreFactory; import org.geotools.jdbc.JDBCJNDIDataSourceTest; +import org.geotools.jdbc.JDBCJNDIDataStoreFactory; import org.geotools.jdbc.JDBCJNDITestSetup; public class SQLServerJNDIDataSourceTest extends JDBCJNDIDataSourceTest { @@ -26,4 +28,14 @@ return new JDBCJNDITestSetup(new SQLServerTestSetup()); } + @Override + protected JDBCJNDIDataStoreFactory getJNDIStoreFactory() { + return new SQLServerJNDIDataStoreFactory(); + } + + @Override + protected JDBCDataStoreFactory getDataStoreFactory() { + return new SQLServerDataStoreFactory(); + } + } Modified: branches/2.7.x/modules/plugin/jdbc/jdbc-teradata/src/test/java/org/geotools/data/teradata/TeradataJNDIDataSourceTest.java =================================================================== --- branches/2.7.x/modules/plugin/jdbc/jdbc-teradata/src/test/java/org/geotools/data/teradata/TeradataJNDIDataSourceTest.java 2012-04-26 12:25:19 UTC (rev 38690) +++ branches/2.7.x/modules/plugin/jdbc/jdbc-teradata/src/test/java/org/geotools/data/teradata/TeradataJNDIDataSourceTest.java 2012-04-26 16:19:13 UTC (rev 38691) @@ -17,7 +17,9 @@ package org.geotools.data.teradata; +import org.geotools.jdbc.JDBCDataStoreFactory; import org.geotools.jdbc.JDBCJNDIDataSourceTest; +import org.geotools.jdbc.JDBCJNDIDataStoreFactory; import org.geotools.jdbc.JDBCJNDITestSetup; public class TeradataJNDIDataSourceTest extends JDBCJNDIDataSourceTest { @@ -26,4 +28,14 @@ return new JDBCJNDITestSetup(new TeradataTestSetup()); } + @Override + protected JDBCJNDIDataStoreFactory getJNDIStoreFactory() { + return new TeradataJNDIDataStoreFactory(); + } + + @Override + protected JDBCDataStoreFactory getDataStoreFactory() { + return new TeradataDataStoreFactory(); + } + } |
From: <svn...@os...> - 2012-04-26 12:25:29
|
Author: jdeolive Date: 2012-04-26 05:25:19 -0700 (Thu, 26 Apr 2012) New Revision: 38690 Modified: trunk/modules/library/jdbc/src/test/java/org/geotools/jdbc/JDBCGeographyTest.java trunk/modules/plugin/jdbc/jdbc-postgis/src/main/java/org/geotools/data/postgis/PostGISDialect.java Log: GEOT-4120, registring typename mapping for geography Modified: trunk/modules/library/jdbc/src/test/java/org/geotools/jdbc/JDBCGeographyTest.java =================================================================== --- trunk/modules/library/jdbc/src/test/java/org/geotools/jdbc/JDBCGeographyTest.java 2012-04-26 12:17:35 UTC (rev 38689) +++ trunk/modules/library/jdbc/src/test/java/org/geotools/jdbc/JDBCGeographyTest.java 2012-04-26 12:25:19 UTC (rev 38690) @@ -264,4 +264,18 @@ assertEquals("Reykjavik", feature.getAttribute("name")); fi.close(); } + + public void testVirtualTable() throws Exception { + //geopoint( id:Integer; name:String; geo:Geography(Point) ) + StringBuffer sb = new StringBuffer(); + sb.append("select * from "); + dialect.encodeTableName(tname("geopoint"), sb); + + VirtualTable vt = new VirtualTable("geopoint_vt", sb.toString()); + dataStore.addVirtualTable(vt); + + SimpleFeatureType featureType = dataStore.getSchema("geopoint_vt"); + assertNotNull(featureType); + assertNotNull(featureType.getGeometryDescriptor()); + } } Modified: trunk/modules/plugin/jdbc/jdbc-postgis/src/main/java/org/geotools/data/postgis/PostGISDialect.java =================================================================== --- trunk/modules/plugin/jdbc/jdbc-postgis/src/main/java/org/geotools/data/postgis/PostGISDialect.java 2012-04-26 12:17:35 UTC (rev 38689) +++ trunk/modules/plugin/jdbc/jdbc-postgis/src/main/java/org/geotools/data/postgis/PostGISDialect.java 2012-04-26 12:25:19 UTC (rev 38690) @@ -68,6 +68,7 @@ final static Map<String, Class> TYPE_TO_CLASS_MAP = new HashMap<String, Class>() { { put("GEOMETRY", Geometry.class); + put("GEOGRAPHY", Geometry.class); put("POINT", Point.class); put("POINTM", Point.class); put("LINESTRING", LineString.class); @@ -564,6 +565,7 @@ super.registerSqlTypeNameToClassMappings(mappings); mappings.put("geometry", Geometry.class); + mappings.put("geography", Geometry.class); mappings.put("text", String.class); mappings.put("int8", Long.class); mappings.put("int4", Integer.class); |
From: <svn...@os...> - 2012-04-26 12:17:46
|
Author: jdeolive Date: 2012-04-26 05:17:35 -0700 (Thu, 26 Apr 2012) New Revision: 38689 Modified: branches/2.7.x/modules/library/jdbc/src/test/java/org/geotools/jdbc/JDBCGeographyTest.java branches/2.7.x/modules/plugin/jdbc/jdbc-postgis/src/main/java/org/geotools/data/postgis/PostGISDialect.java Log: GEOT-4120, registring typename mapping for geography Modified: branches/2.7.x/modules/library/jdbc/src/test/java/org/geotools/jdbc/JDBCGeographyTest.java =================================================================== --- branches/2.7.x/modules/library/jdbc/src/test/java/org/geotools/jdbc/JDBCGeographyTest.java 2012-04-24 06:36:40 UTC (rev 38688) +++ branches/2.7.x/modules/library/jdbc/src/test/java/org/geotools/jdbc/JDBCGeographyTest.java 2012-04-26 12:17:35 UTC (rev 38689) @@ -259,4 +259,18 @@ assertEquals("Reykjavik", feature.getAttribute("name")); fi.close(); } + + public void testVirtualTable() throws Exception { + //geopoint( id:Integer; name:String; geo:Geography(Point) ) + StringBuffer sb = new StringBuffer(); + sb.append("select * from "); + dialect.encodeTableName(tname("geopoint"), sb); + + VirtualTable vt = new VirtualTable("geopoint_vt", sb.toString()); + dataStore.addVirtualTable(vt); + + SimpleFeatureType featureType = dataStore.getSchema("geopoint_vt"); + assertNotNull(featureType); + assertNotNull(featureType.getGeometryDescriptor()); + } } Modified: branches/2.7.x/modules/plugin/jdbc/jdbc-postgis/src/main/java/org/geotools/data/postgis/PostGISDialect.java =================================================================== --- branches/2.7.x/modules/plugin/jdbc/jdbc-postgis/src/main/java/org/geotools/data/postgis/PostGISDialect.java 2012-04-24 06:36:40 UTC (rev 38688) +++ branches/2.7.x/modules/plugin/jdbc/jdbc-postgis/src/main/java/org/geotools/data/postgis/PostGISDialect.java 2012-04-26 12:17:35 UTC (rev 38689) @@ -63,6 +63,7 @@ final static Map<String, Class> TYPE_TO_CLASS_MAP = new HashMap<String, Class>() { { put("GEOMETRY", Geometry.class); + put("GEOGRAPHY", Geometry.class); put("POINT", Point.class); put("POINTM", Point.class); put("LINESTRING", LineString.class); @@ -546,6 +547,7 @@ super.registerSqlTypeNameToClassMappings(mappings); mappings.put("geometry", Geometry.class); + mappings.put("geography", Geometry.class); mappings.put("text", String.class); mappings.put("int8", Long.class); mappings.put("int4", Integer.class); |
From: <svn...@os...> - 2012-04-24 06:36:52
|
Author: ang05a Date: 2012-04-23 23:36:40 -0700 (Mon, 23 Apr 2012) New Revision: 38688 Modified: trunk/modules/extension/app-schema/app-schema-resolver/src/main/java/org/geotools/xml/AppSchemaValidator.java trunk/modules/extension/app-schema/app-schema-resolver/src/test/java/org/geotools/xml/AppSchemaValidatorTest.java Log: Enable using catalog in AppSchemaValidator for app-schema-test. Modified: trunk/modules/extension/app-schema/app-schema-resolver/src/main/java/org/geotools/xml/AppSchemaValidator.java =================================================================== --- trunk/modules/extension/app-schema/app-schema-resolver/src/main/java/org/geotools/xml/AppSchemaValidator.java 2012-04-23 03:17:54 UTC (rev 38687) +++ trunk/modules/extension/app-schema/app-schema-resolver/src/main/java/org/geotools/xml/AppSchemaValidator.java 2012-04-24 06:36:40 UTC (rev 38688) @@ -21,6 +21,8 @@ import java.io.IOException; import java.io.InputStream; import java.io.UnsupportedEncodingException; +import java.net.MalformedURLException; +import java.net.URL; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -91,6 +93,17 @@ private AppSchemaValidator(AppSchemaResolver resolver) { this.resolver = resolver; } + + /** + * Construct an {@link AppSchemaValidator} that performs schema validation against schemas found + * using an {@link AppSchemaResolver} with a {@link AppSchemaCatalog}. + * + * @param catalog + * AppSchemaCatalog + */ + private AppSchemaValidator(AppSchemaCatalog catalog) { + this(new AppSchemaResolver(catalog)); + } /** * Return the list of failures found during parsing. @@ -212,6 +225,17 @@ public static AppSchemaValidator buildValidator(AppSchemaResolver resolver) { return new AppSchemaValidator(resolver); } + + /** + * Construct an {@link AppSchemaValidator} that performs schema validation against schemas found + * using an {@link AppSchemaResolver} with a {@link AppSchemaCatalog}. + * + * @param catalog + * AppSchemaCatalog + */ + public static AppSchemaValidator buildValidator(AppSchemaCatalog catalog) { + return new AppSchemaValidator(catalog); + } /** * @@ -225,12 +249,14 @@ * * @param name * resource name of XML instance document + * @param catalog + * AppSchemaCatalog to aide local schema resolution or null */ - public static void validateResource(String name) { + public static void validateResource(String name, AppSchemaCatalog catalog) { InputStream input = null; try { input = AppSchemaValidator.class.getResourceAsStream(name); - validate(input); + validate(input, catalog); } finally { if (input != null) { try { @@ -254,8 +280,10 @@ * * @param xml * string containing XML instance document + * @param catalog + * AppSchemaCatalog to aide local schema resolution or null */ - public static void validate(String xml) { + public static void validate(String xml, AppSchemaCatalog catalog) { byte[] bytes = null; String encoding = getEncoding(xml); if (encoding != null) { @@ -273,7 +301,7 @@ InputStream input = null; try { input = new ByteArrayInputStream(bytes); - validate(input); + validate(input, catalog); } finally { if (input != null) { try { @@ -314,9 +342,11 @@ * * @param input * stream providing XML instance document + * @param catalog + * AppSchemaCatalog file to aide local schema resolution or null */ - public static void validate(InputStream input) { - AppSchemaValidator validator = buildValidator(); + public static void validate(InputStream input, AppSchemaCatalog catalog) { + AppSchemaValidator validator = buildValidator(catalog); validator.parse(input); validator.checkForFailures(); } Modified: trunk/modules/extension/app-schema/app-schema-resolver/src/test/java/org/geotools/xml/AppSchemaValidatorTest.java =================================================================== --- trunk/modules/extension/app-schema/app-schema-resolver/src/test/java/org/geotools/xml/AppSchemaValidatorTest.java 2012-04-23 03:17:54 UTC (rev 38687) +++ trunk/modules/extension/app-schema/app-schema-resolver/src/test/java/org/geotools/xml/AppSchemaValidatorTest.java 2012-04-24 06:36:40 UTC (rev 38688) @@ -39,7 +39,7 @@ */ @Test public void validateErMineralOccurrence() { - AppSchemaValidator.validateResource("/test-data/er_MineralOccurrence.xml"); + AppSchemaValidator.validateResource("/test-data/er_MineralOccurrence.xml", null); } /** @@ -49,7 +49,7 @@ @Test public void validateErMineralOccurrenceWithErrors() { try { - AppSchemaValidator.validateResource("/test-data/er_MineralOccurrence_with_errors.xml"); + AppSchemaValidator.validateResource("/test-data/er_MineralOccurrence_with_errors.xml", null); Assert.fail("Unexpected schema validation success for known-invalid XML instance document"); } catch (Exception e) { Assert.assertTrue( @@ -65,7 +65,7 @@ */ @Test public void validateWfs20Example01() { - AppSchemaValidator.validateResource("/test-data/Example01.xml"); + AppSchemaValidator.validateResource("/test-data/Example01.xml", null); } /** @@ -104,7 +104,7 @@ int count = input.read(bytes); Assert.assertEquals("Unexpected read underrun", bytes.length, count); String xml = new String(bytes); - AppSchemaValidator.validate(xml); + AppSchemaValidator.validate(xml, null); } catch (IOException e) { throw new RuntimeException(e); } finally { @@ -164,7 +164,7 @@ + "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " // + "xsi:schemaLocation=\"" // + "http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.1.0/wfs.xsd" // - + "\"><wfs:Query typeName=\"test\"/></wfs:GetFeature>"); + + "\"><wfs:Query typeName=\"test\"/></wfs:GetFeature>", null); } /** @@ -175,7 +175,7 @@ try { AppSchemaValidator.validate("<wfs:GetFeature " // + "xmlns:wfs=\"http://www.opengis.net/wfs\">" // - + "<wfs:Query typeName=\"test\"/></wfs:GetFeature>"); + + "<wfs:Query typeName=\"test\"/></wfs:GetFeature>", null); Assert.fail("Unexpected validation success for GetFeature with missing schemaLocation"); } catch (Exception e) { Assert.assertEquals(e.getMessage(), "Schema validation failure caused by " |
From: <svn...@os...> - 2012-04-23 03:18:01
|
Author: ang05a Date: 2012-04-22 20:17:54 -0700 (Sun, 22 Apr 2012) New Revision: 38687 Modified: trunk/modules/extension/xsd/xsd-core/src/main/java/org/geotools/xml/impl/BindingPropertyExtractor.java Log: GEOT-4094: Adding a bracket for multiple conditions in BindingPropertyExtractor Modified: trunk/modules/extension/xsd/xsd-core/src/main/java/org/geotools/xml/impl/BindingPropertyExtractor.java =================================================================== --- trunk/modules/extension/xsd/xsd-core/src/main/java/org/geotools/xml/impl/BindingPropertyExtractor.java 2012-04-23 00:54:37 UTC (rev 38686) +++ trunk/modules/extension/xsd/xsd-core/src/main/java/org/geotools/xml/impl/BindingPropertyExtractor.java 2012-04-23 03:17:54 UTC (rev 38687) @@ -332,8 +332,8 @@ child = child.getResolvedElementDeclaration(); } if (child.getName().equals(partContent.getName()) && - child.getTargetNamespace()==null? partContent.getTargetNamespace()==null : - child.getTargetNamespace().equals(partContent.getTargetNamespace())) { + (child.getTargetNamespace()==null? partContent.getTargetNamespace()==null : + child.getTargetNamespace().equals(partContent.getTargetNamespace()))) { notFound = false; break; } |
From: <svn...@os...> - 2012-04-23 00:54:43
|
Author: mbedward Date: 2012-04-22 17:54:37 -0700 (Sun, 22 Apr 2012) New Revision: 38686 Modified: trunk/modules/library/render/src/main/java/org/geotools/map/MapViewport.java trunk/modules/library/render/src/test/java/org/geotools/map/MapViewportTest.java Log: GEOT-4118: fixed coordinate transforms when aspect raio matching is disabled; added tests Modified: trunk/modules/library/render/src/main/java/org/geotools/map/MapViewport.java =================================================================== --- trunk/modules/library/render/src/main/java/org/geotools/map/MapViewport.java 2012-04-22 23:17:04 UTC (rev 38685) +++ trunk/modules/library/render/src/main/java/org/geotools/map/MapViewport.java 2012-04-23 00:54:37 UTC (rev 38686) @@ -327,7 +327,7 @@ private void copyBounds(ReferencedEnvelope newBounds) { if (newBounds == null || newBounds.isEmpty()) { this.bounds = new ReferencedEnvelope(); - } else { + } else { this.bounds = new ReferencedEnvelope(newBounds); } } @@ -560,9 +560,11 @@ private void calculateSimpleTransforms(ReferencedEnvelope requestedBounds) { double xscale = screenArea.getWidth() / requestedBounds.getWidth(); double yscale = screenArea.getHeight() / requestedBounds.getHeight(); - double scale = Math.min(xscale, yscale); - worldToScreen = new AffineTransform(scale, 0, 0, -scale, - -requestedBounds.getMinX(), requestedBounds.getMaxY()); + + worldToScreen = new AffineTransform( + xscale, 0, 0, -yscale, + -xscale * requestedBounds.getMinX(), + yscale * requestedBounds.getMaxY()); try { screenToWorld = worldToScreen.createInverse(); Modified: trunk/modules/library/render/src/test/java/org/geotools/map/MapViewportTest.java =================================================================== --- trunk/modules/library/render/src/test/java/org/geotools/map/MapViewportTest.java 2012-04-22 23:17:04 UTC (rev 38685) +++ trunk/modules/library/render/src/test/java/org/geotools/map/MapViewportTest.java 2012-04-23 00:54:37 UTC (rev 38686) @@ -18,6 +18,8 @@ package org.geotools.map; import java.awt.Rectangle; +import java.awt.geom.AffineTransform; +import java.awt.geom.Point2D; import java.io.ByteArrayOutputStream; import java.util.logging.Handler; import java.util.logging.Level; @@ -242,6 +244,53 @@ } @Test + public void coordinateTransform_MatchingAspectRatioDisabled() throws Exception { + MapViewport vp = new MapViewport(false); + + // world and screen bounds with different aspect ratios + final ReferencedEnvelope world = WORLD_1_1; + final Rectangle screen = SCREEN_2_1; + vp.setBounds(world); + vp.setScreenArea(screen); + + double[] screenXY = { + screen.getMinX(), screen.getMinY(), screen.getMaxX(), screen.getMaxY() + }; + + double[] worldXY = new double[screenXY.length]; + vp.getScreenToWorld().transform(screenXY, 0, worldXY, 0, screenXY.length / 2); + + assertEquals(world.getMinX(), worldXY[0], TOL); + assertEquals(world.getMaxY(), worldXY[1], TOL); + assertEquals(world.getMaxX(), worldXY[2], TOL); + assertEquals(world.getMinY(), worldXY[3], TOL); + } + + @Test + public void coordinateTransform_MatchingAspectRatioEnabled() throws Exception { + MapViewport vp = new MapViewport(true); + + // world and screen bounds with different aspect ratios + final Rectangle screen = SCREEN_2_1; + vp.setBounds(WORLD_1_1); + vp.setScreenArea(screen); + + ReferencedEnvelope actualWorld = vp.getBounds(); + + double[] screenXY = { + screen.getMinX(), screen.getMinY(), screen.getMaxX(), screen.getMaxY() + }; + + double[] worldXY = new double[screenXY.length]; + vp.getScreenToWorld().transform(screenXY, 0, worldXY, 0, screenXY.length / 2); + + assertEquals(actualWorld.getMinX(), worldXY[0], TOL); + assertEquals(actualWorld.getMaxY(), worldXY[1], TOL); + assertEquals(actualWorld.getMaxX(), worldXY[2], TOL); + assertEquals(actualWorld.getMinY(), worldXY[3], TOL); + } + + @Test public void boundsCtorSetsNullWorldToScreen() { MapViewport vp = new MapViewport(WORLD_1_1); assertNull( vp.getWorldToScreen() ); |
From: <svn...@os...> - 2012-04-22 23:17:13
|
Author: mbedward Date: 2012-04-22 16:17:04 -0700 (Sun, 22 Apr 2012) New Revision: 38685 Modified: trunk/modules/unsupported/mongodb/ Log: set svn:ignore target Property changes on: trunk/modules/unsupported/mongodb ___________________________________________________________________ Added: svn:ignore + target |
From: <svn...@os...> - 2012-04-21 23:10:38
|
Author: aaime Date: 2012-04-21 16:10:31 -0700 (Sat, 21 Apr 2012) New Revision: 38684 Added: trunk/modules/plugin/shapefile/src/test/resources/org/geotools/data/shapefile/test-data/lsOnePoint/ trunk/modules/plugin/shapefile/src/test/resources/org/geotools/data/shapefile/test-data/lsOnePoint/lsOnePoint.dbf trunk/modules/plugin/shapefile/src/test/resources/org/geotools/data/shapefile/test-data/lsOnePoint/lsOnePoint.prj trunk/modules/plugin/shapefile/src/test/resources/org/geotools/data/shapefile/test-data/lsOnePoint/lsOnePoint.shp trunk/modules/plugin/shapefile/src/test/resources/org/geotools/data/shapefile/test-data/lsOnePoint/lsOnePoint.shx Modified: trunk/modules/plugin/shapefile/src/main/java/org/geotools/data/shapefile/shp/MultiLineHandler.java trunk/modules/plugin/shapefile/src/test/java/org/geotools/data/shapefile/ShapefileDataStoreTest.java Log: [GEOT-4090] Features missing when importing shapefile Modified: trunk/modules/plugin/shapefile/src/main/java/org/geotools/data/shapefile/shp/MultiLineHandler.java =================================================================== --- trunk/modules/plugin/shapefile/src/main/java/org/geotools/data/shapefile/shp/MultiLineHandler.java 2012-04-21 22:27:55 UTC (rev 38683) +++ trunk/modules/plugin/shapefile/src/main/java/org/geotools/data/shapefile/shp/MultiLineHandler.java 2012-04-21 23:10:31 UTC (rev 38684) @@ -146,6 +146,7 @@ } length = finish - start; + int xyLength = length; if (length == 1) { length = 2; clonePoint = true; @@ -154,9 +155,9 @@ } CoordinateSequence cs = geometryFactory.getCoordinateSequenceFactory().create(length, dimensions); - double[] xy = new double[length * 2]; + double[] xy = new double[xyLength * 2]; doubleBuffer.get(xy); - for (int i = 0; i < length; i++) { + for (int i = 0; i < xyLength; i++) { cs.setOrdinate(i, 0, xy[i * 2]); cs.setOrdinate(i, 1, xy[i * 2 + 1]); } Modified: trunk/modules/plugin/shapefile/src/test/java/org/geotools/data/shapefile/ShapefileDataStoreTest.java =================================================================== --- trunk/modules/plugin/shapefile/src/test/java/org/geotools/data/shapefile/ShapefileDataStoreTest.java 2012-04-21 22:27:55 UTC (rev 38683) +++ trunk/modules/plugin/shapefile/src/test/java/org/geotools/data/shapefile/ShapefileDataStoreTest.java 2012-04-21 23:10:31 UTC (rev 38684) @@ -47,7 +47,6 @@ import org.geotools.data.simple.SimpleFeatureCollection; import org.geotools.data.simple.SimpleFeatureIterator; import org.geotools.data.simple.SimpleFeatureSource; -import org.geotools.factory.CommonFactoryFinder; import org.geotools.feature.FeatureCollections; import org.geotools.feature.FeatureTypes; import org.geotools.feature.simple.SimpleFeatureBuilder; @@ -60,14 +59,15 @@ import org.opengis.feature.type.AttributeDescriptor; import org.opengis.feature.type.FeatureType; import org.opengis.filter.Filter; -import org.opengis.filter.FilterFactory2; import org.opengis.referencing.crs.CoordinateReferenceSystem; import com.vividsolutions.jts.geom.Coordinate; import com.vividsolutions.jts.geom.Geometry; import com.vividsolutions.jts.geom.GeometryCollection; import com.vividsolutions.jts.geom.GeometryFactory; +import com.vividsolutions.jts.geom.LineString; import com.vividsolutions.jts.geom.LinearRing; +import com.vividsolutions.jts.geom.MultiLineString; import com.vividsolutions.jts.geom.Point; import com.vividsolutions.jts.geom.Polygon; @@ -930,7 +930,40 @@ doTestReadWriteDate("2000-01-01"); } + public void testLinestringOnePoint() throws Exception { + URL u = TestData.url(TestCaseSupport.class, "lsOnePoint/lsOnePoint.shp"); + File f = DataUtilities.urlToFile(u); + assertTrue(f.exists()); + + store = new ShapefileDataStore(u); + SimpleFeatureSource fs = store.getFeatureSource(store.getTypeNames()[0]); + SimpleFeatureCollection fc = fs.getFeatures(); + assertEquals(3, fc.size()); + + int i = 418; + SimpleFeatureIterator it = fc.features(); + while(it.hasNext()) { + SimpleFeature sf = it.next(); + assertEquals("Activity" + i, sf.getAttribute("Name")); + + if(i == 419) { + assertNotNull(sf.getDefaultGeometry()); + assertTrue(sf.getDefaultGeometry() instanceof MultiLineString); + MultiLineString mls = (MultiLineString) sf.getDefaultGeometry(); + assertEquals(1, mls.getNumGeometries()); + LineString ls = (LineString) mls.getGeometryN(0); + assertEquals(2, ls.getNumPoints()); + assertEquals(ls.getStartPoint(), ls.getEndPoint()); + } + i++; + } + + assertEquals(421, i); + + assertEquals(3, fc.toArray().length); + } + /** * This is useful to dump a UTF16 character to an UT16 escape sequence, * basically the only way to represent the chars we don't have on the Added: trunk/modules/plugin/shapefile/src/test/resources/org/geotools/data/shapefile/test-data/lsOnePoint/lsOnePoint.dbf =================================================================== --- trunk/modules/plugin/shapefile/src/test/resources/org/geotools/data/shapefile/test-data/lsOnePoint/lsOnePoint.dbf (rev 0) +++ trunk/modules/plugin/shapefile/src/test/resources/org/geotools/data/shapefile/test-data/lsOnePoint/lsOnePoint.dbf 2012-04-21 23:10:31 UTC (rev 38684) @@ -0,0 +1,2 @@ +_ |
From: <svn...@os...> - 2012-04-21 22:28:02
|
Author: aaime Date: 2012-04-21 15:27:55 -0700 (Sat, 21 Apr 2012) New Revision: 38683 Modified: trunk/modules/library/main/src/test/java/org/geotools/styling/SLDTransformerTest.java Log: Test for GEOT-4109 Modified: trunk/modules/library/main/src/test/java/org/geotools/styling/SLDTransformerTest.java =================================================================== --- trunk/modules/library/main/src/test/java/org/geotools/styling/SLDTransformerTest.java 2012-04-21 08:23:12 UTC (rev 38682) +++ trunk/modules/library/main/src/test/java/org/geotools/styling/SLDTransformerTest.java 2012-04-21 22:27:55 UTC (rev 38683) @@ -776,6 +776,28 @@ assertEquals("parsed xml must contain attribbute type with correct value", -1, st.transform(cm).indexOf("type=")); } + @Test + public void testColorMapExtended() throws Exception { + SLDTransformer st = new SLDTransformer(); + ColorMap cm = sf.createColorMap(); + + // Test type = values, extended = true + cm.setType(ColorMap.TYPE_VALUES); + cm.setExtendedColors(true); + assertTrue("parsed xml must contain attribbute type with correct value", st.transform(cm).contains("extended=\"true\"")); + + // Test type = intervals, extended = true + cm.setType(ColorMap.TYPE_INTERVALS); + cm.setExtendedColors(true); + assertTrue("parsed xml must contain attribbute type with correct value", st.transform(cm).contains("extended=\"true\"")); + + // Test type = ramp, extended = true + cm.setType(ColorMap.TYPE_RAMP); + cm.setExtendedColors(true); + assertTrue("parsed xml must contain attribbute type with correct value", st.transform(cm).contains("extended=\"true\"")); + + } + /** * Checks the output of encoding a default line symbolizer does not include all the default values * @throws Exception |
From: <svn...@os...> - 2012-04-21 08:23:19
|
Author: mbedward Date: 2012-04-21 01:23:12 -0700 (Sat, 21 Apr 2012) New Revision: 38682 Modified: trunk/docs/user/library/render/gtrenderer.rst trunk/docs/user/library/render/map.rst trunk/docs/user/library/render/style.rst Log: Documented MapViewport aspect-ratio behaviour. Tweaked page titles. Modified: trunk/docs/user/library/render/gtrenderer.rst =================================================================== --- trunk/docs/user/library/render/gtrenderer.rst 2012-04-20 15:10:20 UTC (rev 38681) +++ trunk/docs/user/library/render/gtrenderer.rst 2012-04-21 08:23:12 UTC (rev 38682) @@ -1,5 +1,5 @@ -GTRenderer ----------- +GTRenderer to draw maps +----------------------- GTRenderer renderer is the reason why you signed up for this whole GeoTools experience; you want to see a Map. Modified: trunk/docs/user/library/render/map.rst =================================================================== --- trunk/docs/user/library/render/map.rst 2012-04-20 15:10:20 UTC (rev 38681) +++ trunk/docs/user/library/render/map.rst 2012-04-21 08:23:12 UTC (rev 38682) @@ -1,5 +1,5 @@ -Map ---- +Map data and display classes +---------------------------- The gt-render module defines a new data structure to represent the contents of a map. MapContent defines a map as a series of layers (which are drawn in order). This is not part of the formal @@ -20,15 +20,19 @@ * **MapViewport** - Represents the area of the map to drawn. This includes both: + Represents the area of the map to drawn. The viewport stores: + + * the world bounds (spatial extent in world units) of the area to be drawn; + * the screen, image or device bounds to draw into; + * the coordinate transforms used to convert between world and screen positions. + + In practice, you provide the world and screen bounds to a MapViewport object and + it calculates the coordinate transforms for you (see :ref:`aspect-ratio` for more details). + + Potentially, a viewport could also work with parameters other than horizontal spatial extent when + defining the map data to be drawn such as height or time. The MapViewport class does not presently + support such usage but you could derive a sub-class for this purpose. - * The area of the world: the spatial extent (and conceptually the height / depth / time - information) needed to render a slice of data. - At a pragmatic level the MapViewport includes the "world" coordinate reference system - into which all content is transformed prior to display. - * The area of the screen: either expressed as a rectangle or provided as an affine transform - used to zoom into a specific area. - * **Layer** - represents a layer of content to be drawn; layers are held in a list and are drawn in order. @@ -63,6 +67,28 @@ } viewport.setBounds( maxBounds ); + +.. _aspect-ratio: + +Aspect-ratio of map and screen bounds +''''''''''''''''''''''''''''''''''''' + +Very often, the aspect ratio (ratio of width to height) of the world and screen bounds will differ. +By default, MapViewport does not make any correction for this (this behaviour accords with the OGC +WMS specification which states that a map server should honour the bounds provided by the user +regardless of any distortion which results). + +In many cases, it is preferable to have MapViewport automagically correct for differing aspect +ratios, thereby avoiding distortion in the map display. You can request this behaviour as follows:: + + MapViewport vp = myMapContent.getViewport(); + vp.setMatchingAspectRatio( true ); + +With this setting, the viewport will calculate coordinate transforms such that the user requested +world bounds are centered in the screen or image display area. Note that when such a correction has +been applied, the world bounds stored by the viewport will be larger than those requested by the +user. + Layer ^^^^^ Modified: trunk/docs/user/library/render/style.rst =================================================================== --- trunk/docs/user/library/render/style.rst 2012-04-20 15:10:20 UTC (rev 38681) +++ trunk/docs/user/library/render/style.rst 2012-04-21 08:23:12 UTC (rev 38682) @@ -1,7 +1,10 @@ -Style ------ +Styling features for display +---------------------------- -GeoTools Rendering process is controlled styling information that you provide. The data structures we use to describe styling are based on the Style Layer Descriptor (SLD) and Symbology Encoding (SE) specifications provided by the OGC. The SLD specification defines an XML document you can use to save and load your styles. +GeoTools Rendering process is controlled styling information that you provide. The data structures +we use to describe styling are based on the Style Layer Descriptor (SLD) and Symbology Encoding (SE) +specifications provided by the OGC. The SLD specification defines an XML document you can use to +save and load your styles. This page is devoted to examples, to review the concepts consult the references below. |
From: <svn...@os...> - 2012-04-20 15:10:30
|
Author: moovida Date: 2012-04-20 08:10:20 -0700 (Fri, 20 Apr 2012) New Revision: 38681 Modified: trunk/modules/unsupported/swt/src/main/java/org/geotools/swt/SwtMapPane.java trunk/modules/unsupported/swt/src/main/java/org/geotools/swt/event/MapMouseEvent.java trunk/modules/unsupported/swt/src/main/java/org/geotools/swt/tool/AbstractZoomTool.java trunk/modules/unsupported/swt/src/main/java/org/geotools/swt/tool/CursorTool.java trunk/modules/unsupported/swt/src/main/java/org/geotools/swt/tool/InfoTool.java trunk/modules/unsupported/swt/src/main/java/org/geotools/swt/tool/PanTool.java trunk/modules/unsupported/swt/src/main/java/org/geotools/swt/tool/ZoomInTool.java trunk/modules/unsupported/swt/src/main/java/org/geotools/swt/tool/ZoomOutTool.java Log: enhancements to mouse when dragging + tools bbox style config by Michael Gruebsch Modified: trunk/modules/unsupported/swt/src/main/java/org/geotools/swt/SwtMapPane.java =================================================================== --- trunk/modules/unsupported/swt/src/main/java/org/geotools/swt/SwtMapPane.java 2012-04-20 10:03:30 UTC (rev 38680) +++ trunk/modules/unsupported/swt/src/main/java/org/geotools/swt/SwtMapPane.java 2012-04-20 15:10:20 UTC (rev 38681) @@ -152,6 +152,10 @@ private Color white; private Color yellow; + private Color cursorToolColor; + private int cursorToolLineWidth; + private int cursorToolLineStyle; + /** * Constructor - creates an instance of JMapPane with no map * context or renderer initially @@ -216,6 +220,9 @@ } }); + cursorToolColor = getDisplay().getSystemColor(SWT.COLOR_YELLOW); + cursorToolLineWidth = 2; + cursorToolLineStyle = SWT.LINE_SOLID; } /** @@ -1123,7 +1130,7 @@ * draw a boundingbox while dragging, we draw the box * keeping the current drawn image */ - if (toolCanDraw && isDragging) { + if (toolCanDraw && toolManager.getCursorTool().isDrawing() && isDragging) { // System.out.println("draw box: " + startX + "/" + startY + "/" + endX + // "/" + endY); if (swtImage != null) { @@ -1132,8 +1139,9 @@ gc.setXORMode(true); org.eclipse.swt.graphics.Color fC = gc.getForeground(); - gc.setLineWidth(2); - gc.setForeground(yellow); + gc.setLineStyle(cursorToolLineStyle); + gc.setLineWidth(cursorToolLineWidth); + gc.setForeground(cursorToolColor); gc.drawRectangle(startX, startY, endX - startX, endY - startY); gc.setForeground(fC); @@ -1181,7 +1189,7 @@ swtImage.dispose(); swtImage = null; } - System.out.println("READRAWBASEIMAGE"); + // System.out.println("READRAWBASEIMAGE"); swtImage = new Image(getDisplay(), awtToSwt(baseImage, curPaintArea.width + 1, curPaintArea.height + 1)); } @@ -1290,4 +1298,72 @@ public void layerPreDispose( MapLayerListEvent event ) { } + + /** + * Returns the colour which is used to draw the bounding box + * of the currently active cursor tool. The bounding box is + * drawn in xor mode. + * + * @return the colour used for the tool's bounding box + */ + public Color getCursorToolColor() { + return cursorToolColor; + } + + /** + * Sets the colour which is used to draw the bounding box + * of the currently active cursor tool. The bounding box is + * drawn in xor mode. + * + * @param color the colour used for the tool's bounding box + */ + public void setCursorToolColor( Color color ) { + this.cursorToolColor = color; + } + + /** + * Returns the line width of the bounding box of the currently + * active cursor tool. + * + * @return line width + */ + public int getCursorToolLineWidth() { + return cursorToolLineWidth; + } + + /** + * Sets the line width of the bounding box of the currently + * active cursor tool. + * + * @param lineWidth line width + */ + public void setCursorToolLineWidth( int lineWidth ) { + this.cursorToolLineWidth = lineWidth; + } + + /** + * Returns the line style of the bounding box of the currently + * active cursor tool. + * + * @return line style + */ + public int getCursorToolLineStyle() { + return cursorToolLineStyle; + } + + /** + * Sets the line style of the bounding box of the currently + * active cursor tool. + * + * @param lineStyle line style + * @see SWT#LINE_SOLID + * @see SWT#LINE_DASH + * @see SWT#LINE_DOT + * @see SWT#LINE_DASHDOT + * @see SWT#LINE_DASHDOTDOT + */ + public void setCursorToolLineStyle( int lineStyle ) { + this.cursorToolLineStyle = lineStyle; + } + } Modified: trunk/modules/unsupported/swt/src/main/java/org/geotools/swt/event/MapMouseEvent.java =================================================================== --- trunk/modules/unsupported/swt/src/main/java/org/geotools/swt/event/MapMouseEvent.java 2012-04-20 10:03:30 UTC (rev 38680) +++ trunk/modules/unsupported/swt/src/main/java/org/geotools/swt/event/MapMouseEvent.java 2012-04-20 15:10:20 UTC (rev 38681) @@ -99,7 +99,8 @@ /** * The button that was pressed or released; 1 for the * first button, 2 for the second button, and 3 for the - * third button, etc. + * third button, etc. On mouse dragging this function may + * return 0. * * @return the button that was pressed or released * @see MouseEvent#button @@ -109,6 +110,15 @@ } /** + * Returns the state mask of the mouse event. + * @return the state mask + * @see MouseEvent#stateMask + */ + public int getStateMask() { + return event.stateMask; + } + + /** * Get the position, in map (world) coordinates of this mouse event * * @return a new DirectPosition2D object for the world coordinates Modified: trunk/modules/unsupported/swt/src/main/java/org/geotools/swt/tool/AbstractZoomTool.java =================================================================== --- trunk/modules/unsupported/swt/src/main/java/org/geotools/swt/tool/AbstractZoomTool.java 2012-04-20 10:03:30 UTC (rev 38680) +++ trunk/modules/unsupported/swt/src/main/java/org/geotools/swt/tool/AbstractZoomTool.java 2012-04-20 15:10:20 UTC (rev 38681) @@ -17,7 +17,9 @@ package org.geotools.swt.tool; +import org.eclipse.swt.SWT; + /** * Abstract base class for the zoom-in and zoom-out tools. Provides getter / setter * methods for the zoom increment. @@ -38,12 +40,15 @@ protected double zoom; /** - * Constructs a new abstract zoom tool. - * @param triggeringMouseButton Mouse button which triggers the tool's activation + * Constructs a new abstract zoom tool. To activate the tool only on certain + * mouse events provide a single mask, e.g. {@link SWT#BUTTON1}, or + * a combination of multiple SWT-masks. + * + * @param triggerButtonMask Mouse button which triggers the tool's activation * or {@value #ANY_BUTTON} if the tool is to be triggered by any button */ - public AbstractZoomTool(int triggeringMouseButton) { - super(triggeringMouseButton); + public AbstractZoomTool(int triggerButtonMask) { + super(triggerButtonMask); setZoom(DEFAULT_ZOOM_FACTOR); } Modified: trunk/modules/unsupported/swt/src/main/java/org/geotools/swt/tool/CursorTool.java =================================================================== --- trunk/modules/unsupported/swt/src/main/java/org/geotools/swt/tool/CursorTool.java 2012-04-20 10:03:30 UTC (rev 38680) +++ trunk/modules/unsupported/swt/src/main/java/org/geotools/swt/tool/CursorTool.java 2012-04-20 15:10:20 UTC (rev 38681) @@ -17,6 +17,7 @@ package org.geotools.swt.tool; +import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Cursor; import org.geotools.swt.SwtMapPane; import org.geotools.swt.event.MapMouseAdapter; @@ -41,19 +42,22 @@ * Flag indicating that the tool should be triggered whenever any mouse button * is used. */ - public static final int ANY_BUTTON = -1; + public static final int ANY_BUTTON = SWT.BUTTON_MASK; private SwtMapPane mapPane; - private int triggeringMouseButton; + private int triggerButtonMask; /** - * Constructs a new cursor tool. - * @param triggeringMouseButton Mouse button which triggers the tool's activation + * Constructs a new cursor tool. To activate the tool only on certain + * mouse events provide a single mask, e.g. {@link SWT#BUTTON1}, or + * a combination of multiple SWT-masks. + * + * @param triggerButtonMask Mouse button which triggers the tool's activation * or {@value #ANY_BUTTON} if the tool is to be triggered by any button */ - public CursorTool(int triggeringMouseButton) { - this.triggeringMouseButton = triggeringMouseButton; + public CursorTool(int triggerButtonMask) { + this.triggerButtonMask = triggerButtonMask; } /** @@ -110,12 +114,37 @@ public abstract boolean canMove(); /** + * Returns <code>true</code> for any tool which is drawing + * while dragging. For tools which are triggered only by a certain + * mouse event it might be the case that {@link #canDraw()} is + * <code>true</code> while they are actually not active. + * + * @return <code>true</code> if the tool is drawing while dragging + */ + public boolean isDrawing() + { + return canDraw(); + } + + /** * Checks if the tool should be triggered by the event. * @param event event to be checked * @return <code>true</code> if the tool is triggered by the event */ protected boolean isTriggerMouseButton(MapMouseEvent event) { - return triggeringMouseButton == ANY_BUTTON || triggeringMouseButton == event.getMouseButton(); + return + triggerButtonMask == ANY_BUTTON + || // on mouse move or mouse drag the mouse button field is 0 but the state mask is set + 0 != (triggerButtonMask & event.getStateMask()) + || // on mouse click the state mask is 0, but the mouse button field is set + ( event.getStateMask() == 0 + && ( ((triggerButtonMask & SWT.BUTTON1) != 0 && event.getMouseButton() == 1) + || ((triggerButtonMask & SWT.BUTTON2) != 0 && event.getMouseButton() == 2) + || ((triggerButtonMask & SWT.BUTTON3) != 0 && event.getMouseButton() == 3) + || ((triggerButtonMask & SWT.BUTTON4) != 0 && event.getMouseButton() == 4) + || ((triggerButtonMask & SWT.BUTTON5) != 0 && event.getMouseButton() == 5) + ) + ); } } Modified: trunk/modules/unsupported/swt/src/main/java/org/geotools/swt/tool/InfoTool.java =================================================================== --- trunk/modules/unsupported/swt/src/main/java/org/geotools/swt/tool/InfoTool.java 2012-04-20 10:03:30 UTC (rev 38680) +++ trunk/modules/unsupported/swt/src/main/java/org/geotools/swt/tool/InfoTool.java 2012-04-20 15:10:20 UTC (rev 38681) @@ -84,13 +84,16 @@ private WeakHashMap<Layer, InfoToolHelper<?>> helperTable; /** - * Constructs a new info tool. - * @param triggeringMouseButton Mouse button which triggers the tool's activation + * Constructs a new info tool. To activate the tool only on certain + * mouse events provide a single mask, e.g. {@link SWT#BUTTON1}, or + * a combination of multiple SWT-masks. + * + * @param triggerButtonMask Mouse button which triggers the tool's activation * or {@value #ANY_BUTTON} if the tool is to be triggered by any button */ - public InfoTool(int triggeringMouseButton) { + public InfoTool(int triggerButtonMask) { - super(triggeringMouseButton); + super(triggerButtonMask); cursor = CursorManager.getInstance().getInfoCursor(); Modified: trunk/modules/unsupported/swt/src/main/java/org/geotools/swt/tool/PanTool.java =================================================================== --- trunk/modules/unsupported/swt/src/main/java/org/geotools/swt/tool/PanTool.java 2012-04-20 10:03:30 UTC (rev 38680) +++ trunk/modules/unsupported/swt/src/main/java/org/geotools/swt/tool/PanTool.java 2012-04-20 15:10:20 UTC (rev 38681) @@ -17,6 +17,7 @@ package org.geotools.swt.tool; +import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Cursor; import org.eclipse.swt.graphics.Point; import org.geotools.swt.SwtMapPane; @@ -50,12 +51,15 @@ boolean panning; /** - * Constructs a new pan tool. - * @param triggeringMouseButton Mouse button which triggers the tool's activation + * Constructs a new pan tool. To activate the tool only on certain + * mouse events provide a single mask, e.g. {@link SWT#BUTTON1}, or + * a combination of multiple SWT-masks. + * + * @param triggerButtonMask Mouse button which triggers the tool's activation * or {@value #ANY_BUTTON} if the tool is to be triggered by any button */ - public PanTool(int triggeringMouseButton) { - super(triggeringMouseButton); + public PanTool(int triggerButtonMask) { + super(triggerButtonMask); cursor = CursorManager.getInstance().getPanCursor(); Modified: trunk/modules/unsupported/swt/src/main/java/org/geotools/swt/tool/ZoomInTool.java =================================================================== --- trunk/modules/unsupported/swt/src/main/java/org/geotools/swt/tool/ZoomInTool.java 2012-04-20 10:03:30 UTC (rev 38680) +++ trunk/modules/unsupported/swt/src/main/java/org/geotools/swt/tool/ZoomInTool.java 2012-04-20 15:10:20 UTC (rev 38681) @@ -22,6 +22,7 @@ import java.awt.geom.Point2D; +import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Cursor; import org.eclipse.swt.graphics.Rectangle; import org.geotools.geometry.DirectPosition2D; @@ -62,12 +63,15 @@ private boolean dragged; /** - * Constructs a new zoom in tool. - * @param triggeringMouseButton Mouse button which triggers the tool's activation + * Constructs a new zoom in tool. To activate the tool only on certain + * mouse events provide a single mask, e.g. {@link SWT#BUTTON1}, or + * a combination of multiple SWT-masks. + * + * @param triggerButtonMask Mouse button which triggers the tool's activation * or {@value #ANY_BUTTON} if the tool is to be triggered by any button */ - public ZoomInTool(int triggeringMouseButton) { - super(triggeringMouseButton); + public ZoomInTool(int triggerButtonMask) { + super(triggerButtonMask); cursor = CursorManager.getInstance().getZoominCursor(); @@ -177,7 +181,12 @@ return false; } - public static double pythagoras( double d1, double d2 ) { + @Override + public boolean isDrawing() { + return dragged; + } + + public static double pythagoras( double d1, double d2 ) { return sqrt(pow(d1, 2.0) + pow(d2, 2.0)); } } Modified: trunk/modules/unsupported/swt/src/main/java/org/geotools/swt/tool/ZoomOutTool.java =================================================================== --- trunk/modules/unsupported/swt/src/main/java/org/geotools/swt/tool/ZoomOutTool.java 2012-04-20 10:03:30 UTC (rev 38680) +++ trunk/modules/unsupported/swt/src/main/java/org/geotools/swt/tool/ZoomOutTool.java 2012-04-20 15:10:20 UTC (rev 38681) @@ -17,6 +17,7 @@ package org.geotools.swt.tool; +import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Cursor; import org.eclipse.swt.graphics.Rectangle; import org.geotools.geometry.DirectPosition2D; @@ -52,12 +53,15 @@ private Cursor cursor; /** - * Constructs a new zoom out tool. - * @param triggeringMouseButton Mouse button which triggers the tool's activation + * Constructs a new zoom out tool. To activate the tool only on certain + * mouse events provide a single mask, e.g. {@link SWT#BUTTON1}, or + * a combination of multiple SWT-masks. + * + * @param triggerButtonMask Mouse button which triggers the tool's activation * or {@value #ANY_BUTTON} if the tool is to be triggered by any button */ - public ZoomOutTool(int triggeringMouseButton) { - super(triggeringMouseButton); + public ZoomOutTool(int triggerButtonMask) { + super(triggerButtonMask); cursor = CursorManager.getInstance().getZoomoutCursor(); } @@ -105,7 +109,7 @@ } public boolean canDraw() { - return true; + return false; } public boolean canMove() { |
From: <svn...@os...> - 2012-04-20 10:03:44
|
Author: moovida Date: 2012-04-20 03:03:30 -0700 (Fri, 20 Apr 2012) New Revision: 38680 Modified: trunk/modules/unsupported/swt/src/main/java/org/geotools/swt/event/MapMouseEvent.java trunk/modules/unsupported/swt/src/main/java/org/geotools/swt/tool/AbstractZoomTool.java trunk/modules/unsupported/swt/src/main/java/org/geotools/swt/tool/CursorTool.java trunk/modules/unsupported/swt/src/main/java/org/geotools/swt/tool/InfoTool.java trunk/modules/unsupported/swt/src/main/java/org/geotools/swt/tool/PanTool.java trunk/modules/unsupported/swt/src/main/java/org/geotools/swt/tool/ZoomInTool.java trunk/modules/unsupported/swt/src/main/java/org/geotools/swt/tool/ZoomOutTool.java Log: applying patch GEOT-4112 Modified: trunk/modules/unsupported/swt/src/main/java/org/geotools/swt/event/MapMouseEvent.java =================================================================== --- trunk/modules/unsupported/swt/src/main/java/org/geotools/swt/event/MapMouseEvent.java 2012-04-20 08:34:35 UTC (rev 38679) +++ trunk/modules/unsupported/swt/src/main/java/org/geotools/swt/event/MapMouseEvent.java 2012-04-20 10:03:30 UTC (rev 38680) @@ -97,6 +97,18 @@ } /** + * The button that was pressed or released; 1 for the + * first button, 2 for the second button, and 3 for the + * third button, etc. + * + * @return the button that was pressed or released + * @see MouseEvent#button + */ + public int getMouseButton() { + return event.button; + } + + /** * Get the position, in map (world) coordinates of this mouse event * * @return a new DirectPosition2D object for the world coordinates Modified: trunk/modules/unsupported/swt/src/main/java/org/geotools/swt/tool/AbstractZoomTool.java =================================================================== --- trunk/modules/unsupported/swt/src/main/java/org/geotools/swt/tool/AbstractZoomTool.java 2012-04-20 08:34:35 UTC (rev 38679) +++ trunk/modules/unsupported/swt/src/main/java/org/geotools/swt/tool/AbstractZoomTool.java 2012-04-20 10:03:30 UTC (rev 38680) @@ -38,11 +38,22 @@ protected double zoom; /** - * Constructor + * Constructs a new abstract zoom tool. + * @param triggeringMouseButton Mouse button which triggers the tool's activation + * or {@value #ANY_BUTTON} if the tool is to be triggered by any button */ - public AbstractZoomTool() { - setZoom(DEFAULT_ZOOM_FACTOR); - } + public AbstractZoomTool(int triggeringMouseButton) { + super(triggeringMouseButton); + setZoom(DEFAULT_ZOOM_FACTOR); + } + + /** + * Constructs a new abstract zoom tool which is triggered by any mouse button. + */ + public AbstractZoomTool() { + this(CursorTool.ANY_BUTTON); + } + /** * Get the current areal zoom increment. Modified: trunk/modules/unsupported/swt/src/main/java/org/geotools/swt/tool/CursorTool.java =================================================================== --- trunk/modules/unsupported/swt/src/main/java/org/geotools/swt/tool/CursorTool.java 2012-04-20 08:34:35 UTC (rev 38679) +++ trunk/modules/unsupported/swt/src/main/java/org/geotools/swt/tool/CursorTool.java 2012-04-20 10:03:30 UTC (rev 38680) @@ -20,6 +20,7 @@ import org.eclipse.swt.graphics.Cursor; import org.geotools.swt.SwtMapPane; import org.geotools.swt.event.MapMouseAdapter; +import org.geotools.swt.event.MapMouseEvent; import org.geotools.swt.utils.CursorManager; import org.geotools.swt.utils.Messages; @@ -36,9 +37,33 @@ */ public abstract class CursorTool extends MapMouseAdapter { + /** + * Flag indicating that the tool should be triggered whenever any mouse button + * is used. + */ + public static final int ANY_BUTTON = -1; + private SwtMapPane mapPane; + private int triggeringMouseButton; + /** + * Constructs a new cursor tool. + * @param triggeringMouseButton Mouse button which triggers the tool's activation + * or {@value #ANY_BUTTON} if the tool is to be triggered by any button + */ + public CursorTool(int triggeringMouseButton) { + this.triggeringMouseButton = triggeringMouseButton; + } + + /** + * Constructs a new cursor tool which is triggered by any mouse button. + */ + public CursorTool() { + this(ANY_BUTTON); + } + + /** * Set the map pane that this cursor tool is associated with * @param pane the map pane * @throws IllegalArgumentException if mapPane is null @@ -83,4 +108,14 @@ * @return <code>true</code> if the tool can move the map while dragging. */ public abstract boolean canMove(); + + /** + * Checks if the tool should be triggered by the event. + * @param event event to be checked + * @return <code>true</code> if the tool is triggered by the event + */ + protected boolean isTriggerMouseButton(MapMouseEvent event) + { + return triggeringMouseButton == ANY_BUTTON || triggeringMouseButton == event.getMouseButton(); + } } Modified: trunk/modules/unsupported/swt/src/main/java/org/geotools/swt/tool/InfoTool.java =================================================================== --- trunk/modules/unsupported/swt/src/main/java/org/geotools/swt/tool/InfoTool.java 2012-04-20 08:34:35 UTC (rev 38679) +++ trunk/modules/unsupported/swt/src/main/java/org/geotools/swt/tool/InfoTool.java 2012-04-20 10:03:30 UTC (rev 38680) @@ -84,16 +84,28 @@ private WeakHashMap<Layer, InfoToolHelper<?>> helperTable; /** - * Constructor + * Constructs a new info tool. + * @param triggeringMouseButton Mouse button which triggers the tool's activation + * or {@value #ANY_BUTTON} if the tool is to be triggered by any button */ - public InfoTool() { + public InfoTool(int triggeringMouseButton) { + super(triggeringMouseButton); + cursor = CursorManager.getInstance().getInfoCursor(); helperTable = new WeakHashMap<Layer, InfoToolHelper<?>>(); } /** + * Constructs a new info tool which is triggered by any mouse button. + */ + public InfoTool() { + this(CursorTool.ANY_BUTTON); + } + + + /** * Respond to a mouse click by querying each of the {@code MapLayers}. The * details of features lying within the threshold distance of the mouse * position are reported on screen using a {@code JTextReporter} dialog. @@ -111,6 +123,11 @@ */ @Override public void onMouseClicked( MapMouseEvent ev ) { + + if ( ! isTriggerMouseButton(ev)) { + return; + } + DirectPosition2D pos = ev.getMapPosition(); report(pos); Modified: trunk/modules/unsupported/swt/src/main/java/org/geotools/swt/tool/PanTool.java =================================================================== --- trunk/modules/unsupported/swt/src/main/java/org/geotools/swt/tool/PanTool.java 2012-04-20 08:34:35 UTC (rev 38679) +++ trunk/modules/unsupported/swt/src/main/java/org/geotools/swt/tool/PanTool.java 2012-04-20 10:03:30 UTC (rev 38680) @@ -50,21 +50,37 @@ boolean panning; /** - * Constructor + * Constructs a new pan tool. + * @param triggeringMouseButton Mouse button which triggers the tool's activation + * or {@value #ANY_BUTTON} if the tool is to be triggered by any button */ - public PanTool() { + public PanTool(int triggeringMouseButton) { + super(triggeringMouseButton); + cursor = CursorManager.getInstance().getPanCursor(); panning = false; } /** + * Constructs a new pan tool which is triggered by any mouse button. + */ + public PanTool() { + this(CursorTool.ANY_BUTTON); + } + + /** * Respond to a mouse button press event from the map mapPane. This may * signal the start of a mouse drag. Records the event's window position. * @param ev the mouse event */ @Override public void onMousePressed( MapMouseEvent ev ) { + + if ( ! isTriggerMouseButton(ev)) { + return; + } + panePos = ev.getPoint(); panning = true; } @@ -91,8 +107,10 @@ */ @Override public void onMouseReleased( MapMouseEvent ev ) { - panning = false; - getMapPane().redraw(); + if (panning) { + panning = false; + getMapPane().redraw(); + } } /** Modified: trunk/modules/unsupported/swt/src/main/java/org/geotools/swt/tool/ZoomInTool.java =================================================================== --- trunk/modules/unsupported/swt/src/main/java/org/geotools/swt/tool/ZoomInTool.java 2012-04-20 08:34:35 UTC (rev 38679) +++ trunk/modules/unsupported/swt/src/main/java/org/geotools/swt/tool/ZoomInTool.java 2012-04-20 10:03:30 UTC (rev 38680) @@ -62,9 +62,13 @@ private boolean dragged; /** - * Constructor + * Constructs a new zoom in tool. + * @param triggeringMouseButton Mouse button which triggers the tool's activation + * or {@value #ANY_BUTTON} if the tool is to be triggered by any button */ - public ZoomInTool() { + public ZoomInTool(int triggeringMouseButton) { + super(triggeringMouseButton); + cursor = CursorManager.getInstance().getZoominCursor(); startDragPos = new DirectPosition2D(); @@ -72,6 +76,13 @@ } /** + * Constructs a new zoom in tool which is triggered by any mouse button. + */ + public ZoomInTool() { + this(CursorTool.ANY_BUTTON); + } + + /** * Zoom in by the currently set increment, with the map * centred at the location (in world coords) of the mouse * click @@ -80,6 +91,11 @@ */ @Override public void onMouseClicked( MapMouseEvent e ) { + + if ( ! isTriggerMouseButton(e)) { + return; + } + startDragPos = new DirectPosition2D(); startDragPos.setLocation(e.getMapPosition()); } @@ -101,6 +117,11 @@ */ @Override public void onMouseDragged( MapMouseEvent ev ) { + + if ( ! isTriggerMouseButton(ev)) { + return; + } + dragged = true; } @@ -114,6 +135,11 @@ */ @Override public void onMouseReleased( MapMouseEvent ev ) { + + if ( ! isTriggerMouseButton(ev)) { + return; + } + if (dragged) { Envelope2D env = new Envelope2D(); env.setFrameFromDiagonal(startDragPos, ev.getMapPosition()); Modified: trunk/modules/unsupported/swt/src/main/java/org/geotools/swt/tool/ZoomOutTool.java =================================================================== --- trunk/modules/unsupported/swt/src/main/java/org/geotools/swt/tool/ZoomOutTool.java 2012-04-20 08:34:35 UTC (rev 38679) +++ trunk/modules/unsupported/swt/src/main/java/org/geotools/swt/tool/ZoomOutTool.java 2012-04-20 10:03:30 UTC (rev 38680) @@ -52,13 +52,23 @@ private Cursor cursor; /** - * Constructor + * Constructs a new zoom out tool. + * @param triggeringMouseButton Mouse button which triggers the tool's activation + * or {@value #ANY_BUTTON} if the tool is to be triggered by any button */ - public ZoomOutTool() { + public ZoomOutTool(int triggeringMouseButton) { + super(triggeringMouseButton); cursor = CursorManager.getInstance().getZoomoutCursor(); } /** + * Constructs a new zoom out tool which is triggered by any mouse button. + */ + public ZoomOutTool() { + this(CursorTool.ANY_BUTTON); + } + + /** * Zoom out by the currently set increment, with the map * centred at the location (in world coords) of the mouse * click @@ -67,6 +77,11 @@ */ @Override public void onMouseClicked( MapMouseEvent ev ) { + + if ( ! isTriggerMouseButton(ev)) { + return; + } + Rectangle paneArea = getMapPane().getBounds(); DirectPosition2D mapPos = ev.getMapPosition(); |
From: <svn...@os...> - 2012-04-20 08:34:42
|
Author: ang05a Date: 2012-04-20 01:34:35 -0700 (Fri, 20 Apr 2012) New Revision: 38679 Modified: trunk/modules/extension/app-schema/app-schema/src/main/java/org/geotools/data/complex/DataAccessMappingFeatureIterator.java trunk/modules/extension/app-schema/app-schema/src/main/java/org/geotools/jdbc/JoiningJDBCFeatureSource.java Log: GEOT-4116: App-schema joining needs to sort by primary key Modified: trunk/modules/extension/app-schema/app-schema/src/main/java/org/geotools/data/complex/DataAccessMappingFeatureIterator.java =================================================================== --- trunk/modules/extension/app-schema/app-schema/src/main/java/org/geotools/data/complex/DataAccessMappingFeatureIterator.java 2012-04-20 01:57:09 UTC (rev 38678) +++ trunk/modules/extension/app-schema/app-schema/src/main/java/org/geotools/data/complex/DataAccessMappingFeatureIterator.java 2012-04-20 08:34:35 UTC (rev 38679) @@ -20,9 +20,7 @@ import java.io.IOException; import java.net.URI; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; -import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; @@ -32,7 +30,6 @@ import javax.xml.namespace.QName; -import org.apache.commons.lang.math.NumberUtils; import org.apache.commons.lang.StringUtils; import org.geotools.data.DataAccess; import org.geotools.data.DataSourceException; @@ -92,35 +89,6 @@ * @since 2.4 */ public class DataAccessMappingFeatureIterator extends AbstractMappingFeatureIterator { - - class ValueComparator implements Comparator { - @Override - public int compare(Object o1, Object o2) { - if (o1 == null) { - if (o2 == null) { - return 0; - } else { - return -1; - } - } - if (o2 == null) { - return 1; - } - - String string1 = o1.toString(); - String string2 = o2.toString(); - - // in case numbers are stored as string, make sure the order is correct - if (NumberUtils.isNumber(string1) && NumberUtils.isNumber(string2)) { - return Double.valueOf(string1).compareTo(Double.valueOf(string2)); - } - - if (o1 instanceof Comparable) { - return ((Comparable) o1).compareTo(o2); - } - return string1.compareTo(string2); - } - } /** * Hold on to iterator to allow features to be streamed. */ @@ -151,8 +119,6 @@ private ArrayList<String> filteredFeatures; - private ValueComparator comparator; - public DataAccessMappingFeatureIterator(AppSchemaDataAccess store, FeatureTypeMapping mapping, Query query, boolean isFiltered) throws IOException { this(store, mapping, query, null); @@ -861,11 +827,7 @@ for (Feature source : sources) { values[i] = getValue(sourceExpr, source); i++; - } - if (comparator == null) { - comparator = new ValueComparator(); } - Arrays.sort(values, comparator); String valueString = StringUtils.join(values, " "); StepList fullPath = attMapping.getTargetXPath(); StepList leafPath = fullPath.subList(fullPath.size() - 1, fullPath.size()); Modified: trunk/modules/extension/app-schema/app-schema/src/main/java/org/geotools/jdbc/JoiningJDBCFeatureSource.java =================================================================== --- trunk/modules/extension/app-schema/app-schema/src/main/java/org/geotools/jdbc/JoiningJDBCFeatureSource.java 2012-04-20 01:57:09 UTC (rev 38678) +++ trunk/modules/extension/app-schema/app-schema/src/main/java/org/geotools/jdbc/JoiningJDBCFeatureSource.java 2012-04-20 08:34:35 UTC (rev 38679) @@ -23,10 +23,12 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.util.HashSet; +import java.util.LinkedHashSet; import java.util.Set; import java.util.concurrent.atomic.AtomicReference; import java.util.logging.Logger; +import org.apache.commons.lang.StringUtils; import org.geotools.data.FeatureReader; import org.geotools.data.Query; import org.geotools.data.Transaction; @@ -131,45 +133,46 @@ * * @param tableName * @param sort - * @param sql + * @param orderByFields * @throws IOException * @throws SQLException */ - protected void sort(String tableName, SortBy[] sort , StringBuffer sql, boolean alias) throws IOException, SQLException { + protected void sort(String tableName, SortBy[] sort , Set<String> orderByFields, boolean alias) throws IOException, SQLException { for (int i = 0; i < sort.length; i++) { - String order; - if (sort[i].getSortOrder() == SortOrder.DESCENDING) { - order = " DESC"; - } else { - order = " ASC"; - } - if(SortBy.NATURAL_ORDER.equals(sort[i])|| SortBy.REVERSE_ORDER.equals(sort[i])) { throw new IOException("Cannot do natural order in joining queries"); } else { + StringBuffer sql = new StringBuffer(); if (alias) { - encodeColumnName2(sort[i].getPropertyName().getPropertyName(), tableName , sql, null); + encodeColumnName2(sort[i].getPropertyName().getPropertyName(), tableName, sql, null); } else { - encodeColumnName(sort[i].getPropertyName().getPropertyName(), tableName , sql, null); + encodeColumnName(sort[i].getPropertyName().getPropertyName(), tableName, sql, null); } - sql.append(order); - sql.append(","); + if (sort[i].getSortOrder() == SortOrder.DESCENDING) { + sql.append(" DESC"); + } else { + sql.append(" ASC"); + } + if (!sql.toString().isEmpty()) { + orderByFields.add(sql.toString()); + } } } } - protected void addMultiValuedSort(String tableName, StringBuffer sql, + protected void addMultiValuedSort(String tableName, Set<String> orderByFields, JoiningQuery.QueryJoin join) throws IOException, FilterToSQLException, SQLException { - sql.append(" CASE WHEN "); + StringBuffer orderString = new StringBuffer(" CASE WHEN "); FilterToSQL toSQL1 = createFilterToSQL(getDataStore().getSchema(tableName)); toSQL1.setFieldEncoder(new JoiningFieldEncoder(tableName)); FilterToSQL toSQL2 = createFilterToSQL(getDataStore().getSchema(join.getJoiningTypeName())); toSQL2.setFieldEncoder(new JoiningFieldEncoder(join.getJoiningTypeName())); - sql.append(toSQL2.encodeToString(join.getForeignKeyName())); - sql.append(" = "); - sql.append(toSQL1.encodeToString(join.getJoiningKeyName())); - sql.append(" THEN 0 ELSE 1 END ASC,"); + orderString.append(toSQL2.encodeToString(join.getForeignKeyName())); + orderString.append(" = "); + orderString.append(toSQL1.encodeToString(join.getJoiningKeyName())); + orderString.append(" THEN 0 ELSE 1 END ASC"); + orderByFields.add(orderString.toString()); } /** @@ -181,9 +184,9 @@ * @throws IOException * @throws SQLException */ - protected void sort(JoiningQuery query, StringBuffer sql, String[] aliases) throws IOException, SQLException, FilterToSQLException { + protected void sort(JoiningQuery query, StringBuffer sql, String[] aliases, Set<String> pkColumnNames) throws IOException, SQLException, FilterToSQLException { boolean orderby = false; - + Set<String> orderByFields = new LinkedHashSet<String>(); for (int j = query.getQueryJoins() == null? -1 : query.getQueryJoins().size() -1; j >= -1 ; j-- ) { JoiningQuery.QueryJoin join = j<0 ? null : query.getQueryJoins().get(j); SortBy[] sort = j<0? query.getSortBy() : join.getSortBy(); @@ -194,26 +197,41 @@ sql.append(" ORDER BY "); } if (j < 0) { - sort(query.getTypeName(), sort, sql, false); + sort(query.getTypeName(), sort, orderByFields, false); if (query.getQueryJoins() != null && query.getQueryJoins().size() > 0) { - addMultiValuedSort(query.getTypeName(), sql, query.getQueryJoins().get(0)); + addMultiValuedSort(query.getTypeName(), orderByFields, query.getQueryJoins().get(0)); } + if (!pkColumnNames.isEmpty()) { + for (String pk : pkColumnNames) { + orderByFields.add(query.getTypeName() + "." + pk); + } + } } else { if (aliases != null && aliases[j] != null) { - sort(aliases[j], sort, sql, true); + sort(aliases[j], sort, orderByFields, true); } else { - sort(join.getJoiningTypeName(), sort, sql, false); + sort(join.getJoiningTypeName(), sort, orderByFields, false); } if (query.getQueryJoins().size() > j + 1) { - addMultiValuedSort(join.getJoiningTypeName(), sql, query.getQueryJoins() - .get(j + 1)); - } + addMultiValuedSort(join.getJoiningTypeName(), orderByFields, query + .getQueryJoins().get(j + 1)); + } + try { + // sort by primary key to cater for multi valued rows + JDBCDataStore ds = getDataStore(); + PrimaryKey key = ds.getPrimaryKey(ds.getSchema(join.getJoiningTypeName())); + pkColumnNames = new HashSet<String>(); + for (PrimaryKeyColumn pkCol : key.getColumns()) { + pkColumnNames.add(pkCol.getName()); + } + } catch (IOException e) { + throw new RuntimeException(e); + } } } - } - + } if (orderby) { - sql.setLength(sql.length() - 1); + sql.append(StringUtils.join(orderByFields.toArray(), ", ")); } } @@ -370,11 +388,13 @@ } catch (IOException e) { throw new RuntimeException(e); } - Set<String> pkColumnNames = getDataStore().getColumnNames(key); - + Set<String> pkColumnNames = new HashSet<String>(); + String colName; for ( PrimaryKeyColumn col : key.getColumns() ) { - encodeColumnName(col.getName(), featureType.getTypeName(), sql, query.getHints()); + colName = col.getName(); + encodeColumnName(colName, featureType.getTypeName(), sql, query.getHints()); sql.append(","); + pkColumnNames.add(colName); } //other columns @@ -471,7 +491,7 @@ } //sorting - sort(query, sql, aliases); + sort(query, sql, aliases, pkColumnNames); // finally encode limit/offset, if necessary getDataStore().applyLimitOffset(sql, query); |
From: <svn...@os...> - 2012-04-20 01:57:16
|
Author: jive Date: 2012-04-19 18:57:09 -0700 (Thu, 19 Apr 2012) New Revision: 38678 Modified: trunk/modules/library/cql/src/main/java/org/geotools/filter/text/commons/FilterToTextUtil.java trunk/modules/library/cql/src/test/java/org/geotools/filter/text/ecql/ECQLTest.java Log: Update FilterToTextUtil to represent Filter.INCLUDE as INCLUDE - now matches ECQL parser as per GEOT-4110 Modified: trunk/modules/library/cql/src/main/java/org/geotools/filter/text/commons/FilterToTextUtil.java =================================================================== --- trunk/modules/library/cql/src/main/java/org/geotools/filter/text/commons/FilterToTextUtil.java 2012-04-19 09:06:22 UTC (rev 38677) +++ trunk/modules/library/cql/src/main/java/org/geotools/filter/text/commons/FilterToTextUtil.java 2012-04-20 01:57:09 UTC (rev 38678) @@ -80,13 +80,13 @@ public static Object buildInclude(Object extraData) { StringBuilder output = FilterToTextUtil.asStringBuilder(extraData); - output.append("1 = 1"); + output.append("INCLUDE"); return output; } public static Object buildExclude(Object extraData) { StringBuilder output = FilterToTextUtil.asStringBuilder(extraData); - output.append("1 = 0"); + output.append("EXCLUDE"); return output; } Modified: trunk/modules/library/cql/src/test/java/org/geotools/filter/text/ecql/ECQLTest.java =================================================================== --- trunk/modules/library/cql/src/test/java/org/geotools/filter/text/ecql/ECQLTest.java 2012-04-19 09:06:22 UTC (rev 38677) +++ trunk/modules/library/cql/src/test/java/org/geotools/filter/text/ecql/ECQLTest.java 2012-04-20 01:57:09 UTC (rev 38678) @@ -29,9 +29,11 @@ import org.junit.Assert; import org.junit.Test; import org.opengis.filter.And; +import org.opengis.filter.ExcludeFilter; import org.opengis.filter.Filter; import org.opengis.filter.FilterFactory; import org.opengis.filter.Id; +import org.opengis.filter.IncludeFilter; import org.opengis.filter.Not; import org.opengis.filter.Or; import org.opengis.filter.PropertyIsBetween; @@ -74,6 +76,27 @@ */ public final class ECQLTest { + @Test + public void include() throws CQLException{ + + Assert.assertEquals("INCLUDE", ECQL.toCQL(Filter.INCLUDE) ); + + Filter filter = ECQL.toFilter("INCLUDE"); + + Assert.assertEquals(Filter.INCLUDE, filter); + } + + @Test + public void exclude() throws CQLException{ + + Assert.assertEquals("EXCLUDE", ECQL.toCQL(Filter.EXCLUDE) ); + + Filter filter = ECQL.toFilter("EXCLUDE"); + + Assert.assertEquals(Filter.EXCLUDE, filter); + + } + /** * Between predicate sample |
From: <svn...@os...> - 2012-04-19 09:06:33
|
Author: jive Date: 2012-04-19 02:06:22 -0700 (Thu, 19 Apr 2012) New Revision: 38677 Modified: trunk/modules/library/main/src/main/java/org/geotools/styling/SLDTransformer.java Log: Fix how colour map is encoded as per GEOT-4109 Modified: trunk/modules/library/main/src/main/java/org/geotools/styling/SLDTransformer.java =================================================================== --- trunk/modules/library/main/src/main/java/org/geotools/styling/SLDTransformer.java 2012-04-18 13:43:21 UTC (rev 38676) +++ trunk/modules/library/main/src/main/java/org/geotools/styling/SLDTransformer.java 2012-04-19 09:06:22 UTC (rev 38677) @@ -524,9 +524,9 @@ if(!"ramp".equals(typeString)) { atts.addAttribute("", "type", "type", "", typeString); } - - if(colorMap.getExtendedColors()) { - atts.addAttribute("", "extended", "extended", "", typeString); + final boolean extended = colorMap.getExtendedColors(); + if(extended) { + atts.addAttribute("", "extended", "extended", "", ""+extended); } start("ColorMap", atts); |
From: <svn...@os...> - 2012-04-18 13:43:32
|
Author: jdeolive Date: 2012-04-18 06:43:21 -0700 (Wed, 18 Apr 2012) New Revision: 38676 Modified: trunk/modules/extension/xsd/xsd-gml3/src/test/java/org/geotools/gml3/GML3EncodingTest.java Log: GEOT-4111, fixing issue with schema path containing space, patch supplied by Brett Walker Modified: trunk/modules/extension/xsd/xsd-gml3/src/test/java/org/geotools/gml3/GML3EncodingTest.java =================================================================== --- trunk/modules/extension/xsd/xsd-gml3/src/test/java/org/geotools/gml3/GML3EncodingTest.java 2012-04-18 13:42:37 UTC (rev 38675) +++ trunk/modules/extension/xsd/xsd-gml3/src/test/java/org/geotools/gml3/GML3EncodingTest.java 2012-04-18 13:43:21 UTC (rev 38676) @@ -120,8 +120,8 @@ return; } - String schemaLocation = new File(TestConfiguration.class.getResource("test.xsd").getFile()) - .getAbsolutePath(); + // The schema location needs to be a well formed URI/URL, a file path is not sufficient. + String schemaLocation = TestConfiguration.class.getResource("test.xsd").toString(); ApplicationSchemaConfiguration configuration = new ApplicationSchemaConfiguration(TEST.NAMESPACE, schemaLocation); |
From: <svn...@os...> - 2012-04-18 13:42:49
|
Author: jdeolive Date: 2012-04-18 06:42:37 -0700 (Wed, 18 Apr 2012) New Revision: 38675 Modified: branches/2.7.x/modules/extension/xsd/xsd-gml3/src/test/java/org/geotools/gml3/GML3EncodingTest.java Log: GEOT-4111, fixing issue with schema path containing space, patch supplied by Brett Walker Modified: branches/2.7.x/modules/extension/xsd/xsd-gml3/src/test/java/org/geotools/gml3/GML3EncodingTest.java =================================================================== --- branches/2.7.x/modules/extension/xsd/xsd-gml3/src/test/java/org/geotools/gml3/GML3EncodingTest.java 2012-04-16 03:06:37 UTC (rev 38674) +++ branches/2.7.x/modules/extension/xsd/xsd-gml3/src/test/java/org/geotools/gml3/GML3EncodingTest.java 2012-04-18 13:42:37 UTC (rev 38675) @@ -115,8 +115,8 @@ return; } - String schemaLocation = new File(TestConfiguration.class.getResource("test.xsd").getFile()) - .getAbsolutePath(); + // The schema location needs to be a well formed URI/URL, a file path is not sufficient. + String schemaLocation = TestConfiguration.class.getResource("test.xsd").toString(); ApplicationSchemaConfiguration configuration = new ApplicationSchemaConfiguration(TEST.NAMESPACE, schemaLocation); |
From: <svn...@os...> - 2012-04-16 03:06:44
|
Author: bencaradocdavies Date: 2012-04-15 20:06:37 -0700 (Sun, 15 Apr 2012) New Revision: 38674 Modified: branches/2.7.x/modules/library/main/src/main/java/org/geotools/filter/function/StaticGeometry.java branches/2.7.x/modules/library/main/src/test/java/org/geotools/filter/function/StringFunctionTest.java Log: GEOT-4103: Can't select last character with OCQL strSubstring() Modified: branches/2.7.x/modules/library/main/src/main/java/org/geotools/filter/function/StaticGeometry.java =================================================================== --- branches/2.7.x/modules/library/main/src/main/java/org/geotools/filter/function/StaticGeometry.java 2012-04-16 03:06:09 UTC (rev 38673) +++ branches/2.7.x/modules/library/main/src/main/java/org/geotools/filter/function/StaticGeometry.java 2012-04-16 03:06:37 UTC (rev 38674) @@ -546,14 +546,14 @@ static public String strSubstring(String s1, Integer beg, Integer end) { if (s1 == null || beg == null || end == null) return null; - if (beg < 0 || end < 0 || beg >= s1.length() || end >= s1.length()) return null; + if (beg < 0 || end > s1.length() || beg > end) return null; return s1.substring(beg,end); } static public String strSubstringStart(String s1, Integer beg) { if (s1 == null || beg == null) return null; - if (beg < 0 || beg >= s1.length()) return null; + if (beg < 0 || beg > s1.length()) return null; return s1.substring(beg); } Modified: branches/2.7.x/modules/library/main/src/test/java/org/geotools/filter/function/StringFunctionTest.java =================================================================== --- branches/2.7.x/modules/library/main/src/test/java/org/geotools/filter/function/StringFunctionTest.java 2012-04-16 03:06:09 UTC (rev 38673) +++ branches/2.7.x/modules/library/main/src/test/java/org/geotools/filter/function/StringFunctionTest.java 2012-04-16 03:06:37 UTC (rev 38674) @@ -17,6 +17,7 @@ package org.geotools.filter.function; import static junit.framework.Assert.assertEquals; +import static junit.framework.Assert.assertNull; import org.geotools.factory.CommonFactoryFinder; import org.junit.Test; @@ -91,4 +92,70 @@ assertEquals("4", ff.function("strPosition", ff.literal("l"), ff.literal("hello"), ff.literal("backToFront")).evaluate(null, String.class)); } + + @Test + public void testStrSubstring() throws Exception { + // test bad ranges return null + assertNull(ff.function("strSubstring", ff.literal("ABCD"), ff.literal(-1), ff.literal(2)) + .evaluate(null)); + assertNull(ff.function("strSubstring", ff.literal("ABCD"), ff.literal(2), ff.literal(5)) + .evaluate(null)); + assertNull(ff.function("strSubstring", ff.literal("ABCD"), ff.literal(3), ff.literal(2)) + .evaluate(null)); + // test empty string input + assertEquals("", ff.function("strSubstring", ff.literal(""), ff.literal(0), ff.literal(0)) + .evaluate(null)); + // test empty string output + assertEquals("", + ff.function("strSubstring", ff.literal("ABCD"), ff.literal(0), ff.literal(0)) + .evaluate(null)); + assertEquals("", + ff.function("strSubstring", ff.literal("ABCD"), ff.literal(2), ff.literal(2)) + .evaluate(null)); + assertEquals("", + ff.function("strSubstring", ff.literal("ABCD"), ff.literal(4), ff.literal(4)) + .evaluate(null)); + // test non-empty substrings + assertEquals("ABCD", + ff.function("strSubstring", ff.literal("ABCD"), ff.literal(0), ff.literal(4)) + .evaluate(null)); + assertEquals("A", + ff.function("strSubstring", ff.literal("ABCD"), ff.literal(0), ff.literal(1)) + .evaluate(null)); + assertEquals("AB", + ff.function("strSubstring", ff.literal("ABCD"), ff.literal(0), ff.literal(2)) + .evaluate(null)); + assertEquals("BC", + ff.function("strSubstring", ff.literal("ABCD"), ff.literal(1), ff.literal(3)) + .evaluate(null)); + assertEquals("CD", + ff.function("strSubstring", ff.literal("ABCD"), ff.literal(2), ff.literal(4)) + .evaluate(null)); + assertEquals("D", + ff.function("strSubstring", ff.literal("ABCD"), ff.literal(3), ff.literal(4)) + .evaluate(null)); + } + + @Test + public void testStrSubstringStart() throws Exception { + // test bad index returns null + assertNull(ff.function("strSubstringStart", ff.literal("ABCD"), ff.literal(-1)).evaluate( + null)); + assertNull(ff.function("strSubstringStart", ff.literal("ABCD"), ff.literal(5)).evaluate( + null)); + // test empty string input + assertEquals("", + ff.function("strSubstringStart", ff.literal(""), ff.literal(0)).evaluate(null)); + // test empty string output + assertEquals("", ff.function("strSubstringStart", ff.literal("ABCD"), ff.literal(4)) + .evaluate(null)); + // test non-empty substrings + assertEquals("ABCD", ff.function("strSubstringStart", ff.literal("ABCD"), ff.literal(0)) + .evaluate(null)); + assertEquals("CD", ff.function("strSubstringStart", ff.literal("ABCD"), ff.literal(2)) + .evaluate(null)); + assertEquals("D", ff.function("strSubstringStart", ff.literal("ABCD"), ff.literal(3)) + .evaluate(null)); + } + } |
From: <svn...@os...> - 2012-04-16 03:06:16
|
Author: bencaradocdavies Date: 2012-04-15 20:06:09 -0700 (Sun, 15 Apr 2012) New Revision: 38673 Modified: trunk/modules/library/main/src/main/java/org/geotools/filter/function/StaticGeometry.java trunk/modules/library/main/src/test/java/org/geotools/filter/function/StringFunctionTest.java Log: GEOT-4103: Can't select last character with OCQL strSubstring() Modified: trunk/modules/library/main/src/main/java/org/geotools/filter/function/StaticGeometry.java =================================================================== --- trunk/modules/library/main/src/main/java/org/geotools/filter/function/StaticGeometry.java 2012-04-16 00:52:09 UTC (rev 38672) +++ trunk/modules/library/main/src/main/java/org/geotools/filter/function/StaticGeometry.java 2012-04-16 03:06:09 UTC (rev 38673) @@ -560,14 +560,14 @@ static public String strSubstring(String s1, Integer beg, Integer end) { if (s1 == null || beg == null || end == null) return null; - if (beg < 0 || end < 0 || beg >= s1.length() || end >= s1.length()) return null; + if (beg < 0 || end > s1.length() || beg > end) return null; return s1.substring(beg,end); } static public String strSubstringStart(String s1, Integer beg) { if (s1 == null || beg == null) return null; - if (beg < 0 || beg >= s1.length()) return null; + if (beg < 0 || beg > s1.length()) return null; return s1.substring(beg); } Modified: trunk/modules/library/main/src/test/java/org/geotools/filter/function/StringFunctionTest.java =================================================================== --- trunk/modules/library/main/src/test/java/org/geotools/filter/function/StringFunctionTest.java 2012-04-16 00:52:09 UTC (rev 38672) +++ trunk/modules/library/main/src/test/java/org/geotools/filter/function/StringFunctionTest.java 2012-04-16 03:06:09 UTC (rev 38673) @@ -17,6 +17,7 @@ package org.geotools.filter.function; import static junit.framework.Assert.assertEquals; +import static junit.framework.Assert.assertNull; import org.geotools.factory.CommonFactoryFinder; import org.junit.Test; @@ -96,4 +97,70 @@ assertEquals("4", ff.function("strPosition", ff.literal("l"), ff.literal("hello"), ff.literal("backToFront")).evaluate(null, String.class)); } + + @Test + public void testStrSubstring() throws Exception { + // test bad ranges return null + assertNull(ff.function("strSubstring", ff.literal("ABCD"), ff.literal(-1), ff.literal(2)) + .evaluate(null)); + assertNull(ff.function("strSubstring", ff.literal("ABCD"), ff.literal(2), ff.literal(5)) + .evaluate(null)); + assertNull(ff.function("strSubstring", ff.literal("ABCD"), ff.literal(3), ff.literal(2)) + .evaluate(null)); + // test empty string input + assertEquals("", ff.function("strSubstring", ff.literal(""), ff.literal(0), ff.literal(0)) + .evaluate(null)); + // test empty string output + assertEquals("", + ff.function("strSubstring", ff.literal("ABCD"), ff.literal(0), ff.literal(0)) + .evaluate(null)); + assertEquals("", + ff.function("strSubstring", ff.literal("ABCD"), ff.literal(2), ff.literal(2)) + .evaluate(null)); + assertEquals("", + ff.function("strSubstring", ff.literal("ABCD"), ff.literal(4), ff.literal(4)) + .evaluate(null)); + // test non-empty substrings + assertEquals("ABCD", + ff.function("strSubstring", ff.literal("ABCD"), ff.literal(0), ff.literal(4)) + .evaluate(null)); + assertEquals("A", + ff.function("strSubstring", ff.literal("ABCD"), ff.literal(0), ff.literal(1)) + .evaluate(null)); + assertEquals("AB", + ff.function("strSubstring", ff.literal("ABCD"), ff.literal(0), ff.literal(2)) + .evaluate(null)); + assertEquals("BC", + ff.function("strSubstring", ff.literal("ABCD"), ff.literal(1), ff.literal(3)) + .evaluate(null)); + assertEquals("CD", + ff.function("strSubstring", ff.literal("ABCD"), ff.literal(2), ff.literal(4)) + .evaluate(null)); + assertEquals("D", + ff.function("strSubstring", ff.literal("ABCD"), ff.literal(3), ff.literal(4)) + .evaluate(null)); + } + + @Test + public void testStrSubstringStart() throws Exception { + // test bad index returns null + assertNull(ff.function("strSubstringStart", ff.literal("ABCD"), ff.literal(-1)).evaluate( + null)); + assertNull(ff.function("strSubstringStart", ff.literal("ABCD"), ff.literal(5)).evaluate( + null)); + // test empty string input + assertEquals("", + ff.function("strSubstringStart", ff.literal(""), ff.literal(0)).evaluate(null)); + // test empty string output + assertEquals("", ff.function("strSubstringStart", ff.literal("ABCD"), ff.literal(4)) + .evaluate(null)); + // test non-empty substrings + assertEquals("ABCD", ff.function("strSubstringStart", ff.literal("ABCD"), ff.literal(0)) + .evaluate(null)); + assertEquals("CD", ff.function("strSubstringStart", ff.literal("ABCD"), ff.literal(2)) + .evaluate(null)); + assertEquals("D", ff.function("strSubstringStart", ff.literal("ABCD"), ff.literal(3)) + .evaluate(null)); + } + } |
Author: aaime Date: 2012-04-15 17:52:09 -0700 (Sun, 15 Apr 2012) New Revision: 38672 Added: trunk/modules/library/render/src/test/java/org/geotools/renderer/style/OpacityFinderTest.java trunk/modules/library/render/src/test/resources/org/geotools/renderer/style/test-data/raster-cmalpha.sld trunk/modules/library/render/src/test/resources/org/geotools/renderer/style/test-data/raster.sld Modified: trunk/modules/library/render/src/main/java/org/geotools/renderer/lite/OpacityFinder.java Log: [GEOT-4102] Enable OpacityFinder to handle RasterSymbolizer, patch by Frank Gasdorf with additions by yours truly Modified: trunk/modules/library/render/src/main/java/org/geotools/renderer/lite/OpacityFinder.java =================================================================== --- trunk/modules/library/render/src/main/java/org/geotools/renderer/lite/OpacityFinder.java 2012-04-16 00:35:58 UTC (rev 38671) +++ trunk/modules/library/render/src/main/java/org/geotools/renderer/lite/OpacityFinder.java 2012-04-16 00:52:09 UTC (rev 38672) @@ -51,17 +51,17 @@ import org.opengis.filter.expression.Expression; import org.opengis.filter.expression.Literal; - /** * Searches for translucent symbolizers - * + * * @author jones - * - * + * + * * @source $URL$ */ public class OpacityFinder implements StyleVisitor { private Class[] acceptableTypes; + public boolean hasOpacity; public OpacityFinder(Class[] acceptableTypes) { @@ -70,7 +70,7 @@ /* * (non-Javadoc) - * + * * @see org.geotools.styling.StyleVisitor#visit(org.geotools.styling.Style) */ public void visit(Style style) { @@ -87,7 +87,7 @@ /* * (non-Javadoc) - * + * * @see org.geotools.styling.StyleVisitor#visit(org.geotools.styling.Rule) */ public void visit(Rule rule) { @@ -104,7 +104,7 @@ /* * (non-Javadoc) - * + * * @see org.geotools.styling.StyleVisitor#visit(org.geotools.styling.FeatureTypeStyle) */ public void visit(FeatureTypeStyle fts) { @@ -121,7 +121,7 @@ /* * (non-Javadoc) - * + * * @see org.geotools.styling.StyleVisitor#visit(org.geotools.styling.Fill) */ public void visit(Fill fill) { @@ -150,6 +150,13 @@ } else if (obj instanceof Byte) { Byte i = (Byte) obj; opacity = i.floatValue(); + } else if (obj instanceof String) { + try { + Double value = Double.valueOf((String) obj); + opacity = value.floatValue(); + } catch (NumberFormatException e) { + return; + } } else { return; } @@ -162,7 +169,7 @@ /* * (non-Javadoc) - * + * * @see org.geotools.styling.StyleVisitor#visit(org.geotools.styling.Stroke) */ public void visit(Stroke stroke) { @@ -171,7 +178,7 @@ /* * (non-Javadoc) - * + * * @see org.geotools.styling.StyleVisitor#visit(org.geotools.styling.Symbolizer) */ public void visit(Symbolizer sym) { @@ -189,11 +196,16 @@ PolygonSymbolizer ps = (PolygonSymbolizer) sym; ps.accept(this); } + + if (sym instanceof RasterSymbolizer) { + RasterSymbolizer rs = (RasterSymbolizer) sym; + rs.accept(this); + } } /* * (non-Javadoc) - * + * * @see org.geotools.styling.StyleVisitor#visit(org.geotools.styling.PointSymbolizer) */ public void visit(PointSymbolizer ps) { @@ -216,33 +228,33 @@ /* * (non-Javadoc) - * + * * @see org.geotools.styling.StyleVisitor#visit(org.geotools.styling.LineSymbolizer) */ public void visit(LineSymbolizer line) { if (isAcceptable(line)) { - if( line.getStroke()!=null ) - line.getStroke().accept(this); + if (line.getStroke() != null) + line.getStroke().accept(this); } } /* * (non-Javadoc) - * + * * @see org.geotools.styling.StyleVisitor#visit(org.geotools.styling.PolygonSymbolizer) */ public void visit(PolygonSymbolizer poly) { if (isAcceptable(poly)) { - if( poly.getStroke()!=null ) + if (poly.getStroke() != null) poly.getStroke().accept(this); - if( poly.getFill()!=null) + if (poly.getFill() != null) poly.getFill().accept(this); } } /* * (non-Javadoc) - * + * * @see org.geotools.styling.StyleVisitor#visit(org.geotools.styling.TextSymbolizer) */ public void visit(TextSymbolizer text) { @@ -250,16 +262,23 @@ /* * (non-Javadoc) - * + * * @see org.geotools.styling.StyleVisitor#visit(org.geotools.styling.RasterSymbolizer) */ public void visit(RasterSymbolizer raster) { - // TODO Auto-generated method stub + if (isAcceptable(raster)) { + if (raster.getOpacity() != null) { + checkOpacity(raster.getOpacity()); + } + if (raster.getColorMap() != null) { + raster.getColorMap().accept(this); + } + } } /* * (non-Javadoc) - * + * * @see org.geotools.styling.StyleVisitor#visit(org.geotools.styling.Graphic) */ public void visit(Graphic gr) { @@ -268,7 +287,7 @@ /* * (non-Javadoc) - * + * * @see org.geotools.styling.StyleVisitor#visit(org.geotools.styling.Mark) */ public void visit(Mark mark) { @@ -277,7 +296,7 @@ /* * (non-Javadoc) - * + * * @see org.geotools.styling.StyleVisitor#visit(org.geotools.styling.ExternalGraphic) */ public void visit(ExternalGraphic exgr) { @@ -286,7 +305,7 @@ /* * (non-Javadoc) - * + * * @see org.geotools.styling.StyleVisitor#visit(org.geotools.styling.PointPlacement) */ public void visit(PointPlacement pp) { @@ -295,7 +314,7 @@ /* * (non-Javadoc) - * + * * @see org.geotools.styling.StyleVisitor#visit(org.geotools.styling.AnchorPoint) */ public void visit(AnchorPoint ap) { @@ -304,7 +323,7 @@ /* * (non-Javadoc) - * + * * @see org.geotools.styling.StyleVisitor#visit(org.geotools.styling.Displacement) */ public void visit(Displacement dis) { @@ -313,7 +332,7 @@ /* * (non-Javadoc) - * + * * @see org.geotools.styling.StyleVisitor#visit(org.geotools.styling.LinePlacement) */ public void visit(LinePlacement lp) { @@ -322,7 +341,7 @@ /* * (non-Javadoc) - * + * * @see org.geotools.styling.StyleVisitor#visit(org.geotools.styling.Halo) */ public void visit(Halo halo) { @@ -331,70 +350,73 @@ /** * DOCUMENT ME! - * + * * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub } - public void visit(StyledLayerDescriptor sld) { - // TODO Auto-generated method stub - - } + public void visit(StyledLayerDescriptor sld) { + // TODO Auto-generated method stub - public void visit(NamedLayer layer) { - // TODO Auto-generated method stub - - } + } - public void visit(UserLayer layer) { - // TODO Auto-generated method stub - - } + public void visit(NamedLayer layer) { + // TODO Auto-generated method stub - public void visit(FeatureTypeConstraint ftc) { - // TODO Auto-generated method stub - - } + } - public void visit(ColorMap arg0) { - // TODO Auto-generated method stub - - } + public void visit(UserLayer layer) { + // TODO Auto-generated method stub - public void visit(ColorMapEntry arg0) { - // TODO Auto-generated method stub - - } + } - public void visit(ContrastEnhancement contrastEnhancement) { - // TODO Auto-generated method stub - - } + public void visit(FeatureTypeConstraint ftc) { + // TODO Auto-generated method stub - public void visit(ImageOutline outline) { - // TODO Auto-generated method stub - - } + } - public void visit(ChannelSelection cs) { - // TODO Auto-generated method stub - - } + public void visit(ColorMap cm) { + for (ColorMapEntry cme : cm.getColorMapEntries()) { + cme.accept(this); + } + } - public void visit(OverlapBehavior ob) { - // TODO Auto-generated method stub - - } + public void visit(ColorMapEntry cme) { + if(cme.getOpacity() != null) { + checkOpacity(cme.getOpacity()); + } - public void visit(SelectedChannelType sct) { - // TODO Auto-generated method stub - - } + } - public void visit(ShadedRelief sr) { - // TODO Auto-generated method stub - - } + public void visit(ContrastEnhancement contrastEnhancement) { + // TODO Auto-generated method stub + + } + + public void visit(ImageOutline outline) { + // TODO Auto-generated method stub + + } + + public void visit(ChannelSelection cs) { + // TODO Auto-generated method stub + + } + + public void visit(OverlapBehavior ob) { + // TODO Auto-generated method stub + + } + + public void visit(SelectedChannelType sct) { + // TODO Auto-generated method stub + + } + + public void visit(ShadedRelief sr) { + // TODO Auto-generated method stub + + } } Added: trunk/modules/library/render/src/test/java/org/geotools/renderer/style/OpacityFinderTest.java =================================================================== --- trunk/modules/library/render/src/test/java/org/geotools/renderer/style/OpacityFinderTest.java (rev 0) +++ trunk/modules/library/render/src/test/java/org/geotools/renderer/style/OpacityFinderTest.java 2012-04-16 00:52:09 UTC (rev 38672) @@ -0,0 +1,47 @@ +package org.geotools.renderer.style; + +import java.net.URL; + +import junit.framework.TestCase; + +import org.geotools.factory.CommonFactoryFinder; +import org.geotools.renderer.lite.OpacityFinder; +import org.geotools.styling.RasterSymbolizer; +import org.geotools.styling.SLDParser; +import org.geotools.styling.Style; +import org.geotools.styling.StyleFactory; +import org.geotools.test.TestData; + + +public class OpacityFinderTest extends TestCase { + + public void testRasterOpacity() throws Exception { + StyleFactory factory = CommonFactoryFinder.getStyleFactory(null); + URL styleURL = TestData.getResource(this, "raster.sld"); + + SLDParser stylereader = new SLDParser(factory, styleURL); + + Style style = stylereader.readXML()[0]; + + OpacityFinder opacityFinder = new OpacityFinder(new Class[] { RasterSymbolizer.class }); + + style.accept(opacityFinder); + + org.junit.Assert.assertTrue(opacityFinder.hasOpacity); + } + + public void testColorMapOpacity() throws Exception { + StyleFactory factory = CommonFactoryFinder.getStyleFactory(null); + URL styleURL = TestData.getResource(this, "raster-cmalpha.sld"); + + SLDParser stylereader = new SLDParser(factory, styleURL); + + Style style = stylereader.readXML()[0]; + + OpacityFinder opacityFinder = new OpacityFinder(new Class[] { RasterSymbolizer.class }); + + style.accept(opacityFinder); + + org.junit.Assert.assertTrue(opacityFinder.hasOpacity); + } +} Added: trunk/modules/library/render/src/test/resources/org/geotools/renderer/style/test-data/raster-cmalpha.sld =================================================================== --- trunk/modules/library/render/src/test/resources/org/geotools/renderer/style/test-data/raster-cmalpha.sld (rev 0) +++ trunk/modules/library/render/src/test/resources/org/geotools/renderer/style/test-data/raster-cmalpha.sld 2012-04-16 00:52:09 UTC (rev 38672) @@ -0,0 +1,27 @@ +<?xml version="1.0" encoding="UTF-8"?> +<StyledLayerDescriptor xmlns="http://www.opengis.net/sld" +xmlns:ogc="http://www.opengis.net/ogc" xmlns:xlink="http://www.w3.org/1999/xlink" +xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/sld http://schemas.opengis.net/sld/1.0.0/StyledLayerDescriptor.xsd" version="1.0.0"> + <UserLayer> + <Name>raster_layer</Name> + <LayerFeatureConstraints> + <FeatureTypeConstraint/> + </LayerFeatureConstraints> + <UserStyle> + <Name>raster</Name> + <Title>A boring default style</Title> + <Abstract>A sample style for rasters</Abstract> + <FeatureTypeStyle> + <FeatureTypeName>Feature</FeatureTypeName> + <Rule> + <RasterSymbolizer> + <ColorMap> + <ColorMapEntry color="#008000" quantity="70" /> + <ColorMapEntry color="#008000" quantity="256" opacity="0.5"/> + </ColorMap> + </RasterSymbolizer> + </Rule> + </FeatureTypeStyle> + </UserStyle> + </UserLayer> +</StyledLayerDescriptor> \ No newline at end of file Added: trunk/modules/library/render/src/test/resources/org/geotools/renderer/style/test-data/raster.sld =================================================================== --- trunk/modules/library/render/src/test/resources/org/geotools/renderer/style/test-data/raster.sld (rev 0) +++ trunk/modules/library/render/src/test/resources/org/geotools/renderer/style/test-data/raster.sld 2012-04-16 00:52:09 UTC (rev 38672) @@ -0,0 +1,35 @@ +<?xml version="1.0" encoding="UTF-8"?> +<StyledLayerDescriptor xmlns="http://www.opengis.net/sld" +xmlns:ogc="http://www.opengis.net/ogc" xmlns:xlink="http://www.w3.org/1999/xlink" +xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/sld http://schemas.opengis.net/sld/1.0.0/StyledLayerDescriptor.xsd" version="1.0.0"> + <UserLayer> + <Name>raster_layer</Name> + <LayerFeatureConstraints> + <FeatureTypeConstraint/> + </LayerFeatureConstraints> + <UserStyle> + <Name>raster</Name> + <Title>A boring default style</Title> + <Abstract>A sample style for rasters</Abstract> + <FeatureTypeStyle> + <FeatureTypeName>Feature</FeatureTypeName> + <Rule> + <RasterSymbolizer> + <Opacity>.5</Opacity> + <ChannelSelection> + <RedChannel> + <SourceChannelName>11</SourceChannelName> + </RedChannel> + <GreenChannel> + <SourceChannelName>9</SourceChannelName> > + </GreenChannel> + <BlueChannel> + <SourceChannelName>1</SourceChannelName> + </BlueChannel> + </ChannelSelection> + </RasterSymbolizer> + </Rule> + </FeatureTypeStyle> + </UserStyle> + </UserLayer> +</StyledLayerDescriptor> \ No newline at end of file |