Source Code Cross Referenced for ShapefileRTreeReadWriteTest.java in  » GIS » GeoTools-2.4.1 » org » geotools » data » shapefile » indexed » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » GIS » GeoTools 2.4.1 » org.geotools.data.shapefile.indexed 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *    GeoTools - OpenSource mapping toolkit
003:         *    http://geotools.org
004:         *    (C) 2002-2006, GeoTools Project Managment Committee (PMC)
005:         *
006:         *    This library is free software; you can redistribute it and/or
007:         *    modify it under the terms of the GNU Lesser General Public
008:         *    License as published by the Free Software Foundation;
009:         *    version 2.1 of the License.
010:         *
011:         *    This library is distributed in the hope that it will be useful,
012:         *    but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014:         *    Lesser General Public License for more details.
015:         */
016:        package org.geotools.data.shapefile.indexed;
017:
018:        import java.io.File;
019:        import java.io.IOException;
020:        import java.net.MalformedURLException;
021:
022:        import junit.framework.AssertionFailedError;
023:
024:        import org.geotools.TestData;
025:        import org.geotools.data.FeatureSource;
026:        import org.geotools.data.FeatureStore;
027:        import org.geotools.data.Query;
028:        import org.geotools.feature.Feature;
029:        import org.geotools.feature.FeatureCollection;
030:        import org.geotools.feature.FeatureIterator;
031:        import org.geotools.feature.FeatureType;
032:
033:        import com.vividsolutions.jts.geom.Geometry;
034:
035:        /**
036:         * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/plugin/shapefile/src/test/java/org/geotools/data/shapefile/indexed/ShapefileRTreeReadWriteTest.java $
037:         * @version $Id: ShapefileRTreeReadWriteTest.java 22666 2006-11-09 03:50:28Z jgarnett $
038:         * @author Ian Schneider
039:         */
040:        public class ShapefileRTreeReadWriteTest extends TestCaseSupport {
041:            final String[] files = { "shapes/statepop.shp",
042:                    "shapes/polygontest.shp", "shapes/pointtest.shp",
043:                    "shapes/holeTouchEdge.shp", "shapes/stream.shp" };
044:            boolean readStarted = false;
045:            Exception exception = null;
046:
047:            /**
048:             * Creates a new instance of ShapefileReadWriteTest
049:             */
050:            public ShapefileRTreeReadWriteTest(String name) throws IOException {
051:                super (name);
052:            }
053:
054:            public void testAll() throws Throwable {
055:                StringBuffer errors = new StringBuffer();
056:                Exception bad = null;
057:
058:                for (int i = 0, ii = files.length; i < ii; i++) {
059:                    try {
060:                        test(files[i]);
061:                    } catch (Exception e) {
062:                        e.printStackTrace();
063:                        errors.append("\nFile " + files[i] + " : "
064:                                + e.getMessage());
065:                        bad = e;
066:                    }
067:                }
068:
069:                if (errors.length() > 0) {
070:                    fail(errors.toString(), bad);
071:                }
072:            }
073:
074:            public void fail(String message, Throwable cause) throws Throwable {
075:                Throwable fail = new AssertionFailedError(message);
076:                fail.initCause(cause);
077:                throw fail;
078:            }
079:
080:            public void testWriteTwice() throws Exception {
081:                copyShapefiles("shapes/stream.shp");
082:                IndexedShapefileDataStore s1 = new IndexedShapefileDataStore(
083:                        TestData.url(this , "shapes/stream.shp"));
084:                String typeName = s1.getTypeNames()[0];
085:                FeatureSource source = s1.getFeatureSource(typeName);
086:                FeatureType type = source.getSchema();
087:                FeatureCollection one = source.getFeatures();
088:
089:                IndexedShapefileDataStoreFactory maker = new IndexedShapefileDataStoreFactory();
090:
091:                doubleWrite(type, one, getTempFile(), maker, false);
092:                doubleWrite(type, one, getTempFile(), maker, true);
093:            }
094:
095:            private void doubleWrite(FeatureType type, FeatureCollection one,
096:                    File tmp, IndexedShapefileDataStoreFactory maker,
097:                    boolean memorymapped) throws IOException,
098:                    MalformedURLException {
099:                IndexedShapefileDataStore s;
100:                s = (IndexedShapefileDataStore) maker.createDataStore(tmp
101:                        .toURL(), memorymapped);
102:
103:                s.createSchema(type);
104:                FeatureStore store = (FeatureStore) s.getFeatureSource(type
105:                        .getTypeName());
106:
107:                store.addFeatures(one);
108:                store.addFeatures(one);
109:
110:                s = new IndexedShapefileDataStore(tmp.toURL());
111:                assertEquals(one.size() * 2, store.getCount(Query.ALL));
112:            }
113:
114:            void test(String f) throws Exception {
115:                copyShapefiles(f); // Work on File rather than URL from JAR.
116:                IndexedShapefileDataStore s = new IndexedShapefileDataStore(
117:                        TestData.url(f));
118:                String typeName = s.getTypeNames()[0];
119:                FeatureSource source = s.getFeatureSource(typeName);
120:                FeatureType type = source.getSchema();
121:                FeatureCollection one = source.getFeatures();
122:
123:                IndexedShapefileDataStoreFactory maker = new IndexedShapefileDataStoreFactory();
124:                test(type, one, getTempFile(), maker, false);
125:                test(type, one, getTempFile(), maker, true);
126:            }
127:
128:            private void test(FeatureType type, FeatureCollection one,
129:                    File tmp, IndexedShapefileDataStoreFactory maker,
130:                    boolean memorymapped) throws IOException,
131:                    MalformedURLException, Exception {
132:                IndexedShapefileDataStore s;
133:                String typeName;
134:                s = (IndexedShapefileDataStore) maker.createDataStore(tmp
135:                        .toURL(), memorymapped);
136:
137:                s.createSchema(type);
138:
139:                FeatureStore store = (FeatureStore) s.getFeatureSource(type
140:                        .getTypeName());
141:                store.addFeatures(one);
142:
143:                s = new IndexedShapefileDataStore(tmp.toURL());
144:                typeName = s.getTypeNames()[0];
145:
146:                FeatureCollection two = s.getFeatureSource(typeName)
147:                        .getFeatures();
148:
149:                compare(one.features(), two.features());
150:            }
151:
152:            static void compare(FeatureIterator fs1, FeatureIterator fs2)
153:                    throws Exception {
154:
155:                int i = 0;
156:
157:                while (fs1.hasNext()) {
158:                    Feature f1 = fs1.next();
159:                    Feature f2 = fs2.next();
160:
161:                    if ((i++ % 50) == 0) {
162:                        if (verbose) {
163:                            System.out.print("*");
164:                        }
165:                    }
166:
167:                    compare(f1, f2);
168:                }
169:            }
170:
171:            static void compare(Feature f1, Feature f2) throws Exception {
172:                if (f1.getNumberOfAttributes() != f2.getNumberOfAttributes()) {
173:                    throw new Exception("Unequal number of attributes");
174:                }
175:
176:                for (int i = 0; i < f1.getNumberOfAttributes(); i++) {
177:                    Object att1 = f1.getAttribute(i);
178:                    Object att2 = f2.getAttribute(i);
179:
180:                    if (att1 instanceof  Geometry && att2 instanceof  Geometry) {
181:                        Geometry g1 = ((Geometry) att1);
182:                        Geometry g2 = ((Geometry) att2);
183:                        g1.normalize();
184:                        g2.normalize();
185:
186:                        if (!g1.equalsExact(g2)) {
187:                            throw new Exception("Different geometries (" + i
188:                                    + "):\n" + g1 + "\n" + g2);
189:                        }
190:                    } else {
191:                        if (!att1.equals(att2)) {
192:                            throw new Exception("Different attribute (" + i
193:                                    + "): [" + att1 + "] - [" + att2 + "]");
194:                        }
195:                    }
196:                }
197:            }
198:
199:            public static final void main(String[] args) throws Exception {
200:                verbose = true;
201:                junit.textui.TestRunner
202:                        .run(suite(ShapefileRTreeReadWriteTest.class));
203:            }
204:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.