Project

General

Profile

« Previous | Next » 

Revision 5829

geoserver upgrade:
-remove embedded geoserver
-include geotools api and update spatial harvesting
-include simple template for using maps in skin (openlayers now, not mapbuilder)

View differences:

SpatialFeatureSchema.java
22 22
 */
23 23
package edu.ucsb.nceas.metacat.spatial;
24 24

  
25
import org.apache.log4j.Logger;
26
import org.geotools.feature.simple.SimpleFeatureTypeBuilder;
27
import org.opengis.feature.simple.SimpleFeatureType;
28

  
25 29
import edu.ucsb.nceas.metacat.util.SystemUtil;
26 30
import edu.ucsb.nceas.utilities.PropertyNotFoundException;
27 31

  
28
import com.vividsolutions.jts.geom.MultiPolygon;
29
import com.vividsolutions.jts.geom.MultiPoint;
30
import org.geotools.feature.AttributeType;
31
import org.geotools.feature.AttributeTypeFactory;
32
import org.geotools.feature.FeatureType;
33
import org.geotools.feature.FeatureTypeFactory;
34
import org.geotools.feature.SchemaException;
35

  
36
import org.apache.log4j.Logger;
37

  
38 32
/**
39 33
 * Class representing the geotools feature schemas and file paths
40 34
 * for the spatial data cache.
......
43 37

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

  
46
	private static String certPath;
40
	public static String polygonShpUri = null;
41
	public static String pointShpUri = null;
47 42
	static {
48 43
		try {
49
			certPath = SystemUtil.getContextDir();
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
			
50 55
		} catch (PropertyNotFoundException pnfe) {
51 56
			System.err.println("Error in SpatialFeatureSchema static block:"
52 57
                    + pnfe.getMessage());
53 58
            pnfe.printStackTrace();
54 59
		}
55 60
	}
56
	public static String polygonShpUri = certPath + "/data/metacat_shps/data_bounds.shp";
57
	public static String pointShpUri = certPath + "/data/metacat_shps/data_points.shp";
61
	
58 62

  
59 63

  
60 64
  // EPSG for latlong coordinate system w/ WGS84 datum
......
68 72
  /**
69 73
   * Creates the featuretype schema for polygon bounds
70 74
   */
71
  public static FeatureType getPolygonFeatureType() {
75
  public static SimpleFeatureType getPolygonFeatureType() {
72 76
    try {
73
        AttributeType[] types = new AttributeType[4];
74
        types[0] = AttributeTypeFactory.newAttributeType("the_geom", com.vividsolutions.jts.geom.MultiPolygon.class);
75
        types[1] = AttributeTypeFactory.newAttributeType("docid", String.class);
76
        types[2] = AttributeTypeFactory.newAttributeType("url", String.class);
77
        types[3] = AttributeTypeFactory.newAttributeType("title", String.class);
78
        FeatureType boundsType = FeatureTypeFactory.newFeatureType(types, "bounds");
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();
79 84
        return boundsType;
80
    } catch(SchemaException e) {
81
        log.error("schema exception : "+e);
85
    } catch(Exception e) {
86
        log.error("Problem building feature type : " + e);
82 87
        return null;
83 88
    }
84 89
  }
......
86 91
  /**
87 92
   * Creates the featuretype schema for point centroids
88 93
   */
89
  public static FeatureType getPointFeatureType() {
94
  public static SimpleFeatureType getPointFeatureType() {
90 95
    try {
91
        AttributeType[] types = new AttributeType[4];
92
        types[0] = AttributeTypeFactory.newAttributeType("the_geom", com.vividsolutions.jts.geom.MultiPoint.class);
93
        types[1] = AttributeTypeFactory.newAttributeType("docid", String.class);
94
        types[2] = AttributeTypeFactory.newAttributeType("url", String.class);
95
        types[3] = AttributeTypeFactory.newAttributeType("title", String.class);
96
        FeatureType centroidsType = FeatureTypeFactory.newFeatureType(types, "centroids");
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();
97 103
        return centroidsType;
98
    } catch(SchemaException e) {
99
        log.error("schema exception : "+e);
104
    } catch(Exception e) {
105
        log.error("Problem building feature : "+e);
100 106
        return null;
101 107
    }
102 108
  }

Also available in: Unified diff