Hi ,
I´m trying to do a program that I get one shapefile and show in a Jframe. It
runs and show a shapefile but there is still some errors that I put at the end
of this email.
If someone have one code source that do it , please send to me .
I have to deliver this program in a week.
What I am doing wrong ?
My code is :
import java.awt.*;
import java.awt.Dimension;
import java.awt.geom.AffineTransform;
import java.io.IOException;
import javax.swing.JComponent;
import org.geotools.data.shapefile.ShapefileDataStore;
import org.geotools.map.*;
import org.geotools.renderer.shape.ShapefileRenderer;
import org.geotools.styling.*;
import com.vividsolutions.jts.geom.*;
/**
* Esta classe representa um componente gráfico capaz de desenhar o conteúdo
* (geometria) de uma instância de ShapefileDataStore.
*/
public class ShapeFileInfo extends JComponent
{
private ShapefileDataStore sds;
private ShapefileRenderer renderer;
private Envelope envelope;
private final Coordinate center;
private double zoom;
private final int width = 640;
private final int height = 640;
public ShapeFileInfo(ShapefileDataStore sds) throws IOException
{
this.sds = sds;
// Criamos um Style
StyleBuilder sb = new StyleBuilder();
// Criamos símbolos para a linha
LineSymbolizer lineSymb = (LineSymbolizer) sb.createLineSymbolizer(Color.RED,
1);
Style style = sb.createStyle(lineSymb);
// Criamos um MapContext com os dados e um estilo
MapContext mc = new DefaultMapContext();
mc.addLayer(sds.getFeatureSource(),style);
// Agora com o contexto criamos um ShapefileRenderer
renderer = new ShapefileRenderer(mc);
envelope = mc.getLayerBounds();
center = new Coordinate((envelope.getMinX()+envelope.getMaxX())/2,
(envelope.getMinY()+envelope.getMaxY())/2);
zoom = 1;
}
public Dimension getMaximumSize() { return getPreferredSize(); }
public Dimension getMinimumSize() { return getPreferredSize(); }
public Dimension getPreferredSize() { return new Dimension(width,height); }
protected void paintComponent(Graphics g)
{
Graphics2D g2d = (Graphics2D)g;
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
g2d.setColor(Color.WHITE);
g2d.fillRect(0,0,width,height);
// Uma AffineTransform que mapeie dados no shapefile com a área para plotagem
AffineTransform at = new AffineTransform();
// Calculamos a escala
double escala = (Math.min(getWidth()/envelope.getWidth(),
getHeight()/envelope.getHeight())
*zoom);
// Fazemos a translação para o centro do componente.
at.translate (getWidth()/2,getHeight()/2);
// Mudamos a escala vertical para corrigir a orientação.
at.scale(escala,-escala);
// Fazemos a translação para o centro da geometria.
at.translate(-center.x,-center.y);
// Pintamos a geometria no componente.
renderer.paint(g2d,getBounds(),at);
}
}
import java.io.*;
import java.net.URL;
import javax.swing.JFrame;
import org.geotools.data.shapefile.ShapefileDataStore;
/*
* DisplayShapefile.java
*
* Created on 27 de Março de 2008, 11:13
*/
/**
*
* @author Felipe Gutierrez
*/
public class DisplayShapefile extends javax.swing.JFrame {
/** Creates new form DisplayShapefile */
public DisplayShapefile() throws IOException
{
super("Shapefile");
String baseDir = "E://Ufla//Projeto GeoProcessamento";
// Criamos uma URL com o shapefile que nos interessa.
URL s = new File(baseDir+"//Municipios.shp").toURL();
ShapefileDataStore data = new ShapefileDataStore(s);
ShapeFileInfo sc = new ShapeFileInfo(data);
getContentPane().add(sc);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
pack();
setVisible(true);
initComponents();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc=" Código Gerado ">
private void initComponents() {
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
javax.swing.GroupLayout layout = new
javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 400, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 300, Short.MAX_VALUE)
);
pack();
}// </editor-fold>
/**
* @param args the command line arguments
*/
public static void main(String args[])throws IOException {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
try {
new DisplayShapefile().setVisible(true);
System.out.println("ERRO");
} catch (IOException ex) {
ex.printStackTrace();
}
}
});
}
// Declaração de variáveis - não modifique
// Fim da declaração de variáveis
}
erros : Unavailable authority factory: European Petroleum Survey Group
org.opengis.referencing.FactoryException: Failed to connect to the EPSG
database.
at javax.imageio.spi.FilterIterator.advance(ServiceRegistry.java:793)
at javax.imageio.spi.FilterIterator.<init>(ServiceRegistry.java:787)
at
javax.imageio.spi.ServiceRegistry.getServiceProviders(ServiceRegistry.java:491)
at ShapeFileInfo.<init>(ShapeFileInfo.java:38)
at DisplayShapefile.<init>(DisplayShapefile.java:26)
at DisplayShapefile$1.run(DisplayShapefile.java:64)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
at
java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
at
java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
at
java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)
Caused by: java.sql.SQLException: [Microsoft][ODBC Driver Manager] Data source
name not found and no default driver specified
What I am doing wrong ?
If someone have one code source that do it , please send to me .
Thanks,
_________________________________________________________________
Cansado de espaço para só 50 fotos? Conheça o Spaces, o site de relacionamentos
com até 6,000 fotos!
http://www.amigosdomessenger.com.br-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
Geotools-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-devel