[Gvsig_desarrolladores] Excepcion al intentar escribir en la capa vectorial
vangel
vianber en hotmail.com
Lun Nov 12 17:47:55 CET 2012
Hola a todos,
estoy tratando de pintar puntos en una capa vectorial. Ejecuto el siguiente
codigo
public FLayer createLayer(String layerName, VectorialFileDriver d,
File f, IProjection proj) throws ReadDriverException {
VectorialFileAdapter adapter = new VectorialFileAdapter(f);
adapter.setDriver((VectorialDriver) d);
VectorialEditableAdapter vea=new VectorialEditableAdapter();
vea.setOriginalVectorialAdapter(adapter);
//FileEditableFeatureSource fefs=new
FileEditableFeatureSource((VectorialFileAdapter)adapter);
//MemoryExpansionFile mef=new MemoryExpansionFile();
//DefaultEditableFeatureSource defs=new
DefaultEditableFeatureSource(mef,fefs, new FBitSet());
// vea.start();
//FLyrVect capa = new FLyrVect();
FLyrVect capa = capaVectorial;
capa.setName(layerName);
//TODO Meter esto dentro de la comprobación de si hay memoria
if (false) {
} else {
capa.setSource(adapter);
capa.setProjection(proj);
}
try {
// Le asignamos también una legenda por defecto acorde con
// el tipo de shape que tenga. Tampoco sé si es aquí el
// sitio adecuado, pero en fin....
if (d instanceof WithDefaultLegend) {
WithDefaultLegend aux = (WithDefaultLegend) d;
adapter.start();
capa.setLegend((IVectorLegend) aux.getDefaultLegend());
adapter.stop();
} else {
capa.setLegend(LegendFactory.createSingleSymbolLegend(
capa.getShapeType()));
}
vea.startEdition(EditionEvent.GRAPHIC);
Value[] values=new Value[7];
values[0]=ValueFactory.createValue("hola0");
values[1]=ValueFactory.createValue("hola1");
values[2]=ValueFactory.createValue("hola2");
values[3]=ValueFactory.createValue("hello");
values[4]=ValueFactory.createValue("mec");
values[5]=ValueFactory.createValue(300d);
values[6]=ValueFactory.createValue(1d);
DefaultFeature df0=new
DefaultFeature(ShapeFactory.createPoint2D(1,3),values);
vea.addRow(df0,"",EditionEvent.GRAPHIC);
DefaultFeature df1=new
DefaultFeature(ShapeFactory.createPoint2D(2,4),values);
vea.addRow(df1,"",EditionEvent.GRAPHIC);
DefaultFeature df2=new
DefaultFeature(ShapeFactory.createPoint2D(3,5),values);
vea.addRow(df2,"", EditionEvent.GRAPHIC);
DefaultFeature df3=new
DefaultFeature(ShapeFactory.createPoint2D(4,6),values);
vea.addRow(df3,"", EditionEvent.GRAPHIC);
ShpWriter writer=null;
writer = (ShpWriter)LayerFactory.getWM().getWriter("Shape
Writer");
writer.initialize(capa);
vea.stopEdition(writer,EditionEvent.GRAPHIC);
} catch (ReadDriverException e) {
e.printStackTrace();
} catch (LegendLayerException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ValidateRowException e) {
e.printStackTrace();
} catch (StartWriterVisitorException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (DriverLoadException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (InitializeWriterException e) {
e.printStackTrace();
} catch (StopWriterVisitorException e) {
e.printStackTrace();
}
return null; //capa;
}
y parece que si que añade los puntos pero cuando ejecuta la línia
writer.initialize(capa);
me da la siguiente excepción:
Añade una Row en la posición: 5
Añade una Row en la posición: 6
Añade una Row en la posición: 7
Añade una Row en la posición: 8
java.lang.NullPointerException
at
com.iver.cit.gvsig.fmap.edition.writers.shp.ShpWriter.setFile(ShpWriter.java:82)
at
com.iver.cit.gvsig.fmap.edition.writers.shp.ShpWriter.initialize(ShpWriter.java:202)
at
com.iver.cit.gvsig.fmap.edition.writers.shp.ShpWriter.initialize(ShpWriter.java:167)
at org.gvsig.expedientsextension.Test.createLayer(Test.java:1120)
at
org.gvsig.expedientsextension.FinestraImportarExpedients.actionPerformed(FinestraImportarExpedients.java:280)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.AWTEventMulticaster.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at
com.iver.andami.ui.AndamiEventQueue.dispatchEvent(AndamiEventQueue.java:58)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
¿Alguien sabe que puede estar pasando?
--
View this message in context: http://osgeo-org.1560.n6.nabble.com/Excepcion-al-intentar-escribir-en-la-capa-vectorial-tp5015687.html
Sent from the gvSIG desarrolladores mailing list archive at Nabble.com.
Más información sobre la lista de distribución gvSIG_desarrolladores