Exemple #1
0
 def test02_bad_wkt(self):
     "Testing initialization on invalid WKT."
     for bad in bad_srlist:
         try:
             srs = SpatialReference(bad)
             srs.validate()
         except (SRSException, OGRException):
             pass
         else:
             self.fail('Should not have initialized on bad WKT "%s"!')
Exemple #2
0
 def test02_bad_wkt(self):
     "Testing initialization on invalid WKT."
     for bad in bad_srlist:
         try:
             srs = SpatialReference(bad)
             srs.validate()
         except (SRSException, GDALException):
             pass
         else:
             self.fail('Should not have initialized on bad WKT "%s"!')
Exemple #3
0
    def data(self):
        '''
        Read the output file and provide an iterable result
        '''
        if not hasattr(self, '_data'):
            if self.raster_obj is None:
                self._data = None
                return None
            layer = geom_extent = geom_type = spatial_ref = geom_srid = None
            # If we get here, then we have successfully determined the file type
            # that was provided, using OGR.  ogr_obj contains the OGR DataSource
            # object, and fn contains the name of the file we read to get that.

            # We only support single layer uploads, if there is more than one
            # layer then we will raise an exception
            driver = self.raster_obj.driver.name

            layer = None
            geom_extent = self.raster_obj.extent
            geom_type = 99

            srs = self.raster_obj.srs
            geos_extent = Polygon.from_bbox(self.raster_obj.extent)
            ogr_extent = geos_extent.ogr
            srid = epsg = None
            # User supplied SRID, so we will use that...
            if self._srid:
                srs = None
                geom_srid = self._srid
                epsg = str('EPSG:%s' % (geom_srid,))
                logger.debug('Setting output SRID to %s',
                             epsg)
                try:
                    srs = SpatialReference(epsg)

                    srs.validate()
                    geom_srid = srs.srid
                except Exception, e:
                    logger.debug('Invalid SRS (or none): %s', e,
                                 exc_info=True)
                    srs = None
            # No SRID! Let's try to detect it
            if srs and not geom_srid:
                if not srs.srid:
                    try:
                        srs.identify_epsg()
                        logger.debug('Auto-detect of SRID yielded %s',
                                     geom_srid)
                    except Exception as e:
                        logger.debug(
                            'SRID identification failed: %s', e,
                            exc_info=True)
                else:
                    geom_srid = srs.srid
                epsg = str('EPSG:%s' % (geom_srid,))
                logger.debug('Final SRID of file is %s', geom_srid)

            if srs and not geom_srid:
                '''
                Still no SRID - but we have an srs - so let's try to 
                reproject...
                '''
                try:
                    reprojection = CoordTransform(
                        r.srs, SpatialReference('EPSG:4326'))
                    ogr_extent.transform(reprojection)
                    geos_extent = ogr_extent.geos
                    geom_srid = geos_extent.srid
                except Exception, e:
                    if logger.isEnabledFor(logging.DEBUG):
                        logger.exception('Failed to transform: %s', e)
                    raise FormatException('Unable to determine valid SRID ' +
                                          'for this data')
Exemple #4
0
    def data(self):
        '''
        Read the output file and provide an iterable result
        '''
        if not hasattr(self, '_data'):
            if self.raster_obj is None:
                self._data = None
                return None
            layer = geom_extent = geom_type = spatial_ref = geom_srid = None
            # If we get here, then we have successfully determined the file type
            # that was provided, using OGR.  ogr_obj contains the OGR DataSource
            # object, and fn contains the name of the file we read to get that.

            # We only support single layer uploads, if there is more than one
            # layer then we will raise an exception
            driver = self.raster_obj.driver.name

            layer = None
            geom_extent = self.raster_obj.extent
            geom_type = 99

            srs = self.raster_obj.srs
            geos_extent = Polygon.from_bbox(self.raster_obj.extent)
            ogr_extent = geos_extent.ogr
            srid = epsg = None
            # User supplied SRID, so we will use that...
            if self._srid:
                srs = None
                geom_srid = self._srid
                epsg = str('EPSG:%s' % (geom_srid, ))
                logger.debug('Setting output SRID to %s', epsg)
                try:
                    srs = SpatialReference(epsg)

                    srs.validate()
                    geom_srid = srs.srid
                except Exception, e:
                    logger.debug('Invalid SRS (or none): %s', e, exc_info=True)
                    srs = None
            # No SRID! Let's try to detect it
            if srs and not geom_srid:
                if not srs.srid:
                    try:
                        srs.identify_epsg()
                        logger.debug('Auto-detect of SRID yielded %s',
                                     geom_srid)
                    except Exception as e:
                        logger.debug('SRID identification failed: %s',
                                     e,
                                     exc_info=True)
                else:
                    geom_srid = srs.srid
                epsg = str('EPSG:%s' % (geom_srid, ))
                logger.debug('Final SRID of file is %s', geom_srid)

            if srs and not geom_srid:
                '''
                Still no SRID - but we have an srs - so let's try to 
                reproject...
                '''
                try:
                    reprojection = CoordTransform(
                        r.srs, SpatialReference('EPSG:4326'))
                    ogr_extent.transform(reprojection)
                    geos_extent = ogr_extent.geos
                    geom_srid = geos_extent.srid
                except Exception, e:
                    if logger.isEnabledFor(logging.DEBUG):
                        logger.exception('Failed to transform: %s', e)
                    raise FormatException('Unable to determine valid SRID ' +
                                          'for this data')