001: package org.geotools.renderer.shape;
002:
003: import junit.framework.TestCase;
004:
005: import org.geotools.data.DataUtilities;
006: import org.geotools.feature.FeatureType;
007:
008: public class BoundsExtractorTest extends TestCase {
009: private FeatureType schema;
010:
011: protected void setUp() throws Exception {
012: schema = DataUtilities.createType("type",
013: "the_geom:Geometry,name:String");
014: }
015:
016: public void testBBoxFilter() throws Exception {
017: // FilterFactory factory=FilterFactoryFinder.createFilterFactory();
018: //
019: // GeometryFilter filter=factory.createGeometryFilter(org.geotools.filter.Filter.GEOMETRY_BBOX);
020: //
021: // testFilter(factory, filter);
022: }
023: // public void testCONTAINSFilter() throws Exception {
024: // FilterFactory factory=FilterFactoryFinder.createFilterFactory();
025: //
026: // GeometryFilter filter=factory.createGeometryFilter(org.geotools.filter.Filter.GEOMETRY_CONTAINS);
027: //
028: // testFilter(factory, filter);
029: // }
030: // public void testCROSSESFilter() throws Exception {
031: // FilterFactory factory=FilterFactoryFinder.createFilterFactory();
032: //
033: // GeometryFilter filter=factory.createGeometryFilter(org.geotools.filter.Filter.GEOMETRY_CROSSES);
034: //
035: // testFilter(factory, filter);
036: // }
037: // public void testDWITHINFilter() throws Exception {
038: // FilterFactory factory=FilterFactoryFinder.createFilterFactory();
039: //
040: // GeometryFilter filter=factory.createGeometryFilter(org.geotools.filter.Filter.GEOMETRY_DWITHIN);
041: //
042: // testFilter(factory, filter);
043: // }
044: // public void testEQUALSFilter() throws Exception {
045: // FilterFactory factory=FilterFactoryFinder.createFilterFactory();
046: //
047: // GeometryFilter filter=factory.createGeometryFilter(org.geotools.filter.Filter.GEOMETRY_EQUALS);
048: //
049: // testFilter(factory, filter);
050: // }
051: // public void testINTERSECTSFilter() throws Exception {
052: // FilterFactory factory=FilterFactoryFinder.createFilterFactory();
053: //
054: // GeometryFilter filter=factory.createGeometryFilter(org.geotools.filter.Filter.GEOMETRY_INTERSECTS);
055: //
056: // testFilter(factory, filter);
057: // }
058: // public void testOVERLAPSFilter() throws Exception {
059: // FilterFactory factory=FilterFactoryFinder.createFilterFactory();
060: //
061: // GeometryFilter filter=factory.createGeometryFilter(org.geotools.filter.Filter.GEOMETRY_OVERLAPS);
062: //
063: // testFilter(factory, filter);
064: // }
065: // public void testTOUCHESFilter() throws Exception {
066: // FilterFactory factory=FilterFactoryFinder.createFilterFactory();
067: //
068: // GeometryFilter filter=factory.createGeometryFilter(org.geotools.filter.Filter.GEOMETRY_TOUCHES);
069: //
070: // testFilter(factory, filter);
071: // }
072: // public void testWITHINFilter() throws Exception {
073: // FilterFactory factory=FilterFactoryFinder.createFilterFactory();
074: //
075: // GeometryFilter filter=factory.createGeometryFilter(org.geotools.filter.Filter.GEOMETRY_WITHIN);
076: //
077: // testFilter(factory, filter);
078: // }
079: //
080: // private void testFilter(FilterFactory factory, GeometryFilter filter) throws IllegalFilterException {
081: // Envelope bbox=new Envelope (10,100,10,100);
082: // BBoxExpression bb = factory.createBBoxExpression(bbox);
083: //
084: // String geomName=schema.getDefaultGeometry().getName();
085: // AttributeExpression attr = factory.createAttributeExpression(geomName);
086: //
087: // filter.addLeftGeometry(attr);
088: // filter.addRightGeometry(bb);
089: //
090: // GeometryFilter filter2=factory.createGeometryFilter(org.geotools.filter.Filter.GEOMETRY_BBOX);
091: // filter2.addLeftGeometry(attr);
092: // Coordinate[] coords=new Coordinate[]{new Coordinate(0,0),new Coordinate(30,0),new Coordinate(25,30)};
093: // Geometry geom=new GeometryFactory().createLineString(coords);
094: // filter2.addRightGeometry(factory.createLiteralExpression(geom));
095: //
096: // /*
097: // * Extract bounds from F^F2
098: // */
099: //
100: // BoundsExtractor extractor=new BoundsExtractor(new Envelope(-10,40, -10,40));
101: // filter.and(filter2).accept(extractor);
102: // assertEquals(new Envelope(10,30,10,30), extractor.getIntersection());
103: //
104: // /*
105: // * Extract bounds from F|F2
106: // */
107: // extractor=new BoundsExtractor(new Envelope(-10,40, -10,40));
108: // filter.or(filter2).accept(extractor);
109: // assertEquals(new Envelope(0,40,0,40), extractor.getIntersection());
110: //
111: // /*
112: // * Extract bounds from ~F
113: // */
114: // extractor=new BoundsExtractor(new Envelope(-10,40, -10,40));
115: // filter.not().accept(extractor);
116: // assertEquals(new Envelope(-10,40,-10,40), extractor.getIntersection());
117: //
118: // /*
119: // * Extract bounds from ~(F^F2)
120: // */
121: // extractor=new BoundsExtractor(new Envelope(-10,40, -10,40));
122: // filter.and(filter2).not().accept(extractor);
123: // assertEquals(new Envelope(-10,40,-10,40), extractor.getIntersection());
124: //
125: // /*
126: // * Extract bounds from ~(~(F|F2))
127: // */
128: // extractor=new BoundsExtractor(new Envelope(-10,40, -10,40));
129: // filter.or(filter2).not().not().accept(extractor);
130: // assertEquals(new Envelope(0,40,0,40), extractor.getIntersection());
131: //
132: // /*
133: // * Extract bounds from ~(F|F2)^F2)=(F|F2|F2)=F|F2 but since F contains F2 ~(F1|F2) is always false so
134: // *
135: // */
136: // extractor=new BoundsExtractor(new Envelope(-10,40, -10,40));
137: // Filter newF=filter.or(filter2).not().and(filter2).not();
138: // newF.accept(extractor);
139: // assertTrue(new Envelope(0,40,0,40).contains(extractor.getIntersection()));
140: //
141: // /*
142: // * Disjoint case
143: // * |--| |--|
144: // * | | | |
145: // * |--| |--|
146: // */
147: // extractor=new BoundsExtractor(-10,0,-10,0);
148: // filter.accept(extractor);
149: // assertTrue(extractor.getIntersection().isNull());
150: //
151: // /*
152: // * Contains case
153: // * |------|
154: // * | |--| |
155: // * | | | |
156: // * | |--| |
157: // * |------|
158: // */
159: // extractor=new BoundsExtractor(new Envelope(0,110, 0,110));
160: // filter.accept(extractor);
161: // assertEquals(new Envelope(10,100,10,100), extractor.getIntersection());
162: //
163: // /*
164: // * |------|
165: // *|---| |
166: // *| | | |
167: // *|---| |
168: // * |------|
169: // */
170: // extractor=new BoundsExtractor(new Envelope(0,20, 20,90));
171: // filter.accept(extractor);
172: // assertEquals(new Envelope(10,20,20,90), extractor.getIntersection());
173: //
174: // /*
175: // *|---|
176: // *| |-|----|
177: // *| | | |
178: // *| | | |
179: // *| | | |
180: // *| |-|----|
181: // *|---|
182: // */
183: // extractor=new BoundsExtractor(new Envelope(0,20, 0,110));
184: // filter.accept(extractor);
185: // assertEquals(new Envelope(10,20,10,100), extractor.getIntersection());
186: //
187: // /*
188: // * |---|
189: // * |-|---|-|
190: // * | |---| |
191: // * | |
192: // * | |
193: // * |-------|
194: // *
195: // */
196: // extractor=new BoundsExtractor(new Envelope(20,90, 90,110));
197: // filter.accept(extractor);
198: // assertEquals(new Envelope(20,90,90,100), extractor.getIntersection());
199: //
200: // /*
201: // *|-----------|
202: // *| |-------| |
203: // *|-----------|
204: // * | |
205: // * | |
206: // * |-------|
207: // *
208: // */
209: // extractor=new BoundsExtractor(new Envelope(0,110, 90,110));
210: // filter.accept(extractor);
211: // assertEquals(new Envelope(10,100,90,100), extractor.getIntersection());
212: //
213: // /*
214: // *
215: // * |-------|
216: // * | |---|
217: // * | | | |
218: // * | |---|
219: // * |-------|
220: // *
221: // */
222: // extractor=new BoundsExtractor(new Envelope(90,110, 20,90));
223: // filter.accept(extractor);
224: // assertEquals(new Envelope(90,100,20,90), extractor.getIntersection());
225: //
226: // /*
227: // * |---|
228: // * |-----|-| |
229: // * | | | |
230: // * | | | |
231: // * |-----|-| |
232: // * |---|
233: // */
234: // extractor=new BoundsExtractor(new Envelope(90,100, 0,110));
235: // filter.accept(extractor);
236: // assertEquals(new Envelope(90,100,10,100), extractor.getIntersection());
237: //
238: // /*
239: // *
240: // * |-------|
241: // * | |
242: // * | |---| |
243: // * |-|---|-|
244: // * |---|
245: // */
246: // extractor=new BoundsExtractor(new Envelope(20,90, 0,20));
247: // filter.accept(extractor);
248: // assertEquals(new Envelope(20,90,10,20), extractor.getIntersection());
249: //
250: //
251: // /*
252: // *
253: // * |-------|
254: // * | |
255: // *|-----------|
256: // *| |-------| |
257: // *|---------- |
258: // */
259: // extractor=new BoundsExtractor(new Envelope(0,110, 0,20));
260: // filter.accept(extractor);
261: // assertEquals(new Envelope(10,100,10,20), extractor.getIntersection());
262: //
263: // /*
264: // *
265: // * |-------|
266: // *|-----------|
267: // *|-----------|
268: // * |-------|
269: // *
270: // */
271: // extractor=new BoundsExtractor(new Envelope(0,110, 20,90));
272: // filter.accept(extractor);
273: // assertEquals(new Envelope(10,100,20,90), extractor.getIntersection());
274: //
275: // /*
276: // * |---|
277: // * |-|---|-|
278: // * | | | |
279: // * | | | |
280: // * |-|---|-|
281: // * |---|
282: // */
283: // extractor=new BoundsExtractor(new Envelope(20,90,0,110));
284: // filter.accept(extractor);
285: // assertEquals(new Envelope(20,90,10,100), extractor.getIntersection());
286: //
287: // }
288:
289: }
|