프로그래밍/Java

Shape File을 CSV로 변환하기(1)-Shape File 로드하기

kingroad 2019. 11. 20. 13:11

import org.geotools.data.shapefile.ShapefileDataStore;
import org.geotools.data.simple.SimpleFeatureCollection;
import org.geotools.data.simple.SimpleFeatureIterator;
import org.geotools.data.simple.SimpleFeatureSource;


public class loadToShp {
private static SimpleFeatureIterator simpleFeatureIterator;

public void DefaultLoad(String filePath) {
// Open the shapefile
File dataFile = new File(filePath);

ShapefileDataStore store;

try {
store = new ShapefileDataStore(new URL("file://" + dataFile));
store.setCharset(Charset.forName("UTF-8"));
SimpleFeatureSource source = store.getFeatureSource(store.getTypeNames()[0]); 

//file의 이름을 인자로 하여 그 이름에 해당된 정보를 가지고 옴
SimpleFeatureCollection featureCollection = source.getFeatures();
simpleFeatureIterator = featureCollection.features();

} catch (IOException e) {
e.printStackTrace();
}
}

public SimpleFeatureIterator getIter() {
return simpleFeatureIterator;
}
}