[Gvsig_desarrolladores] ayuda

Andres Felipe jama felipes177 en hotmail.com
Sab Sep 24 18:33:15 CEST 2011








> >
> >
> > hola señores desarrolladores
> > estoy  tratando de llamas unas capas de mi base de datos postgres,   pero al
> > importar esto me generar error import
> > com.iver.cit.gvsig.fmap.DriverException; , saben uds donde puede encontrar
> > ese paquete o librería gracias
> > ackage org.gvsig.proyecto;
> > import java.awt.Cursor;
> > import java.beans.Statement;
> > import java.io.*;
> > import java.sql.Connection;
> > import java.sql.DriverManager;
> > import java.sql.ResultSet;
> > import java.sql.SQLException;
> > import javax.swing.JOptionPane;
> >
> > import org.geotools.data.DataSourceException;
> > import org.geotools.data.DataStore;
> > import org.geotools.data.FeatureSource;
> > import org.geotools.data.postgis.PostgisDataStore;
> > import org.geotools.data.postgis.PostgisDataStoreFactory;
> > import com.iver.cit.gvsig.fmap.DriverException;
> > import com.iver.cit.gvsig.fmap.MapContext;
> > import com.iver.cit.gvsig.fmap.MapControl;
> > import com.iver.cit.gvsig.fmap.drivers.*;
> > import com.iver.cit.gvsig.fmap.drivers.jdbc.postgis.PostGisDriver;
> > import com.iver.cit.gvsig.fmap.layers.*;
> > import com.iver.cit.gvsig.project.documents.view.IProjectView;
> > import com.iver.cit.gvsig.project.documents.view.gui.BaseView;
> > import com.iver.cit.gvsig.project.documents.view.gui.IView;
> > import com.iver.cit.gvsig.project.documents.view.gui.View;
> > import com.iver.andami.PluginServices;
> > import com.iver.andami.messages.NotificationManager;
> > import com.iver.andami.plugins.Extension;
> > /**
> >  *
> >  * @author Felipe
> >  */
> > public class Intento {
> >
> >     public void initialize() {
> > }
> > public void execute(String actionCommand) {
> > com.iver.andami.ui.mdiManager.IWindow view =
> > PluginServices.getMDIManager().getActiveWindow();
> > if(view instanceof View)
> > {
> >  View vista=(View)view;
> >  IProjectView model = vista.getModel();
> >  MapContext mapa = model.getMapContext();
> >  MapControl mapCtrl = vista.getMapControl();
> >         CargadorCapas cargador = new CargadorCapas();
> >  JOptionPane.showMessageDialog(null, "Esto es una vista");
> >
> >       cargador.cargarTabla("parcelas", 0, mapCtrl, vista);
> >       cargador.cargarTabla("pozo", 1, mapCtrl, vista);
> >       cargador.cargarTabla("marabu", 2, mapCtrl, vista);
> >       cargador.cargarTabla("const", 3, mapCtrl, vista);
> > }
> > else
> > {
> > JOptionPane.showMessageDialog(null, "Esto no es una vista");
> > }
> > }
> >
> > public boolean isEnabled() {
> > return true;
> > }
> > public boolean isVisible() {
> > return true;
> > }
> > }
> >
> >
> > package org.gvsig.proyecto;
> > import java.sql.Connection;
> > import java.sql.DatabaseMetaData;
> > import java.sql.ResultSet;
> > import java.util.ArrayList;
> > import javax.swing.JOptionPane;
> > import org.apache.log4j.Logger;
> > import org.cresques.cts.IProjection;
> > import org.cresques.cts.ProjectionPool;
> > import com.hardcode.driverManager.Driver;
> > import com.iver.andami.PluginServices;
> > import com.iver.cit.gvsig.fmap.MapControl;
> > import com.iver.cit.gvsig.fmap.core.ICanReproject;
> > import com.iver.cit.gvsig.fmap.crs.CRSFactory;
> > import com.iver.cit.gvsig.fmap.drivers.ConnectionFactory;
> > import com.iver.cit.gvsig.fmap.drivers.ConnectionJDBC;
> > import com.iver.cit.gvsig.fmap.drivers.DBLayerDefinition;
> > import com.iver.cit.gvsig.fmap.drivers.FieldDescription;
> > import com.iver.cit.gvsig.fmap.drivers.IConnection;
> > import com.iver.cit.gvsig.fmap.drivers.IVectorialJDBCDriver;
> > import com.iver.cit.gvsig.fmap.drivers.jdbc.postgis.PostGISWriter;
> > import com.iver.cit.gvsig.fmap.layers.FLayer;
> > import com.iver.cit.gvsig.fmap.layers.FLyrVect;
> > import com.iver.cit.gvsig.fmap.layers.LayerFactory;
> > import com.iver.cit.gvsig.project.documents.view.gui.View;
> >
> > /**
> >  *
> >  * @author Felipe
> >  */
> > public class CargadorCapas {
> >
> >      private static String selectedDriver;
> > private static Logger log = Logger.getLogger(CargadorCapas.class);
> >
> >
> > public CargadorCapas() {
> > selectedDriver = "PostGIS JDBC Driver";
> > }
> > /**
> > * Crea una capa a partir de una tabla de la BD y la añade al
> > <code>mapControl y a la Vista <code>v
> > * @param mapControl
> > * @param v
> > */
> >
> > public FLyrVect cargarTabla(String nombreTabla,  int posicion ,MapControl
> > mapControl, View v) {
> > String dbURL = "jdbc:postgresql://localhost:5432/gps_geored";
> >         String user = "postgres";
> >         String pwd = "postgres";
> >
> >         IConnection conex = null;
> > try {
> > IVectorialJDBCDriver dbDriver = (IVectorialJDBCDriver)
> > LayerFactory.getDM().getDriver("PostGIS JDBC Driver");
> > Driver drv = LayerFactory.getDM().getDriver(selectedDriver);
> > conex = ConnectionFactory.createConnection(dbURL, user, pwd);
> > /*creamos la definicion para la capa*/
> > DBLayerDefinition dbLayerDef = new DBLayerDefinition();
> > dbLayerDef.setCatalogName("gps_geored"); //Nombre de la base de datos
> > dbLayerDef.setSchema("public"); //Nombre del esquema
> > dbLayerDef.setTableName(nombreTabla); //Nombre de la tabla
> > dbLayerDef.setFieldGeometry("the_geom");
> > dbLayerDef.setFieldID("gid");
> > dbLayerDef.setWhereClause("");
> > dbLayerDef.setConnection(conex);
> > /*obtenemos conexion JDBC*/
> > Connection conexion = ((ConnectionJDBC) conex).getConnection();
> > DatabaseMetaData metadataDB = conexion.getMetaData();
> > String tipos[] = new String[1];
> > tipos[0] = "TABLE";
> > ResultSet tablas = metadataDB.getTables(null, null, nombreTabla, tipos);
> > tablas.next();
> > String t = tablas.getString(tablas.findColumn( "TABLE_NAME" ));
> > ResultSet columnas = metadataDB.getColumns(null,null,nombreTabla, "%");
> > ResultSet claves = metadataDB.getPrimaryKeys(null, null, nombreTabla);
> > ArrayList<FieldDescription> descripciones = new ArrayList
> > <FieldDescription>();
> > ArrayList<String> nombres = new ArrayList<String>();
> > while(columnas.next()) {
> > log.info("Tratando atributo: \""+columnas.getString("Column_Name")+"\" de la
> > tabla: "+nombreTabla);
> > if(columnas.getString("Type_Name").equalsIgnoreCase("geometry")) {
> > /*si es la columna de geometria*/
> > log.info("Encontrado atributo de geometria para la tabla:"+nombreTabla);
> > dbLayerDef.setFieldGeometry(columnas.getString("Column_Name"));
> > }
> > else {
> > FieldDescription fieldDescription = new FieldDescription();
> > fieldDescription.setFieldName(columnas.getString("Column_Name"));
> > fieldDescription.setFieldType(columnas.getType());
> > descripciones.add(fieldDescription);
> > nombres.add(columnas.getString("Column_Name"));
> > }
> > }
> > FieldDescription fields[] = new FieldDescription[descripciones.size()];
> > String s[] = new String[nombres.size()];
> > for(int i = 0; i < descripciones.size(); i++)  {
> > fields[i] = descripciones.get(i);
> > s[i] = nombres.get(i);
> > }
> > dbLayerDef.setFieldsDesc(fields);
> > dbLayerDef.setFieldNames(s);
> > /*buscamos clave primaria y la añadimos a la definicion de la capa*/
> >   while(claves.next()) {
> >    dbLayerDef.setFieldID(claves.getString("Column_Name"));
> >    }
> > PostGISWriter writer = new PostGISWriter();
> > writer.setWriteAll(false);
> > writer.setCreateTable(false);
> > IProjection proj = null;
> > String strEPSG = "3115";
> > if (drv instanceof ICanReproject)
> > {
> > dbLayerDef.setSRID_EPSG(strEPSG);
> >     if (dbDriver instanceof ICanReproject)
> >     {
> >         ((ICanReproject)dbDriver).setDestProjection(strEPSG);
> >     }
> >       dbDriver.setData(conex, dbLayerDef);
> >
> >     if (dbDriver instanceof ICanReproject)
> >     {
> >      // el error lo da aquiiiiiii
> >
> >     // proj = CRSFactory.getCRS("EPSG:" +
> > ((ICanReproject)dbDriver).getSourceProjection(null,dbLayerDef));
> >
> >     proj = CRSFactory.getCRS("EPSG:3115");
> >
> >     }
> > }
> > FLayer lyr =  LayerFactory.createDBLayer(dbDriver, nombreTabla, proj);
> > if (lyr != null) {
> >     lyr.setVisible(true);
> >     v.getMapControl().getMapContext().beginAtomicEvent();
> >     // Comprobamos si es necesario reproyectar
> >     checkProjection(lyr, v.getMapControl());
> >
> >     v.getMapControl().getMapContext().getLayers().addLayer(lyr);
> >     v.getMapControl().getMapContext().endAtomicEvent();
> > }
> >
> > return (FLyrVect) lyr;
> > } catch (Exception e) {
> > log.warn("No se pudo cargar capa de la tabla: "+nombreTabla);
> > e.printStackTrace();
> > return null;
> > }
> > }
> >
> > private void checkProjection(FLayer lyr, MapControl mc)
> >     {
> >         if (lyr instanceof FLyrVect)
> >         {
> >             FLyrVect lyrVect = (FLyrVect) lyr;
> >             IProjection proj = lyr.getProjection();
> >             // Comprobar que la proyección es la misma que la vista
> >             if (proj == null)
> >             {
> >                 // SUPONEMOS que la capa está en la proyección que
> >                 // estamos pidiendo (que ya es mucho suponer, ya).
> >                  log.warn("Reproyectando capa "+lyr.getName()+" porque no
> > tenía proyección asignada");
> >                 lyrVect.setProjection( mc.getViewPort().getProjection());
> >                 return;
> >             }
> >             if
> >
> > (!proj.getAbrev().equals(mc.getViewPort().getProjection().getAbrev())) {
> >                 int option =
> > JOptionPane.showConfirmDialog(null,PluginServices.getText(this,
> > "reproyectar_aviso"),
> >                              PluginServices.getText(this,
> > "reproyectar_pregunta"),JOptionPane.YES_NO_OPTION);
> >                 if (option == JOptionPane.NO_OPTION) {
> >                     return;
> >                 } else {
> >                     log.error("coordTrans = " + proj.getAbrev() + " " +
> > mc.getViewPort().getProjection().getAbrev());
> >
> >                     lyrVect.reProject(mc);
> >                     System.err.println("coordTrans = " +
> >                         proj.getAbrev() + " " +
> >                         mc.getViewPort().getProjection().getAbrev());
> >                 }
> >             }
> >         }
> >     }
> >
> > }
> > tambien me genera error aqui    lyrVect.reProject(mc); y no se a que se debe
> > su ayuda me seria  muy util muchismas gracias
> >
> > pd: trabajo con netbeans y compilo con apache ant!!!
> >
> > Andrés Felipe Jama Cuellar
> > Estudiante de Ingeniería Topográfica
> > Universidad del Valle
> 
> 
> 
> -- 
> Francisco Puga
> Grupo de Desarrollo
> Cartolab - Laboratorio de Ingeniería Cartográfica.
> http://www.cartolab.es
> 
> ETS Ingeniería de Caminos, Canales y Puertos
> Universidade da Coruña
> Campus de Elviña - 15071 A Coruña (España)
> (34)981167000 ext. 5493
 		 	   		  
------------ próxima parte ------------
Se ha borrado un adjunto en formato HTML...
URL: http://listserv.gva.es/pipermail/gvsig_desarrolladores/attachments/20110924/74682544/attachment.htm 


Más información sobre la lista de distribución gvSIG_desarrolladores