Commit f5469f9a authored by Matija Obreza's avatar Matija Obreza

Make shape file source folder configurable

parent a3f21dcf
Pipeline #5202 passed with stage
in 1 minute and 10 seconds
......@@ -56,12 +56,11 @@ public class ShapefileUtils {
* @throws MalformedURLException the malformed url exception
* @throws IOException Signals that an I/O exception has occurred.
*/
public static DataStore openShapeFile(final String shapeFilePath) throws MalformedURLException, IOException {
public static DataStore openShapeFile(final File shapeFile) throws MalformedURLException, IOException {
final File file = new File("data", shapeFilePath);
final Map<String, Object> map = new HashMap<>();
map.put("url", file.toURI().toURL());
System.err.println(file.toURI().toURL());
map.put("url", shapeFile.toURI().toURL());
System.err.println(shapeFile.toURI().toURL());
final DataStore dataStore = DataStoreFinder.getDataStore(map);
return dataStore;
......
......@@ -16,6 +16,7 @@
package org.genesys.geotools.service.impl;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.util.concurrent.ExecutionException;
......@@ -74,6 +75,12 @@ public class CountryOfOriginServiceImpl implements CountryOfOriginService {
/** The debug. */
private final boolean debug = false;
private String dataFolderPath = "data";
public void setDataFolderPath(String dataFolderPath) {
this.dataFolderPath = dataFolderPath;
}
static {
try {
// Initialize stuff
......@@ -93,8 +100,8 @@ public class CountryOfOriginServiceImpl implements CountryOfOriginService {
public void afterPropertiesSet() throws MalformedURLException, IOException {
// http://www.gadm.org/version2
// Use "six dissolved layers"
final DataStore dataStoreAdm0 = ShapefileUtils.openShapeFile("TM_WORLD_BORDERS-0.3.shp");
final DataStore dataStoreAdm0X = ShapefileUtils.openShapeFile("gadm28_adm1.shp");
final DataStore dataStoreAdm0 = ShapefileUtils.openShapeFile(new File(dataFolderPath, "TM_WORLD_BORDERS-0.3.shp"));
final DataStore dataStoreAdm0X = ShapefileUtils.openShapeFile(new File(dataFolderPath, "gadm28_adm1.shp"));
sourceAdmin0 = dataStoreAdm0.getFeatureSource(dataStoreAdm0.getTypeNames()[0]);
sourceAdmin0X = dataStoreAdm0X.getFeatureSource(dataStoreAdm0X.getTypeNames()[0]);
......
......@@ -19,8 +19,6 @@ package org.genesys.geotools.service.impl;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
......@@ -28,7 +26,6 @@ import org.genesys.geotools.service.LandOrSeaService;
import org.genesys.geotools.service.LonLatCacheKey;
import org.genesys.geotools.service.ShapefileUtils;
import org.geotools.data.DataStore;
import org.geotools.data.DataStoreFinder;
import org.geotools.data.FeatureSource;
import org.geotools.factory.CommonFactoryFinder;
import org.geotools.feature.FeatureCollection;
......@@ -74,6 +71,12 @@ public class LandOrSeaServiceImpl implements LandOrSeaService {
/** The classifier cache. */
private LoadingCache<LonLatCacheKey, String> classifierCache;
private String dataFolderPath = "data";
public void setDataFolderPath(String dataFolderPath) {
this.dataFolderPath = dataFolderPath;
}
/**
* After properties set.
*
......@@ -83,11 +86,11 @@ public class LandOrSeaServiceImpl implements LandOrSeaService {
public void afterPropertiesSet() throws MalformedURLException, IOException {
// http://openstreetmapdata.com/data/land-polygons
// Use "split large polygons"
final DataStore dataStoreLand = openShapeFile("land_polygons.shp");
final DataStore dataStoreLand = ShapefileUtils.openShapeFile(new File(dataFolderPath, "land_polygons.shp"));
// http://openstreetmapdata.com/data/water-polygons
// Use "split large polygons"
final DataStore dataStoreWater = openShapeFile("water_polygons.shp");
final DataStore dataStoreWater = ShapefileUtils.openShapeFile(new File(dataFolderPath, "water_polygons.shp"));
sourceLand = dataStoreLand.getFeatureSource(dataStoreLand.getTypeNames()[0]);
sourceWater = dataStoreWater.getFeatureSource(dataStoreWater.getTypeNames()[0]);
......@@ -237,23 +240,4 @@ public class LandOrSeaServiceImpl implements LandOrSeaService {
}
}
/**
* Open shape file.
*
* @param shapeFilePath the shape file path
* @return the data store
* @throws MalformedURLException the malformed url exception
* @throws IOException Signals that an I/O exception has occurred.
*/
private DataStore openShapeFile(final String shapeFilePath) throws MalformedURLException, IOException {
final File file = new File("data", shapeFilePath);
final Map<String, Object> map = new HashMap<>();
map.put("url", file.toURI().toURL());
LOG.debug("Opening shapeFile at {}", file.toURI().toURL());
final DataStore dataStore = DataStoreFinder.getDataStore(map);
return dataStore;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment