jlchassaing/ezgeodatagouv

EzGeoDataGouv 扩展包帮助与 datagouv 交互,导入位置信息并使用 geo.data.gouv 工具进行搜索

安装: 249

依赖: 0

建议: 0

安全: 0

星级: 1

关注者: 2

分支: 0

开放问题: 9

类型:ezplatform-bundle


README

Latest Stable Version Total Downloads Latest Unstable Version License

eZ Geo Data Gouv 项目

此扩展包有两个用途

  • 帮助导入 CSV 位置列表,并基于 geo.api.gouv.fr 提供地理编码功能
  • 提供一个基于 geo data gouv 的 React 搜索表单,具有自动完成功能

内容将导入 eZ Platform 内容,由 solr 索引,以帮助位置邻近度搜索

安装

此版本旨在安装在 eZ Platform 2.5 和 Symfony 3.4 上

此扩展包使用 eZ Platform 和 Code Rhapsodie eZ Dataflow Bundle

composer require jlchassaing/ezgeodatagouv

在 AppKernel.php 中添加

<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = [
        // ...
        new Kaliop\eZMigrationBundle\EzMigrationBundle(),
        new CodeRhapsodie\DataflowBundle\CodeRhapsodieDataflowBundle(),
        new CodeRhapsodie\EzDataflowBundle\CodeRhapsodieEzDataflowBundle(),
        new eZGeoDataGouvBundle\EzGeoDataGouvBundle(),
        // ...
    ];
}

在 routing.yml 中添加 coderhapsody 路由参数

_cr.dataflow:
    resource: '@CodeRhapsodieEzDataflowBundle/Resources/config/routing.yaml'

_ezGeoDataGouv:
    resource: '@EzGeoDataGouvBundle/Resources/config/rest_routing.yml'
    prefix: '%ezpublish_rest.path_prefix%'

创建新的位置内容类型

bin/console kaliop:migration:migrate --siteaccess=admin --path=vendor/jlchassaing/ezgeodatagouv/src/bundle/MigrationVersions/20200407105655_create_location_content_type.yml

如何导入数据

设置资源

资源在 config.yml 文件中设置

ez_geo_data_gouv:
    resources:
        resource_key_name:
            do_geocoding: true|false
            content_type: content_type_identifier # content type where to import data
            language: import_language # should be eng-GB or fre-FR or any other language default is eng-GB
            id_key: csv_uniq_id_key
            name: csv_field_used_for_name
            address:
                longitude: longitude
                latitude: latitude
                address: csv_field_used_for_full_address
            fields: # if using a custom class identifier cet specific fields
                url:
                    datatype: ezurl
                    value: url
            geocoding_fields:
                columns:
                    - commune # csv field to send for geo coding in geo.api.gouv
                    - voie
                postcode: code_postal 
                citycode: code_commune_insee
                result_columns:
                    - result_label # set specific fields for result if not set default are longitude and latidue

设置帮助确定 CSV 字段的使用方式。资源名称必须作为选项传递给导入脚本

字段部分帮助您添加特定的内容类型字段。键是内容类型字段标识符。数据类型是内容类型字段的类型,值是 CSV 字段名称

运行导入

导入脚本的别名是 'dtgi'

如果您没有提供 siteaccess 参数,则将使用默认的 siteaccess

提供的选项包括

  • 添加内容的父位置 ID
  • csv_source 路径,其中可以找到 csv 源(目前文件必须是分号字段分隔,并带有引号)
  • 资源名称
bin/console code-rhapsodie:dataflow:execute --siteaccess=<siteaccess> dtgi  '{"parent-location-id":<locationId>,"csv-source":"<csvpath>","resource":"<resource_name>"}'

邻近度搜索

eZ Rest API 已扩展,以返回邻近点的查询

有 4 种方式调用执行请求

  • /ez_geo_data_gouv/search/{longitude}/{latitude}
  • /ez_geo_data_gouv/search/{distance}/{longitude}/{latitude}
  • /ez_geo_data_gouv/search/{contentType}/{longitude}/{latitude}
  • /ez_geo_data_gouv/search/{contentType}/{distance}/{longitude}/{latitude}

默认 contentType 是 "location",默认距离是 5

请记住使用 ezpublish api 请求前缀。在您的请求中添加 Accept: application/vnd.ez.api.ContentList+json 标头将返回一个格式为 JSON 的响应。

查询将返回最多 5 个答案

扩展以添加自定义导入管理器

DataGouvImportLocationsDataFlowType 类可以扩展

这可能是必要的,在创建内容之前对 CSV 数据进行一些更改。

创建一个扩展 DataGouvImportLocationsDataFlowType 的自定义类并添加方法

...
    public function getLabel(): string
    {
        return "My DataFlow";
    }

    public function getAliases(): iterable
    {
        return ['mydf'];
    }

    protected function addFilterTask(DataflowBuilder $builder)
    {
        $builder->addStep(function ($data){
            /** add here your code and return data or null to invalidate line */
            return $data;
        });
    }
... 

一旦创建了类,将其声明为服务并添加标签 coderhapsodie.dataflow.type

AppBundle\DataFlow\MyDataFlowType:
    tags:
        - { name: coderhapsodie.dataflow.type }

待办事项

  • 添加 CSV 配置
  • 如果没有提供位置参数(经度、纬度),则在导入数据之前进行地理编码
  • 设置映射配置界面,并且只传递配置 ID 给导入脚本
  • 添加参数以连接字段来构建地址字段