Project

General

Profile

1 3035 perry
/**
2
 *  '$RCSfile$'
3
 *  Copyright: 2003 Regents of the University of California.
4
 *
5
 * Author: Matthew Perry
6
 * '$Date$'
7
 * '$Revision$'
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 5829 leinfelder
import org.apache.log4j.Logger;
26
import org.geotools.feature.simple.SimpleFeatureTypeBuilder;
27
import org.opengis.feature.simple.SimpleFeatureType;
28
29 5847 leinfelder
import edu.ucsb.nceas.metacat.properties.PropertyService;
30 4080 daigle
import edu.ucsb.nceas.metacat.util.SystemUtil;
31
import edu.ucsb.nceas.utilities.PropertyNotFoundException;
32 3035 perry
33 3040 perry
/**
34
 * Class representing the geotools feature schemas and file paths
35
 * for the spatial data cache.
36
 */
37 3035 perry
public class SpatialFeatureSchema {
38
39 4080 daigle
	private static Logger log = Logger.getLogger(SpatialFeatureSchema.class.getName());
40 3035 perry
41 5829 leinfelder
	public static String polygonShpUri = null;
42
	public static String pointShpUri = null;
43 4080 daigle
	static {
44
		try {
45 5829 leinfelder
46 5847 leinfelder
			String geoserverDataDir = PropertyService.getProperty("geoserver.GEOSERVER_DATA_DIR");
47 5913 leinfelder
			if (geoserverDataDir != null && geoserverDataDir.length() > 0) {
48 5835 leinfelder
				// use configured resource (might be same as local)
49 5829 leinfelder
				polygonShpUri = geoserverDataDir + "/data/metacat_shps/data_bounds.shp";
50
				pointShpUri = geoserverDataDir + "/data/metacat_shps/data_points.shp";
51
			} else {
52 5835 leinfelder
				// use local resource
53 5829 leinfelder
				String certPath = SystemUtil.getContextDir();
54 5835 leinfelder
				polygonShpUri = certPath + "/spatial/geoserver/data/data/metacat_shps/data_bounds.shp";
55
				pointShpUri = certPath + "/spatial/geoserver/data/data/metacat_shps/data_points.shp";
56 5829 leinfelder
			}
57
58 4080 daigle
		} catch (PropertyNotFoundException pnfe) {
59
			System.err.println("Error in SpatialFeatureSchema static block:"
60
                    + pnfe.getMessage());
61
            pnfe.printStackTrace();
62
		}
63
	}
64 5829 leinfelder
65 3035 perry
66 4080 daigle
67 3035 perry
  // 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 3040 perry
  /**
76 3035 perry
   * Creates the featuretype schema for polygon bounds
77
   */
78 5829 leinfelder
  public static SimpleFeatureType getPolygonFeatureType() {
79 3035 perry
    try {
80 5829 leinfelder
    	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 3035 perry
        return boundsType;
88 5829 leinfelder
    } catch(Exception e) {
89
        log.error("Problem building feature type : " + e);
90 3035 perry
        return null;
91
    }
92
  }
93
94 3040 perry
  /**
95 3035 perry
   * Creates the featuretype schema for point centroids
96
   */
97 5829 leinfelder
  public static SimpleFeatureType getPointFeatureType() {
98 3035 perry
    try {
99 5829 leinfelder
    	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 3035 perry
        return centroidsType;
107 5829 leinfelder
    } catch(Exception e) {
108
        log.error("Problem building feature : "+e);
109 3035 perry
        return null;
110
    }
111
  }
112
113
}