PageSourceSearch

https://turfjs.org/assets/js/146d54d6.39f52937.js

js turfjs.org collected 2026-09-24 09:17:07 UTC 8,824 bytes, 1 lines download raw bytes

1"use strict";(globalThis.webpackChunkturf_www||=[]).push([[10691],{39751(e,n,t){t.r(n),t.d(n,{Map0:()=>m,assets:()=>g,contentTitle:()=>u,default:()=>y,frontMatter:()=>h,metadata:()=>o,toc:()=>x});const o=JSON.parse('{"id":"api/difference","title":"difference","description":"Description","source":"@site/versioned_docs/version-7.3.0/api/difference.mdx","sourceDirName":"api","slug":"/api/difference","permalink":"/docs/7.3.0/api/difference","draft":false,"unlisted":false,"editUrl":"https://github.com/Turfjs/turf-www/tree/master/versioned_docs/version-7.3.0/api/difference.mdx","tags":[],"version":"7.3.0","frontMatter":{"title":"difference"},"sidebar":"apiSidebar","previous":{"title":"convex","permalink":"/docs/7.3.0/api/convex"},"next":{"title":"dissolve","permalink":"/docs/7.3.0/api/dissolve"}}');var i=t(86070),r=t(67028),l=t(15388),s=t(6428),a=t(64776),c={};t.r(c),t.d(c,{along:()=>a.Qwm,angle:()=>a.g7h,applyFilter:()=>a.$hf,area:()=>a.Wcw,areaFactors:()=>a.i26,azimuthToBearing:()=>a.Oe8,bbox:()=>a.Qk1,bboxClip:()=>a.ywB,bboxPolygon:()=>a.kJI,bearing:()=>a.dcc,bearingToAzimuth:()=>a.u8E,bezierSpline:()=>a.vKl,booleanClockwise:()=>a.D2R,booleanConcave:()=>a.U7O,booleanContains:()=>a.yxm,booleanCrosses:()=>a.hkq,booleanDisjoint:()=>a.t5S,booleanEqual:()=>a.x0k,booleanIntersects:()=>a.lgr,booleanOverlap:()=>a.cYD,booleanParallel:()=>a.Y5$,booleanPointInPolygon:()=>a.mFO,booleanPointOnLine:()=>a.O84,booleanTouches:()=>a.UsQ,booleanValid:()=>a.hxF,booleanWithin:()=>a.Cei,buffer:()=>a.ra8,center:()=>a.gXo,centerMean:()=>a.rb,centerMedian:()=>a.eZr,centerOfMass:()=>a.NAY,centroid:()=>a.vh2,circle:()=>a.n1W,cleanCoords:()=>a.ayX,clone:()=>a.o8B,cloneProperties:()=>a.Rdw,clusterEach:()=>a.UZ0,clusterReduce:()=>a.HYf,clusters:()=>a.qf7,clustersDbscan:()=>a.Zqw,clustersKmeans:()=>a.pPd,collect:()=>a.Fod,collectionOf:()=>a.iww,combine:()=>a.kg7,concave:()=>a.Ms8,containsNumber:()=>a.lOq,convertArea:()=>a.vnt,convertLength:()=>a.I3T,convex:()=>a.y5H,coordAll:()=>a.D3w,coordEach:()=>a.Fh1,coordReduce:()=>a.k7X,createBins:()=>a.f8u,degreesToRadians:()=>a.tRv,destination:()=>a.j_,difference:()=>a.iv2,directionalMean:()=>a.eFb,dissolve:()=>a.a1F,distance:()=>a.IoC,distanceWeight:()=>a.mJ,earthRadius:()=>a.zXD,ellipse:()=>a.pw2,envelope:()=>a.REH,explode:()=>a.Gdr,factors:()=>a.PgN,feature:()=>a.N4z,featureCollection:()=>a.Lrk,featureEach:()=>a.usj,featureOf:()=>a.mo4,featureReduce:()=>a.n4j,filterProperties:()=>a.qV7,findPoint:()=>a.Yd2,findSegment:()=>a.ptW,flatten:()=>a.Bqz,flattenEach:()=>a.iwz,flattenReduce:()=>a.VJK,flip:()=>a.UUz,geojsonRbush:()=>a.sZS,geojsonType:()=>a.e8v,geomEach:()=>a.kX6,geomReduce:()=>a.jEc,geometry:()=>a.lCx,geometryCollection:()=>a.zbs,getCluster:()=>a.dB3,getCoord:()=>a.uGX,getCoords:()=>a.$Rn,getGeom:()=>a.bgk,getType:()=>a.Pwh,greatCircle:()=>a.Glg,helpers:()=>a._$r,hexGrid:()=>a.O9B,interpolate:()=>a.GWP,intersect:()=>a.y$5,invariant:()=>a.V1S,isNumber:()=>a.EtT,isObject:()=>a.Gvm,isobands:()=>a.Mii,isolines:()=>a.LNI,kinks:()=>a.nUT,length:()=>a.Bw9,lengthToDegrees:()=>a.vlv,lengthToRadians:()=>a.GfV,lineArc:()=>a.FsR,lineChunk:()=>a.W26,lineEach:()=>a.Iet,lineIntersect:()=>a.kVe,lineOffset:()=>a.uO7,lineOverlap:()=>a._Jg,lineReduce:()=>a.t0h,lineSegment:()=>a.wdR,lineSlice:()=>a.ne9,lineSliceAlong:()=>a.qMT,lineSplit:()=>a.JQ7,lineString:()=>a.wiw,lineStrings:()=>a.Nls,lineToPolygon:()=>a.gP4,mask:()=>a.dKf,meta:()=>a.mIj,midpoint:()=>a.PVF,moranIndex:()=>a.KFB,multiLineString:()=>a.NUZ,multiPoint:()=>a.kBJ,multiPolygon:()=>a.g52,nearestNeighborAnalysis:()=>a.rBB,nearestPoint:()=>a.xCI,nearestPointOnLine:()=>a.W1F,nearestPointToLine:()=>a.K9N,planepoint:()=>a.xYr,point:()=>a.zx7,pointGrid:()=>a.hq2,pointOnFeature:()=>a.QwJ,pointToLineDistance:()=>a.d4V,pointToPolygonDistance:()=>a.fJX,points:()=>a.WRA,pointsWithinPolygon:()=>a.nj9,polygon:()=>a.n1,polygonSmooth:()=>a.bmV,polygonTangents:()=>a.v4M,polygonToLine:()=>a.CNZ,polygonize:()=>a.Tz9,polygons:()=>a.qFD,projection:()=>a.Qju,propEach:()=>a.nPV,propReduce:()=>a.qBo,propertiesContainsFilter:()=>a.NLl,quadratAnalysis:()=>a.txz,radiansToDegrees:()=>a.nv6,radiansToLength:()=>a.cJD,random:()=>a.yTv,randomLineString:()=>a.lWQ,randomPoint:()=>a._eC,randomPolygon:()=>a.myJ,randomPosition:()=>a.Dxs,rectangleGrid:()=>a.K1I,rewind:()=>a.KrA,rhumbBearing:()=>
1a.Fc$,rhumbDestination:()=>a.rmV,rhumbDistance:()=>a.EUY,round:()=>a.LIG,sample:()=>a.XM1,sector:()=>a.rkH,segmentEach:()=>a.RPu,segmentReduce:()=>a.OQs,shortestPath:()=>a._6q,simplify:()=>a.CRN,square:()=>a.EwI,squareGrid:()=>a.cS4,standardDeviationalEllipse:()=>a.C0c,tag:()=>a.TcI,tesselate:()=>a.nYW,tin:()=>a.ucs,toMercator:()=>a.FU4,toWgs84:()=>a.zY8,transformRotate:()=>a.qS_,transformScale:()=>a.nIv,transformTranslate:()=>a.tLh,triangleGrid:()=>a.Vwd,truncate:()=>a.xvE,union:()=>a.KCZ,unkinkPolygon:()=>a.BoU,validateBBox:()=>a.O6s,validateId:()=>a.GZo,voronoi:()=>a.B8d});var d=t(36796),f=t(35876),p=t(25333);const h={title:"difference"},u=void 0,g={};function m(){var e=l.polygon([[[128,-26],[141,-26],[141,-21],[128,-21],[128,-26]]],{fill:"#F00","fill-opacity":.1}),n=l.polygon([[[126,-28],[140,-28],[140,-20],[126,-20],[126,-28]]],{fill:"#00F","fill-opacity":.1}),t={polygon1:e,polygon2:n,difference:s.i(l.featureCollection([e,n]))};return(0,i.jsx)(d.A,{addToMap:t})}const x=[{value:"Description",id:"description",level:3},{value:"Parameters",id:"parameters",level:3},{value:"Returns",id:"returns",level:3},{value:"Examples",id:"examples",level:3},{value:"Installation",id:"installation",level:3}];function j(e){const n={a:"a",code:"code",h3:"h3",p:"p",pre:"pre",strong:"strong",table:"table",tbody:"tbody",td:"td",th:"th",thead:"thead",tr:"tr",...(0,r.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(n.h3,{id:"description",children:"Description"}),"\n",(0,i.jsxs)(n.p,{children:["Finds the difference between multiple ",(0,i.jsx)(n.a,{href:"https://tools.ietf.org/html/rfc7946#section-3.1.6",children:"polygons"})," by clipping the subsequent polygon from the first."]}),"\n",(0,i.jsx)(n.h3,{id:"parameters",children:"Parameters"}),"\n",(0,i.jsxs)(n.table,{children:[(0,i.jsx)(n.thead,{children:(0,i.jsxs)(n.tr,{children:[(0,i.jsx)(n.th,{children:"Name"}),(0,i.jsx)(n.th,{children:"Type"}),(0,i.jsx)(n.th,{children:"Description"})]})}),(0,i.jsx)(n.tbody,{children:(0,i.jsxs)(n.tr,{children:[(0,i.jsx)(n.td,{children:"features"}),(0,i.jsx)(n.td,{children:(0,i.jsxs)(n.strong,{children:[(0,i.jsx)(n.a,{href:"https://tools.ietf.org/html/rfc7946#section-3.3",children:"FeatureCollection"}),"<",(0,i.jsx)(n.a,{href:"https://tools.ietf.org/html/rfc7946#section-3.1.6",children:"Polygon"})," | ",(0,i.jsx)(n.a,{href:"https://tools.ietf.org/html/rfc7946#section-3.1.7",children:"MultiPolygon"}),">"]})}),(0,i.jsx)(n.td,{children:"input Polygon features"})]})})]}),"\n",(0,i.jsx)(n.h3,{id:"returns",children:"Returns"}),"\n",(0,i.jsxs)(n.p,{children:[(0,i.jsxs)(n.strong,{children:[(0,i.jsx)(n.a,{href:"https://tools.ietf.org/html/rfc7946#section-3.2",children:"Feature"}),"<",(0,i.jsx)(n.a,{href:"https://tools.ietf.org/html/rfc7946#section-3.1.6",children:"Polygon"})," | ",(0,i.jsx)(n.a,{href:"https://tools.ietf.org/html/rfc7946#section-3.1.7",children:"MultiPolygon"}),"> | null"]})," a Polygon or MultiPolygon feature showing the area of ",(0,i.jsx)(n.code,{children:"polygon1"})," excluding the area of ",(0,i.jsx)(n.code,{children:"polygon2"})," (if empty returns ",(0,i.jsx)(n.code,{children:"null"}),")"]}),"\n",(0,i.jsx)(n.h3,{id:"examples",children:"Examples"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-javascript",children:'var polygon1 = turf.polygon(\n  [\n    [\n      [128, -26],\n      [141, -26],\n      [141, -21],\n      [128, -21],\n      [128, -26],\n    ],\n  ],\n  {\n    fill: "#F00",\n    "fill-opacity": 0.1,\n  },\n);\nvar polygon2 = turf.polygon(\n  [\n    [\n      [126, -28],\n      [140, -28],\n      [140, -20],\n      [126, -20],\n      [126, -28],\n    ],\n  ],\n  {\n    fill: "#00F",\n    "fill-opacity": 0.1,\n  },\n);\n\nvar difference = turf.difference(turf.featureCollection([polygon1, polygon2]));\n'})}),"\n",(0,i.jsx)(p.A,{children:()=>(0,i.jsx)(m,{})}),"\n",(0,i.jsx)(n.h3,{id:"installation",children:"Installation"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-javascript",children:'$ npm install @turf/difference\n\nimport { difference } from "@turf/difference";\nconst result = difference(...);\n'})}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-javascript",children:'$ npm install @turf/turf\n\nimport * as turf from "@turf/turf";\nconst result = turf.difference(...);\n'})}),"\n",(0,i.jsx)(p.A,{children:()=>(0,i.jsx)(f.A,{turf:c})})]})}function y(e={}){const{wrapper:n}={...(0,r.R)(),...e.components};return n?(0,i.jsx)(n,{...e,children:(0,i.jsx)(j,{...e})}):j(e)}}}]);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.