arnauld:

From the below link I show a label rotation for multi LineString:

http://osgeo-org.1803224.n2.nabble.com/How-to-Make-Transparent-Overlay-Layer-td4127023.html#a4183749

If the issue is parsing xml you may want to start with SAX and then going to 
DOM.

Get the simple case working then move to a List of objects of lat, lon for more 
dynamic data population.

The following is a simple LineString plot:
package org.geotools.demo.examples;

import java.util.ArrayList;

import org.geotools.data.DataUtilities;
import org.geotools.feature.FeatureCollection;
import org.geotools.feature.FeatureCollections;
import org.geotools.feature.simple.SimpleFeatureBuilder;

import org.geotools.geometry.jts.JTSFactoryFinder;
import org.opengis.feature.simple.SimpleFeature;
import org.opengis.feature.simple.SimpleFeatureType;

import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.CoordinateArrays;
import com.vividsolutions.jts.geom.GeometryFactory;
import com.vividsolutions.jts.geom.LineString;
import com.vividsolutions.jts.geom.Point;

import org.geotools.feature.FeatureIterator;
import com.vividsolutions.jts.geom.Geometry;

import org.geotools.data.FeatureSource;

import org.geotools.map.DefaultMapContext;
import org.geotools.map.MapContext;
import org.geotools.swing.JMapFrame;

public class DisplayForcedLineString {


public static void main(String[] args) throws Exception {
    final SimpleFeatureType TYPE = DataUtilities.createType("Location", 
"location:LineString,name:String"); // see createFeatureType();

    FeatureCollection collection = FeatureCollections.newCollection();

        
    double lon[] = {15, 23, 50};
    double lat[] = {15, 30, 25};
        String name="test";
        
        ArrayList cords = new ArrayList();

        for(int i=0;i<=2;i++){
            cords.add(new Coordinate(lon[i],lat[i]));
        }
         
        GeometryFactory factory = JTSFactoryFinder.getGeometryFactory(null);    
        
        CoordinateArrays ca = new CoordinateArrays();
        Coordinate[] cord = ca.toCoordinateArray(cords);
        
        LineString lineString = factory.createLineString(cord);
        SimpleFeature feature = SimpleFeatureBuilder.build( TYPE, new 
Object[]{lineString, name}, null );

        collection.add( feature );
        
        FeatureIterator iterator = collection.features();
        try {
            while (iterator.hasNext()) {
                SimpleFeature features = (SimpleFeature)iterator.next();

                Geometry geometry = (Geometry) features.getDefaultGeometry();
                
                Coordinate[] coords = geometry.getCoordinates();
                for( int i = 0; i < coords.length; i++ ) {
                    System.out.println(coords[i]);
                }
            }
        }
        finally {
            if( iterator != null ){
                // YOU MUST CLOSE THE ITERATOR!
                iterator.close();
            }
        }
        
        
        
        FeatureSource featureSource = DataUtilities.source(collection);
        MapContext map = new DefaultMapContext();
        map.setTitle("Quickstart");
        map.addLayer(featureSource, null);

        // Now display the map
        JMapFrame.showMap(map);
}
}


-----Original Message-----
From: "arnauld ndefo" <[email protected]>
Sent: Wednesday, June 9, 2010 5:48pm
To: [email protected]
Subject: [Geotools-gt2-users] geotool+coordinate latitude, longitude





Here is all my java code
import org.geotools.feature.SchemaException;import 
org.geotools.feature.simple.SimpleFeatureBuilder;import 
org.geotools.geometry.jts.ReferencedEnvelope;import org.geotools.map.*;import 
org.geotools.referencing.CRS;import 
org.geotools.referencing.crs.DefaultGeocentricCRS;import 
org.geotools.referencing.crs.DefaultGeographicCRS;import 
org.geotools.renderer.lite.StreamingRenderer;import 
org.geotools.renderer.style.IconStyle2D;import 
org.geotools.resources.CRSUtilities;import org.geotools.styling.*;import 
org.geotools.swing.JMapFrame;import org.geotools.swing.JMapPane;import 
org.opengis.feature.simple.SimpleFeature;import 
org.opengis.feature.simple.SimpleFeatureType;import 
org.opengis.referencing.FactoryException;import 
org.opengis.referencing.NoSuchAuthorityCodeException;import 
org.opengis.referencing.crs.CoordinateReferenceSystem;import 
org.opengis.referencing.operation.TransformException;public class App {    
public static void main( String[] args ) throws IOException, 
FactoryRegistryException, SchemaException, ClassNotFoundException, Exception    
{        App app=new App();        Map params= new HashMap();        
params.put("dbtype", "postgis");        params.put("host", "localhost");        
params.put("port", "5432");        params.put("database", "gis");        
params.put("user", "arnauld");        params.put("passwd","root");        
//params.put(PostgisDataStoreFactory.LOOSEBBOX, "true" );        
params.put(PostgisDataStoreFactory.SCHEMA.key, "public" );      DataStore 
pgDatastore = DataStoreFinder.getDataStore(params);      FeatureSource osmline 
= pgDatastore.getFeatureSource("planet_osm_line");      FeatureSource osmpoint 
= pgDatastore.getFeatureSource("planet_osm_point");      FeatureSource 
osmpolygon=pgDatastore.getFeatureSource("planet_osm_polygon");      
FeatureSource osmroad=pgDatastore.getFeatureSource("planet_osm_roads"); 
StyleBuilder sb= new StyleBuilder();      ///Style des lignes      
LineSymbolizer line=  sb.createLineSymbolizer(Color.yellow,4);      Style 
style=sb.createStyle(line);      MapContext map=new 
DefaultMapContext();CoordinateReferenceSystem crs=CRS.decode("EPSG:4326",true); 
     //CoordinateReferenceSystem crs=DefaultGeographicCRS.WGS84;      
ReferencedEnvelope re=new ReferencedEnvelope(10.1602292, 
10.1741338,36.8468991,36.853853199999996, crs);      
map.setCoordinateReferenceSystem(crs);      map.setAreaOfInterest(re);      
map.setTitle("Carte géographique de menzah 6");      
map.addLayer(osmline.getFeatures(),null);      
map.addLayer(osmpoint.getFeatures(),null);      
map.addLayer(osmroad.getFeatures(),null);      
map.addLayer(osmpolygon.getFeatures(), stylepolygon); GeometryFactory geo=new 
GeometryFactory();Coordinate coord2 = new 
Coordinate(1131439.2747,4418792.6636);                Coordinate coord3 = new 
Coordinate(1131081.0001,4418731.4201);Coordinate coord1 = new 
Coordinate(1131270.8550,4418856.9693);Coordinate[] 
coord={coord3,coord1,coord2};    LineString lines =geo.createLineString(coord); 
    SimpleFeatureType 
type=DataUtilities.createType("line","centerline:LineString:srid=4326,name:String");
     FeatureCollection<SimpleFeatureType, SimpleFeature> fcline = 
FeatureCollections.newCollection();     SimpleFeatureBuilder featureBuilder = 
new SimpleFeatureBuilder(type);     featureBuilder.add(lines);     
SimpleFeature feature = featureBuilder.buildFeature(null);     
fcline.add(feature);map.addLayer(fcline, style);JMapFrame frame =new 
JMapFrame(map);               frame.enableStatusBar(true);        
frame.enableToolBar(true);              frame.setSize(700,700);        
frame.setVisible(true);This code draw LineString fine on the map. But in my 
file .xml i have rather this kind of data:<bounds minlat='36.8468991' 
minlon='10.1602292' maxlat='36.853853199999996' maxlon='10.1741338' 
origin='CGImap 0.0.2' />  <node id='243997182' timestamp='2008-01-29T14:58:17Z' 
uid='22060' user='chrischan' visible='true' version='1' changeset='708944' 
lat='36.8570917' lon='10.1670734' />  <node id='243997183' 
timestamp='2008-01-29T14:58:17Z' uid='22060' user='chrischan' visible='true' 
version='1' changeset='708944' lat='36.8554984' lon='10.1685669' />  <node 
id='243997185' timestamp='2009-05-12T23:28:34Z' uid='123321' user='Hatem' 
visible='true' version='2' changeset='1170291' lat='36.8536855' 
lon='10.1699434' />When i construct the coordinate with x=lon and y=lat,  my 
LineString don't draw on a JMapframe frame.How can i do to use without problem 
the lat and lon which are in my .xml file???Ndefo Kamgne ArnauldCité 
Ettayour,Immeuble Bolbol 1,Appartement A2,Ariana0021624249357
      
------------------------------------------------------------------------------
ThinkGeek and WIRED's GeekDad team up for the Ultimate 
GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the 
lucky parental unit.  See the prize list and enter to win: 
http://p.sf.net/sfu/thinkgeek-promo
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to