title: Extract polygons from shapefile using Geotools
body: <p>I have a shape file (Sample.shp) along with two other files (Sample.shx and Sample.dbf), which has geometry (polygons) defined for 15 pincodes of Bombay.</p>
  
  <p>I am able to view the .shp file using the Quickstart tutorial. </p>
  
  <pre><code>    File file = JFileDataStoreChooser.showOpenFile("shp", null);
      if (file == null) {
          return;
      }
  
      FileDataStore store = FileDataStoreFinder.getDataStore(file);
      SimpleFeatureSource featureSource = store.getFeatureSource();
  
      // Create a map content and add our shapefile to it
      MapContent map = new MapContent();
      map.setTitle("Quickstart");
  
      Style style = SLD.createSimpleStyle(featureSource.getSchema());
      Layer layer = new FeatureLayer(featureSource, style);
      map.addLayer(layer);
  
      // Now display the map
      JMapFrame.showMap(map);
  </code></pre>
  
  <p>Now I want to convert the geometry of these 15 pincodes to 15 Geometry/Polygon objects so that I can use Geometry.contains() to find if a point falls in a particular Geometry/Polygon.</p>
  
  <p>I tried:</p>
  
  <pre><code>ShapefileReader r = new ShapefileReader(new ShpFiles(file),true,false,geometryFactory);
  System.out.println(r.getCount(0)); &gt;&gt; returns 51
  System.out.println(r.hasNext()); &gt;&gt; returns false
  </code></pre>
  
  <p>Any help is really appreciated</p>