[udig-devel] Adding a layer with a custom georesource
Nils Liebelt
Nils.Liebelt at web.de
Tue Jun 27 03:09:28 PDT 2006
Hi,
first of all I am new to udig and my question aims towards using udig. I could not find a users list so I try my luck here.
I want to write a plugin which fetches some coordinates from a normal (non geo) relational database. Build up some features with it and then display them in a new layer. For my first tests I tried using the MemoryDatasource and MemoryDataService:
Coordinate center = PlatformGIS.getActiveMap().getViewportModel().getCenter();
AttributeType geom = AttributeTypeFactory.newAttributeType("the_geom", LineString.class);
AttributeType roadWidth = AttributeTypeFactory.newAttributeType("width", Float.class);
FeatureTypeFactory factory = FeatureTypeFactory.newInstance("road");
factory.addTypes(new AttributeType[] { geom, roadWidth });
FeatureType ftRoad = factory.getFeatureType();
GeometryFactory gFactory = new GeometryFactory();
LineString geometry = gFactory.createLineString(new Coordinate[]{new Coordinate(center.x,center.y), new Coordinate(center.x+1,center.y+1), new Coordinate(center.x+10,center.y+10)});
Feature feat = ftRoad.create(new Object[]{geometry,new Float(10)}, "myFeature");
MemoryServiceImpl service = new MemoryServiceImpl();
AnotherMemoryDataStore ds = service.resolve(AnotherMemoryDataStore.class, null);
ds.createSchema(ftRoad);
ds.addFeature(feat);
IGeoResource res = new MemoryGeoResourceImpl("road",service);
List<IGeoResource> rL = new ArrayList<IGeoResource>();
rL.add(res);
PlatformGIS.addLayersToActiveMap(rL);
The layers command gets executed and the layer can be seen in the application; but for some reason the features cannot be accessed.
I debugged for hours through the udig code but I cannot really tell what's going on.
Whats is the best way in doing this? Am I on the right path..
Regards,
Nils Liebelt
More information about the udig-devel
mailing list