Return Context as a GeoJson FeatureCollection, only compatible with NGSIv2API
@return \stdClass
542684
public function toGeoJson() {
        $Context = $this->_context;


        //If is a invalid object
        if (null === $Context) {
            return $Context;
        }


        //If is not an array(query response) and  is a object
        if (!is_array($Context)) {
            //Check if is a valid entity object
            if (is_object($Context) && isset($Context->id) && isset($Context->type)) {
                $Context = [$Context];
            } else {
                return null;
            }
        }

        $geoJson = (object) ["type" => "FeatureCollection", "features" => []];

        //Build FeatureCollection
//        $countContext = count($Context);
        foreach ($Context as $Entity) { //0.0080490112304688 Seconds
//        for ($i = 0; $i < $countContext; $i++) { //0.025826215744019 Seconds
//            $Entity = $Context[$i];

            if (!(isset($Entity->id) && isset($Entity->type))) {
                continue;
            }
            
            $Feature = (object) ["type" => "Feature", "properties" => ['__metadata'=>[]], "geometry" => null];

            $entityType = null;
            $entityID = null;
            //Roll-out all properties of this feature
            foreach ($Entity as $key => $attr) {
                switch ($key) {
                    case "id":
                        $entityID = $attr;
                        $Feature->properties[$key] = $attr;
                        break;
                    case "type":
                        $entityType = $attr;
                        $Feature->properties[$key] = $attr;
                        break;
                    default:
                        switch ($attr->type) {
                            case "geo:json":
                                $Feature->geometry = $attr->value;
                                $Feature->geometry->type = ucfirst(strtolower($Feature->geometry->type)); //Normalization of geoJson geometry type name.
                                if (isset($attr->metadata) && !empty((array) $attr->metadata)) {
                                    $Feature->properties['geo_metadata'] = $attr->metadata;
                                }
                                break;
                            case "geo:point":
                                $coords = array_reverse(explode(",", $attr->value)); //Change WGS84 Lat Long to Long Lat as GeoJson specifications.

                                array_filter($coords, function($coord) {
                                    return floatval(trim($coord));
                                });

                                $Feature->geometry = (object) [
                                            "type" => "Point",
                                            "coordinates" => $coords
                                ];

                                if (isset($attr->metadata) && !empty((array) $attr->metadata)) {
                                    $Feature->properties['geo_metadata'] = $attr->metadata;
                                }
                                break;
                            case "geo:box":
                                $x = array_reverse(explode(",", $attr->value[0])); //Change WGS84 Lat Long to Long Lat as GeoJson specifications.
                                $y = array_reverse(explode(",", $attr->value[1])); //Change WGS84 Lat Long to Long Lat as GeoJson specifications.
                                //Convert boundary box to polygon using WKT  format POLYGON(x1 y1, x1 y2, x2 y2, x2 y1, x1 y1)
                                $coords = [
                                    [$x[0], $y[0]], //x1 y1
                                    [$x[0], $y[1]], //x1 y2
                                    [$x[1], $y[1]], //x2 y2
                                    [$x[0], $y[0]], //x2 y1                                      
                                    [$x[0], $y[0]] //x1 y1
                                ];

                                $Feature->geometry = (object) [
                                            "type" => "Polygon",
                                            "coordinates" => $coords
                                ];

                                if (isset($attr->metadata) && !empty((array) $attr->metadata)) {
                                    $Feature->properties['geo_metadata'] = $attr->metadata;
                                }
                                break;
                            case "geo:polygon":
                            case "geo:line":
                                //Transform Value Pairs to Polygon/Line Coords
                                $coords = array_filter($attr->value, function($rawvalue) {
                                    $coords = array_reverse(explode(",", $rawvalue)); //Change WGS84 Lat Long to Long Lat as GeoJson specifications.
                                    array_filter($coords, function($coord) {
                                        return floatval(trim($coord));
                                    });
                                    return $coords;
                                });

                                $Feature->geometry = (object) [
                                            "type" => ($attr->type == "geo:polygon") ? "Polygon" : "LineString",
                                            "coordinates" => $coords
                                ];

                                if (isset($attr->metadata) && !empty((array) $attr->metadata)) {
                                    $Feature->properties['geo_metadata'] = $attr->metadata;
                                }
                                break;
                            default:
                                $Feature->properties[$key] = $attr->value;
                                if (isset($attr->metadata) && !empty((array) $attr->metadata)) {
                                    $Feature->properties['__metadata'][$key] = $attr->metadata;
                                }

                                //Add type to metadata
                                if(isset($attr->type)){
                                    if(!isset($Feature->properties['__metadata'][$key])){
                                        $Feature->properties['__metadata'][$key] = [];
                                    }

                                    $Feature->properties['__metadata'][$key]['type'] = $attr->type;
                                }

                                break;
                        }
                        break;
                }
            }
            
            $Feature->id = "{$entityType}-{$entityID}";

            //Finally if this context have a valid geometry append to feature collection
            if ($Feature->geometry != null) {
                $Feature->properties = (object) $Feature->properties;
                array_push($geoJson->features, $Feature);
            }
        }

        return $geoJson;
    }
334950
public function jsonSerialize()
    {
        $data = [
            '@context' => [],
            '@id' => $this->uri,
        ];
        $types = $this->types;
        if (!empty($types)) {
            $data['@type'] = $this->transfromArray($types);
        }

        if (!$this->triples instanceof \core_kernel_classes_ContainerCollection) {
            return $data;
        }

        $triples = $this->triples->toArray();
        $map = [];
        foreach ($triples as $key => $triple) {
            if (in_array($triple->predicate, $this->blackList)) {
                continue;
            }

            if (!isset($map[$triple->predicate])) {
                $id = $this->generateId($triple->predicate);
                if (in_array($id, $map)) {
                    $nr = 0;
                    while (in_array($id . '_' . $nr, $map)) {
                        $nr++;
                    }
                    $id = $id . '_' . $nr;
                }
                $map[$triple->predicate] = $id;
                $data['@context'][$id] = $triple->predicate;
            }

            $key = $map[$triple->predicate];
            if (isset($data[$key])) {
                if (!is_array($data[$key])) {
                    $data[$key] = array($data[$key]);
                }
                $data[$key][] = $this->encodeValue($triple->object, $triple->predicate);
            } else {
                $data[$key] = $this->encodeValue($triple->object, $triple->predicate);
            }
        }

        // Enforce serialization to object if context is empty
        $data['@context'] = (object) $data['@context'];

        return $data;
    }
53139
def convert_to_feature_collection(self):
        """"""
        if self.data['type'] == 'FeatureCollection':
            return
        if not self.embed:
            raise ValueError(
                'Data is not a FeatureCollection, but it should be to apply '
                'style or highlight. Because `embed=False` it cannot be '
                'converted into one.\nEither change your geojson data to a '
                'FeatureCollection, set `embed=True` or disable styling.')
        # Catch case when GeoJSON is just a single Feature or a geometry.
        if 'geometry' not in self.data.keys():
            # Catch case when GeoJSON is just a geometry.
            self.data = {'type': 'Feature', 'geometry': self.data}
        self.data = {'type': 'FeatureCollection', 'features': [self.data]}
1022379
public function serializeContextFunction($context)
    {
        $json = array();

        foreach ($context as $key => $value) {
            if (!in_array($key, array('_parent', 'assetic', 'app')) && !preg_match('#sonata#', $key)) {
                try {
                    $serializedValue = $this->serializer->serialize($value, 'json');
                } catch (\JMS\Serializer\Exception\RuntimeException $ex) {
                    $serializedValue = json_encode($value, null, 2);
                }

                if (!empty($serializedValue)) {
                    $json[] = $this->serializer->serialize($key, 'json').':'.$serializedValue;
                }
            }
        }

        return '{'.implode(',', $json).'}';
    }
1091114
protected function context()
    {
        return collect($this->option())->only([
            'ansi',
            'no-ansi',
            'no-interaction',
            'quiet',
            'verbose',
        ])->filter()->mapWithKeys(function ($value, $key) {
            return ["--{$key}" => $value];
        })->all();
    }
1349593
public function getMapToken ()
	{
		/** @var Settings $settings */
		$settings = SimpleMap::getInstance()->getSettings();

		return GeoService::getToken(
			$settings->mapToken,
			$settings->mapTiles
		);
	}
706018
def build_feature_collection(node, name=None):
    
    # Initialize
    geojson = {
      'type': 'FeatureCollection',
      'features': [],
    }

    # Build features
    for placemark in get(node, 'Placemark'):
        feature = build_feature(placemark)
        if feature is not None:
            geojson['features'].append(feature)

    # Give the collection a name if requested
    if name is not None:
        geojson['name'] = name

    return geojson
988780
public function jsonSerialize(): stdClass
    {
        $object = (object)object_get_properties($this, $this instanceof DynamicEntity);

        /** @var Event\ToJson $event */
        $event = $this->dispatchEvent(new Event\ToJson($this, $object));
        $data = i\type_check($event->getPayload(), stdClass::class, new UnexpectedValueException());

        return $data;
    }
171589
public function toStdObject()
    {
        $object = new \stdClass();
        $object->uid = $this->getUid();
        $object->level = $this->getLevel();
        $object->keyword = $this->getKeyword();
        $object->children = array();
        return $object;
    }
392256
public function jsonSerialize() {
        $ret = new \stdClass();
        $requiredTargetAttributes = array();
        $requiredTargetAttributes['requiredTargetAttributes'] = $this->requiredTargetAttributes;
        $ret->requiredTargetAttributes = $requiredTargetAttributes;
        $ret->targetAttributes = $this->targetAttributes;

        return $ret;
    }
327452
public function jsonSerialize()
    {
        $linestrings = [];

        foreach ($this->linestrings as $linestring) {
            $linestrings[] = $linestring->jsonSerialize();
        }

        return new \GeoJson\Geometry\MultiLineString($linestrings);
    }
127704
public function jsonSerialize()
    {
        $geometries = [];
        foreach ($this->geometries as $geometry) {
            $geometries[] = $geometry->jsonSerialize();
        }

        return new \GeoJson\Geometry\GeometryCollection($geometries);
    }
300749
protected function formatJSON()
    {
        $result = new \stdClass();

        if ($this->outputMode == self::MODE_ERROR) {
            $this->formatFailure($result);
        } else {
            $this->formatSuccess($result);
        }

        // include valid, plain non-namespace data
        foreach ($this->plain as $key => $value) {
            $result->$key = $value;
        }
        //TODO: better handling of links (self, related, pagination) http://jsonapi.org/format/#document-links

        if ($this->meta) {
            $result->meta = $this->meta;
        }

        return $result;
    }
369093
public function getGeoJson(): ?string
    {
        if (! ($code = $this->getIsoAlpha2())) {
            return null;
        }

        return file_exists($file = __DIR__.'/../resources/geodata/'.mb_strtolower($code).'.json') ? file_get_contents($file) : null;
    }
1016566
final public static function getClassFile():\stdClass
    {
        $a = json_decode(file_get_contents(FEnv::get("framework.config.core.apps.file")));
        return ($a == null ? new \stdClass() : $a);
    }
451934
public function getJSONObject()
    {
        $app = Application::getFacadeApplication();
        $urlResolver = $app->make(ResolverManagerInterface::class);
        $r = new stdClass();
        $fp = new Permissions($this->getFile());
        $r->canCopyFile = $fp->canCopyFile();
        $r->canEditFileProperties = $fp->canEditFileProperties();
        $r->canEditFilePermissions = $fp->canEditFilePermissions();
        $r->canDeleteFile = $fp->canDeleteFile();
        $r->canReplaceFile = $fp->canEditFileContents();
        $r->canEditFileContents = $fp->canEditFileContents();
        $r->canViewFileInFileManager = $fp->canRead();
        $r->canRead = $fp->canRead();
        $r->canViewFile = $this->canView();
        $r->canEditFile = $this->canEdit();
        $r->url = $this->getURL();
        $r->urlInline = (string) $urlResolver->resolve(['/download_file', 'view_inline', $this->getFileID()]);
        $r->urlDownload = (string) $urlResolver->resolve(['/download_file', 'view', $this->getFileID()]);
        $r->title = $this->getTitle();
        $r->genericTypeText = $this->getGenericTypeText();
        $r->description = $this->getDescription();
        $r->fileName = $this->getFileName();
        $r->resultsThumbnailImg = $this->getListingThumbnailImage();
        $r->fID = $this->getFileID();
        $r->treeNodeMenu = new Menu($this->getfile());

        return $r;
    }
513948
protected function formatJSON()
    {
        $result = new \stdClass;

        if ($this->outputMode == self::MODE_ERROR) {
            $this->formatFailure($result);
        } else {
            $this->formatSuccess($result);
        }

        // only include if it has valid data
        if ($this->meta) {
            $result->meta = $this->meta;
        }

        return $result;
    }