Ticket #848 (closed task: fixed)

Opened 12 years ago

Last modified 12 years ago

[WG] Need to be able to loop over features in a feature collection pythonically.

Reported by: lawrence Owned by: domlowe
Priority: desirable Milestone: PROD Step3
Component: CSML Version:
Keywords: Cc: awoolf

Description

It would seem that CSML feature collections could consist of multiple featuremembers which are of different feature types.

I vaguely remember we decided in NDG that we would ensure that granules consisted of feature collections which consist of feature members which are of the same type.

That would appear not be a requirement of CSML ...

Hence, in order to inspect the features, we need to be able to do something like

x=xmlHandler2('someCSMLFile')
d=csml.parser.Dataset()
dd=d.parseElemTree(x.tree)
fc=dd.FeatureCollection
for i in fc: print i.featureType

How do I do the last line, it's not obviously possible. For a start a CSMLFeatureCollection isn't iterable ... surely it wants to be?

Change History

comment:1 Changed 12 years ago by domlowe

  • Status changed from new to assigned

A FeatureCollection? has a set of featureMembers which is iterable, so the last line can be done as:

for i in fc.featureMembers: print type(i)

However, i.featureType would be better than type(i) - I'll add this attribute into the parser now (won't take long..).

comment:2 Changed 12 years ago by domlowe

  • Status changed from assigned to closed
  • Resolution set to fixed

Okay, fixed now in changeset:2812

x=xmlHandler2('someCSMLFile')
d=csml.parser.Dataset()
d.parseElemTree(x.tree)
fc=d.featureCollection
for f in fc.featureMembers:
    print f.featureType
Note: See TracTickets for help on using tickets.