Source Code Cross Referenced for SpatialJoinExecuter.java in  » GIS » openjump » com » vividsolutions » jump » workbench » ui » plugin » analysis » 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 » openjump » com.vividsolutions.jump.workbench.ui.plugin.analysis 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.vividsolutions.jump.workbench.ui.plugin.analysis;
002:
003:        import java.util.*;
004:        import com.vividsolutions.jump.task.*;
005:
006:        import com.vividsolutions.jts.geom.*;
007:        import com.vividsolutions.jump.feature.*;
008:
009:        /**
010:         * Exceutes a spatial query with a given mask FeatureCollection, source FeatureCollection,
011:         * and predicate.
012:         * Ensures result does not contain duplicates.
013:         *
014:         * @author Martin Davis
015:         * @version 1.2
016:         */
017:        public class SpatialJoinExecuter {
018:            private FeatureCollection srcAFC;
019:            private FeatureCollection srcBFC;
020:
021:            private FeatureCollection queryFC;
022:
023:            private boolean isExceptionThrown = false;
024:
025:            private Geometry geoms[] = new Geometry[2];
026:            private Set resultSet = new HashSet();
027:
028:            public SpatialJoinExecuter(FeatureCollection srcAFC,
029:                    FeatureCollection srcBFC) {
030:                this .srcAFC = srcAFC;
031:                this .srcBFC = srcBFC;
032:            }
033:
034:            /**
035:             * Gets the feature collection to query.
036:             * A spatial index may be created if this would improve performance.
037:             *
038:             * @param func
039:             * @return
040:             */
041:            private void createQueryFeatureCollection(GeometryPredicate pred) {
042:                boolean buildIndex = false;
043:                if (srcAFC.size() > 10)
044:                    buildIndex = true;
045:                if (srcBFC.size() > 100)
046:                    buildIndex = true;
047:                if (pred instanceof  GeometryPredicate.DisjointPredicate)
048:                    buildIndex = false;
049:
050:                if (buildIndex) {
051:                    queryFC = new IndexedFeatureCollection(srcBFC);
052:                } else {
053:                    queryFC = srcBFC;
054:                }
055:            }
056:
057:            private Iterator query(GeometryPredicate pred, double[] params,
058:                    Geometry gMask) {
059:                Envelope queryEnv = gMask.getEnvelopeInternal();
060:                // special hack for withinDistance
061:                if (pred instanceof  GeometryPredicate.WithinDistancePredicate) {
062:                    queryEnv.expandBy(params[0]);
063:                }
064:
065:                boolean useQuery = true;
066:                if (pred instanceof  GeometryPredicate.DisjointPredicate)
067:                    useQuery = false;
068:
069:                Iterator queryIt = null;
070:                if (useQuery) {
071:                    Collection queryResult = queryFC.query(queryEnv);
072:                    queryIt = queryResult.iterator();
073:                } else {
074:                    queryIt = queryFC.iterator();
075:                }
076:                return queryIt;
077:            }
078:
079:            public boolean isExceptionThrown() {
080:                return isExceptionThrown;
081:            }
082:
083:            private FeatureSchema createResultSchema() {
084:                FeatureSchema resultFS = new FeatureSchema();
085:                resultFS.addAttribute("GEOMETRY", AttributeType.GEOMETRY);
086:                copyAttributesToSchema(srcAFC.getFeatureSchema(), "A_",
087:                        resultFS);
088:                copyAttributesToSchema(srcBFC.getFeatureSchema(), "B_",
089:                        resultFS);
090:                return resultFS;
091:            }
092:
093:            private void copyAttributesToSchema(FeatureSchema srcFS,
094:                    String prefix, FeatureSchema resultFS) {
095:                for (int i = 0; i < srcFS.getAttributeCount(); i++) {
096:                    if (srcFS.getAttributeType(i) != AttributeType.GEOMETRY) {
097:                        resultFS.addAttribute(prefix
098:                                + srcFS.getAttributeName(i), srcFS
099:                                .getAttributeType(i));
100:                    }
101:                }
102:            }
103:
104:            public FeatureCollection getResultFC() {
105:                return new FeatureDataset(createResultSchema());
106:            }
107:
108:            private boolean isInResult(Feature f) {
109:                return resultSet.contains(f);
110:            }
111:
112:            /**
113:             * Computes geomSrc.func(geomMask)
114:             *
115:             * @param monitor
116:             * @param func
117:             * @param params
118:             * @param resultFC
119:             */
120:            public void execute(TaskMonitor monitor, GeometryPredicate func,
121:                    double[] params, FeatureCollection resultFC) {
122:                createQueryFeatureCollection(func);
123:
124:                int total = srcAFC.size();
125:                int count = 0;
126:                for (Iterator iMask = srcAFC.iterator(); iMask.hasNext();) {
127:
128:                    monitor.report(count++, total, "features");
129:                    if (monitor.isCancelRequested())
130:                        return;
131:
132:                    Feature fMask = (Feature) iMask.next();
133:                    Geometry gMask = fMask.getGeometry();
134:
135:                    Iterator queryIt = query(func, params, gMask);
136:                    for (; queryIt.hasNext();) {
137:                        Feature fSrc = (Feature) queryIt.next();
138:
139:                        // optimization - if feature already in result no need to re-test
140:                        if (isInResult(fSrc))
141:                            continue;
142:
143:                        Geometry gSrc = fSrc.getGeometry();
144:                        geoms[0] = gSrc;
145:                        geoms[1] = gMask;
146:                        boolean isInResult = isTrue(func, gSrc, gMask, params);
147:
148:                        if (isInResult) {
149:                            addToResult(fSrc, fMask, resultFC);
150:                        }
151:                    }
152:                }
153:            }
154:
155:            private void addToResult(Feature fA, Feature fB,
156:                    FeatureCollection resultFC) {
157:                Feature fResult = new BasicFeature(resultFC.getFeatureSchema());
158:                // for now just use A's geometry - in future make a geometry pair
159:                fResult.setGeometry(fA.getGeometry());
160:                //	copyAttributesToFeature(fA, "A_", fResult);
161:                //	copyAttributesToFeature(fB, "B_", fResult);
162:                //  Ed Deen: Switched the above such that the right prefixes are used 
163:                //		     for the right features attribute names.	
164:                copyAttributesToFeature(fA, "B_", fResult);
165:                copyAttributesToFeature(fB, "A_", fResult);
166:                resultFC.add(fResult);
167:            }
168:
169:            private void copyAttributesToFeature(Feature fSrc, String prefix,
170:                    Feature fResult) {
171:                FeatureSchema srcFS = fSrc.getSchema();
172:                for (int i = 0; i < srcFS.getAttributeCount(); i++) {
173:                    if (srcFS.getAttributeType(i) != AttributeType.GEOMETRY) {
174:                        fResult.setAttribute(
175:                                prefix + srcFS.getAttributeName(i), fSrc
176:                                        .getAttribute(i));
177:                    }
178:                }
179:            }
180:
181:            private boolean isTrue(GeometryPredicate func, Geometry geom0,
182:                    Geometry geom1, double[] params) {
183:                try {
184:                    return func.isTrue(geom0, geom1, params);
185:                } catch (RuntimeException ex) {
186:                    // simply eat exceptions and report them by returning null
187:                    isExceptionThrown = true;
188:                }
189:                return false;
190:
191:            }
192:
193:        }
w___w___w___._j_a_v__a__2__s.c__o__m___ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.