Skip to main content
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Tweeted twitter.com/#!/StackGIS/status/391586809995489280

` public static void main(String[] args) { File file = JFileDataStoreChooser.showOpenFile("shp", null); if (file == null) return; try{

public static void main(String[] args) {
    File file = JFileDataStoreChooser.showOpenFile("shp", null);
     if (file == null) return;
 try{
                
        FileDataStore store = FileDataStoreFinder.getDataStore(file);
        SimpleFeatureSource featureSource = store.getFeatureSource();
          
        FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2();
        
        String[] selection = new String[1000];
        
        for(int i=0; i<selection.length; i++){
            
            selection[i] = i+"";
            
        }
        
        ArrayList<Filter> match = new ArrayList<Filter>();

        for (String name : selection) {
            Filter aMatch = ff.equal(ff.property("ID"), ff.literal(name), false);
            match.add(aMatch);
        }
        Filter filter = ff.or(match);
        
        SimpleFeatureCollection features = featureSource.getFeatures(filter);
        
 
        
        // Create a map content and add our shapefile to it
        MapContent map = new MapContent();
        map.setTitle("Quickstart");
        
        
        Style style = SLD.createSimpleStyle(features.getSchema());
       

        Layer layer = new FeatureLayer(features, style);

        map.addLayer(layer);

        // Now display the map
        JMapFrame.showMap(map);
        
        }catch (Exception e)
        {
            e.printStackTrace();
}

}`

Are there some faster way to do this? ......

` public static void main(String[] args) { File file = JFileDataStoreChooser.showOpenFile("shp", null); if (file == null) return; try{

        FileDataStore store = FileDataStoreFinder.getDataStore(file);
        SimpleFeatureSource featureSource = store.getFeatureSource();
          
        FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2();
        
        String[] selection = new String[1000];
        
        for(int i=0; i<selection.length; i++){
            
            selection[i] = i+"";
            
        }
        
        ArrayList<Filter> match = new ArrayList<Filter>();

        for (String name : selection) {
            Filter aMatch = ff.equal(ff.property("ID"), ff.literal(name), false);
            match.add(aMatch);
        }
        Filter filter = ff.or(match);
        
        SimpleFeatureCollection features = featureSource.getFeatures(filter);
        
 
        
        // Create a map content and add our shapefile to it
        MapContent map = new MapContent();
        map.setTitle("Quickstart");
        
        
        Style style = SLD.createSimpleStyle(features.getSchema());
       

        Layer layer = new FeatureLayer(features, style);

        map.addLayer(layer);

        // Now display the map
        JMapFrame.showMap(map);
        
        }catch (Exception e)
        {
            e.printStackTrace();

}`

Are there some faster way to do this?

public static void main(String[] args) {
    File file = JFileDataStoreChooser.showOpenFile("shp", null);
     if (file == null) return;
 try{
                
        FileDataStore store = FileDataStoreFinder.getDataStore(file);
        SimpleFeatureSource featureSource = store.getFeatureSource();
          
        FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2();
        
        String[] selection = new String[1000];
        
        for(int i=0; i<selection.length; i++){
            
            selection[i] = i+"";
            
        }
        
        ArrayList<Filter> match = new ArrayList<Filter>();

        for (String name : selection) {
            Filter aMatch = ff.equal(ff.property("ID"), ff.literal(name), false);
            match.add(aMatch);
        }
        Filter filter = ff.or(match);
        
        SimpleFeatureCollection features = featureSource.getFeatures(filter);
        
 
        
        // Create a map content and add our shapefile to it
        MapContent map = new MapContent();
        map.setTitle("Quickstart");
        
        
        Style style = SLD.createSimpleStyle(features.getSchema());
       

        Layer layer = new FeatureLayer(features, style);

        map.addLayer(layer);

        // Now display the map
        JMapFrame.showMap(map);
        
        }catch (Exception e)
        {
            e.printStackTrace();
}

Are there some faster way to do this? ......

edited tags
Link
Felix
  • 41
  • 2
Source Link
Felix
  • 41
  • 2

Filtered SimpleFeatureCollection really slow on Map and other operations

I'm working with a shapefile having about 85.000 features. I need to select some of these using a filter and then showing these on a map. Now... If I draw the entire shapefile's features the creation of the map, the zooming and moving around is fast but if I select, even only 100, features from the SimpleFeatureSource, these steps are really slow. Here is how I select, for example, the first 1000 features and then draw:

The execution stuks at Layer layer = new FeatureLayer (features, style);

and at JMapFrame.showMap(map);

` public static void main(String[] args) { File file = JFileDataStoreChooser.showOpenFile("shp", null); if (file == null) return; try{

        FileDataStore store = FileDataStoreFinder.getDataStore(file);
        SimpleFeatureSource featureSource = store.getFeatureSource();
          
        FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2();
        
        String[] selection = new String[1000];
        
        for(int i=0; i<selection.length; i++){
            
            selection[i] = i+"";
            
        }
        
        ArrayList<Filter> match = new ArrayList<Filter>();

        for (String name : selection) {
            Filter aMatch = ff.equal(ff.property("ID"), ff.literal(name), false);
            match.add(aMatch);
        }
        Filter filter = ff.or(match);
        
        SimpleFeatureCollection features = featureSource.getFeatures(filter);
        
 
        
        // Create a map content and add our shapefile to it
        MapContent map = new MapContent();
        map.setTitle("Quickstart");
        
        
        Style style = SLD.createSimpleStyle(features.getSchema());
       

        Layer layer = new FeatureLayer(features, style);

        map.addLayer(layer);

        // Now display the map
        JMapFrame.showMap(map);
        
        }catch (Exception e)
        {
            e.printStackTrace();

}`

Are there some faster way to do this?