def readJSON(json): """ Reads a :class:`Layer <geoscript.layer.layer.Layer>` from GML. *input* is the GML to read specified as a str, file, or some other input stream. *ver* specifies the gml version to encode. Supported versions include 2, 3, >>> json = '{"type":"FeatureCollection","features":[{"type":"Feature","geometry":{"type":"Point","coordinates":[1,2]},"properties":{},"id":"fid"}]}' >>> l = readJSON(json) >>> l.count() 1 """ fcol = doInput(lambda input: _fjson.readFeatureCollection(input), json) from geoscript.workspace import Workspace ws = Workspace() ws._store.addFeatures(fcol) return [ws[name] for name in ws.layers()][0]
def readGML(input, ver=2): """ Reads a :class:`Layer <geoscript.layer.layer.Layer>` from GML. *input* is the GML to read specified as a str, file, or some other input stream. *ver* specifies the gml version to encode. Supported versions include 2, 3, >>> xml = '<wfs:FeatureCollection xmlns:gml="http://www.opengis.net/gml" xmlns:wfs="http://www.opengis.net/wfs" xmlns:gsf="http://geoscript.org/feature"><gml:featureMember><gsf:layer_0 fid="fid"><gsf:geom><gml:Point><gml:coord><gml:X>1.0</gml:X><gml:Y>2.0</gml:Y></gml:coord></gml:Point></gsf:geom></gsf:layer_0></gml:featureMember></wfs:FeatureCollection>' >>> l = readGML(xml) >>> l.count() 1 """ fc = xml.wfs.parse(input, ver) from geoscript.workspace import Workspace ws = Workspace() for f in fc.feature: ws._store.addFeatures(f) layers = [ws[name] for name in ws.layers()] return layers if len(layers) > 1 else layers[0]
def data(self): return Workspace(ds=self._info.getDataStore(None))