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 { ...@@ -56,12 +56,11 @@ public class ShapefileUtils {
* @throws MalformedURLException the malformed url exception * @throws MalformedURLException the malformed url exception
* @throws IOException Signals that an I/O exception has occurred. * @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<>(); final Map<String, Object> map = new HashMap<>();
map.put("url", file.toURI().toURL()); map.put("url", shapeFile.toURI().toURL());
System.err.println(file.toURI().toURL()); System.err.println(shapeFile.toURI().toURL());
final DataStore dataStore = DataStoreFinder.getDataStore(map); final DataStore dataStore = DataStoreFinder.getDataStore(map);
return dataStore; return dataStore;
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
package org.genesys.geotools.service.impl; package org.genesys.geotools.service.impl;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
...@@ -74,6 +75,12 @@ public class CountryOfOriginServiceImpl implements CountryOfOriginService { ...@@ -74,6 +75,12 @@ public class CountryOfOriginServiceImpl implements CountryOfOriginService {
/** The debug. */ /** The debug. */
private final boolean debug = false; private final boolean debug = false;
private String dataFolderPath = "data";
public void setDataFolderPath(String dataFolderPath) {
this.dataFolderPath = dataFolderPath;
}
static { static {
try { try {
// Initialize stuff // Initialize stuff
...@@ -93,8 +100,8 @@ public class CountryOfOriginServiceImpl implements CountryOfOriginService { ...@@ -93,8 +100,8 @@ public class CountryOfOriginServiceImpl implements CountryOfOriginService {
public void afterPropertiesSet() throws MalformedURLException, IOException { public void afterPropertiesSet() throws MalformedURLException, IOException {
// http://www.gadm.org/version2 // http://www.gadm.org/version2
// Use "six dissolved layers" // Use "six dissolved layers"
final DataStore dataStoreAdm0 = ShapefileUtils.openShapeFile("TM_WORLD_BORDERS-0.3.shp"); final DataStore dataStoreAdm0 = ShapefileUtils.openShapeFile(new File(dataFolderPath, "TM_WORLD_BORDERS-0.3.shp"));
final DataStore dataStoreAdm0X = ShapefileUtils.openShapeFile("gadm28_adm1.shp"); final DataStore dataStoreAdm0X = ShapefileUtils.openShapeFile(new File(dataFolderPath, "gadm28_adm1.shp"));
sourceAdmin0 = dataStoreAdm0.getFeatureSource(dataStoreAdm0.getTypeNames()[0]); sourceAdmin0 = dataStoreAdm0.getFeatureSource(dataStoreAdm0.getTypeNames()[0]);
sourceAdmin0X = dataStoreAdm0X.getFeatureSource(dataStoreAdm0X.getTypeNames()[0]); sourceAdmin0X = dataStoreAdm0X.getFeatureSource(dataStoreAdm0X.getTypeNames()[0]);
......
...@@ -19,8 +19,6 @@ package org.genesys.geotools.service.impl; ...@@ -19,8 +19,6 @@ package org.genesys.geotools.service.impl;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
...@@ -28,7 +26,6 @@ import org.genesys.geotools.service.LandOrSeaService; ...@@ -28,7 +26,6 @@ import org.genesys.geotools.service.LandOrSeaService;
import org.genesys.geotools.service.LonLatCacheKey; import org.genesys.geotools.service.LonLatCacheKey;
import org.genesys.geotools.service.ShapefileUtils; import org.genesys.geotools.service.ShapefileUtils;
import org.geotools.data.DataStore; import org.geotools.data.DataStore;
import org.geotools.data.DataStoreFinder;
import org.geotools.data.FeatureSource; import org.geotools.data.FeatureSource;
import org.geotools.factory.CommonFactoryFinder; import org.geotools.factory.CommonFactoryFinder;
import org.geotools.feature.FeatureCollection; import org.geotools.feature.FeatureCollection;
...@@ -74,6 +71,12 @@ public class LandOrSeaServiceImpl implements LandOrSeaService { ...@@ -74,6 +71,12 @@ public class LandOrSeaServiceImpl implements LandOrSeaService {
/** The classifier cache. */ /** The classifier cache. */
private LoadingCache<LonLatCacheKey, String> classifierCache; private LoadingCache<LonLatCacheKey, String> classifierCache;
private String dataFolderPath = "data";
public void setDataFolderPath(String dataFolderPath) {
this.dataFolderPath = dataFolderPath;
}
/** /**
* After properties set. * After properties set.
* *
...@@ -83,11 +86,11 @@ public class LandOrSeaServiceImpl implements LandOrSeaService { ...@@ -83,11 +86,11 @@ public class LandOrSeaServiceImpl implements LandOrSeaService {
public void afterPropertiesSet() throws MalformedURLException, IOException { public void afterPropertiesSet() throws MalformedURLException, IOException {
// http://openstreetmapdata.com/data/land-polygons // http://openstreetmapdata.com/data/land-polygons
// Use "split large 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 // http://openstreetmapdata.com/data/water-polygons
// Use "split large 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]); sourceLand = dataStoreLand.getFeatureSource(dataStoreLand.getTypeNames()[0]);
sourceWater = dataStoreWater.getFeatureSource(dataStoreWater.getTypeNames()[0]); sourceWater = dataStoreWater.getFeatureSource(dataStoreWater.getTypeNames()[0]);
...@@ -237,23 +240,4 @@ public class LandOrSeaServiceImpl implements LandOrSeaService { ...@@ -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