Hello, a part of my web-app needed the implementation of a client that can connect to OWS datastores in order to fetch layers that can be used directly in MapServer mapfiles (Being that my web app is written in python OWSLib is ideal) The nature of this requirement includes WFS, thus a mapserver mapfile could need a LABEL and subsequently a fieldname. Thus I added some support to the WFS module that does it.
The first diff modifies the WebFeatureService class, while the seconds adds a
new class named FieldnameReader(). (i attach this to in case it does not
display quite right)
111a112,121
> def requestFieldnames(self,method='{http://www.opengis.net/wfs}Get'):
> base_url =
> self.getOperationByName('{http://www.opengis.net/wfs}DescribeFeatureType').methods[method]['url']
> request = {'service': 'WFS', 'version': self.version, 'request':
> 'DescribeFeatureType'}
>
> fieldReader = FieldnameReader(base_url,request)
> self._fielddict = fieldReader.requestFieldnames()
>
> def getLayerFieldnames(self,typename):
> return self._fielddict[typename.rpartition(":")[2]]
>
196a207,228
>
> class FieldnameReader():
> def __init__(self,url,request):
> self._infoset = None
> data = urlencode(request)
> self._infoset = self.read(url,data)
>
> def read(self, url, data):
> u = urlopen(url+data)
> return etree.fromstring(u.read())
>
> def requestFieldnames(self):
> complexMappings={}
> for elem in
> self._infoset.findall(nspath('element',ns='http://www.w3.org/2001/XMLSchema')):
> complexMappings[elem.attrib.get('type',
> '').rpartition(":")[2]]=elem.attrib.get('name', '')
> fieldDict={}
> for elem in
> self._infoset.findall(nspath('complexType',ns='http://www.w3.org/2001/XMLSchema')):
> fieldListing=[]
> for field in
> elem.findall(nspath('complexContent/extension/sequence/element',ns='http://www.w3.org/2001/XMLSchema')):
>
> fieldListing.append(field.attrib.get('name', ''))
> fieldDict[complexMappings[elem.attrib.get('name',
> '')]]=fieldListing
> return fieldDict
One can use it like:
wfs.requestFieldnames()
layers = list(wfs.contents) # layers -> ['wfs:LEVEL1', 'wfs:Airport',
'wfs:LEVEL3', 'wfs:LEVEL4', 'wfs:LEVEL2']
for elem in layers:
print wfs.getLayerFieldnames(elem)
I would like to know whether it would be useful, thus it could be included to a
next version.
_________________________________________________________________
News, entertainment and everything you care about at Live.com. Get it now!
http://www.live.com/getstarted.aspx
wfspatch
Description: Binary data
_______________________________________________ Community mailing list [email protected] http://lists.gispython.org/mailman/listinfo/community
