Project

General

Profile

1
/**
2
 *  '$RCSfile$'
3
 *  Copyright: 2003 Regents of the University of California.
4
 *
5
 * Author: Matthew Perry 
6
 * '$Date: 2011-01-21 15:08:31 -0800 (Fri, 21 Jan 2011) $'
7
 * '$Revision: 5829 $'
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.util.SystemUtil;
30
import edu.ucsb.nceas.utilities.PropertyNotFoundException;
31

    
32
/**
33
 * Class representing the geotools feature schemas and file paths
34
 * for the spatial data cache.
35
 */
36
public class SpatialFeatureSchema {
37

    
38
	private static Logger log = Logger.getLogger(SpatialFeatureSchema.class.getName());
39

    
40
	public static String polygonShpUri = null;
41
	public static String pointShpUri = null;
42
	static {
43
		try {
44
			
45
			String geoserverDataDir = System.getProperty("GEOSERVER_DATA_DIR");
46
			if (geoserverDataDir != null) {
47
				polygonShpUri = geoserverDataDir + "/data/metacat_shps/data_bounds.shp";
48
				pointShpUri = geoserverDataDir + "/data/metacat_shps/data_points.shp";
49
			} else {
50
				String certPath = SystemUtil.getContextDir();
51
				polygonShpUri = certPath + "/data/metacat_shps/data_bounds.shp";
52
				pointShpUri = certPath + "/data/metacat_shps/data_points.shp";
53
			}			
54
			
55
		} catch (PropertyNotFoundException pnfe) {
56
			System.err.println("Error in SpatialFeatureSchema static block:"
57
                    + pnfe.getMessage());
58
            pnfe.printStackTrace();
59
		}
60
	}
61
	
62

    
63

    
64
  // EPSG for latlong coordinate system w/ WGS84 datum
65
  public static int srid = 4326;
66

    
67
  /** empty constructor **/
68
  public SpatialFeatureSchema() {
69
         
70
  }
71

    
72
  /**
73
   * Creates the featuretype schema for polygon bounds
74
   */
75
  public static SimpleFeatureType getPolygonFeatureType() {
76
    try {
77
    	SimpleFeatureTypeBuilder featureBuilder = new SimpleFeatureTypeBuilder();
78
    	featureBuilder.add("the_geom", com.vividsolutions.jts.geom.MultiPolygon.class);
79
    	featureBuilder.add("docid", String.class);
80
    	featureBuilder.add("url", String.class);
81
    	featureBuilder.add("title", String.class);
82
    	featureBuilder.setName("bounds");
83
        SimpleFeatureType boundsType = featureBuilder.buildFeatureType();
84
        return boundsType;
85
    } catch(Exception e) {
86
        log.error("Problem building feature type : " + e);
87
        return null;
88
    }
89
  }
90

    
91
  /**
92
   * Creates the featuretype schema for point centroids
93
   */
94
  public static SimpleFeatureType getPointFeatureType() {
95
    try {
96
    	SimpleFeatureTypeBuilder featureBuilder = new SimpleFeatureTypeBuilder();
97
    	featureBuilder.add("the_geom", com.vividsolutions.jts.geom.MultiPolygon.class);
98
    	featureBuilder.add("docid", String.class);
99
    	featureBuilder.add("url", String.class);
100
    	featureBuilder.add("title", String.class);
101
    	featureBuilder.setName("centroids");
102
        SimpleFeatureType centroidsType = featureBuilder.buildFeatureType();
103
        return centroidsType;
104
    } catch(Exception e) {
105
        log.error("Problem building feature : "+e);
106
        return null;
107
    }
108
  }
109

    
110
}
(4-4/8)