Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Genesys PGR
Geo Tools
Commits
f5469f9a
Commit
f5469f9a
authored
Apr 19, 2018
by
Matija Obreza
Browse files
Make shape file source folder configurable
parent
a3f21dcf
Changes
3
Hide whitespace changes
Inline
Side-by-side
genesys-geotools/src/main/java/org/genesys/geotools/service/ShapefileUtils.java
View file @
f5469f9a
...
...
@@ -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
shapeFile
Path
)
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"
,
f
ile
.
toURI
().
toURL
());
System
.
err
.
println
(
f
ile
.
toURI
().
toURL
());
map
.
put
(
"url"
,
shapeF
ile
.
toURI
().
toURL
());
System
.
err
.
println
(
shapeF
ile
.
toURI
().
toURL
());
final
DataStore
dataStore
=
DataStoreFinder
.
getDataStore
(
map
);
return
dataStore
;
...
...
genesys-geotools/src/main/java/org/genesys/geotools/service/impl/CountryOfOriginServiceImpl.java
View file @
f5469f9a
...
...
@@ -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
]);
...
...
genesys-geotools/src/main/java/org/genesys/geotools/service/impl/LandOrSeaServiceImpl.java
View file @
f5469f9a
...
...
@@ -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
;
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment