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

Reply via email to