[geotk] Re: Geotoolkit Digest, Vol 29, Issue 3
Arnaud Vandecasteele
arnaud.sig at gmail.com
Mon Sep 12 04:17:05 EDT 2011
Thanks Martin,
I will wait for Johann comes back;
regards
Arnaud
> Message: 2
> Date: Sun, 11 Sep 2011 22:13:32 +0200
> From: Martin Desruisseaux <martin.desruisseaux at geomatys.fr>
> Subject: Re: [geotk] First try with geo-tk. Display a map with
> Shapefile
> To: geotoolkit at lists.osgeo.org
> Message-ID: <4E6D166C.50702 at geomatys.fr>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>
> Hello Arnaud
>
> Johann is in better position than me for answering your question. Right now he
> is in a rush because of the FOSS4G event which is hapenning this week. But I
> guess that during the next week things will calm down a bit...
>
> Regards,
>
> Martin
>
>
> Le 09/09/11 18:50, Arnaud Vandecasteele a écrit :
>> Hi all,
>>
>>
>> I'm "playing" with geo-tk and I'm trying to display a map which
>> contains a Shapefile.
>> I've almost succeed to do what I want but my data are not visible on the map.
>>
>> Did I miss something ?
>> If you could have a look on my code it will be great.
>>
>> Thanks for your help
>>
>> Best regards
>>
>> Arnaud
>>
>>
>> package geoTest;
>>
>> import java.awt.BorderLayout;
>> import java.awt.Color;
>> import java.awt.Dimension;
>> import java.io.File;
>> import java.net.MalformedURLException;
>> import java.net.URL;
>>
>> import javax.swing.JFrame;
>> import javax.swing.JPanel;
>>
>> import org.geotoolkit.data.FeatureCollection;
>> import org.geotoolkit.data.query.QueryBuilder;
>> import org.geotoolkit.data.shapefile.ShapefileDataStore;
>> import org.geotoolkit.gui.swing.go2.JMap2D;
>> import org.geotoolkit.gui.swing.go2.control.JNavigationBar;
>> import org.geotoolkit.map.MapBuilder;
>> import org.geotoolkit.map.MapContext;
>> import org.geotoolkit.map.MapLayer;
>> import org.geotoolkit.referencing.crs.DefaultGeographicCRS;
>> import org.geotoolkit.storage.DataStoreException;
>> import org.geotoolkit.util.RandomStyleFactory;
>> import org.opengis.feature.simple.SimpleFeature;
>> import org.opengis.feature.type.Name;
>>
>> public class createMapPanel {
>>
>> /**
>> * @param args
>> */
>> public static void main(String[] args) {
>> MapContext mapContext =
>> MapBuilder.createContext(DefaultGeographicCRS.WGS84);
>> addShpData(mapContext);
>>
>> JMap2D map = new JMap2D();
>> map.getContainer().setContext(mapContext);
>> map.setBackground(new Color(0,150,150));
>>
>> JFrame pJFrame = createGUI(map);
>> pJFrame.setVisible(true);
>> }
>>
>> public static JFrame createGUI(JMap2D map){
>> JFrame frm = new JFrame("My first map with GeoToolkit");
>>
>> //Add elements
>> JPanel pJPanel = new JPanel(new BorderLayout());
>> JNavigationBar navBar = new JNavigationBar(map);
>> pJPanel.add(BorderLayout.NORTH,navBar);
>> pJPanel.add(BorderLayout.CENTER, map);
>>
>> //Create
>> frm.setContentPane(pJPanel);
>> frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
>> frm.setSize(new Dimension(500,500));
>> frm.setVisible(true);
>> return frm;
>> }
>>
>> public static void addShpData(MapContext context){
>> try {
>> URL shapeURL = new
>> File("/home/arnaud/GisData/World/TM_WORLD_BORDERS-0.3/TM_WORLD_BORDERS-0.3.shp").toURI().toURL();
>> //final DataStore store = DataStoreFinder.getDataStore("url", shapeURL);
>> ShapefileDataStore store = new ShapefileDataStore(shapeURL);
>> final Name name = store.getNames().iterator().next();
>> final FeatureCollection<SimpleFeature> fs =
>> store.createSession(true).getFeatureCollection(QueryBuilder.all(name));
>> final MapLayer layer = MapBuilder.createFeatureLayer(fs,
>> RandomStyleFactory.createDefaultVectorStyle(fs));
>> layer.setVisible(true);
>> context.layers().add(layer);
>> } catch (MalformedURLException e) {
>> // TODO Auto-generated catch block
>> e.printStackTrace();
>> } catch (DataStoreException e) {
>> // TODO Auto-generated catch block
>> e.printStackTrace();
>> }
>> }
>>
>> }
>
>
>
> ------------------------------
>
> _______________________________________________
> Geotoolkit mailing list
> Geotoolkit at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/geotoolkit
>
>
> End of Geotoolkit Digest, Vol 29, Issue 3
> *****************************************
>
--
--------------------------------------------------------------------
Van De Casteele Arnaud
Mines Paris Tech - CRC
Sophia-Antipolis
0698 24 25 29
SIG - WebMapping - SOLAP - BI - GeoCollaboration
Web Site
http://geotribu.net/
http://www.sismaris.org/
More information about the Geotoolkit
mailing list