Jon Aquino's Mental Garden

Engineering beautiful software jon aquino labs | personal blog

Wednesday, June 09, 2004

BeanShell to add points to a spatial index

import com .vividsolutions .jts .geom .*;
import com .vividsolutions .jts .io .*;
import com .vividsolutions .jts .index .strtree .*;
import com .vividsolutions .jump .feature .*;

STRtree index = new STRtree();
for (Iterator i = wc .getLayerManager() .getLayer("3") .getFeatureCollectionWrapper() .iterator(); i .hasNext(); ) {
Feature feature = (Feature) i .next();
index .insert(feature .getGeometry() .getEnvelopeInternal(), feature .getGeometry());
}

Envelope envelope = new WKTReader() .read("POLYGON ((116.12585183031183 40.11217094218279, 116.12585183031183 40.13284978641936, 116.15504549276343 40.13284978641936, 116.15504549276343 40.11217094218279, 116.12585183031183 40.11217094218279))") .getEnvelopeInternal();

print(index.query(envelope));

>> [POINT (116.151519 40.117252), POINT (116.133806 40.121107), POINT (116.146551 40.122018)]

0 Comments:

Post a Comment

<< Home