示例#1
0
 /**
  * Construct <code>ShpGeoResourceImpl</code>.
  *
  * @param parent
  * @param typename
  */
 public ShpGeoResourceImpl(ShpServiceImpl parent, String typename) {
   this.service = parent;
   this.parent = parent;
   this.typename = typename;
   try {
     identifier = new URL(parent.getIdentifier().toString() + "#" + typename); // $NON-NLS-1$
     id = new ID(parent.getID(), typename);
   } catch (MalformedURLException e) {
     identifier = parent.getIdentifier();
   }
 }
示例#2
0
 /*
  * Required adaptions:
  * <ul>
  * <li>IGeoResourceInfo.class
  * <li>IService.class
  * </ul>
  * @see net.refractions.udig.catalog.IResolve#resolve(java.lang.Class, org.eclipse.core.runtime.IProgressMonitor)
  */
 public <T> T resolve(Class<T> adaptee, IProgressMonitor monitor) throws IOException {
   if (adaptee == null) {
     return null;
   }
   if (adaptee.isAssignableFrom(IGeoResource.class)) {
     return adaptee.cast(this);
   }
   if (adaptee.isAssignableFrom(IGeoResourceInfo.class)) {
     return adaptee.cast(createInfo(monitor));
   }
   if (adaptee.isAssignableFrom(FeatureStore.class)) {
     FeatureSource<SimpleFeatureType, SimpleFeature> fs = featureSource(monitor);
     if (fs instanceof FeatureStore) {
       return adaptee.cast(fs);
     }
   }
   if (adaptee.isAssignableFrom(FeatureSource.class)) {
     return adaptee.cast(featureSource(monitor));
   }
   if (adaptee.isAssignableFrom(IndexedShapefileDataStore.class)) {
     return adaptee.cast(parent.getDS(monitor));
   }
   if (adaptee.isAssignableFrom(Style.class)) {
     Style style = style(monitor);
     if (style != null) {
       return adaptee.cast(style(monitor));
     }
     // proceed to ask the super class, someone may
     // of written an IResolveAdapaterFactory providing us
     // with a style ...
   }
   return super.resolve(adaptee, monitor);
 }
示例#3
0
  public Style style(IProgressMonitor monitor) {
    URL url = parent.getIdentifier();
    File file = URLUtils.urlToFile(url);
    String shp = file.getAbsolutePath();

    StyleFactory styleFactory = CommonFactoryFinder.getStyleFactory(GeoTools.getDefaultHints());

    // strip off the extension and check for sld
    String sld = shp.substring(0, shp.length() - 4) + ".sld"; // $NON-NLS-1$
    File f = new File(sld);
    if (!f.exists()) {
      // try upper case
      sld = shp.substring(0, shp.length() - 4) + ".SLD"; // $NON-NLS-1$
      f = new File(sld);
    }

    if (f.exists()) {
      // parse it up
      SLDParser parser = new SLDParser(styleFactory);
      try {
        parser.setInput(f);
      } catch (FileNotFoundException e) {
        return null; // well that is unexpected since f.exists()
      }
      Style[] styles = parser.readXML();

      FeatureSource<SimpleFeatureType, SimpleFeature> source;
      try {
        source = featureSource(null);
      } catch (IOException e) {
        return null; // does not look like there is anything in the shapefile
      }
      SimpleFeatureType featureType = source.getSchema();
      // put the first one on
      if (styles != null && styles.length > 0) {
        Style style = SLD.matchingStyle(styles, featureType);
        if (style == null) {
          style = styles[0];
        }

        makeGraphicsAbsolute(file, style);
        return style;
      }
    }
    return null; // well nothing worked out; make your own style
  }
示例#4
0
 private FeatureSource<SimpleFeatureType, SimpleFeature> featureSource(IProgressMonitor monitor)
     throws IOException {
   return parent.getDS(monitor).getFeatureSource();
 }
示例#5
0
 /*
  * @see net.refractions.udig.catalog.IGeoResource#getStatusMessage()
  */
 public Throwable getMessage() {
   return parent.getMessage();
 }
示例#6
0
 /*
  * @see net.refractions.udig.catalog.IGeoResource#getStatus()
  */
 public Status getStatus() {
   return parent.getStatus();
 }