Source Code Cross Referenced for TestData.java in  » GIS » GeoTools-2.4.1 » org » geotools » arcsde » data » 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.arcsde.data 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         *    Geotools2 - OpenSource mapping toolkit
0003:         *    http://geotools.org
0004:         *    (C) 2002-2006, Geotools Project Managment Committee (PMC)
0005:         *
0006:         *    This library is free software; you can redistribute it and/or
0007:         *    modify it under the terms of the GNU Lesser General Public
0008:         *    License as published by the Free Software Foundation;
0009:         *    version 2.1 of the License.
0010:         *
0011:         *    This library is distributed in the hope that it will be useful,
0012:         *    but WITHOUT ANY WARRANTY; without even the implied warranty of
0013:         *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0014:         *    Lesser General Public License for more details.
0015:         *
0016:         */
0017:        package org.geotools.arcsde.data;
0018:
0019:        import java.io.IOException;
0020:        import java.io.InputStream;
0021:        import java.util.Calendar;
0022:        import java.util.Properties;
0023:        import java.util.logging.Logger;
0024:
0025:        import org.geotools.arcsde.pool.ArcSDEConnectionConfig;
0026:        import org.geotools.arcsde.pool.ArcSDEConnectionPool;
0027:        import org.geotools.arcsde.pool.ArcSDEConnectionPoolFactory;
0028:        import org.geotools.arcsde.pool.ArcSDEPooledConnection;
0029:        import org.geotools.arcsde.pool.UnavailableArcSDEConnectionException;
0030:        import org.geotools.data.DataSourceException;
0031:        import org.geotools.feature.Feature;
0032:        import org.geotools.feature.FeatureCollection;
0033:        import org.geotools.feature.FeatureCollections;
0034:        import org.geotools.feature.FeatureType;
0035:        import org.geotools.feature.IllegalAttributeException;
0036:
0037:        import com.esri.sde.sdk.client.SDEPoint;
0038:        import com.esri.sde.sdk.client.SeColumnDefinition;
0039:        import com.esri.sde.sdk.client.SeConnection;
0040:        import com.esri.sde.sdk.client.SeCoordinateReference;
0041:        import com.esri.sde.sdk.client.SeException;
0042:        import com.esri.sde.sdk.client.SeExtent;
0043:        import com.esri.sde.sdk.client.SeInsert;
0044:        import com.esri.sde.sdk.client.SeLayer;
0045:        import com.esri.sde.sdk.client.SeRow;
0046:        import com.esri.sde.sdk.client.SeShape;
0047:        import com.esri.sde.sdk.client.SeTable;
0048:        import com.vividsolutions.jts.geom.Coordinate;
0049:        import com.vividsolutions.jts.geom.Geometry;
0050:        import com.vividsolutions.jts.geom.GeometryFactory;
0051:        import com.vividsolutions.jts.geom.LineString;
0052:        import com.vividsolutions.jts.geom.LinearRing;
0053:        import com.vividsolutions.jts.geom.MultiLineString;
0054:        import com.vividsolutions.jts.geom.MultiPoint;
0055:        import com.vividsolutions.jts.geom.MultiPolygon;
0056:        import com.vividsolutions.jts.geom.Point;
0057:        import com.vividsolutions.jts.geom.Polygon;
0058:
0059:        /**
0060:         * Provides access to the ArcSDEDataStore test data configuration.
0061:         * 
0062:         * @author Gabriel Roldan, Axios Engineering
0063:         * @source $URL:
0064:         *         http://svn.geotools.org/geotools/trunk/gt/modules/unsupported/arcsde/datastore/src/test/java/org/geotools/arcsde/data/TestData.java $
0065:         * @version $Id: TestData.java 27863 2007-11-12 20:34:34Z desruisseaux $
0066:         */
0067:        public class TestData {
0068:            /** DOCUMENT ME! */
0069:            private static final Logger LOGGER = org.geotools.util.logging.Logging
0070:                    .getLogger(TestData.class.getPackage().getName());
0071:
0072:            /** DOCUMENT ME! */
0073:            static final String COORD_SYS = "GEOGCS[\"WGS 84\","
0074:                    + "DATUM[\"WGS_1984\","
0075:                    + "  SPHEROID[\"WGS 84\", 6378137.0, 298.257223563, AUTHORITY[\"EPSG\",\"7030\"]],"
0076:                    + "  AUTHORITY[\"EPSG\",\"6326\"]],"
0077:                    + "PRIMEM[\"Greenwich\", 0.0, AUTHORITY[\"EPSG\",\"8901\"]],"
0078:                    + "UNIT[\"degree\", 0.017453292519943295],"
0079:                    + "AXIS[\"Lon\", EAST]," + "AXIS[\"Lat\", NORTH],"
0080:                    + "AUTHORITY[\"EPSG\",\"4326\"]]";
0081:
0082:            /**
0083:             * the set of test parameters loaded from
0084:             * {@code test-data/testparams.properties}
0085:             */
0086:            private Properties conProps = null;
0087:
0088:            /** the name of the table holding the point test features */
0089:            private String point_table;
0090:
0091:            /** the name of the table holding the linestring test features */
0092:            private String line_table;
0093:
0094:            /** the name of the table holding the polygon test features */
0095:            private String polygon_table;
0096:
0097:            /**
0098:             * the name of a table that can be manipulated without risk of loosing
0099:             * important data
0100:             */
0101:            private String temp_table;
0102:
0103:            /** the configuration keyword to use when creating layers and tables */
0104:            private String configKeyword;
0105:
0106:            private ArcSDEConnectionPool pool;
0107:
0108:            /**
0109:             * Creates a new TestData object.
0110:             * 
0111:             * @throws IOException
0112:             *             DOCUMENT ME!
0113:             */
0114:            public TestData() throws IOException {
0115:                // intentionally blank
0116:            }
0117:
0118:            /**
0119:             * Must be called from inside the test's setUp() method. Loads the test
0120:             * fixture from <code>testparams.properties</code>, besides that, does
0121:             * not creates any connection nor any other costly resource.
0122:             * 
0123:             * @throws IOException
0124:             *             DOCUMENT ME!
0125:             */
0126:            public void setUp() throws IOException {
0127:                this .conProps = new Properties();
0128:
0129:                String propsFile = "testparams.properties";
0130:                InputStream in = org.geotools.test.TestData.openStream(null,
0131:                        propsFile);
0132:                // The line above should never returns null. It should thow a
0133:                // FileNotFoundException instead if the resource is not available.
0134:
0135:                this .conProps.load(in);
0136:                in.close();
0137:
0138:                this .point_table = this .conProps.getProperty("point_table");
0139:                this .line_table = this .conProps.getProperty("line_table");
0140:                this .polygon_table = this .conProps.getProperty("polygon_table");
0141:                this .temp_table = this .conProps.getProperty("temp_table");
0142:                this .configKeyword = this .conProps.getProperty("configKeyword");
0143:
0144:                if (this .point_table == null) {
0145:                    throw new IOException("point_table not defined in "
0146:                            + propsFile);
0147:                }
0148:
0149:                if (this .line_table == null) {
0150:                    throw new IOException("line_table not defined in "
0151:                            + propsFile);
0152:                }
0153:
0154:                if (this .polygon_table == null) {
0155:                    throw new IOException("polygon_table not defined in "
0156:                            + propsFile);
0157:                }
0158:
0159:                if (this .temp_table == null) {
0160:                    throw new IOException("temp_table not defined in "
0161:                            + propsFile);
0162:                }
0163:            }
0164:
0165:            /**
0166:             * Must be called from inside the test's tearDown() method.
0167:             */
0168:            public void tearDown(boolean cleanTestTable, boolean cleanPool) {
0169:                if (cleanTestTable) {
0170:                    deleteTempTable();
0171:                }
0172:                if (cleanPool) {
0173:                    ArcSDEConnectionPoolFactory pfac = ArcSDEConnectionPoolFactory
0174:                            .getInstance();
0175:                    pfac.clear();
0176:                }
0177:            }
0178:
0179:            /**
0180:             * creates an ArcSDEDataStore using {@code test-data/testparams.properties}
0181:             * as holder of datastore parameters
0182:             * 
0183:             * @return DOCUMENT ME!
0184:             * 
0185:             * @throws IOException
0186:             *             DOCUMENT ME!
0187:             */
0188:            public ArcSDEDataStore getDataStore() throws IOException {
0189:                ArcSDEConnectionPool pool = getConnectionPool();
0190:                ArcSDEDataStore dataStore = new ArcSDEDataStore(pool);
0191:
0192:                return dataStore;
0193:            }
0194:
0195:            public ArcSDEConnectionPool getConnectionPool()
0196:                    throws DataSourceException {
0197:                if (this .pool == null) {
0198:                    ArcSDEConnectionPoolFactory pfac = ArcSDEConnectionPoolFactory
0199:                            .getInstance();
0200:                    ArcSDEConnectionConfig config = new ArcSDEConnectionConfig(
0201:                            this .conProps);
0202:                    this .pool = pfac.createPool(config);
0203:                }
0204:                return this .pool;
0205:            }
0206:
0207:            /**
0208:             * DOCUMENT ME!
0209:             * 
0210:             * @return Returns the conProps.
0211:             */
0212:            public Properties getConProps() {
0213:                return this .conProps;
0214:            }
0215:
0216:            /**
0217:             * DOCUMENT ME!
0218:             * 
0219:             * @param conProps
0220:             *            The conProps to set.
0221:             */
0222:            public void setConProps(Properties conProps) {
0223:                this .conProps = conProps;
0224:            }
0225:
0226:            /**
0227:             * DOCUMENT ME!
0228:             * 
0229:             * @return Returns the line_table.
0230:             */
0231:            public String getLine_table() {
0232:                return this .line_table;
0233:            }
0234:
0235:            /**
0236:             * DOCUMENT ME!
0237:             * 
0238:             * @param line_table
0239:             *            The line_table to set.
0240:             */
0241:            public void setLine_table(String line_table) {
0242:                this .line_table = line_table;
0243:            }
0244:
0245:            /**
0246:             * DOCUMENT ME!
0247:             * 
0248:             * @return Returns the point_table.
0249:             */
0250:            public String getPoint_table() {
0251:                return this .point_table;
0252:            }
0253:
0254:            /**
0255:             * DOCUMENT ME!
0256:             * 
0257:             * @return Returns the temp_table.
0258:             */
0259:            public String getTemp_table() {
0260:                return this .temp_table;
0261:            }
0262:
0263:            public String getConfigKeyword() {
0264:                return this .configKeyword;
0265:            }
0266:
0267:            /**
0268:             * DOCUMENT ME!
0269:             * 
0270:             * @param point_table
0271:             *            The point_table to set.
0272:             */
0273:            public void setPoint_table(String point_table) {
0274:                this .point_table = point_table;
0275:            }
0276:
0277:            /**
0278:             * DOCUMENT ME!
0279:             * 
0280:             * @return Returns the polygon_table.
0281:             */
0282:            public String getPolygon_table() {
0283:                return this .polygon_table;
0284:            }
0285:
0286:            /**
0287:             * DOCUMENT ME!
0288:             * 
0289:             * @param polygon_table
0290:             *            The polygon_table to set.
0291:             */
0292:            public void setPolygon_table(String polygon_table) {
0293:                this .polygon_table = polygon_table;
0294:            }
0295:
0296:            /**
0297:             * DOCUMENT ME!
0298:             */
0299:            public void deleteTempTable() {
0300:                // only if the datastore was used
0301:                if (this .pool != null) {
0302:                    try {
0303:                        pool = getDataStore().getConnectionPool();
0304:                        deleteTempTable(pool);
0305:                    } catch (Exception e) {
0306:                        LOGGER.fine(e.getMessage());
0307:                    }
0308:                }
0309:            }
0310:
0311:            /**
0312:             * DOCUMENT ME!
0313:             * 
0314:             * @param pool
0315:             *            DOCUMENT ME!
0316:             */
0317:            public void deleteTempTable(ArcSDEConnectionPool pool) {
0318:                ArcSDEPooledConnection conn = null;
0319:
0320:                try {
0321:                    conn = pool.getConnection();
0322:
0323:                    SeTable table = new SeTable(conn, getTemp_table());
0324:                    table.delete();
0325:                } catch (Exception e) {
0326:                    LOGGER.fine(e.getMessage());
0327:                } finally {
0328:                    conn.close();
0329:                }
0330:            }
0331:
0332:            /**
0333:             * Creates an ArcSDE feature type names as <code>getTemp_table()</code> on
0334:             * the underlying database and if <code>insertTestData == true</code> also
0335:             * inserts some sample values.
0336:             * 
0337:             * @param insertTestData
0338:             *            wether to insert some sample rows or not
0339:             * 
0340:             * @throws SeException
0341:             *             for any error
0342:             * @throws IOException
0343:             *             DOCUMENT ME!
0344:             * @throws UnavailableArcSDEConnectionException
0345:             *             DOCUMENT ME!
0346:             */
0347:            public void createTempTable(boolean insertTestData)
0348:                    throws SeException, IOException,
0349:                    UnavailableArcSDEConnectionException {
0350:                ArcSDEConnectionPool connPool = getDataStore()
0351:                        .getConnectionPool();
0352:
0353:                deleteTempTable(connPool);
0354:
0355:                ArcSDEPooledConnection conn = connPool.getConnection();
0356:
0357:                try {
0358:                    SeColumnDefinition[] coldefs;
0359:
0360:                    /*
0361:                     * Create a qualified table name with current user's name and the
0362:                     * name of the table to be created, "EXAMPLE".
0363:                     */
0364:                    SeLayer layer = new SeLayer(conn);
0365:                    String tableName = getTemp_table();
0366:                    SeTable table = new SeTable(conn, tableName);
0367:                    layer.setTableName(tableName);
0368:
0369:                    coldefs = createBaseTable(conn, table, layer, configKeyword);
0370:
0371:                    if (insertTestData) {
0372:                        insertData(layer, conn, coldefs);
0373:                    }
0374:                } catch (SeException e) {
0375:                    e.printStackTrace();
0376:                    throw e;
0377:                } finally {
0378:                    conn.close();
0379:                }
0380:            }
0381:
0382:            /**
0383:             * 
0384:             * 
0385:             */
0386:            private static SeColumnDefinition[] createBaseTable(
0387:                    SeConnection conn, SeTable table, SeLayer layer,
0388:                    String configKeyword) throws SeException {
0389:                SeColumnDefinition[] colDefs = new SeColumnDefinition[6];
0390:
0391:                if (configKeyword == null)
0392:                    configKeyword = "DEFAULTS";
0393:
0394:                /*
0395:                 * Define the columns and their attributes for the table to be created.
0396:                 * NOTE: The valid range/values of size and scale parameters vary from
0397:                 * one database to another.
0398:                 */
0399:                boolean isNullable = true;
0400:
0401:                colDefs[0] = new SeColumnDefinition("INT32_COL",
0402:                        SeColumnDefinition.TYPE_INTEGER, 10, 0, isNullable);
0403:                colDefs[1] = new SeColumnDefinition("INT16_COL",
0404:                        SeColumnDefinition.TYPE_SMALLINT, 4, 0, isNullable);
0405:                colDefs[2] = new SeColumnDefinition("FLOAT32_COL",
0406:                        SeColumnDefinition.TYPE_FLOAT, 5, 2, isNullable);
0407:                colDefs[3] = new SeColumnDefinition("FLOAT64_COL",
0408:                        SeColumnDefinition.TYPE_DOUBLE, 15, 4, isNullable);
0409:                colDefs[4] = new SeColumnDefinition("STRING_COL",
0410:                        SeColumnDefinition.TYPE_STRING, 25, 0, isNullable);
0411:                colDefs[5] = new SeColumnDefinition("DATE_COL",
0412:                        SeColumnDefinition.TYPE_DATE, 1, 0, isNullable);
0413:
0414:                /*
0415:                 * Create the table using the DBMS default configuration keyword. Valid
0416:                 * keywords are defined in the dbtune table.
0417:                 */
0418:                table.create(colDefs, configKeyword);
0419:
0420:                /*
0421:                 * Define the attributes of the spatial column
0422:                 */
0423:                layer.setSpatialColumnName("SHAPE");
0424:
0425:                /*
0426:                 * Set the type of shapes that can be inserted into the layer. Shape
0427:                 * type can be just one or many. NOTE: Layers that contain more than one
0428:                 * shape type can only be accessed through the C and Java APIs and Arc
0429:                 * Explorer Java 3.x. They cannot be seen from ArcGIS desktop
0430:                 * applications.
0431:                 */
0432:                layer.setShapeTypes(SeLayer.SE_NIL_TYPE_MASK
0433:                        | SeLayer.SE_POINT_TYPE_MASK
0434:                        | SeLayer.SE_LINE_TYPE_MASK
0435:                        | SeLayer.SE_SIMPLE_LINE_TYPE_MASK
0436:                        | SeLayer.SE_AREA_TYPE_MASK
0437:                        | SeLayer.SE_MULTIPART_TYPE_MASK);
0438:                layer.setGridSizes(1100.0, 0.0, 0.0);
0439:                layer.setDescription("Layer Example");
0440:
0441:                /*
0442:                 * Define the layer's Coordinate Reference
0443:                 */
0444:                SeCoordinateReference coordref = getGenericCoordRef();
0445:
0446:                // SeExtent ext = new SeExtent(-1000000.0, -1000000.0, 1000000.0,
0447:                // 1000000.0);
0448:                SeExtent ext = coordref.getXYEnvelope();
0449:                layer.setExtent(ext);
0450:                layer.setCoordRef(coordref);
0451:
0452:                layer.setCreationKeyword(configKeyword);
0453:
0454:                /*
0455:                 * Spatially enable the new table...
0456:                 */
0457:                layer.create(3, 4);
0458:
0459:                return colDefs;
0460:            }
0461:
0462:            /*
0463:             * Inserts 8 rows of data into the layer
0464:             * 
0465:             * Columns Inserted 1. Integer - values: 1 -> 8 2. Short - values: 1, 2 or 3
0466:             * 3. Float - values: Random values 4. Double - values: Random values 5.
0467:             * String - values: Describes the Shape Type 6. Date - values: July 28 2004 ->
0468:             * July 2 2004 7. Shape - 2 Rectangles, 1 point shape, 1 multi-point shape,
0469:             * 1 simple line, 1 line, 1 single part polygon, 1 multipart polygon.
0470:             */
0471:            private static void insertData(SeLayer layer, SeConnection conn,
0472:                    SeColumnDefinition[] colDefs) throws SeException {
0473:
0474:                /*
0475:                 * Define the names of the columns that data is to be inserted into.
0476:                 */
0477:                String[] columns = new String[7];
0478:
0479:                columns[0] = new String(colDefs[0].getName()); // INT32 column
0480:                columns[1] = new String(colDefs[1].getName()); // INT16 column
0481:                columns[2] = new String(colDefs[2].getName()); // FLOAT32 column
0482:                columns[3] = new String(colDefs[3].getName()); // FLOAT64 column
0483:                columns[4] = new String(colDefs[4].getName()); // String column
0484:                columns[5] = new String(colDefs[5].getName()); // Date column
0485:                columns[6] = new String("SHAPE"); // Shape column
0486:
0487:                SeInsert insert = null;
0488:
0489:                try {
0490:                    insert = new SeInsert(conn);
0491:                    insert.intoTable(layer.getName(), columns);
0492:                    insert.setWriteMode(true);
0493:
0494:                    SeRow row = insert.getRowToSet();
0495:
0496:                    SeCoordinateReference coordref = layer.getCoordRef();
0497:                    LOGGER.fine("CRS constraints: " + coordref.getXYEnvelope()
0498:                            + ", presision: " + coordref.getXYUnits());
0499:
0500:                    SeShape shape = new SeShape(coordref);
0501:                    Calendar cal = Calendar.getInstance();
0502:
0503:                    // Year, month, date, hour, minute, second.
0504:                    cal.set(2004, 06, 28, 12, 0, 0);
0505:
0506:                    /*
0507:                     * Insert 2 Rectangles into the layer
0508:                     */
0509:                    int numRectangles = 2;
0510:                    SeExtent rectangle = new SeExtent();
0511:                    int rowId = 1;
0512:
0513:                    for (rowId = 1; rowId <= numRectangles; rowId++) {
0514:                        rectangle.setMinX(-1);
0515:                        rectangle.setMinY(-1);
0516:                        rectangle.setMaxX(1);
0517:                        rectangle.setMaxY(1);
0518:                        shape.generateRectangle(rectangle);
0519:
0520:                        // set the values in the row
0521:                        row.setInteger(0, new Integer(rowId));
0522:                        row.setShort(1, new Short((short) ((rowId % 3) + 1)));
0523:                        row.setFloat(2, new Float(-1000.2 + rowId));
0524:                        row.setDouble(3, new Double(0.02 + (rowId / 1000.0)));
0525:                        row.setString(4, "RECTANGLE");
0526:                        row.setTime(5, cal);
0527:                        row.setShape(6, shape);
0528:
0529:                        // Insert row
0530:                        insert.execute();
0531:                    } // End for
0532:
0533:                    /*
0534:                     * Insert a simple line
0535:                     */
0536:                    int points = 2;
0537:                    int numParts = 1;
0538:                    int[] partOffSets = new int[numParts];
0539:                    partOffSets[0] = 0;
0540:
0541:                    SDEPoint[] ptArray = new SDEPoint[points];
0542:
0543:                    for (int i = 0; i < points; i++) {
0544:                        ptArray[i] = new SDEPoint(-5000.0 + (i * 10), -5000.0
0545:                                + (i * 100));
0546:                    }
0547:
0548:                    SeShape line1 = new SeShape(coordref);
0549:                    line1.generateSimpleLine(points, numParts, partOffSets,
0550:                            ptArray);
0551:
0552:                    // set the col values
0553:                    row.setInteger(0, new Integer(rowId));
0554:                    row.setShort(1, new Short((short) ((rowId % 3) + 1)));
0555:                    row.setFloat(2, new Float(10.45));
0556:                    row.setDouble(3, new Double(-120.0232));
0557:                    row.setString(4, "SIMPLE LINE");
0558:                    row.setTime(5, cal);
0559:                    cal.roll(Calendar.DATE, true);
0560:                    row.setShape(6, line1);
0561:
0562:                    // insert row
0563:                    insert.execute();
0564:
0565:                    /*
0566:                     * Insert a multipart line
0567:                     */
0568:                    numParts = 3;
0569:
0570:                    int[] partOffsets = new int[numParts];
0571:                    partOffsets[0] = 0;
0572:                    partOffsets[1] = 3;
0573:                    partOffsets[2] = 7;
0574:
0575:                    int numPts = 12;
0576:                    ptArray = new SDEPoint[numPts];
0577:
0578:                    // line 1
0579:                    ptArray[0] = new SDEPoint(100, 100);
0580:                    ptArray[1] = new SDEPoint(200, 200);
0581:                    ptArray[2] = new SDEPoint(300, 100);
0582:
0583:                    // line 2 - Self intersecting line
0584:                    ptArray[3] = new SDEPoint(200, 300);
0585:                    ptArray[4] = new SDEPoint(300, 400);
0586:                    ptArray[5] = new SDEPoint(300, 300);
0587:                    ptArray[6] = new SDEPoint(200, 400);
0588:
0589:                    // line 3
0590:                    ptArray[7] = new SDEPoint(100, 700);
0591:                    ptArray[8] = new SDEPoint(300, 500);
0592:                    ptArray[9] = new SDEPoint(500, 500);
0593:                    ptArray[10] = new SDEPoint(600, 600);
0594:                    ptArray[11] = new SDEPoint(700, 800);
0595:
0596:                    SeShape multiLine = new SeShape(coordref);
0597:                    multiLine.generateLine(numPts, numParts, partOffsets,
0598:                            ptArray);
0599:
0600:                    rowId++;
0601:
0602:                    // set the col values
0603:                    row.setInteger(0, new Integer(rowId));
0604:                    row.setShort(1, new Short((short) ((rowId % 3) + 1)));
0605:                    row.setFloat(2, new Float(40.05));
0606:                    row.setDouble(3, new Double(-120.000232));
0607:                    row.setString(4, "MULTI-PART LINE");
0608:                    row.setTime(5, cal);
0609:                    cal.roll(Calendar.DATE, true);
0610:                    row.setShape(6, multiLine);
0611:
0612:                    // insert row
0613:                    insert.execute();
0614:
0615:                    /*
0616:                     * Insert simple area shape
0617:                     */
0618:                    numParts = 1;
0619:                    partOffsets = new int[numParts];
0620:                    partOffsets[0] = 0;
0621:                    numPts = 5;
0622:                    ptArray = new SDEPoint[numPts];
0623:                    ptArray[0] = new SDEPoint(-1, 0);
0624:                    ptArray[1] = new SDEPoint(0, 1);
0625:                    ptArray[2] = new SDEPoint(1, 0);
0626:                    ptArray[3] = new SDEPoint(0, -1);
0627:                    ptArray[4] = new SDEPoint(-1, 0);
0628:
0629:                    SeShape polygon = new SeShape(coordref);
0630:                    polygon.generatePolygon(numPts, numParts, partOffsets,
0631:                            ptArray);
0632:
0633:                    rowId++;
0634:
0635:                    // set the col values
0636:                    row.setInteger(0, new Integer(rowId));
0637:                    row.setShort(1, new Short((short) ((rowId % 3) + 1)));
0638:                    row.setFloat(2, new Float(1.456));
0639:                    row.setDouble(3, new Double(30.177));
0640:                    row.setString(4, "SINGLE PART POLYGON");
0641:                    row.setTime(5, cal);
0642:                    cal.roll(Calendar.DATE, true);
0643:                    row.setShape(6, polygon);
0644:
0645:                    // insert row
0646:                    insert.execute();
0647:
0648:                    /*
0649:                     * Insert single point shape
0650:                     */
0651:                    SeShape point = null;
0652:                    point = new SeShape(coordref);
0653:                    numPts = 1;
0654:                    ptArray = new SDEPoint[numPts];
0655:                    ptArray[0] = new SDEPoint(8000, 8000);
0656:                    point.generatePoint(numPts, ptArray);
0657:
0658:                    rowId++;
0659:
0660:                    // set the col values
0661:                    row.setInteger(0, new Integer(rowId));
0662:                    row.setShort(1, new Short((short) ((rowId % 3) + 1)));
0663:                    row.setFloat(2, new Float(0.78782));
0664:                    row.setDouble(3, new Double(4332.3414233));
0665:                    row.setString(4, "SINGLE POINT SHAPE");
0666:                    row.setTime(5, cal);
0667:                    cal.roll(Calendar.DATE, true);
0668:                    row.setShape(6, point);
0669:
0670:                    // insert row
0671:                    insert.execute();
0672:
0673:                    /*
0674:                     * Insert a multi part point
0675:                     */
0676:                    numPts = 4;
0677:                    ptArray = new SDEPoint[numPts];
0678:                    ptArray[0] = new SDEPoint(3000, 100);
0679:                    ptArray[1] = new SDEPoint(3000, 300);
0680:                    ptArray[2] = new SDEPoint(4000, 300);
0681:                    ptArray[3] = new SDEPoint(4000, 100);
0682:
0683:                    point.generatePoint(numPts, ptArray);
0684:
0685:                    rowId++;
0686:
0687:                    // set the col values
0688:                    row.setInteger(0, new Integer(rowId));
0689:                    row.setShort(1, new Short((short) ((rowId % 3) + 1)));
0690:                    row.setFloat(2, new Float(0.786456));
0691:                    row.setDouble(3, new Double(42342.177));
0692:                    row.setString(4, "MULTI POINT SHAPE");
0693:                    row.setTime(5, cal);
0694:                    cal.roll(Calendar.DATE, true);
0695:                    row.setShape(6, point);
0696:
0697:                    // insert row
0698:                    insert.execute();
0699:
0700:                    /*
0701:                     * Generate complex area shape
0702:                     */
0703:                    numParts = 2;
0704:                    partOffsets = new int[numParts];
0705:                    partOffsets[0] = 0;
0706:                    partOffsets[1] = 14;
0707:                    numPts = 18;
0708:                    ptArray = new SDEPoint[numPts];
0709:
0710:                    // part one
0711:                    ptArray[0] = new SDEPoint(100, 1100);
0712:                    ptArray[1] = new SDEPoint(1500, 1100);
0713:                    ptArray[2] = new SDEPoint(1500, 1900);
0714:                    ptArray[3] = new SDEPoint(100, 1900);
0715:                    ptArray[4] = new SDEPoint(100, 1100);
0716:
0717:                    // Hole - sub part of part one
0718:                    ptArray[5] = new SDEPoint(200, 1200);
0719:                    ptArray[6] = new SDEPoint(200, 1500);
0720:                    ptArray[7] = new SDEPoint(500, 1500);
0721:                    ptArray[8] = new SDEPoint(500, 1700);
0722:                    ptArray[9] = new SDEPoint(800, 1700);
0723:                    ptArray[10] = new SDEPoint(800, 1500);
0724:                    ptArray[11] = new SDEPoint(500, 1500);
0725:                    ptArray[12] = new SDEPoint(500, 1200);
0726:                    ptArray[13] = new SDEPoint(200, 1200);
0727:
0728:                    // part two
0729:                    ptArray[14] = new SDEPoint(1600, 1200);
0730:                    ptArray[15] = new SDEPoint(2800, 1650);
0731:                    ptArray[16] = new SDEPoint(1800, 2000);
0732:                    ptArray[17] = new SDEPoint(1600, 1200);
0733:
0734:                    polygon.generatePolygon(numPts, numParts, partOffsets,
0735:                            ptArray);
0736:
0737:                    rowId++;
0738:
0739:                    // set the col values
0740:                    row.setInteger(0, new Integer(rowId));
0741:                    row.setShort(1, new Short((short) ((rowId % 3) + 1)));
0742:                    row.setFloat(2, new Float(230.7862));
0743:                    row.setDouble(3, new Double(4234.33177));
0744:                    row.setString(4, "MULTI PART POLYGON");
0745:                    row.setTime(5, cal);
0746:                    cal.roll(Calendar.DATE, true);
0747:                    row.setShape(6, polygon);
0748:
0749:                    // insert row
0750:                    insert.execute();
0751:
0752:                    insert.close();
0753:                } catch (SeException e) {
0754:                    /*
0755:                     * Making sure the insert stream was closed. If the stream isn't
0756:                     * closed, the resources used by the stream will be held/locked by
0757:                     * the stream until the associated connection is closed.
0758:                     */
0759:                    try {
0760:                        insert.close();
0761:                    } catch (SeException se) {
0762:                        System.out.println(se.getSeError().getErrDesc());
0763:                    }
0764:
0765:                    System.out.println(e.getSeError().getSdeError());
0766:                    System.out.println(e.getSeError().getExtError());
0767:                    throw e;
0768:                }
0769:            } // End method insertData
0770:
0771:            /**
0772:             * Creates a FeatureCollection with features whose schema adheres to the one
0773:             * created in <code>createTestData()</code> and returns it.
0774:             * 
0775:             * <p>
0776:             * This schema is something like:
0777:             * 
0778:             * <pre>
0779:             *  colDefs[0] &quot;INT32_COL&quot;, SeColumnDefinition.TYPE_INTEGER, 10, 0, true
0780:             *  colDefs[1] = &quot;INT16_COL&quot;, SeColumnDefinition.TYPE_SMALLINT, 4, 0, true
0781:             *  colDefs[2] = &quot;FLOAT32_COL&quot;, SeColumnDefinition.TYPE_FLOAT, 5, 2, true
0782:             *  colDefs[3] = &quot;FLOAT64_COL&quot;, SeColumnDefinition.TYPE_DOUBLE, 15, 4, true
0783:             *  colDefs[4] = &quot;STRING_COL&quot;, SeColumnDefinition.TYPE_STRING, 25, 0, true
0784:             *  colDefs[5] = &quot;DATE_COL&quot;, SeColumnDefinition.TYPE_DATE, 1, 0, true
0785:             *  colDefs[6] = &quot;SHAPE&quot;, Geometry, 1, 0, true
0786:             * </pre>
0787:             * 
0788:             * </p>
0789:             * 
0790:             * @param jtsGeomType
0791:             *            class of JTS geometry to create
0792:             * @param numFeatures
0793:             *            number of features to create.
0794:             * 
0795:             * 
0796:             * @throws IOException
0797:             *             if the schema for te test table cannot be fetched from the
0798:             *             database.
0799:             * @throws IllegalAttributeException
0800:             *             if the feature type created from the test table cannot build
0801:             *             a feature with the given attribute values.
0802:             */
0803:            public FeatureCollection createTestFeatures(Class jtsGeomType,
0804:                    int numFeatures) throws IOException,
0805:                    IllegalAttributeException {
0806:                FeatureCollection col = FeatureCollections.newCollection();
0807:                FeatureType type = getDataStore().getSchema(getTemp_table());
0808:                Object[] values = new Object[type.getAttributeCount()];
0809:
0810:                for (int i = 0; i < numFeatures; i++) {
0811:                    values[0] = new Integer(i);
0812:
0813:                    // put some nulls
0814:                    values[1] = ((i % 2) == 0) ? null : new Integer(2 * i);
0815:                    values[2] = new Float(0.1 * i);
0816:                    values[3] = new Double(1000 * i);
0817:                    values[4] = "String value #" + i;
0818:
0819:                    Calendar cal = Calendar.getInstance();
0820:                    cal.set(Calendar.DAY_OF_MONTH, i);
0821:                    values[5] = cal.getTime();
0822:                    values[6] = createTestGeometry(jtsGeomType, i);
0823:
0824:                    Feature f = type.create(values);
0825:                    col.add(f);
0826:                }
0827:
0828:                return col;
0829:            }
0830:
0831:            /**
0832:             * DOCUMENT ME!
0833:             * 
0834:             * @param geomType
0835:             *            DOCUMENT ME!
0836:             * @param index
0837:             *            DOCUMENT ME!
0838:             * 
0839:             * @return DOCUMENT ME!
0840:             * 
0841:             * @throws UnsupportedOperationException
0842:             *             DOCUMENT ME!
0843:             */
0844:            private static Geometry createTestGeometry(Class geomType, int index) {
0845:                Geometry geom = null;
0846:                GeometryFactory gf = new GeometryFactory();
0847:
0848:                if (geomType == Geometry.class) {
0849:                    geom = createTestGenericGeometry(gf, index);
0850:                } else if (geomType == Point.class) {
0851:                    geom = createTestPoint(gf, index);
0852:                } else if (geomType == MultiPoint.class) {
0853:                    geom = createTestMultiPoint(gf, index);
0854:                } else if (geomType == LineString.class) {
0855:                    geom = createTestLineString(gf, index);
0856:                } else if (geomType == MultiLineString.class) {
0857:                    geom = createTestMultiLineString(gf, index);
0858:                } else if (geomType == Polygon.class) {
0859:                    geom = createTestPolygon(gf, index);
0860:                } else if (geomType == MultiPolygon.class) {
0861:                    geom = createTestMultiPolygon(gf, index);
0862:                } else {
0863:                    throw new UnsupportedOperationException(
0864:                            "finish implementing this!");
0865:                }
0866:
0867:                return geom;
0868:            }
0869:
0870:            /**
0871:             * DOCUMENT ME!
0872:             * 
0873:             * @param gf
0874:             *            DOCUMENT ME!
0875:             * @param index
0876:             *            DOCUMENT ME!
0877:             * 
0878:             * @return DOCUMENT ME!
0879:             */
0880:            private static Geometry createTestGenericGeometry(
0881:                    GeometryFactory gf, int index) {
0882:                if ((index % 6) == 0) {
0883:                    return createTestPoint(gf, index);
0884:                } else if ((index % 4) == 0) {
0885:                    return createTestMultiPoint(gf, index);
0886:                } else if ((index % 3) == 0) {
0887:                    return createTestLineString(gf, index);
0888:                } else if ((index % 2) == 0) {
0889:                    return createTestMultiLineString(gf, index);
0890:                } else if ((index % 1) == 0) {
0891:                    return createTestPolygon(gf, index);
0892:                } else {
0893:                    return createTestMultiPolygon(gf, index);
0894:                }
0895:            }
0896:
0897:            /**
0898:             * DOCUMENT ME!
0899:             * 
0900:             * @param gf
0901:             *            DOCUMENT ME!
0902:             * @param index
0903:             *            DOCUMENT ME!
0904:             * 
0905:             * @return DOCUMENT ME!
0906:             */
0907:            private static Point createTestPoint(GeometryFactory gf, int index) {
0908:                return gf.createPoint(new Coordinate(index, index));
0909:            }
0910:
0911:            /**
0912:             * DOCUMENT ME!
0913:             * 
0914:             * @param gf
0915:             *            DOCUMENT ME!
0916:             * @param index
0917:             *            DOCUMENT ME!
0918:             * 
0919:             * @return DOCUMENT ME!
0920:             */
0921:            private static MultiPoint createTestMultiPoint(GeometryFactory gf,
0922:                    int index) {
0923:                Coordinate[] coords = { new Coordinate(index, index),
0924:                        new Coordinate(-index, -index) };
0925:
0926:                return gf.createMultiPoint(coords);
0927:            }
0928:
0929:            /**
0930:             * DOCUMENT ME!
0931:             * 
0932:             * @param gf
0933:             *            DOCUMENT ME!
0934:             * @param index
0935:             *            DOCUMENT ME!
0936:             * 
0937:             * @return DOCUMENT ME!
0938:             */
0939:            private static LineString createTestLineString(GeometryFactory gf,
0940:                    int index) {
0941:                Coordinate[] coords = { new Coordinate(0, 0),
0942:                        new Coordinate(++index, -index) };
0943:
0944:                return gf.createLineString(coords);
0945:            }
0946:
0947:            /**
0948:             * DOCUMENT ME!
0949:             * 
0950:             * @param gf
0951:             *            DOCUMENT ME!
0952:             * @param index
0953:             *            DOCUMENT ME!
0954:             * 
0955:             * @return DOCUMENT ME!
0956:             */
0957:            private static MultiLineString createTestMultiLineString(
0958:                    GeometryFactory gf, int index) {
0959:                Coordinate[] coords1 = { new Coordinate(0, 0),
0960:                        new Coordinate(++index, ++index) };
0961:                Coordinate[] coords2 = { new Coordinate(0, index),
0962:                        new Coordinate(index, 0) };
0963:                LineString[] lines = { gf.createLineString(coords1),
0964:                        gf.createLineString(coords2) };
0965:
0966:                return gf.createMultiLineString(lines);
0967:            }
0968:
0969:            /**
0970:             * DOCUMENT ME!
0971:             * 
0972:             * @param gf
0973:             *            DOCUMENT ME!
0974:             * @param index
0975:             *            DOCUMENT ME!
0976:             * 
0977:             * @return DOCUMENT ME!
0978:             */
0979:            private static Polygon createTestPolygon(GeometryFactory gf,
0980:                    int index) {
0981:                Coordinate[] coords = { new Coordinate(index, index),
0982:                        new Coordinate(index, index + 1),
0983:                        new Coordinate(index + 1, index + 1),
0984:                        new Coordinate(index + 1, index),
0985:                        new Coordinate(index, index) };
0986:                LinearRing shell = gf.createLinearRing(coords);
0987:
0988:                return gf.createPolygon(shell, null);
0989:            }
0990:
0991:            /**
0992:             * DOCUMENT ME!
0993:             * 
0994:             * @param gf
0995:             *            DOCUMENT ME!
0996:             * @param index
0997:             *            DOCUMENT ME!
0998:             * 
0999:             * @return DOCUMENT ME!
1000:             */
1001:            private static MultiPolygon createTestMultiPolygon(
1002:                    GeometryFactory gf, int index) {
1003:                Polygon[] polys = { createTestPolygon(gf, index),
1004:                        createTestPolygon(gf, 1 + index) };
1005:
1006:                MultiPolygon mp = gf.createMultiPolygon(polys);
1007:                // System.out.println(mp);
1008:
1009:                return mp;
1010:            }
1011:
1012:            /**
1013:             * Creates and returns a <code>SeCoordinateReference</code> CRS, though
1014:             * based on WGS84, is inclusive enough (in terms of valid coordinate range
1015:             * and presicion) to deal with most coordintates.
1016:             * 
1017:             * <p>
1018:             * Actually tested to deal with coordinates with 0.0002 units of separation
1019:             * as well as with large coordinates such as UTM (values greater than
1020:             * 500,000.00)
1021:             * </p>
1022:             * 
1023:             * @return DOCUMENT ME!
1024:             * 
1025:             * @throws SeException
1026:             *             DOCUMENT ME!
1027:             */
1028:            public static SeCoordinateReference getGenericCoordRef()
1029:                    throws SeException {
1030:                // create a sde CRS with a huge value range and 5 digits of presission
1031:                SeCoordinateReference seCRS = new SeCoordinateReference();
1032:                int shift = 100000;
1033:                SeExtent validRange = new SeExtent(-shift, -shift, shift, shift);
1034:                seCRS.setXYByEnvelope(validRange);
1035:                GeometryBuilderTest.LOGGER
1036:                        .fine("CRS: " + seCRS.getXYEnvelope());
1037:
1038:                return seCRS;
1039:            }
1040:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.