Hi Jody,

I finally got it working. I needed to create a new ListFeatureCollection.
My question now is: do I need to dispose the in memory collection somewhere 
after it is used in FeatureLayer to avoid memory leakage.
How do I do this?



                SimpleFeatureTypeBuilder typeBuilder = new 
SimpleFeatureTypeBuilder();
                typeBuilder.setName(strObjectName);
                typeBuilder.add("GEOMETRY", Point.class, m_RD_crs);

                SimpleFeatureType simpleFeatureType = 
typeBuilder.buildFeatureType();

                final SimpleFeatureBuilder featureBuilder = new 
SimpleFeatureBuilder(simpleFeatureType);
                final ListFeatureCollection features = new 
ListFeatureCollection(simpleFeatureType);

                FeatureCollection featureCollection = 
featureSource.getFeatures(query);
                final Expression xpath = 
m_filterFactory.property(strXAttributeName);
                final Expression ypath = 
m_filterFactory.property(strYAttributeName);

                featureCollection.accepts( new FeatureVisitor(){
                    public void visit(Feature feature)
                    {
                        Double x = xpath.evaluate(feature, Double.class);
                        Double y = ypath.evaluate(feature, Double.class);

                        featureBuilder.add(m_geometryFactory.createPoint(new 
Coordinate(x, y)));
                        
features.add(featureBuilder.buildFeature(feature.getIdentifier().getID()));
                    }
                }, null);

                layer = new FeatureLayer(features, styleGeometry);


Ron





________________________________
 From: Jody Garnett <[email protected]>
To: Ron Lindhoudt <[email protected]> 
Cc: "[email protected]" 
<[email protected]> 
Sent: Wednesday, November 7, 2012 2:26 PM
Subject: Re: [Geotools-gt2-users] Construct Geometry from X, Y attribute (using 
geomFromWKT?)
 

We have a range of functions that are able to create a geometry, including a 
"point" function:

      final Expression pointExpression = ff.function("point, ff.properaty("X"), 
ff.property("Y") );
      Point point = pointExpression.evaulate( feature, Point.class );

Or CQL:  point( X, Y )

However my statement still stands, you can use a geometry factory, while 
visiting a feature collection to create points.

final Expression xpath = ff.property("X");
final Expression ypath = ff.property("Y");
featureCollection.accepts( new FeatureVisitor(){
    public void visit( Feature feature ){
          Double x = xpath.evaualte( feature, Double.class );
          Double y = ypath.evaualte( feature, Double.class );
          Point pt = gf.createPoint( x,y );
    }
}, null );


-- 
Jody Garnett


On Wednesday, 7 November 2012 at 5:28 PM, Ron Lindhoudt wrote:
Hi Jody,
>
>I mean dynamically, based on a column attribute in a table. Like in an 
>ExternalGraphic where you can reference an attribute ${ATT_NAME}.png for the 
>URL
>
>
>
>Ron
>
>
>
>
>________________________________
> From: Jody Garnett <[email protected]>
>To: Ron Lindhoudt <[email protected]> 
>Cc: "[email protected]" 
><[email protected]> 
>Sent: Wednesday, November 7, 2012 2:46 AM
>Subject: Re: [Geotools-gt2-users] Construct Geometry from X, Y attribute 
>(using geomFromWKT?)
> 
>
>Use a GeometryFactory directly? 
>
>
>The documentation has many examples of how t o create a point, including with 
>WKT:
>
>
>- http://docs.geotools.org/latest/userguide/library/jts/geometry.html#creating-a-point
>
>
>-- 
>Jody Garnett
>
>
>
>On Tuesday, 6 November 2012 at 5:55 PM, Ron Lindhoudt wrote:
>Hello,
>>
>>
>>Is it possible to construct a Geometry from X, Y attribute in a table?
>>I tried some function expressions for setGeometry, but they don't work:
>>
>>
>>String strExpression = "geomFromWKT('Point(X Y)')";
>>// or
>>
>>String strExpression = "geomFromWKT('Point(${X} ${Y})')";
>>
>>
>>rule.getSymbolizers()[0].setGeometry(ECQL.toExpression(strExpression));
>>
>>
>>Thanks for any input.
>>
>>Ron
>>
>>------------------------------------------------------------------------------
>>LogMeIn Central: Instant, anywhere, Remote PC access and management.
>>Stay in control, update software, and manage PCs from one command center
>>Diagnose problems and improve visibility into emerging IT issues
>>Automate, monitor and manage. Do more in less time with Central
>>http://p.sf.net/sfu/logmein12331_d2d
>>_______________________________________________
>>GeoTools-GT2-Users mailing list
>>[email protected]
>>https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users 
>
>
>
> 
------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_nov
_______________________________________________
GeoTools-GT2-Users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to