Revision 5829
Added by ben leinfelder over 13 years ago
SpatialQuery.java | ||
---|---|---|
24 | 24 |
|
25 | 25 |
package edu.ucsb.nceas.metacat.spatial; |
26 | 26 |
|
27 |
import org.geotools.feature.FeatureType; |
|
28 | 27 |
import org.geotools.data.shapefile.ShapefileDataStore; |
29 | 28 |
import org.geotools.data.FeatureStore; |
30 | 29 |
import org.geotools.data.FeatureSource; |
31 | 30 |
import org.geotools.data.DefaultTransaction; |
32 | 31 |
import org.geotools.data.Transaction; |
33 |
import org.geotools.feature.Feature; |
|
34 | 32 |
import org.geotools.filter.Filter; |
35 | 33 |
import org.geotools.filter.AbstractFilter; |
36 | 34 |
import org.geotools.filter.Expression; |
... | ... | |
41 | 39 |
import org.geotools.filter.IllegalFilterException; |
42 | 40 |
import org.geotools.feature.FeatureCollection; |
43 | 41 |
import org.geotools.feature.FeatureCollections; |
42 |
import org.opengis.feature.simple.SimpleFeature; |
|
43 |
import org.opengis.feature.simple.SimpleFeatureType; |
|
44 |
|
|
44 | 45 |
import com.vividsolutions.jts.geom.Envelope; |
45 | 46 |
import com.vividsolutions.jts.geom.Geometry; |
46 | 47 |
import com.vividsolutions.jts.geom.GeometryFactory; |
... | ... | |
115 | 116 |
Polygon bboxGeom = geomFac.createPolygon( geomFac.createLinearRing(linestringCoordinates), null); |
116 | 117 |
|
117 | 118 |
// Set up geometry filter based on bbox |
118 |
FeatureType featureType = store.getSchema( store.getTypeNames()[0] ); |
|
119 |
Expression geometry = filterFactory.createAttributeExpression( featureType.getDefaultGeometry().getName() );
|
|
119 |
SimpleFeatureType featureType = store.getSchema( store.getTypeNames()[0] );
|
|
120 |
Expression geometry = filterFactory.createAttributeExpression( featureType.getGeometryDescriptor().getName().toString());
|
|
120 | 121 |
GeometryFilter bboxFilter = filterFactory.createGeometryFilter(AbstractFilter.GEOMETRY_BBOX); |
121 | 122 |
bboxFilter.addLeftGeometry( geometry ); |
122 | 123 |
bboxFilter.addRightGeometry( bbox ); |
... | ... | |
127 | 128 |
Iterator iterator = collection.iterator(); |
128 | 129 |
try { |
129 | 130 |
for( Iterator i=collection.iterator(); i.hasNext(); ) { |
130 |
Feature feature = (Feature) i.next();
|
|
131 |
SimpleFeature feature = (SimpleFeature) i.next();
|
|
131 | 132 |
|
132 | 133 |
Geometry geom = (Geometry)feature.getAttribute(0); |
133 | 134 |
if ( geom.within( bboxGeom ) ) { |
... | ... | |
151 | 152 |
|
152 | 153 |
// Set up geometry filter based on bbox |
153 | 154 |
featureType = store.getSchema( store.getTypeNames()[0] ); |
154 |
geometry = filterFactory.createAttributeExpression( featureType.getDefaultGeometry().getName() );
|
|
155 |
geometry = filterFactory.createAttributeExpression( featureType.getGeometryDescriptor().getName().toString() );
|
|
155 | 156 |
bboxFilter = filterFactory.createGeometryFilter(AbstractFilter.GEOMETRY_BBOX); |
156 | 157 |
bboxFilter.addLeftGeometry( geometry ); |
157 | 158 |
bboxFilter.addRightGeometry( bbox ); |
... | ... | |
164 | 165 |
String docid = null; |
165 | 166 |
try { |
166 | 167 |
for( Iterator i=collection.iterator(); i.hasNext(); ) { |
167 |
Feature feature = (Feature) i.next();
|
|
168 |
SimpleFeature feature = (SimpleFeature) i.next();
|
|
168 | 169 |
Geometry geom = (Geometry)feature.getAttribute(0); |
169 | 170 |
if ( geom.intersects( bboxGeom ) ) { |
170 | 171 |
// assumes docid is attribute number 1 |
Also available in: Unified diff
geoserver upgrade:
-remove embedded geoserver
-include geotools api and update spatial harvesting
-include simple template for using maps in skin (openlayers now, not mapbuilder)