Problem with Feature

7 messages Options
Embed this post
Permalink
suneesh kumar

Problem with Feature

Reply Threaded More More options
Print post
Permalink
Hello,

I am trying to extract geometry of feature by iterating  FeatureCollection.

My code is this :
feature.getDefaultGeometryProperty().getValue()

But it is giving the following error :

java.lang.ClassCastException: org.geotools.feature.DefaultFeature$1 cannot be cast to com.vividsolutions.jts.geom.Geometry
        at org.geotools.feature.DefaultFeature.getDefaultGeometry(DefaultFeature.java:365)
        at org.geotools.feature.DefaultFeature.getDefaultGeometry(DefaultFeature.java:67)
        at org.geotools.feature.simple.SimpleFeatureImpl.getDefaultGeometryProperty(SimpleFeatureImpl.java:240)


How can I etract geometry from a feature collection? I am using the Geotools2.6

Thanks in advance.
Sunish.



Keep up with people you care about with Yahoo! India Mail. Learn how.
------------------------------------------------------------------------------
Come build with us! The BlackBerry® 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/devconf
_______________________________________________
Geotools-gt2-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
Jody Garnett-2

Re: Problem with Feature

Reply Threaded More More options
Print post
Permalink
You found a geometry Suneesh - GeoTools uses the JTS Geometry class.

Jody


On Mon, Oct 5, 2009 at 6:54 PM, suneesh kumar <[hidden email]> wrote:
Hello,

I am trying to extract geometry of feature by iterating  FeatureCollection.

My code is this :
feature.getDefaultGeometryProperty().getValue()

But it is giving the following error :

java.lang.ClassCastException: org.geotools.feature.DefaultFeature$1 cannot be cast to com.vividsolutions.jts.geom.Geometry
        at org.geotools.feature.DefaultFeature.getDefaultGeometry(DefaultFeature.java:365)
        at org.geotools.feature.DefaultFeature.getDefaultGeometry(DefaultFeature.java:67)
        at org.geotools.feature.simple.SimpleFeatureImpl.getDefaultGeometryProperty(SimpleFeatureImpl.java:240)


How can I etract geometry from a feature collection? I am using the Geotools2.6

Thanks in advance.
Sunish.



Keep up with people you care about with Yahoo! India Mail. Learn how.

------------------------------------------------------------------------------
Come build with us! The BlackBerry® 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/devconf
_______________________________________________
Geotools-gt2-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users



------------------------------------------------------------------------------
Come build with us! The BlackBerry® 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/devconf
_______________________________________________
Geotools-gt2-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
Ben Caradoc-Davies

Re: Problem with Feature

Reply Threaded More More options
Print post
Permalink
No, I think the ClassCastException indicates that Suneesh does not have
a Geometry.

On 05/10/09 16:15, Jody Garnett wrote:

> You found a geometry Suneesh - GeoTools uses the JTS Geometry class.
>
> Jody
>
>
> On Mon, Oct 5, 2009 at 6:54 PM, suneesh kumar<[hidden email]<mailto:[hidden email]>>  wrote:
> Hello,
>
> I am trying to extract geometry of feature by iterating  FeatureCollection.
>
> My code is this :
> feature.getDefaultGeometryProperty().getValue()
>
> But it is giving the following error :
>
> java.lang.ClassCastException: org.geotools.feature.DefaultFeature$1 cannot be cast to com.vividsolutions.jts.geom.Geometry
>          at org.geotools.feature.DefaultFeature.getDefaultGeometry(DefaultFeature.java:365)
>          at org.geotools.feature.DefaultFeature.getDefaultGeometry(DefaultFeature.java:67)
>          at org.geotools.feature.simple.SimpleFeatureImpl.getDefaultGeometryProperty(SimpleFeatureImpl.java:240)
>
>
> How can I etract geometry from a feature collection? I am using the Geotools2.6
>
> Thanks in advance.
> Sunish.
>
>
>
> ________________________________
> Keep up with people you care about with Yahoo! India Mail. Learn how<http://in.rd.yahoo.com/tagline_galaxy_1/*http://in.overview.mail.yahoo.com/connectmore>.
>
> ------------------------------------------------------------------------------
> Come build with us! The BlackBerry® 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/devconf
> _______________________________________________
> Geotools-gt2-users mailing list
> [hidden email]<mailto:[hidden email]>
> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
>
>
>


--
Ben Caradoc-Davies <[hidden email]>
Software Engineer, CSIRO Earth Science and Resource Engineering
Australian Resources Research Centre
26 Dick Perry Ave, Kensington WA 6151, Australia

------------------------------------------------------------------------------
Come build with us! The BlackBerry® 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/devconf
_______________________________________________
Geotools-gt2-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
Ben Caradoc-Davies

Re: Problem with Feature

Reply Threaded More More options
Print post
Permalink
In reply to this post by suneesh kumar
Suneesh, this error (rather obscurely) indicates that GeoTools is unable
to locate the default Geometry for this feature type.

 From where are you getting your features? Are you sure that they do
have a default geometry (or any Geometry at all)?

I suspect that you may have a problem in your features. They may not
have a default geometry set.

Kind regards,
Ben.


On 05/10/09 15:54, suneesh kumar wrote:

> Hello,
>
> I am trying to extract geometry of feature by iterating  FeatureCollection.
>
> My code is this :
> feature.getDefaultGeometryProperty().getValue()
>
> But it is giving the following error :
>
> java.lang.ClassCastException: org.geotools.feature.DefaultFeature$1 cannot be cast to com.vividsolutions.jts.geom.Geometry
>          at org.geotools.feature.DefaultFeature.getDefaultGeometry(DefaultFeature.java:365)
>          at org.geotools.feature.DefaultFeature.getDefaultGeometry(DefaultFeature.java:67)
>          at org.geotools.feature.simple.SimpleFeatureImpl.getDefaultGeometryProperty(SimpleFeatureImpl.java:240)
>
>
> How can I etract geometry from a feature collection? I am using the Geotools2.6
>
> Thanks in advance.
> Sunish.
>
>
>
> ________________________________
> ________________________________
> Keep up with people you care about with Yahoo! India Mail. Learn how<http://in.rd.yahoo.com/tagline_galaxy_1/*http://in.overview.mail.yahoo.com/connectmore>.
>


--
Ben Caradoc-Davies <[hidden email]>
Software Engineer, CSIRO Earth Science and Resource Engineering
Australian Resources Research Centre
26 Dick Perry Ave, Kensington WA 6151, Australia

------------------------------------------------------------------------------
Come build with us! The BlackBerry® 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/devconf
_______________________________________________
Geotools-gt2-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
suneesh kumar

Re: Problem with Feature

Reply Threaded More More options
Print post
Permalink

Hello Ben,
Thanks for your help.

When I printed the feature I got this result:

Feature[ id=fid-210abac6_12423ea2025_-8000 , the_geom=:the_geom=MULTIPOLYGON (((923781.578765854 1021445.18786308, 923793.237430999 1021443.68264572, 923812.807279689 1021440.48084847, 923833.982821523 1021433.35355761, 923837.074482658 1021408.83317833, 923841.057925336 1021387.92080829, 923850.455079465 1021374.3725159, 923855.689341004 1021371.12791891, 923866.990216335 1021360.11423809, 923873.175970243 1021354.17299777, 923878.613217111 1021355.55663781, 923883.180570544 1021355.19577407, 923888.687962009 1021344.8147054, 923892.552220043 1021331.48443413, 923904.075641697 1021328.60576522, 923906.351669354 1021299.1541609, 923897.267681752 1021298.88531351, 923897.554207871 1021262.81799109, 923899.871765895 1021244.15937833, 923900.352417863 1021217.2042322, 923901.217576539 1021168.44719693, 923900.397923364 1021150.40450225, 923806.068185044 1021153.25573024, 923795.07605981 1021153.27552583, 923794.149411961 1021245.34178948, 923790.885418252 1021347.02973132, 923791.038644846 1021348.73135388, 923792.196211136 1021361.58643905, 923785.839753911 1021399.74348569, 923780.324004925 1021426.57385127, 923781.578765854 1021445.18786308))) , NAME=:NAME=111/9 ]


But when I am trying feature.getDefaultGeometryProperty().getValue()
I get the ClassCastException.
Do you think there is any problem with the geometry?


Thanks,
Sunish./

--- On Mon, 5/10/09, Ben Caradoc-Davies <[hidden email]> wrote:

From: Ben Caradoc-Davies <[hidden email]>
Subject: Re: [Geotools-gt2-users] Problem with Feature
To: "suneesh kumar" <[hidden email]>
Cc: "[hidden email]" <[hidden email]>
Date: Monday, 5 October, 2009, 2:12 PM

Suneesh, this error (rather obscurely) indicates that GeoTools is unable
to locate the default Geometry for this feature type.

From where are you getting your features? Are you sure that they do
have a default geometry (or any Geometry at all)?

I suspect that you may have a problem in your features. They may not
have a default geometry set.

Kind regards,
Ben.


On 05/10/09 15:54, suneesh kumar wrote:

> Hello,
>
> I am trying to extract geometry of feature by iterating  FeatureCollection.
>
> My code is this :
> feature.getDefaultGeometryProperty().getValue()
>
> But it is giving the following error :
>
> java.lang.ClassCastException: org.geotools.feature.DefaultFeature$1 cannot be cast to com.vividsolutions.jts.geom.Geometry
>          at org.geotools.feature.DefaultFeature.getDefaultGeometry(DefaultFeature.java:365)
>          at org.geotools.feature.DefaultFeature.getDefaultGeometry(DefaultFeature.java:67)
>          at org.geotools.feature.simple.SimpleFeatureImpl.getDefaultGeometryProperty(SimpleFeatureImpl.java:240)
>
>
> How can I etract geometry from a feature collection? I am using the Geotools2.6
>
> Thanks in advance.
> Sunish.
>
>
>
> ________________________________
> ________________________________
> Keep up with people you care about with Yahoo! India Mail. Learn how<http://in.rd.yahoo.com/tagline_galaxy_1/*http://in.overview.mail.yahoo.com/connectmore>.
>


--
Ben Caradoc-Davies <Ben.Caradoc-Davies@...>
Software Engineer, CSIRO Earth Science and Resource Engineering
Australian Resources Research Centre
26 Dick Perry Ave, Kensington WA 6151, Australia


Connect more, do more and share more with Yahoo! India Mail. Learn more.
------------------------------------------------------------------------------
Come build with us! The BlackBerry® 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/devconf
_______________________________________________
Geotools-gt2-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
mbedward

Re: Problem with Feature

Reply Threaded More More options
Print post
Permalink
Hi Sunish,

Try this instead...

Geometry geometry = (Geometry) feature.getDefaultGeometry();

Hope this helps
Michael

------------------------------------------------------------------------------
Come build with us! The BlackBerry® 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/devconf
_______________________________________________
Geotools-gt2-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
Ben Caradoc-Davies

Re: Problem with Feature

Reply Threaded More More options
Print post
Permalink
In reply to this post by suneesh kumar
I expect that feature.getAttribute("the_geom") should get your geometry
in this case.

Your original method should also work, so it might be a bug, or
something unusual about your feature. You should not need to know the
name of the geometry of it has been configured correctly as the default
geometry.

Is this feature from a database?

Kind regards,
Ben.


On 05/10/09 17:00, suneesh kumar wrote:
>
> Hello Ben,
> Thanks for your help.
>
> When I printed the feature I got this result:
>
> Feature[ id=fid-210abac6_12423ea2025_-8000 , the_geom=:the_geom=MULTIPOLYGON (((923781.578765854 1021445.18786308, 923793.237430999 1021443.68264572, 923812.807279689 1021440.48084847, 923833.982821523 1021433.35355761, 923837.074482658 1021408.83317833, 923841.057925336 1021387.92080829, 923850.455079465 1021374.3725159, 923855.689341004 1021371.12791891, 923866.990216335 1021360.11423809, 923873.175970243 1021354.17299777, 923878.613217111 1021355.55663781, 923883.180570544 1021355.19577407, 923888.687962009 1021344.8147054, 923892.552220043 1021331.48443413, 923904.075641697 1021328.60576522, 923906.351669354 1021299.1541609, 923897.267681752 1021298.88531351, 923897.554207871 1021262.81799109, 923899.871765895 1021244.15937833, 923900.352417863 1021217.2042322, 923901.217576539 1021168.44719693, 923900.397923364 1021150.40450225, 923806.068185044 1021153.25573024, 923795.07605981 1021153.27552583, 923794.149411961 1021245.34178948, 923790.885418252 1021347.02973132, 923
791.038644846 1021348.73135388, 923792.196211136 1021361.58643905, 923785.839753911 1021399.74348569, 923780.324004925 1021426.57385127, 923781.578765854 1021445.18786308))) , NAME=:NAME=111/9 ]

>
>
> But when I am trying feature.getDefaultGeometryProperty().getValue()
> I get the ClassCastException.
> Do you think there is any problem with the geometry?
>
>
> Thanks,
> Sunish./
>
> --- On Mon, 5/10/09, Ben Caradoc-Davies<[hidden email]>  wrote:
>
> From: Ben Caradoc-Davies<[hidden email]>
> Subject: Re: [Geotools-gt2-users] Problem with Feature
> To: "suneesh kumar"<[hidden email]>
> Cc: "[hidden email]"<[hidden email]>
> Date: Monday, 5 October, 2009, 2:12 PM
>
> Suneesh, this error (rather obscurely) indicates that GeoTools is unable
> to locate the default Geometry for this feature type.
>
>> From where are you getting your features? Are you sure that they do
> have a default geometry (or any Geometry at all)?
>
> I suspect that you may have a problem in your features. They may not
> have a default geometry set.
>
> Kind regards,
> Ben.
>
>
> On 05/10/09 15:54, suneesh kumar wrote:
>> Hello,
>>
>> I am trying to extract geometry of feature by iterating  FeatureCollection.
>>
>> My code is this :
>> feature.getDefaultGeometryProperty().getValue()
>>
>> But it is giving the following error :
>>
>> java.lang.ClassCastException: org.geotools.feature.DefaultFeature$1 cannot be cast to com.vividsolutions.jts.geom.Geometry
>>           at org.geotools.feature.DefaultFeature.getDefaultGeometry(DefaultFeature.java:365)
>>           at org.geotools.feature.DefaultFeature.getDefaultGeometry(DefaultFeature.java:67)
>>           at org.geotools.feature.simple.SimpleFeatureImpl.getDefaultGeometryProperty(SimpleFeatureImpl.java:240)
>>
>>
>> How can I etract geometry from a feature collection? I am using the Geotools2.6
>>
>> Thanks in advance.
>> Sunish.
>>
>>
>>
>> ________________________________
>> ________________________________
>> Keep up with people you care about with Yahoo! India Mail. Learn how<http://in.rd.yahoo.com/tagline_galaxy_1/*http://in.overview.mail.yahoo.com/connectmore>.
>>
>
>
> --
> Ben Caradoc-Davies<[hidden email]</[hidden email]>>
> Software Engineer, CSIRO Earth Science and Resource Engineering
> Australian Resources Research Centre
> 26 Dick Perry Ave, Kensington WA 6151, Australia
>
>
> ________________________________
> ________________________________
> Connect more, do more and share more with Yahoo! India Mail. Learn more<http://in.rd.yahoo.com/tagline_galaxy_3/*http://in.overview.mail.yahoo.com/>.
>


--
Ben Caradoc-Davies <[hidden email]>
Software Engineer, CSIRO Earth Science and Resource Engineering
Australian Resources Research Centre
26 Dick Perry Ave, Kensington WA 6151, Australia

------------------------------------------------------------------------------
Come build with us! The BlackBerry® 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/devconf
_______________________________________________
Geotools-gt2-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users