Ok, reading through the postGIS module test cases for GeoTools 2.5.5 I
figured it out.
One way to do it is to use SimpleFeatures and then extract the Geometry
through that. Just out of curiousity is there a way to do this using
"Feature" objects instead of SimpleFeature objects?
Here's the relevant code that works:
org.opengis.filter.Filter filter = null;
FeatureReader<SimpleFeatureType,SimpleFeature> featureReader = null;
Transaction transaction = null;
try
{
String[] columns = new String[]
{
"the_geom", "mtfcc",
"fullname"
};
filter = CQL.toFilter("mtfcc='S1100' and fullname like 'I%-%'");
DefaultQuery q = new DefaultQuery("roads", filter, columns);
transaction = new DefaultTransaction();
featureReader = ds.getFeatureReader(q, transaction);
while (featureReader.hasNext())
{
SimpleFeature f = featureReader.next();
Integer interstateNumber = getInterstateNumber((String)
f.getProperty("fullname").getValue());
List<Geometry> geomList =
s1100InterstateGeometry.get(interstateNumber + "");
if (geomList == null)
{
geomList = new ArrayList<Geometry>();
}
Geometry geom = (Geometry)f.getDefaultGeometry();
System.out.println("the_geom: " + geom);
}
featureReader.close();
}
catch (CQLException ex)
{
ex.printStackTrace();
}
catch (IOException ex)
{
ex.printStackTrace();
}
finally
{
if (featureReader != null)
{
try
{
featureReader.close();
}
catch (IOException ex)
{
ex.printStackTrace();
}
}
if (transaction != null)
{
try
{
transaction.close();
}
catch (IOException ex)
{
ex.printStackTrace();
}
}
}
On Thu, Jun 11, 2009 at 3:14 PM, Alessandro Ferrucci <
alessandroferru...@gmail.com> wrote:
> Ok I was able to extract a GeometryAttribute from the feature's properties
> collection, but I need to get a JTS Geometry since I will need to do a
> LineMerger operation on the Geometries.
>
> How can I do that?
>
> thanks
>
> alessandro ferrucci
>
>
>
> On Thu, Jun 11, 2009 at 3:02 PM, Alessandro Ferrucci <
> alessandroferru...@gmail.com> wrote:
>
>> hello,
>>
>> in previous releases of geotools I could use FeatureReader from a postgis
>> DataSource and extract Features and get the default geometry from those
>> feature objects.
>>
>> Now the FeatureReader uses the opengis Feature and I have no clue how I
>> can extract Geometries from those features..anyone have any examples on how
>> I can do this in geotools 2.5.5 ?
>>
>> Here's the relevant code:
>>
>>
>> org.opengis.filter.Filter filter = null;
>> FeatureReader fr = null;
>> Transaction transaction = null;
>> String[] columns = new String[]
>> {
>> "the_geom", "mtfcc",
>> "fullname"
>> };
>> filter = CQL.toFilter("mtfcc='S1100' and fullname like
>> 'I%-%'");
>> DefaultQuery q = new DefaultQuery("roads", filter, columns);
>> transaction = new DefaultTransaction();
>> fr = ds.getFeatureReader(q, transaction);
>> while (fr.hasNext())
>> {
>> Feature f = fr.next();
>> //HOW TO GET A GEOMETRY OUT OF THIS FEATURE??? No more
>> methods "getDefaultGeometry()"
>> }
>> fr.close();
>> .....
>>
>>
>> Thanks
>>
>> Alessandro Ferrucci
>> --
>> Signed,
>> Alessandro Ferrucci
>>
>
>
>
> --
> Signed,
> Alessandro Ferrucci
>
--
Signed,
Alessandro Ferrucci
------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables unlimited
royalty-free distribution of the report engine for externally facing
server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
Geotools-gt2-users mailing list
Geotools-gt2-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users