def _handler(self, request, response):
        with temp_dir() as tmp:

            input_gml = request.inputs['layer'][0].file
            driver = ogr.GetDriverByName("GML")

            dataSource = driver.Open(input_gml, 0)
            layer = dataSource.GetLayer()
            total = 0
            for feature in layer:
                total = total + feature.length
            response.outputs['total'].data = str(total)
            return response
Beispiel #2
0
 def _handler(self, request, response):
      # ogr2ogr requires gdal-bin
     from shapely.geometry import shape
     with temp_dir() as tmp:
         input_gml = request.inputs['layer'].file
         input_geojson = os.path.join(tmp, 'input.geojson')
         subprocess.check_call(['ogr2ogr', '-f', 'geojson',
                                str(input_geojson), input_gml])
         with open(input_geojson, 'rb') as f:
             data = json.loads(f.read())
         features = []
         for feature in data['features']:
             geom = shape(feature['geometry'])
             feature['area'] = geom.area
         response.outputs['area'].data = [ feature['area'] for feature in data['features']]
         return response
Beispiel #3
0
 def _handler(self, request, response):
      # ogr2ogr requires gdal-bin
     from shapely.geometry import shape
     with temp_dir() as tmp:
         input_gml = request.inputs['layer'][0].file
         input_geojson = os.path.join(tmp, 'input.geojson')
         subprocess.check_call(['ogr2ogr', '-f', 'geojson',
                                str(input_geojson), input_gml])
         with open(input_geojson, 'rb') as f:
             data = json.loads(f.read())
         features = []
         for feature in data['features']:
             geom = shape(feature['geometry'])
             feature['area'] = geom.area
         response.outputs['area'].data = [ feature['area'] for feature in data['features']]
         return response
Beispiel #4
0
    def _handler(self, request, response):
         # ogr2ogr requires gdal-bin
        from shapely.geometry import shape, mapping

        with temp_dir() as tmp:
            input_gml = request.inputs['layer'].file
            input_geojson = os.path.join(tmp, 'input.geojson')
            subprocess.check_call(['ogr2ogr', '-f', 'geojson',
                                   input_geojson, input_gml])
            with open(input_geojson, 'rb') as f:
                data = json.loads(f.read())
            for feature in data['features']:
                geom = shape(feature['geometry'])
                feature['geometry'] = mapping(geom.centroid)
            out_bytes = json.dumps(data, indent=2)
            response.outputs['out'].output_format = Format(FORMATS['JSON'])
            response.outputs['out'].data = out_bytes
            return response
Beispiel #5
0
    def _handler(self, request, response):
        # ogr2ogr requires gdal-bin
        from shapely.geometry import shape, mapping

        with temp_dir() as tmp:
            input_gml = request.inputs['layer'].file
            input_geojson = os.path.join(tmp, 'input.geojson')
            subprocess.check_call(
                ['ogr2ogr', '-f', 'geojson', input_geojson, input_gml])
            with open(input_geojson, 'rb') as f:
                data = json.loads(f.read())
            for feature in data['features']:
                geom = shape(feature['geometry'])
                feature['geometry'] = mapping(geom.centroid)
            out_bytes = json.dumps(data, indent=2)
            response.outputs['out'].output_format = Format(FORMATS['JSON'])
            response.outputs['out'].data = out_bytes
            return response
Beispiel #6
0
        IOHandler.__init__(self, workdir=workdir, mode=mode)
        BasicComplex.__init__(self, data_format, supported_formats)

        self._storage = None

    @property
    def storage(self):
        return self._storage

    @storage.setter
    def storage(self, storage):
        # don't set storage twice
        if self._storage is None:
            self._storage = storage

    # TODO: refactor ?
    def get_url(self):
        """Return URL pointing to data
        """
        (outtype, storage, url) = self.storage.store(self)
        return url


if __name__ == "__main__":
    import doctest
    from pywps.wpsserver import temp_dir

    with temp_dir() as tmp:
        os.chdir(tmp)
        doctest.testmod()
Beispiel #7
0
            passed = False
            LOGGER.exception("ImportError while validating OPeNDAP link {}:\n {}".format(data_input.url, e))
        except IOError as e:
            passed = False
            LOGGER.exception("IOError while validating OPeNDAP link {}:\n {}".format(data_input.url, e))

    return passed


def _get_schemas_home():
    """Get path to schemas directory
    """
    schema_dir = os.path.join(
        os.path.abspath(
            os.path.dirname(__file__)
        ),
        os.path.pardir,
        "schemas")
    LOGGER.debug('Schemas directory: {}'.format(schema_dir))
    return schema_dir


if __name__ == "__main__":
    import doctest

    from pywps.wpsserver import temp_dir

    with temp_dir() as tmp:
        os.chdir(tmp)
        doctest.testmod()