예제 #1
0
    def __init__(self, package_id, resource_id, workspace_name, layer_name, layer_version, username, geoserver, store=None, workspace=None,
                 lat_field=None, lng_field=None):
        self.geoserver = Geoserver.from_ckan_config()
        self.name = layer_name
	self.layer_version = layer_version
        self.username = username
        self.file_resource = toolkit.get_action("resource_show")(None, {"id": resource_id})
        self.package_id = package_id
        self.resource_id = resource_id
        self.store = self.geoserver.get_datastore(workspace, store, workspace_name, layer_version)
	self.workspace_name = workspace_name

        url = self.file_resource["url"]
        kwargs = {"resource_id": self.file_resource["id"]}

        # Determine whether to handle the data with shapefile or datastored csv operators
        if url.endswith('.zip'):
            cls = Shapefile
        elif url.endswith('.csv'):
            cls = Datastored
            kwargs.update({
                "lat_field": lat_field,
                "lng_field": lng_field
            })
        else:
            # The resource cannot be spatialized
            raise Exception(toolkit._("Only CSV and Shapefile data can be spatialized"))

        # '**' unpacks the kwargs dictionary which can contain an arbitrary number of arguments
        self.data = cls(**kwargs)

        # Spatialize
        if not self.data.publish():
            # Spatialization failed
            raise Exception(toolkit._("Spatialization failed."))
예제 #2
0
파일: Layer.py 프로젝트: okfn/ckanext-ngds
    def __init__(self, package_id, resource_id, layer_name, username, geoserver=Geoserver.from_ckan_config(), lat_field=None, lng_field=None):
        self.geoserver = geoserver
        self.store = geoserver.default_datastore()
        self.name = layer_name
        self.username = username
        self.file_resource = toolkit.get_action("resource_show")(None, {"id": resource_id})
        self.package_id = package_id
        self.resource_id = resource_id

        # Spatialize it
        url = self.file_resource["url"]
        kwargs = {"resource_id": self.file_resource["id"]}

        if url.endswith('.zip'):
            cls = Shapefile
        elif url.endswith('.csv'):
            cls = Datastored
            kwargs.update({
                "lat_field": lat_field,
                "lng_field": lng_field
            })
        else:
            # The resource cannot be spatialized
            raise Exception(toolkit._("Only CSV and Shapefile data can be spatialized"))

        self.data = cls(**kwargs)

        # Spatialize
        if not self.data.publish():
            # Spatialization failed
            raise Exception(toolkit._("Spatialization failed."))
예제 #3
0
    def __init__(self,
                 package_id,
                 resource_id,
                 workspace_name,
                 layer_name,
                 layer_version,
                 username,
                 geoserver,
                 store=None,
                 workspace=None,
                 lat_field=None,
                 lng_field=None):
        self.geoserver = Geoserver.from_ckan_config()
        self.name = layer_name
        self.layer_version = layer_version
        self.username = username
        self.file_resource = toolkit.get_action("resource_show")(
            None, {
                "id": resource_id
            })
        self.package_id = package_id
        self.resource_id = resource_id
        self.store = self.geoserver.get_datastore(workspace, store,
                                                  workspace_name,
                                                  layer_version)
        self.workspace_name = workspace_name

        url = self.file_resource["url"]
        kwargs = {"resource_id": self.file_resource["id"]}

        # Determine whether to handle the data with shapefile or datastored csv operators
        if url.endswith('.zip'):
            cls = Shapefile
        elif url.endswith('.csv'):
            cls = Datastored
            kwargs.update({"lat_field": lat_field, "lng_field": lng_field})
        else:
            # The resource cannot be spatialized
            raise Exception(
                toolkit._("Only CSV and Shapefile data can be spatialized"))

        # '**' unpacks the kwargs dictionary which can contain an arbitrary number of arguments
        self.data = cls(**kwargs)

        # Spatialize
        if not self.data.publish():
            # Spatialization failed
            raise Exception(toolkit._("Spatialization failed."))
예제 #4
0
파일: Layer.py 프로젝트: okfn/ckanext-ngds
    def __init__(self,
                 package_id,
                 resource_id,
                 layer_name,
                 username,
                 geoserver=Geoserver.from_ckan_config(),
                 lat_field=None,
                 lng_field=None):
        self.geoserver = geoserver
        self.store = geoserver.default_datastore()
        self.name = layer_name
        self.username = username
        self.file_resource = toolkit.get_action("resource_show")(
            None, {
                "id": resource_id
            })
        self.package_id = package_id
        self.resource_id = resource_id

        # Spatialize it
        url = self.file_resource["url"]
        kwargs = {"resource_id": self.file_resource["id"]}

        if url.endswith('.zip'):
            cls = Shapefile
        elif url.endswith('.csv'):
            cls = Datastored
            kwargs.update({"lat_field": lat_field, "lng_field": lng_field})
        else:
            # The resource cannot be spatialized
            raise Exception(
                toolkit._("Only CSV and Shapefile data can be spatialized"))

        self.data = cls(**kwargs)

        # Spatialize
        if not self.data.publish():
            # Spatialization failed
            raise Exception(toolkit._("Spatialization failed."))