Project

General

Profile

« Previous | Next » 

Revision 3045

Added by perry about 18 years ago

Updated spatial query to also look at point spatial cache as some documents may only be represented as a single point.

View differences:

src/edu/ucsb/nceas/metacat/spatial/SpatialQuery.java
85 85
      Vector docids = new Vector();
86 86
      SpatialFeatureSchema featureSchema = new SpatialFeatureSchema();
87 87
      
88
      // MPTDO, perform geotools spatial query
89
      // test
90
      docids.add("test1.1");
91
      docids.add("test2.1");
92

  
93 88
      ShapefileDataStore store = null;
94 89
      FeatureSource features = null;
95 90
      FeatureCollection collection = null;
96 91
      FilterFactory filterFactory = FilterFactoryFinder.createFilterFactory();
97 92

  
98 93
      try {
94
          // read the spatial cache (polygons)
99 95
          store = new ShapefileDataStore( (new File( featureSchema.polygonShpUri )).toURL() );
100 96
          features = store.getFeatureSource(store.getTypeNames()[0]);
101
          //count features
102
          //col = features.getFeatures();
103
          //System.out.println("# cities (no filter)= "+col.size());
104 97

  
98
          // Construct bounding box
105 99
          Envelope envelope = new Envelope( w, e, s, n ); 
106 100
          Expression bbox = filterFactory.createBBoxExpression( envelope );
107 101

  
102
          // Set up geometry filter based on bbox
108 103
          FeatureType featureType = store.getSchema( store.getTypeNames()[0] );
109 104
          Expression geometry = filterFactory.createAttributeExpression( featureType.getDefaultGeometry().getName()  );
110 105
          GeometryFilter bboxFilter = filterFactory.createGeometryFilter(AbstractFilter.GEOMETRY_BBOX);
111 106
          bboxFilter.addLeftGeometry( geometry );
112 107
          bboxFilter.addRightGeometry( bbox );
113 108

  
114
          //count filtered features
109
          // Iterate through the filtered feature collection
110
          // and add matches to the docid Vector
115 111
          collection = features.getFeatures(bboxFilter);
116
          //System.out.println("# cities (after filter)= "+col.size());
117

  
118 112
          Iterator iterator = collection.iterator();
119 113
          try {
120 114
              for( Iterator i=collection.iterator(); i.hasNext(); ) {
121 115
                  Feature feature = (Feature) i.next();
116
                  // assumes docid is attribute number 1 
117
                  // in a zero-based index of dbf columns
122 118
                  docids.add( (String) feature.getAttribute(1) );
123 119
              }
124 120
          } finally {
125 121
              collection.close( iterator );
126 122
          }
127 123
         
128
        } catch (MalformedURLException ex) {
129
            ex.printStackTrace();
130
        } catch (IOException ex) {
131
            ex.printStackTrace();
132
        } catch (IllegalFilterException ex) {
133
            ex.printStackTrace();
134
        }
124
          /*
125
           * Also query the point cache since there may be point-only documents
126
           * Filter by the bbox AND check against docids Vector so that
127
           * docids already in the Vector don't get duplicated.
128
           */ 
129
          // read the spatial cache (points)
130
          store = new ShapefileDataStore( (new File( featureSchema.pointShpUri )).toURL() );
131
          features = store.getFeatureSource(store.getTypeNames()[0]);
135 132

  
133
          // Set up geometry filter based on bbox
134
          featureType = store.getSchema( store.getTypeNames()[0] );
135
          geometry = filterFactory.createAttributeExpression( featureType.getDefaultGeometry().getName()  );
136
          bboxFilter = filterFactory.createGeometryFilter(AbstractFilter.GEOMETRY_BBOX);
137
          bboxFilter.addLeftGeometry( geometry );
138
          bboxFilter.addRightGeometry( bbox );
136 139

  
140
          // Iterate through the filtered feature collection
141
          // and add matches to the docid Vector IF
142
          // they aren't already present
143
          collection = features.getFeatures(bboxFilter);
144
          iterator = collection.iterator();
145
          String docid = null;
146
          try {
147
              for( Iterator i=collection.iterator(); i.hasNext(); ) {
148
                  Feature feature = (Feature) i.next();
149
                  // assumes docid is attribute number 1 
150
                  // in a zero-based index of dbf columns
151
                  docid = (String) feature.getAttribute(1);
152
                  if( !docids.contains( docid ) ) {
153
                      docids.add( docid );
154
                  }
155
              }
156
          } finally {
157
              collection.close( iterator );
158
          }
159

  
160
      } catch (MalformedURLException ex) {
161
          ex.printStackTrace();
162
      } catch (IOException ex) {
163
          ex.printStackTrace();
164
      } catch (IllegalFilterException ex) {
165
          ex.printStackTrace();
166
      }
167

  
137 168
      return docids;
138 169

  
139 170
  }
src/edu/ucsb/nceas/metacat/MetaCatServlet.java
815 815
        String [] docidArray = new String[docids.size()];
816 816
        docids.toArray(docidArray);
817 817
        String squery = DocumentIdQuery.createDocidQuery( docidArray );
818
        logMetacat.info("-----------\n" + squery + "\n------------------");
818 819

  
819 820
        /*
820 821
         * Pass to squery handler

Also available in: Unified diff