1
|
/**
|
2
|
* '$RCSfile$'
|
3
|
* Copyright: 2003 Regents of the University of California.
|
4
|
*
|
5
|
* Author: Matthew Perry
|
6
|
* '$Date: 2011-02-04 05:57:52 -0800 (Fri, 04 Feb 2011) $'
|
7
|
* '$Revision: 5913 $'
|
8
|
*
|
9
|
* This program is free software; you can redistribute it and/or modify
|
10
|
* it under the terms of the GNU General Public License as published by
|
11
|
* the Free Software Foundation; either version 2 of the License, or
|
12
|
* (at your option) any later version.
|
13
|
*
|
14
|
* This program is distributed in the hope that it will be useful,
|
15
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
16
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
17
|
* GNU General Public License for more details.
|
18
|
*
|
19
|
* You should have received a copy of the GNU General Public License
|
20
|
* along with this program; if not, write to the Free Software
|
21
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
22
|
*/
|
23
|
package edu.ucsb.nceas.metacat.spatial;
|
24
|
|
25
|
import org.apache.log4j.Logger;
|
26
|
import org.geotools.feature.simple.SimpleFeatureTypeBuilder;
|
27
|
import org.opengis.feature.simple.SimpleFeatureType;
|
28
|
|
29
|
import edu.ucsb.nceas.metacat.properties.PropertyService;
|
30
|
import edu.ucsb.nceas.metacat.util.SystemUtil;
|
31
|
import edu.ucsb.nceas.utilities.PropertyNotFoundException;
|
32
|
|
33
|
/**
|
34
|
* Class representing the geotools feature schemas and file paths
|
35
|
* for the spatial data cache.
|
36
|
*/
|
37
|
public class SpatialFeatureSchema {
|
38
|
|
39
|
private static Logger log = Logger.getLogger(SpatialFeatureSchema.class.getName());
|
40
|
|
41
|
public static String polygonShpUri = null;
|
42
|
public static String pointShpUri = null;
|
43
|
static {
|
44
|
try {
|
45
|
|
46
|
String geoserverDataDir = PropertyService.getProperty("geoserver.GEOSERVER_DATA_DIR");
|
47
|
if (geoserverDataDir != null && geoserverDataDir.length() > 0) {
|
48
|
// use configured resource (might be same as local)
|
49
|
polygonShpUri = geoserverDataDir + "/data/metacat_shps/data_bounds.shp";
|
50
|
pointShpUri = geoserverDataDir + "/data/metacat_shps/data_points.shp";
|
51
|
} else {
|
52
|
// use local resource
|
53
|
String certPath = SystemUtil.getContextDir();
|
54
|
polygonShpUri = certPath + "/spatial/geoserver/data/data/metacat_shps/data_bounds.shp";
|
55
|
pointShpUri = certPath + "/spatial/geoserver/data/data/metacat_shps/data_points.shp";
|
56
|
}
|
57
|
|
58
|
} catch (PropertyNotFoundException pnfe) {
|
59
|
System.err.println("Error in SpatialFeatureSchema static block:"
|
60
|
+ pnfe.getMessage());
|
61
|
pnfe.printStackTrace();
|
62
|
}
|
63
|
}
|
64
|
|
65
|
|
66
|
|
67
|
// EPSG for latlong coordinate system w/ WGS84 datum
|
68
|
public static int srid = 4326;
|
69
|
|
70
|
/** empty constructor **/
|
71
|
public SpatialFeatureSchema() {
|
72
|
|
73
|
}
|
74
|
|
75
|
/**
|
76
|
* Creates the featuretype schema for polygon bounds
|
77
|
*/
|
78
|
public static SimpleFeatureType getPolygonFeatureType() {
|
79
|
try {
|
80
|
SimpleFeatureTypeBuilder featureBuilder = new SimpleFeatureTypeBuilder();
|
81
|
featureBuilder.add("the_geom", com.vividsolutions.jts.geom.MultiPolygon.class);
|
82
|
featureBuilder.add("docid", String.class);
|
83
|
featureBuilder.add("url", String.class);
|
84
|
featureBuilder.add("title", String.class);
|
85
|
featureBuilder.setName("bounds");
|
86
|
SimpleFeatureType boundsType = featureBuilder.buildFeatureType();
|
87
|
return boundsType;
|
88
|
} catch(Exception e) {
|
89
|
log.error("Problem building feature type : " + e);
|
90
|
return null;
|
91
|
}
|
92
|
}
|
93
|
|
94
|
/**
|
95
|
* Creates the featuretype schema for point centroids
|
96
|
*/
|
97
|
public static SimpleFeatureType getPointFeatureType() {
|
98
|
try {
|
99
|
SimpleFeatureTypeBuilder featureBuilder = new SimpleFeatureTypeBuilder();
|
100
|
featureBuilder.add("the_geom", com.vividsolutions.jts.geom.MultiPolygon.class);
|
101
|
featureBuilder.add("docid", String.class);
|
102
|
featureBuilder.add("url", String.class);
|
103
|
featureBuilder.add("title", String.class);
|
104
|
featureBuilder.setName("centroids");
|
105
|
SimpleFeatureType centroidsType = featureBuilder.buildFeatureType();
|
106
|
return centroidsType;
|
107
|
} catch(Exception e) {
|
108
|
log.error("Problem building feature : "+e);
|
109
|
return null;
|
110
|
}
|
111
|
}
|
112
|
|
113
|
}
|