jmikola / geojson Goto Github PK
View Code? Open in Web Editor NEWGeoJSON implementation for PHP
License: MIT License
GeoJSON implementation for PHP
License: MIT License
In https://github.com/jmikola/geojson#installation
From:
$ composer require "jmikola/geojson=~1.0"
to
"jmikola/geojson": "1.0.*@dev"
I have figured it out now but before I have downloaded with composer an old version with some bug. I even wrote an issue post with how to solve this bug! ;)
Is the README the only documentation for this library? I don't think I should have to leaf through the test code to find out that a Feature is instantiated with new \GeoJson\Feature\Feature($geometry, $properties, $id);
but how would I know the ordering of the arguments otherwise?
As discussed in #33:
According to the RFC, the "id" property of a Feature is expected to be a JSON string or a number (https://www.rfc-editor.org/rfc/rfc7946#section-3.2), so I added a check for this. This would be a breaking change, so if you're targeting a 1.1 release instead of a 2.0 release, I can remove the check again.
That change was ultimately not included in #33 since it would be a BC break, but this can be considered for 2.0.
Hello,
I needed a way to get the center of a MultiPoint object so I extended the class with a getCenter()
function: https://github.com/Rudloff/openvegemap-editor/blob/develop/classes/MultiPoint.php
Would you like to include it in the main library?
(I guess it might also make sense on a BoundingBox object.)
I would like to suggest that a nice feature would be possibility do add any members to the GeoJSON object. I mean objects that are not specified in GeoJSON standard.
E.g. I am working now on a project, where PHP script will be outputting GeoJSON data. The data will be loaded via AJAX to a JavaScript and then load a Google Map based on the data.
I want to pass via GeoJSON some settings to set up a map e.g. an initial zoom value.
So let's say I have a GeoJSON FeatureColletion object. The collection is made of 1 feature (Point). I am specifying an initial zoom value as 2-nd member. I want my GeoJSON look this:
{
"type":"FeatureCollection",
"zoom": 12,
"bbox":[
19.967651,
53.537043,
19.967651,
53.537043
],
"features":[
{
"type":"Feature",
"geometry":{
"type":"Point",
"coordinates":[
19.967651,
53.537043
]
},
"properties": null
}
]
}
As I understand the specification of GeoJSON standard, it is allowed to add such members.
What do you think about it? I mean, what do you think about extending your lib so that you can add other members (not specified in a GeoJSON spec).
When using PHP 8.1, i get the following log message :
Deprecated: Return type of GeoJson\GeoJson::jsonSerialize() should either be compatible with JsonSerializable::jsonSerialize(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice
I appears all the class extending \JsonSerializable and implementing the "jsonSerializer" method needs their return to be explicitly typed to "mixed" for this deprecation to disappear.
As discussed in #33 (comment), RFC7946 states:
B.1. Normative Changes
Specification of coordinate reference systems has been removed, i.e., the "crs" member of [GJ2008] is no longer used.
If CRS is no longer part of the GeoJSON spec, we can consider removing these classes altogether.
Hello
I am having an issue parsing the following GeoJSON ...
https://gist.github.com/sptdigital/f0b7102bae5e9d72c3845b406c323951
It returns the error message LinearRing requires at least four positions
, even though my LinearRings are compliant with the latest version of the GeoJson standard as far as I can see.
I have no issues using this GeoJson anywhere outside of this package.
Could you possibly point me in the right direction please?
Thanks,
Ally
The code in Point
seems more complicated than necessary. It may be good to modify the constructor so that it's more clear how to structure data going into the class. For instance:
public function __construct(
$latitude,
$longitude,
CoordinateReferenceSystem $crs = null,
BoundingBox $box = null
) {
$this->coordinates = [
$latitude,
$longitude
];
When not correct data is used to create Polygon following php warning is shown
new \GeoJson\Geometry\Polygon([[2,4]]);
PHP Warning: array_map(): An error occurred while invoking the map callback in ...
I suggest removing array_map in Polygon constructor in favor of using foreach to create coordinates array for polygon.
See php bug related to throwing Exception in array_map callback - https://bugs.php.net/bug.php?id=55416
<?php
require 'vendor/autoload.php';
$point = new \GeoJson\Geometry\Point([1, 1]);
result:
PHP Parse error: syntax error, unexpected '[', expecting ')' in /file/path/test.php on line 3
This does work:
$point = new \GeoJson\Geometry\Point(array(1, 1));
Contrast with FeatureCollection, which inherits GeoJson directly. In hindsight, it looks like the Geometry extension was just a typo.
The readme says "jsonSerialize() will need to be manually called and its return value passed to json_encode()."
<?php
require 'vendor/autoload.php';
$point = new \GeoJson\Geometry\Point(array(1, 1));
$json = json_encode(\GeoJson\GeoJson::jsonSerialize($point));
print($json);
Produces two errors
PHP Strict Standards: Non-static method GeoJson\GeoJson::jsonSerialize() should not be called statically in /path/file.php on line 4
PHP Fatal error: Using $this when not in object context in /path/vendor/jmikola/geojson/src/GeoJson/GeoJson.php on line 66
Please advise.
According to the RFC 7946, the properties in a Feature objet must be an array or a null value.
When I provide another value (for instance a string), the value is accepted as-is when using GeoJson::jsonUnserialize
. I was expecting to receive an GeoJson\Exception\UnserializationException
exception. Is this sensible to you ?
It'll more flexible to use library for applications, if it'll provide ready constants for each type
Hello!
I try to use this package, but the examples in the USAGE.md file is not clear for me...
In my case I need to extract points from database and then serve as API to the client, that's show a map with a mapbox gl implementation.
Can you please let me an real example? If you can... In the meantime I'll try to deal with this. If I can reach my goal I'll a PR with my usage example.
Thanks in advance. Regards.
Would be nice to have a patch release. I just ran into 844e43a which was fixed 4 years ago.
Point
,MultiPoint
,LineString
, etc. are all \GeoJson\Geometry
objects, e.g. \GeoJson\Geometry\Point
. This follows spec.
Feature
and FeatureCollection
are both in the \GeoJson\Feature
hierarchy -- \GeoJson\Feature\FeatureCollection
and \GeoJson\Feature\Feature
. I think this is out of spec. The Feature
and FeatureCollection
classes do not extend a common Feature
class -- FeatureCollection
has no properties in common with Feature
.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.