I am not sure what is the problem now. But you are using points style to
display a line?
Check this tutorial on creating styles for different shapes:
http://docs.geotools.org/latest/userguide/tutorial/map/style.html
I think the function "private Style createLineStyle()" (described there) is
what you need
Otherwise NullPointerException should be easily traced using the stack
trace and problematic line numbers....
My guess is geotools tries to call a method of an object, but you did not
pass the object or passed null instead..
Good luck
2014-04-29 16:53 GMT-04:00 Elena Pop <elena0...@gmail.com>:
>
> Thanks a lot Oleksandr! That makes sense.
> However i have another question, apparently i get a new error when i try
> to run the project with only one line and it looks like this: Unable to
> determine bounds of org.geotools.map.FeatureLayer[, VISIBLE]
> java.lang.NullPointerException
>
> Not sure where the problem is since my collection contains at least one
> line to add to the layer. Or am i wrong?
>
>
> On Tue, Apr 29, 2014 at 3:20 PM, Oleksandr Huziy <guziy.sa...@gmail.com>wrote:
>
>> I think one feature is supposed to have only one geometry object. If you
>> want to represent multiple lines with a single geometry use
>> MultiLineString..
>>
>>
>> Cheers
>>
>>
>> 2014-04-29 8:24 GMT-04:00 Elena Pop <elena0...@gmail.com>:
>>
>>> Hello,
>>>
>>> I am working on a project that builds up a graph and due to some errors
>>> i am trying to visualize it.
>>>
>>> The code looks like this and apparently it is not working because i get
>>> this error "java.lang.ArrayIndexOutOfBoundsException: Can handle 1
>>> attributes only, index is 1" on line featureBuilder.add(line);
>>>
>>> networkGraph = featureGen.getGraph();
>>> MapContent content= new MapContent();
>>> content.setTitle("Graph map");
>>>
>>> StyleBuilder styleBuilder = new StyleBuilder();
>>> Style style =
>>> styleBuilder.createStyle(styleBuilder.createPointSymbolizer());
>>>
>>> SimpleFeatureTypeBuilder tbuild = new
>>> SimpleFeatureTypeBuilder();
>>> tbuild.setCRS(DefaultGeographicCRS.WGS84);
>>> tbuild.setName("Line");
>>> tbuild.add("Line", LineString.class);
>>> SimpleFeatureType type = tbuild.buildFeatureType();
>>> SimpleFeatureBuilder featureBuilder = new
>>> SimpleFeatureBuilder(type);
>>> GeometryFactory geometryFactory =
>>> JTSFactoryFinder.getGeometryFactory(null);
>>>
>>>
>>> Collection<org.geotools.graph.structure.Edge> edges =
>>> networkGraph.getEdges();
>>> for(org.geotools.graph.structure.Edge edge:edges){
>>> Point nA = (Point) edge.getNodeA().getObject();
>>> Point nB = (Point) edge.getNodeB().getObject();
>>>
>>> Coordinate c1 = new Coordinate(nA.getX(), nA.getY());
>>> Coordinate c2 = new Coordinate(nB.getX(), nB.getY());
>>>
>>> Coordinate[] coords = new Coordinate[] {c1, c2};
>>> com.vividsolutions.jts.geom.LineString line =
>>> geometryFactory.createLineString(coords);
>>> featureBuilder.add(line);
>>> //System.out.println( nA.getX()+ " "+nA.getY());
>>>
>>> }
>>>
>>> SimpleFeature feature = featureBuilder.buildFeature(null);
>>> DefaultFeatureCollection collection =new
>>> DefaultFeatureCollection();
>>> collection.add(feature);
>>> content.addLayer(new FeatureLayer(collection,
>>> (org.geotools.styling.Style) style));
>>>
>>> JMapFrame.showMap(content);
>>>
>>> I am still trying to get used to geotools, sorry if the question
>>> sounds stupid.
>>> Looking forward to your reply.
>>>
>>>
>>> ------------------------------------------------------------------------------
>>> "Accelerate Dev Cycles with Automated Cross-Browser Testing - For FREE
>>> Instantly run your Selenium tests across 300+ browser/OS combos. Get
>>> unparalleled scalability from the best Selenium testing platform
>>> available.
>>> Simple to use. Nothing to install. Get started now for free."
>>> http://p.sf.net/sfu/SauceLabs
>>> _______________________________________________
>>> GeoTools-GT2-Users mailing list
>>> GeoTools-GT2-Users@lists.sourceforge.net
>>> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
>>>
>>>
>>
>>
>> --
>> Sasha
>>
>
>
>
>
> ------------------------------------------------------------------------------
> "Accelerate Dev Cycles with Automated Cross-Browser Testing - For FREE
> Instantly run your Selenium tests across 300+ browser/OS combos. Get
> unparalleled scalability from the best Selenium testing platform available.
> Simple to use. Nothing to install. Get started now for free."
> http://p.sf.net/sfu/SauceLabs
> _______________________________________________
> GeoTools-GT2-Users mailing list
> GeoTools-GT2-Users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
>
>
--
Sasha
------------------------------------------------------------------------------
"Accelerate Dev Cycles with Automated Cross-Browser Testing - For FREE
Instantly run your Selenium tests across 300+ browser/OS combos. Get
unparalleled scalability from the best Selenium testing platform available.
Simple to use. Nothing to install. Get started now for free."
http://p.sf.net/sfu/SauceLabs
_______________________________________________
GeoTools-GT2-Users mailing list
GeoTools-GT2-Users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users