I wrote the following code to test this out and when I up the size of the
feature collection up to 500,000 (or 100 times bigger than your problem) I
get an average search time of 82 milliseconds for a random bounding box
(over 100 tries).  So I wouldn't worry too much about it

Ian

public LineSearch() {

    try {
      TYPE = DataUtilities.createType("", "Location",
"the_geom:LineString:srid=4326");
    } catch (SchemaException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    ArrayList<SimpleFeature> feats = new ArrayList<>();
    for (int i = 0; i < 500000; i++) {
      feats.add(GenerateRandomData.createSimpleLineFeature(TYPE));
    }
    features = new ListFeatureCollection(TYPE, feats);
    index = new SpatialIndexFeatureCollection(TYPE);
    index.addAll(features);
  }

  public static void main(String[] args) {
    LineSearch me = new LineSearch();
    long sum = 0;
    int loopCount = 100;
    for (int j = 0; j < loopCount; j++) {

      double xMin = (Math.random() * 360.0) - 180.0;
      double xMax = xMin + 10.0;
      double yMin = (Math.random() * 180.0) - 90.0;
      double yMax = yMin + 5.0;

      ReferencedEnvelope bbox = new ReferencedEnvelope(xMin, xMax, yMin,
yMax, DefaultGeographicCRS.WGS84);
      long start = System.currentTimeMillis();
      List<SimpleFeature> nLines = me.search(bbox);
      long end = System.currentTimeMillis();
      long duration = end - start;
      sum+=duration;
    }
    System.out.println("Average search time = "+(sum/loopCount));
  }

  private List<SimpleFeature> search(ReferencedEnvelope bbox) {
    BBOX bbFilter =
FILTERFACTORY.bbox(FILTERFACTORY.property(TYPE.getGeometryDescriptor().getLocalName()),
bbox);
    FeatureCollection<SimpleFeatureType, SimpleFeature> subCollection =
features.subCollection(bbFilter);
    return DataUtilities.list(subCollection);
  }

On 10 February 2016 at 11:23, Stefan Schuster <stefan.m.schus...@gmail.com>
wrote:

> Hello
>
> I have about 5000 LINESTRINGS, in a List. Now I want to create a function
> “filterWithRectangle” that returns all the LINESTRINGS that are inside a
> given rectangle:
>
>
>
> List<LineString> filterWithRectangle(List<LineString> allLineStrings,
> Coordinate leftTop, Coordinate rightBottom)
>
>
>
> It is easys to implement this function by iterating over all Coordinates
> of all LineStrings and compare with the given rectangle.
>
>
>
> But this function will be called very often with the same List of
> “allLineStrings” and with different Coordinates for the rectangle.
> Therefore I wonder if it is possible to create an index for the LineStrings
> for better performance. I read that shapefiles can do something like this,
> but as far as I understood this needs access to a hard disc. I'm lokking
> for a solution that works in memory.
>
> Any ideas?
>
> Thanks for any suggestions!
>
> Stefan
>
>
> ------------------------------------------------------------------------------
> Site24x7 APM Insight: Get Deep Visibility into Application Performance
> APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
> Monitor end-to-end web transactions and take corrective actions now
> Troubleshoot faster and improve end-user experience. Signup Now!
> http://pubads.g.doubleclick.net/gampad/clk?id=272487151&iu=/4140
> _______________________________________________
> GeoTools-GT2-Users mailing list
> GeoTools-GT2-Users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
>
>


-- 
Ian Turton
------------------------------------------------------------------------------
Site24x7 APM Insight: Get Deep Visibility into Application Performance
APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
Monitor end-to-end web transactions and take corrective actions now
Troubleshoot faster and improve end-user experience. Signup Now!
http://pubads.g.doubleclick.net/gampad/clk?id=272487151&iu=/4140
_______________________________________________
GeoTools-GT2-Users mailing list
GeoTools-GT2-Users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to