@Test
public void testReadToPolygonRDD()
        throws Exception
{

    String inputLocation = getShapeFilePath("polygon");
    // load shape with geotool.shapefile
    FeatureCollection<SimpleFeatureType, SimpleFeature> collection = loadFeatures(inputLocation);
    FeatureIterator<SimpleFeature> features = collection.features();
    ArrayList<String> featureTexts = new ArrayList<String>();
    while (features.hasNext()) {
        SimpleFeature feature = features.next();
        Object geometry = feature.getDefaultGeometry();
        if (geometry instanceof MultiPolygon) {
            MultiPolygon multiPolygon = (MultiPolygon) geometry;
            if (multiPolygon.getNumGeometries() == 1) {
                geometry = multiPolygon.getGeometryN(0);
            }
        }
        featureTexts.add(String.valueOf(geometry));
    }
    features.close();
    final Iterator<String> featureIterator = featureTexts.iterator();
    PolygonRDD spatialRDD = ShapefileReader.readToPolygonRDD(sc, inputLocation);
    SpatialRDD<Geometry> geomeryRDD = ShapefileReader.readToGeometryRDD(sc, inputLocation);
    long count = RangeQuery.SpatialRangeQuery(spatialRDD, new Envelope(-180, 180, -90, 90), false, false).count();
    assertEquals(spatialRDD.rawSpatialRDD.count(), count);
    for (Geometry geometry : geomeryRDD.rawSpatialRDD.collect()) {
        assertEquals(featureIterator.next(), geometry.toText());
    }
}