Você está na página 1de 4

package geopack;

import java.awt.*;
import java.awt.event.*;
import java.io.File;
import javax.swing.*;
import org.geotools.data.FileDataStore;
import org.geotools.data.FileDataStoreFinder;
import org.geotools.data.simple.SimpleFeatureSource;
import org.geotools.geometry.jts.JTSFactoryFinder;
import org.geotools.map.FeatureLayer;
import org.geotools.map.Layer;
import org.geotools.map.MapContent;
import org.geotools.renderer.*;
import org.geotools.renderer.lite.StreamingRenderer;
import org.geotools.styling.SLD;
import org.geotools.styling.Style;
import org.geotools.swing.*;
import org.geotools.swing.data.JFileDataStoreChooser;

import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.GeometryFactory;
import com.vividsolutions.jts.geom.Point;
public class geoframe2 {
JMapFrame map;
public geoframe2()
{
map=new JMapFrame();
map.enableToolBar(true);
map.enableLayerTable(true);
map.enableStatusBar(true);
map.setTitle("Goetools JMapFrame");
map.setSize(1280,900);
map.setJMenuBar(this.BuildMenu());
map.setVisible(true);

}
public static void main(String[] args) {
new geoframe2();
}
private JMenuBar BuildMenu()
{
JMenuBar barreMenu = new JMenuBar();
JMenu mFichier = new JMenu("Fichier");
JMenu mOutils = new JMenu("Outils");
barreMenu.add(mFichier);
barreMenu.add(mOutils);
JMenuItem iOpen = new JMenuItem("Open");
iOpen.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
openShapefile();
}
});
mFichier.add(iOpen);
barreMenu.add(mFichier);
barreMenu.add(mOutils);

return barreMenu;
}
private void openShapefile() {
File file = JFileDataStoreChooser.showOpenFile("shp", null);
File fileroad = new File("D:/LIN_DB/MAJORROADS_line.shp");
if (file != null) {
try
{
FileDataStore dataStore =FileDataStoreFinder.getDataStore(file);

SimpleFeatureSource source = dataStore.getFeatureSource();


Style style = SLD.createSimpleStyle(source.getSchema());

FileDataStore dataStore1 =FileDataStoreFinder.getDataStore(filer


oad);
SimpleFeatureSource source1 = dataStore1.getFeatureSource();
Style style1 = SLD.createSimpleStyle(source1.getSchema());

MapContent mapcontent = new MapContent();


Layer layer = new FeatureLayer(source, style);
Layer layer2 = new FeatureLayer(source1, style1);

//point
GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFa
ctory( null );
Coordinate coord = new Coordinate();
coord.x=43.76072222;
coord.y=-23.53838889;
Point point = geometryFactory.createPoint( coord );
//Layer layer3 = new FeatureLayer();

mapcontent.addLayer(layer);
mapcontent.addLayer(layer2);
map.setMapContent(mapcontent);
}
catch (Exception ex) {
throw new RuntimeException(ex);
}
}
}

Você também pode gostar