Ejemplo n.º 1
0
    def geometry(self, value):
        if value is None and (self._where is not None
                              or self._layerDefs is not None):
            return
        elif value is None and self._where is None and self._layerDefs is None:
            raise HTTPBadRequest(
                'Please provide the parameter geometry  (Required)')
        else:
            try:
                if self._geometryType == 'esriGeometryEnvelope':
                    self._geometry = esrijson.to_shape(
                        [float_raise_nan(c) for c in value.split(',')])
                elif self._geometryType == 'esriGeometryPoint' \
                        and 'x' not in value and 'y' not in value:
                    # Simple simplified point geometry
                    value = [float_raise_nan(c) for c in value.split(',')]
                    self._geometry = esrijson.to_shape({
                        'x': value[0],
                        'y': value[1]
                    })
                else:
                    self._geometry = esrijson.to_shape(esrijson.loads(value))

            except Exception:
                raise HTTPBadRequest('Please provide a valid geometry')
        if (self._geometryType == u'esriGeometryPolyline' and not isinstance(self._geometry, LineString)) \
                or (self._geometryType == u'esriGeometryPolygon' and not isinstance(self._geometry, Polygon)):
            raise HTTPBadRequest(
                u"Missmatch between 'geometryType': {} and provided 'geometry' parsed as '{}'"
                .format(self._geometryType, self._geometry.__class__.__name__))
Ejemplo n.º 2
0
 def geometry(self, value):
     if value is None and self._where is not None:
         return
     elif value is None and self._where is None:
         raise HTTPBadRequest('Please provide the parameter geometry  (Required)')
     else:
         try:
             if self._geometryType == 'esriGeometryEnvelope':
                 self._geometry = esrijson.to_shape([float_raise_nan(c) for c in value.split(',')])
             elif self._geometryType == 'esriGeometryPoint':
                 value = [float_raise_nan(c) for c in value.split(',')]
                 self._geometry = esrijson.to_shape({'x': value[0], 'y': value[1]})
             else:
                 self._geometry = esrijson.to_shape(esrijson.loads(value))
         except:
             raise HTTPBadRequest('Please provide a valid geometry')
Ejemplo n.º 3
0
 def lat(self, value):
     if value is None:
         raise HTTPBadRequest("Missing parameter 'norhting'/'lat'")
     try:
         self._lat = float_raise_nan(value)
     except ValueError:
         raise HTTPBadRequest("Please provide numerical values for the parameter 'northing'/'lat'")
Ejemplo n.º 4
0
 def mapExtent(self, value):
     if value is not None:
         try:
             self._mapExtent = esrijson.to_shape(
                 [float_raise_nan(c) for c in value.split(',')])
         except ValueError:
             raise HTTPBadRequest(
                 'Please provide numerical values for the parameter mapExtent'
             )
Ejemplo n.º 5
0
 def tolerance(self, value):
     if value is None and self._where is not None:
         return
     elif value is None and self._where is None:
         raise HTTPBadRequest("Please provide the parameter tolerance (Required)")
     try:
         self._tolerance = float_raise_nan(value)
     except ValueError:
         raise HTTPBadRequest("Please provide an integer value for the pixel tolerance")
Ejemplo n.º 6
0
 def mapExtent(self, value):
     if value is None and self._where is not None:
         return
     elif value is None and self._where is None:
         raise HTTPBadRequest('Please provide the parameter mapExtent  (Required)')
     else:
         try:
             self._mapExtent = esrijson.to_shape([float_raise_nan(c) for c in value.split(',')])
         except:
             raise HTTPBadRequest('Please provide numerical values for the parameter mapExtent')
Ejemplo n.º 7
0
 def tolerance(self, value):
     if value is None and self._where is not None:
         return
     elif value is None and self._where is None:
         raise HTTPBadRequest(
             'Please provide the parameter tolerance (Required)')
     try:
         self._tolerance = float_raise_nan(value)
     except ValueError:
         raise HTTPBadRequest(
             'Please provide an integer value for the pixel tolerance')
Ejemplo n.º 8
0
 def geometry(self, value):
     if value is None and self._where is not None:
         return
     elif value is None and self._where is None:
         raise HTTPBadRequest(
             'Please provide the parameter geometry  (Required)')
     else:
         try:
             if self._geometryType == 'esriGeometryEnvelope':
                 self._geometry = esrijson.to_shape(
                     [float_raise_nan(c) for c in value.split(',')])
             elif self._geometryType == 'esriGeometryPoint':
                 value = [float_raise_nan(c) for c in value.split(',')]
                 self._geometry = esrijson.to_shape({
                     'x': value[0],
                     'y': value[1]
                 })
             else:
                 self._geometry = esrijson.to_shape(esrijson.loads(value))
         except:
             raise HTTPBadRequest('Please provide a valid geometry')
Ejemplo n.º 9
0
 def geometry(self, value):
     if self._clipper:
         return
     if value is None:
         raise HTTPBadRequest('Please provide the parameter geometry (Required if clipper is not defined)')
     try:
         if self._geometryType == 'esriGeometryEnvelope':
             self._geometry = esrijson.to_shape([float_raise_nan(c) for c in value.split(',')])
         else:
             self._geometry = esrijson.to_shape(esrijson.loads(value))
     except:
         raise HTTPBadRequest('Please provide a valid geometry')
Ejemplo n.º 10
0
 def mapExtent(self, value):
     if value is None and self._where is not None:
         return
     elif value is None and self._where is None:
         raise HTTPBadRequest(
             'Please provide the parameter mapExtent  (Required)')
     else:
         try:
             self._mapExtent = esrijson.to_shape(
                 [float_raise_nan(c) for c in value.split(',')])
         except:
             raise HTTPBadRequest(
                 'Please provide numerical values for the parameter mapExtent'
             )
Ejemplo n.º 11
0
 def geometry(self, value):
     if self._clipper:
         return
     if value is None:
         raise HTTPBadRequest(
             'Please provide the parameter geometry (Required if clipper is not defined)'
         )
     try:
         if self._geometryType == 'esriGeometryEnvelope':
             self._geometry = esrijson.to_shape(
                 [float_raise_nan(c) for c in value.split(',')])
         else:
             self._geometry = esrijson.to_shape(esrijson.loads(value))
     except:
         raise HTTPBadRequest('Please provide a valid geometry')
Ejemplo n.º 12
0
    def to_instance(cls, ob, default=None, strict=False):
        if isinstance(ob, list):
            coords = ob
        else:
            coords = [float_raise_nan(x.strip()) for x in ob.split(',')]

        wkid = 21781
        if len(coords) == 2:
            x, y = coords
            if x <= 180 and y <= 180:
                wkid = 4326

            crs = Named(properties=dict(name="urn:ogc:def:crs:EPSG:%d" % wkid))

            return geojson.geometry.Point(coords, crs=crs)

        if len(coords) == 4:
            crs = Named(properties=dict(name="urn:ogc:def:crs:EPSG:%d" % wkid))
            minx, miny, maxx, maxy = coords

            return geojson.geometry.Polygon([[[minx, miny], [minx, maxy], [maxx, maxy], [maxx, miny], [minx, miny]]], crs=crs)

        else:
            raise ValueError("%r is not a simplified esri geometry", coords)
Ejemplo n.º 13
0
    def to_instance(cls, ob, default=None, strict=False):
        if isinstance(ob, list):
            coords = ob
        else:
            coords = [float_raise_nan(x.strip()) for x in ob.split(',')]

        wkid = 21781
        if len(coords) == 2:
            x, y = coords
            if x <= 180 and y <= 180:
                wkid = 4326

            crs = Named(properties=dict(name="urn:ogc:def:crs:EPSG:%d" % wkid))

            return geojson.geometry.Point(coords, crs=crs)

        if len(coords) == 4:
            crs = Named(properties=dict(name="urn:ogc:def:crs:EPSG:%d" % wkid))
            minx, miny, maxx, maxy = coords

            return geojson.geometry.Polygon([[[minx, miny], [minx, maxy], [maxx, maxy], [maxx, miny], [minx, miny]]], crs=crs)

        else:
            raise ValueError("%r is not a simplified esri geometry", coords)
Ejemplo n.º 14
0
 def mapExtent(self, value):
     if value is not None:
         try:
             self._mapExtent = esrijson.to_shape([float_raise_nan(c) for c in value.split(',')])
         except ValueError:
             raise HTTPBadRequest('Please provide numerical values for the parameter mapExtent')
Ejemplo n.º 15
0
 def test_float_raise_nan(self):
     testval = 5
     result = float_raise_nan(testval)
     self.assertEqual(result, 5.0)
     with self.assertRaises(ValueError):
         float_raise_nan(float('nan'))
Ejemplo n.º 16
0
 def test_float_raise_nan(self):
     testval = 5
     result = float_raise_nan(testval)
     self.assertEqual(result, 5.0)
     with self.assertRaises(ValueError):
         float_raise_nan(float('nan'))
Ejemplo n.º 17
0
 def test_float_raise_nan(self):
     testval = 5
     result = float_raise_nan(testval)
     self.assertEqual(result, 5.0)
     self.assertRaises('ValueError')
Ejemplo n.º 18
0
 def test_float_raise_nan(self):
     testval = 5
     result = float_raise_nan(testval)
     self.assertEqual(result, 5.0)
     self.assertRaises('ValueError')