Turfjs / turf

A modular geospatial engine written in JavaScript and TypeScript

Home Page:https://turfjs.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error : Must specify at least 2 geometries

eishynena opened this issue · comments

Hi everyone!

On this week, i notice about some error when this function is is executed "turf.intersect(polygon, polygonToCheck);"

But, i have curious because that was working well for me until the last week.

Please provide the following when reporting an issue:

  • The version of Turf you are using, and any other relevant versions.

On the index.html from Angular 6 project, the import is like this:

<script src='https://npmcdn.com/@turf/turf/turf.min.js'></script>
  • Snippet of source code or for complex examples use jsfiddle.

declare var turf: any;

The functions:

    createPolyTurfjs(polyPoints) {
        let polygon = turf.polygon([
          polyPoints
        ]);
    
        return polygon;
    }

    checkIfPolyIsValid(polyPoints) {
                let polygonToCheck = this.createPolyTurfjs(polyPoints);
                let polygon = turf.polygon([
                  [[0, 0], [1, 1], [0, 1], [0, 0]]
                ]);
            
                try {
            
                  turf.intersect(polygon, polygonToCheck);
            
                  return true;
                } catch (e) {
                  return false;
                }
    }

polygonToCheck is something like this (example):

{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
-102.37738683716641,
20.652262583876137
],
[
-102.30734899537025,
20.674749135360088
],
[
-102.27301671998013,
20.618847850862764
],
[
-102.35335424439182,
20.602137733586616
],
[
-102.37738683716641,
20.652262583876137
]
]
]
}
}

And **polygon ** result is:

{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
0,
0
],
[
1,
1
],
[
0,
1
],
[
0,
0
]
]
]
}
}

But, when the line "turf.intersect(polygon, polygonToCheck);" is executed, the next error appears:

Error: Must specify at least 2 geometries
at Object.intersect (turf.min.js:51:177)
at push../src/app/office/zonas/crear-zona/crear-zona.component.ts.CrearZonaComponent.checkIfPolyIsValid (crear-zona.component.ts:605:12)
at push../src/app/office/zonas/crear-zona/crear-zona.component.ts.CrearZonaComponent.dibujarPoligonoActual (crear-zona.component.ts:518:15)
at push../src/app/office/zonas/crear-zona/crear-zona.component.ts.CrearZonaComponent.onClickDibujarMapa (crear-zona.component.ts:781:17)
at Object.eval [as handleEvent] (CrearZonaComponent.html:184:33)
at handleEvent (core.js:10251:1)
at callWithDebugContext (core.js:11344:1)
at Object.debugHandleEvent [as handleEvent] (core.js:11047:1)
at dispatchEvent (core.js:7710:1)
at core.js:8154:30

Again, that was working very well until a few days. Please, don't be mad with me guys, i just need help to know what happend. If i have to change somenthing (the library import, the line, etc) just let me know please.

If you can help me, i will very appreciated it

Hi @eishynena. Good news - this is easy for you to fix.

Turf was recently upgraded to v7, so that link now points to the newest version of Turf where the intersect function has changed.

To insist on the old 6.5.0 version of Turf that your code matches to, use this link instead:

<script src='https://npmcdn.com/@turf/turf@6.5.0/turf.min.js'></script>

I’m seeing the same error with union in v7. In what way have these methods changed since v6.5.0?

Hi @neave. Take a look at the readme for union. From memory, instead of passing two individual polygons you pass a single feature collection with as many polygons as you need.

Perfect. Thanks @smallsaucepan

Actually, sorry the readme looks out of date. Best take a look at the function signature. Will hopefully have the readme and website documentation synced up shortly.

Hi!

The intersect params have to be like turf.featureCollection([poly1, poly2]), right?

Thanks a lot!

@eishynena Yes it looks so

Thanks for help me. The 6.5 version works well for me.