Forced Coordinate Display for LineString (Example) - More effective/better/flexible?

3 messages Options
Embed this post
Permalink
Oliver Gottwald

Forced Coordinate Display for LineString (Example) - More effective/better/flexible?

Reply Threaded More More options
Print post
Permalink
Some javascript/style in this post has been disabled (why?)
Hi,

I'm continuing my efforts with forced coordinate display by integrating LineString.

In a prior example I did multiple coordinate display for Points.

What I’m wondering is if there is anything more effective/better/flexible I can do then below for displaying a series of coordinates via LineString.

One line specifically that I wonder if could be done better is the following:
final SimpleFeatureType TYPE = DataUtilities.createType("Location", "location:LineString,name:String");

Any input would be greatly appreciated. :-)

Oliver

=======

Below is my main source for forced coordinate LineString display.  Based on input from all you and alteration I will eventually put a full example on the forum.

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

    FeatureCollection collection = FeatureCollections.newCollection();

       
        double lon[] = {20.22, 30.33, 40.44};
        double lat[] = {20.22, 30.33, 40.44};
        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 );
       
        FeatureSource featureSource = DataUtilities.source(collection);
        MapContext map = new DefaultMapContext();
        map.setTitle("Quickstart");
        map.addLayer(featureSource, null);

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


------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Geotools-gt2-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
mbedward

Re: Forced Coordinate Display for LineString (Example) - More effective/better/flexible?

Reply Threaded More More options
Print post
Permalink
Hi Oliver,

I've meddled with your example a bit so that it generates one than one
feature and uses SimpleFeatureTypeBuilder (as shown in the CSV 2 SHP
Lab example at the bottom of the code).

public class Foo
    static final CoordinateReferenceSystem crs = DefaultGeographicCRS.WGS84;
    static final int MAX_NAME_LENGTH = 20;

    public static void main(String[] args) throws Exception {
        SimpleFeatureTypeBuilder typeBuilder = new SimpleFeatureTypeBuilder();
        typeBuilder.setName("mytype");
        typeBuilder.setCRS(crs);
        typeBuilder.add("route", LineString.class);
        typeBuilder.length(MAX_NAME_LENGTH).add("name", String.class);

        final SimpleFeatureType TYPE = typeBuilder.buildFeatureType();

        FeatureCollection collection = FeatureCollections.newCollection();

        double x[][] = {{10, 20, 30, 40, 50}, {10, 20, 30, 40, 50}};
        double y[][] = {{10, 20, 10, 20, 10}, {20, 30, 20, 30, 20}};
        String[] names = {"foo", "bar"};

        GeometryFactory factory = JTSFactoryFinder.getGeometryFactory(null);
        SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(TYPE);
        ArrayList<Coordinate> coordList = new ArrayList<Coordinate>();

        for (int line = 0; line < x.length; line++) {
            for (int i = 0; i < x[line].length; i++) {
                coordList.add(new Coordinate(x[line][i], y[line][i]));
            }

            Coordinate[] coords = CoordinateArrays.toCoordinateArray(coordList);
            LineString lineString = factory.createLineString(coords);

            featureBuilder.add(lineString);
            featureBuilder.add(names[line]);
            collection.add(featureBuilder.buildFeature(null));
            coordList.clear();
        }


        MapContext map = new DefaultMapContext();
        map.setTitle("My beautiful lines");
        map.addLayer(collection, null);

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

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Geotools-gt2-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
mbedward

Re: Forced Coordinate Display for LineString (Example) - More effective/better/flexible?

Reply Threaded More More options
Print post
Permalink
> it generates one than one feature

= it generates more than one feature

Brain not fully connected to fingers today.

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Geotools-gt2-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users