Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [udig-devel] MapEditor Render Problem

Hi Jesse,
 
Thanks for the reply. Currently using Udig 1.2-RC2 which I believe has Geotools 2.6.3
 
Andrew
On 1 April 2010 16:03, Jesse Eichar <jesse.eichar@xxxxxxxxxxxxxx> wrote:
I think you need a new version.  I had this problem on a Geotools project that used 2.6.1 (I think that is the correct version).  I upgraded to the most recent and it all worked.

Jesse

On Thu, Apr 1, 2010 at 4:32 PM, Andrew Cleveland <andrew.cleveland@xxxxxxxxx> wrote:
Hi Guys,
 
Just starting out with Udig. Trying to create a simple polygon on a temporary layer for users to edit within my own RCP, but seem to have a rendering problem. This is the error I see and my code. Is this the correct way to create an editor or should I extend from EditorPart and create an instance of the MapEditor (similar to the rcp tutorial MapView class)
 
Thanks in advance for any help
 
Andrew
 
java.lang.ClassCastException: com.vividsolutions.jts.geom.Polygon cannot be cast to com.vividsolutions.jts.geom.Geometry
 at org.geotools.data.memory.MemoryDataStore.getBounds(MemoryDataStore.java:600)
 at org.geotools.data.AbstractFeatureSource.getBounds(AbstractFeatureSource.java:308)
 at org.geotools.data.AbstractFeatureSource.getBounds(AbstractFeatureSource.java:276)
 at net.refractions.udig.catalog.memory.internal.MemoryGeoResourceImpl$ScratchResourceInfo.getBounds(MemoryGeoResourceImpl.java:155)
 at net.refractions.udig.project.internal.impl.GeoResourceInfoInterceptor$Wrapper.getBounds(GeoResourceInfoInterceptor.java:67)
 at net.refractions.udig.project.internal.impl.LayerImpl.obtainBoundsFromResources(LayerImpl.java:2014)
 at net.refractions.udig.project.internal.impl.LayerImpl.getBounds(LayerImpl.java:1985)
 at net.refractions.udig.project.internal.impl.MapImpl.getBounds(MapImpl.java:676)
 at net.refractions.udig.project.internal.impl.InitMapBoundsInterceptor.run(InitMapBoundsInterceptor.java:43)
 at net.refractions.udig.project.internal.impl.LayersList2.runNonDeprecatedInterceptors(LayersList2.java:189)
 at net.refractions.udig.project.internal.impl.LayersList2.runLayerInterceptor(LayersList2.java:178)
 at net.refractions.udig.project.internal.impl.LayersList2.runAddInterceptors(LayersList2.java:165)
 at net.refractions.udig.project.internal.impl.LayersList2.inverseAdd(LayersList2.java:100)
 at org.eclipse.emf.common.notify.impl.NotifyingListImpl.addAllUnique(NotifyingListImpl.java:458)
 at org.eclipse.emf.common.util.AbstractEList.addAll(AbstractEList.java:410)
 at net.refractions.udig.project.internal.commands.AddLayersCommand.run(AddLayersCommand.java:89)
 at net.refractions.udig.project.command.CommandManager$Executor.execute(CommandManager.java:400)
 at net.refractions.udig.project.command.CommandManager$Executor.run(CommandManager.java:325)
 at net.refractions.udig.project.command.CommandManager$Executor.run(CommandManager.java:311)
 at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)
 
This is my simple class !
 
public class GeoFenceEdit extends MapEditor {
 private Log log = LogFactory.getLog(GeoFenceEdit.class);
 
 private GeofenceSpatialBean geofenceBean;
 
 
 /* (non-Javadoc)
  * @see net.refractions.udig.project.ui.internal.MapEditor#init(org.eclipse.ui.IEditorSite, org.eclipse.ui.IEditorInput)
  */
 @Override
 public void init(IEditorSite site, IEditorInput input) {
  super.init(site, input);
  
  /*
   * Extract the geofence from the input
   */
  geofenceBean = ((GeoFenceEditorInput)input).getGeofenceBean();
  
  /*
   * Set the tab title
   */
  getMap().setName(geofenceBean.getName()); 
 }

 /* (non-Javadoc)
  * @see net.refractions.udig.project.ui.internal.MapEditor#createPartControl(org.eclipse.swt.widgets.Composite)
  */
 @Override
 public void createPartControl(Composite parent) {
  super.createPartControl(parent);
 
  /*
   * Add the geofence layer
   */
  drawGeofence();
 }
 
 private void drawGeofence() {
  try {   
   SimpleFeatureType GEOFENCE = createFeatureType();
   
   SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(GEOFENCE);
 
   featureBuilder.add(geofenceBean.getPolygon());
   featureBuilder.add(geofenceBean.getName());
   
   // build the feature
   SimpleFeature feature = featureBuilder.buildFeature(geofenceBean.getIdAsString());
   FeatureCollection<SimpleFeatureType,SimpleFeature> fc = FeatureCollections.newCollection(geofenceBean.getIdAsString());
   fc.add(feature);
   
   IGeoResource resource = CatalogPlugin.getDefault().getLocalCatalog().createTemporaryResource(GEOFENCE);
    
   resource.resolve(FeatureStore.class, new NullProgressMonitor()).addFeatures(fc);
   
   ApplicationGIS.addLayersToMap(getMap(), Collections.singletonList(resource), -1);  
  } catch (IOException e) {
   log.error(e);
  }
 }
 
 private SimpleFeatureType createFeatureType() {
  SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
  
  builder.setName("Geofence");
  builder.setCRS(DefaultGeographicCRS.WGS84);
  
  // add attributes in order
  builder.add("Location", Polygon.class);
  builder.add("Name", String.class);
  // Set the default geometry
  builder.setDefaultGeometry("Location");
  
  // build the type
  final SimpleFeatureType GEOFENCE = builder.buildFeatureType();
  
  return GEOFENCE;
    }
}
 

_______________________________________________
User-friendly Desktop Internet GIS (uDig)
http://udig.refractions.net
http://lists.refractions.net/mailman/listinfo/udig-devel



_______________________________________________
User-friendly Desktop Internet GIS (uDig)
http://udig.refractions.net
http://lists.refractions.net/mailman/listinfo/udig-devel



Back to the top