Thank you for your reply.
I had this code above for something else and that is not being use and it
seems to cache the geometries in memory from my test.
final SpatialIndex index = new STRtree();
FeatureIterator fi = terrainPolygons.features();
while (fi.hasNext()) {
Feature f = fi.next();
index.insert((Envelope) f.getBounds(), f);
limit = (ReferencedEnvelope)f.getBounds();
}
I haven't been able to figure out how to use spatial index to do simple
query like "select the_geom from table where st_cross(the_geom, new_geom)".
I just see examples from using filter.
aaime wrote:
>
> tommy408 ha scritto:
>> I'm running a query that test a line if it crosses any polygon in a
>> table,
>> and if it doesn't I keep it. And it test 2600 lines.
>>
>> In postgres with postgis I run this query 2600 times ( different lines)
>> which takes 300 milliseconds:
>>
>> PERFORM gid from terrains where ST_Crosses(v_line , the_geom) limit 1;
>> IF NOT FOUND THEN
>> // then keep
>> END IF;
>>
>>
>> With geotools I run this code for the same purpose which takes 1922
>> milliseconds:
>>
>> Filter intersectFilter = CQL.toFilter("CROSS(the_geom, " + lineString +
>> ")");
>> Filter bboxFilter = ff.bbox(ff.property( "the_geom" ), envelope );
>> Filter andFilter = ff.and(bboxFilter ,intersectFilter);
>> FeatureCollection<SimpleFeatureType, SimpleFeature> collection =
>> terrainPolygonSource.getFeatures( andFilter);
>>
>> if ( collection.size() == 0)
>> // then keep lineString
>>
>> What am I doing wrong here? And I already loaded those geometries into
>> memory. I only run the time test for this portion of the code. Is this
>> the
>> best I can get?
>
> How did you load stuff into memory?
>
> Anyways, if it's really in memory you're not using a spatial index,
> that is why postgres is faster. You'll have to restructure your code
> to create an use a JTS STRTree. However, for 2 seconds runtime,
> it's probably not worth it (it has an up-front creation cost that
> you have to factor in).
>
> Cheers
> Andrea
>
>
>
> --
> Andrea Aime
> OpenGeo - http://opengeo.org
> Expert service straight from the developers.
>
> ------------------------------------------------------------------------------
> This SF.Net email is sponsored by the Verizon Developer Community
> Take advantage of Verizon's best-in-class app development support
> A streamlined, 14 day to market process makes app distribution fast and
> easy
> Join now and get one step closer to millions of Verizon customers
> http://p.sf.net/sfu/verizon-dev2dev
> _______________________________________________
> Geotools-gt2-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
>
>
--
View this message in context:
http://n2.nabble.com/Running-crosses-postgis-vs-geotools-tp4349406p4354527.html
Sent from the geotools-gt2-users mailing list archive at Nabble.com.
------------------------------------------------------------------------------
This SF.Net email is sponsored by the Verizon Developer Community
Take advantage of Verizon's best-in-class app development support
A streamlined, 14 day to market process makes app distribution fast and easy
Join now and get one step closer to millions of Verizon customers
http://p.sf.net/sfu/verizon-dev2dev
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users