On Fri, May 4, 2012 at 2:18 AM, Gus MacAulay <[email protected]> wrote:
> Hi All,
>
> I've been happily using the GeoJSON library but have run into a
> problem. Basically it doesn't seem to handle the case where features
> have differing properties, for example;
>
> Reading this feature collection
>
> {"type":"FeatureCollection",
> "features":[
>
>
> {"type":"Feature","geometry":{"type":"Point","coordinates":[144.5719,-37.6786]},"properties":{"A":"1"},"id":"points.1"},
>
>
> {"type":"Feature","geometry":{"type":"Point","coordinates":[144.5976,-37.678]},"properties":{"B":"3"},"id":"points.3"}
> ]
> }
>
> With something like this
>
> FeatureJSON fj = new FeatureJSON();
> FeatureIterator<SimpleFeature> features =
> fj.streamFeatureCollection(url.openConnection().getInputStream());
>
> while (features.hasNext()) {
> SimpleFeature feature = (SimpleFeature) features.next()
> }
>
> Results in an exception
> java.lang.IllegalArgumentException: No such attribute:B
>
> Any thoughts? Is there a workaround?
>
As far as I know the parser assumes all the features have the same
structure as the first one.
Making it work otherwise is going to be hard since FeatureType are meant to
be immutable...
To deal with the above case the geotools geojson parser would have to be
modified.
One approach could be to parse the whole collection twice, the first time
to determine
the full attribute set and then to actually generate the features. This
would be of course slow.
Another approach could be to have a custom implementation that allows the
set of attributes
to be expanded along during the parsing, probably some custom subclass of
SimpleFeatureType
and maybe SimpleFeature too.
Cheers
Andrea
--
Ing. Andrea Aime
GeoSolutions S.A.S.
Tech lead
Via Poggio alle Viti 1187
55054 Massarosa (LU)
Italy
phone: +39 0584 962313
fax: +39 0584 962313
mob: +39 339 8844549
http://www.geo-solutions.it
http://geo-solutions.blogspot.com/
http://www.youtube.com/user/GeoSolutionsIT
http://www.linkedin.com/in/andreaaime
http://twitter.com/geowolf
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
GeoTools-GT2-Users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users