Extend Feeds plugin to allow import of WKT and GeoJson

Created on 15 November 2019, almost 5 years ago
Updated 19 January 2023, almost 2 years ago

I would like to use Feeds to import wkt data from CSV files. I have used the existing Feeds plugin to import point location by splitting the data into lat and long but I want import LINESTRING and MULTILINESTRING. For testing I am replacing the existing Feeds plugin but my aim is to make a plugin that works for lat/long and wkt.
For testing I have simplified the existing code to just pass the wkt string but this doesn't work so I obviously haven't got the format correct. Can someone help with the right format to pass wkt? The code I am using is below

<?php

namespace Drupal\geofield\Feeds\Target;

use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\feeds\Exception\EmptyFeedException;
use Drupal\feeds\FieldTargetDefinition;
use Drupal\feeds\Plugin\Type\Target\FieldTargetBase;

/**
 * Defines a geofield field mapper.
 *
 * @FeedsTarget(
 *   id = "geofield_feeds_target",
 *   field_types = {"geofield"}
 * )
 */
class Geofield extends FieldTargetBase {

  /**
   * {@inheritdoc}
   */
  protected static function prepareTarget(FieldDefinitionInterface $field_definition) {
    return FieldTargetDefinition::createFromFieldDefinition($field_definition)
      ->addProperty('wkt');
  }

  /**
   * {@inheritdoc}
   */
  protected function prepareValue($delta, array &$values) {

    if (isset($values['wkt']) && empty($values['wkt'])) {
       // If wkt is empty set it to null
       $values['wkt'] = NULL;
     }
     dpm($values['wkt']);
  }
}

All help appreciated

💬 Support request
Status

Closed: duplicate

Version

1.0

Component

Code

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

No activities found.

Production build 0.71.5 2024