package org.gcube.application.geoportal.gis;

import java.io.File;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

import org.geotoolkit.data.DataStore;
import org.geotoolkit.data.DataStoreFinder;
import org.geotoolkit.data.FeatureReader;
import org.opengis.feature.Feature;
import org.opengis.feature.GeometryAttribute;

public class ShapeFileManager {

	
	public ShapeFileManager(File shapeFile) {
		

		try {
		  Map<String, Serializable> connect = new HashMap();
		  connect.put("url", shapeFile.toURI().toString());

		  DataStore dataStore = DataStoreFinder.open(connect);
		  String[] typeNames = dataStore.getTypeNames();
		  String typeName = typeNames[0];

		  System.out.println("Reading content " + typeName);

		  //TODO QUERY OBJECT
		  	FeatureReader reader =dataStore.getFeatureReader(null);
		  
//		  featureSource featureSource = dataStore.getFeatureSource(typeName);
//		  FeatureCollection collection = featureSource.getFeatures();
//		  FeatureIterator iterator = collection.features();


		  try {
		    while (reader.hasNext()) {
		      Feature feature = reader.next();
		      GeometryAttribute sourceGeometry = feature.getDefaultGeometryProperty();
		    }
		  } finally {
		    reader.close();
		  }

		} catch (Throwable e) {}
		
	}
	
	
}
