Пример #1
0
    def prepare_value(self, value):
        if not value or not isinstance(value, Proj):
            return value

        epsg = proj4_to_epsg(value)
        if epsg:
            return str(epsg)
        else:
            raise ValidationError('Could not convert projection to EPSG/WKID')
Пример #2
0
    def prepare_value(self, value):
        if not value or not isinstance(value, pyproj.Proj):
            return value

        epsg = proj4_to_epsg(value)
        if epsg:
            return str(epsg)
        else:
            raise ValidationError('Could not convert projection to EPSG/WKID')
Пример #3
0
    def get_layer_data(variable):
        epsg = proj4_to_epsg(variable.full_extent.projection)
        if epsg:
            full_extent = variable.full_extent
        else:
            epsg = 102100
            projection = Proj('+units=m +init=epsg:3857')
            full_extent = variable.full_extent.project(projection)

        data = {
            'id': variable.index,
            'name': variable.name,
            'type': 'Raster Layer',
            'description': variable.description,
            'geometryType': None,
            'hasZ': False,
            'hasM': False,
            'copyrightText': None,
            'parentLayer': None,
            'subLayers': None,
            'minScale': 0,
            'maxScale': 0,
            'defaultVisibility': True,
            'extent': extent_to_envelope(full_extent, epsg),
            'displayField': variable.variable,
            'maxRecordCount': 1000,
            'supportsStatistics': False,
            'supportsAdvancedQueries': False,
            'capabilities': 'Map,Query',
            'supportedQueryFormats': 'JSON',
            'isDataVersioned': False
        }

        if variable.supports_time:
            data['timeInfo'] = {
                'timeExtent': [
                    date_to_timestamp(variable.time_start) * 1000,
                    date_to_timestamp(variable.time_end) * 1000
                ],
                'timeInterval':
                variable.service.time_interval,
                'timeIntervalUnits':
                TIME_UNITS_MAP.get(variable.service.time_interval_units),
                'exportOptions': {
                    'useTime': True,
                    'timeDataCumulative': False
                },
                'hasLiveData':
                False
            }

        return data
Пример #4
0
    def render_to_response(self, context, **response_kwargs):
        epsg = proj4_to_epsg(pyproj.Proj(str(self.object.projection)))
        if epsg:
            full_extent = self.object.full_extent
            initial_extent = self.object.initial_extent
        else:
            epsg = 102100
            projection = pyproj.Proj('+units=m +init=epsg:3857')
            full_extent = self.object.full_extent.project(projection)
            initial_extent = self.object.initial_extent.project(projection)

        data = {
            'currentVersion': '10.1',
            'serviceDescription': self.object.description,
            'mapName': self.object.name,
            'description': self.object.description,
            'copyrightText': '',
            'supportsDynamicLayers': True,
            'layers': [
                {
                    'id': v.index,
                    'name': v.name,
                    'defaultVisibility': True,
                    'parentLayerId': -1,
                    'subLayerIds': None,
                    'minScale': 0,
                    'maxScale': 0
                } for v in self.object.variable_set.all()
            ],
            'spatialReference': {'wkid': epsg},
            'singleFusedMapCache': False,
            'initialExtent': extent_to_envelope(initial_extent, epsg),
            'fullExtent': extent_to_envelope(full_extent, epsg),
            'supportedImageFormatTypes': ','.join(SUPPORTED_IMAGE_FORMATS),
            'capabilities': 'Map,Query',
            'supportedQueryFormat': 'JSON'
        }

        if self.object.supports_time:
            data['timeInfo'] = {
                'timeExtent': [date_to_timestamp(self.object.time_start), date_to_timestamp(self.object.time_end)],
                'timeRelation': 'esriTimeRelationOverlaps',
                'defaultTimeInterval': self.object.time_interval,
                'defaultTimeIntervalUnits': TIME_UNITS_MAP.get(self.object.time_interval_units),
                'hasLiveData': False
            }

        return HttpResponse(json.dumps(data), content_type='application/json')
Пример #5
0
    def get_layer_data(variable):
        epsg = proj4_to_epsg(variable.full_extent.projection)
        if epsg:
            full_extent = variable.full_extent
        else:
            epsg = 102100
            projection = pyproj.Proj('+units=m +init=epsg:3857')
            full_extent = variable.full_extent.project(projection)

        data = {
            'id': variable.index,
            'name': variable.name,
            'type': 'Raster Layer',
            'description': variable.description,
            'geometryType': None,
            'hasZ': False,
            'hasM': False,
            'copyrightText': None,
            'parentLayer': None,
            'subLayers': None,
            'minScale': 0,
            'maxScale': 0,
            'defaultVisibility': True,
            'extent': extent_to_envelope(full_extent, epsg),
            'displayField': variable.variable,
            'maxRecordCount': 1000,
            'supportsStatistics': False,
            'supportsAdvancedQueries': False,
            'capabilities': 'Map,Query',
            'supportedQueryFormats': 'JSON',
            'isDataVersioned': False
        }

        if variable.supports_time:
            data['timeInfo'] = {
                'timeExtent': [date_to_timestamp(variable.time_start), date_to_timestamp(variable.time_end)],
                'timeInterval': variable.service.time_interval,
                'timeIntervalUnits': TIME_UNITS_MAP.get(variable.service.time_interval_units),
                'exportOptions': {
                    'useTime': True,
                    'timeDataCumulative': False
                },
                'hasLiveData': False
            }

        return data
Пример #6
0
    def render_to_response(self, context, **response_kwargs):
        epsg = proj4_to_epsg(Proj(str(self.object.projection)))
        if epsg:
            full_extent = self.object.full_extent
            initial_extent = self.object.initial_extent
        else:
            epsg = 102100
            projection = Proj('+units=m +init=epsg:3857')
            full_extent = self.object.full_extent.project(projection)
            initial_extent = self.object.initial_extent.project(projection)

        data = {
            'currentVersion':
            '10.1',
            'serviceDescription':
            self.object.description,
            'mapName':
            self.object.name,
            'description':
            self.object.description,
            'copyrightText':
            '',
            'supportsDynamicLayers':
            True,
            'layers': [{
                'id': v.index,
                'name': v.name,
                'defaultVisibility': True,
                'parentLayerId': -1,
                'subLayerIds': None,
                'minScale': 0,
                'maxScale': 0
            } for v in self.object.variable_set.all()],
            'spatialReference': {
                'wkid': epsg
            },
            'singleFusedMapCache':
            False,
            'initialExtent':
            extent_to_envelope(initial_extent, epsg),
            'fullExtent':
            extent_to_envelope(full_extent, epsg),
            'supportedImageFormatTypes':
            ','.join(SUPPORTED_IMAGE_FORMATS),
            'capabilities':
            'Map,Query',
            'supportedQueryFormat':
            'JSON'
        }

        if self.object.supports_time:
            data['timeInfo'] = {
                'timeExtent': [
                    date_to_timestamp(self.object.time_start) * 1000,
                    date_to_timestamp(self.object.time_end) * 1000
                ],
                'timeRelation':
                'esriTimeRelationOverlaps',
                'defaultTimeInterval':
                self.object.time_interval,
                'defaultTimeIntervalUnits':
                TIME_UNITS_MAP.get(self.object.time_interval_units),
                'hasLiveData':
                False
            }

        return HttpResponse(json.dumps(data), content_type='application/json')