Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MultiPolygon not parsing although appearing to be valid #26

Open
sptdigital opened this issue Feb 28, 2019 · 2 comments
Open

MultiPolygon not parsing although appearing to be valid #26

sptdigital opened this issue Feb 28, 2019 · 2 comments

Comments

@sptdigital
Copy link

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

@martinburch
Copy link

I can't reproduce this error. Test code returns successfully, no errors.

$ composer require "jmikola/geojson=~1.0"
<?php
require __DIR__ . '/vendor/autoload.php';

$json = file_get_contents('https://gist.githubusercontent.com/sptdigital/f0b7102bae5e9d72c3845b406c323951/raw/09d2d9fef0603320bdce65d93975badf7e1da63c/example.json');
$json = json_decode($json);
$geojson = \GeoJson\GeoJson::jsonUnserialize($json);

var_dump($geojson);

@jmikola
Copy link
Owner

jmikola commented Feb 28, 2019

I can confirm that the JSON file above appears to be valid. In addition to running the script @martinburch shared, I inspected the data with a JS interpreter:

// After assigning the GeoJSON object to x

x.geometry.coordinates.forEach(function(iv, ik) {
   print("MultiPolygon["+ik+"] has "+iv.length+" Polygon(s)");
   iv.forEach(function(jv, jk) {
     print("  Polygon["+jk+"] has "+jv.length+" coordinates");
   });
 });

This produced the following output:

MultiPolygon[0] has 1 Polygon(s)
  Polygon[0] has 203 coordinates
MultiPolygon[1] has 1 Polygon(s)
  Polygon[0] has 278 coordinates
MultiPolygon[2] has 1 Polygon(s)
  Polygon[0] has 61 coordinates
MultiPolygon[3] has 1 Polygon(s)
  Polygon[0] has 116 coordinates
MultiPolygon[4] has 1 Polygon(s)
  Polygon[0] has 438 coordinates
MultiPolygon[5] has 1 Polygon(s)
  Polygon[0] has 157 coordinates
MultiPolygon[6] has 1 Polygon(s)
  Polygon[0] has 9104 coordinates
MultiPolygon[7] has 1 Polygon(s)
  Polygon[0] has 486 coordinates
MultiPolygon[8] has 1 Polygon(s)
  Polygon[0] has 816 coordinates
MultiPolygon[9] has 2 Polygon(s)
  Polygon[0] has 31847 coordinates
  Polygon[1] has 4 coordinates
MultiPolygon[10] has 1 Polygon(s)
  Polygon[0] has 59 coordinates
MultiPolygon[11] has 1 Polygon(s)
  Polygon[0] has 77 coordinates
MultiPolygon[12] has 1 Polygon(s)
  Polygon[0] has 1591 coordinates

I'll note that the tenth polygon (i.e. MultiPolygon[9]) is the only geometry with an interior ring (hole), which consists of 4 coordinates. Since the first and last coordinates must be equivalent, that would be a triangle representing the smallest closed loop. All other polygons have far more than 4 coordinates in their exterior rings.

If you have an exception, it should be possible to analyze the stack trace and determine exactly what data was passed to the LinearRing constructor via Polygon::__construct().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants