turfjs


turf.within() fails but turf.inside() is successful


I am trying to use turf.js to return points within a polygon, but turf.within() generates an empty feature list even for points I know to be within a polygon - turf.inside() returns true for the same points and polygon. I provide an example below. I can successfully run the example at turf.within() and am not sure what it is about my geometry that is the problem.
<script type="text/javascript" src="https://npmcdn.com/#turf/turf/turf.min.js"></script>
....
var thePoint = [-118.049551, 33.866965]
var test = {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": thePoint
}
}, {
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": thePoint
}
}
]
};
var cerrito = { "type": "Feature", "properties": { "GEO_ID": "1600000US0612552", "STATE": "06", "PLACE": "12552", "NAME": "Cerritos", "LSAD": "city", "CENSUSAREA": 8.725, "Shape_STAr": 246572616.215, "Shape_STLe": 118080.76087 }, "geometry": { "type": "MultiPolygon", "coordinates": [ [ [ [ -118.028887999836968, 33.882629000032836 ], [ -118.028681155924062, 33.873316057140322 ], [ -118.028772420533898, 33.873315497179512 ], [ -118.028772240680681, 33.873285861714471 ], [ -118.028761755934283, 33.872110544548683 ], [ -118.028717388339928, 33.866241889545748 ], [ -118.028792999919617, 33.866240999737094 ], [ -118.035119980483032, 33.866020314132811 ], [ -118.035591866241305, 33.866016576824734 ], [ -118.035818357122793, 33.866015383719059 ], [ -118.035983055259194, 33.866014509762415 ], [ -118.036147752309518, 33.8660136310734 ], [ -118.036148847050185, 33.866013630744973 ], [ -118.037598000415159, 33.866012999764315 ], [ -118.037597881676277, 33.866006075268416 ], [ -118.037624048408333, 33.866005950805395 ], [ -118.037575372135976, 33.86388909386703 ], [ -118.037562273006358, 33.863314044528884 ], [ -118.037540454019165, 33.86236905889217 ], [ -118.037606327718564, 33.862368507358319 ], [ -118.037979218998117, 33.862365367620129 ], [ -118.039225723817765, 33.862354938919154 ], [ -118.039350888987059, 33.862353881198253 ], [ -118.039574899257346, 33.862352021930512 ], [ -118.039782079613744, 33.862350277788913 ], [ -118.039963633664883, 33.86234876086143 ], [ -118.040128290807047, 33.862347360175178 ], [ -118.040309482829713, 33.862345842847105 ], [ -118.040474501989308, 33.862344468612086 ], [ -118.040655693999881, 33.862342951664914 ], [ -118.040820383551591, 33.862341577067333 ], [ -118.041001575536058, 33.862340031653119 ], [ -118.041166594672802, 33.862338656470193 ], [ -118.041522357556943, 33.86233567659459 ], [ -118.041555328956449, 33.86233539026582 ], [ -118.04158826686961, 33.86233513188656 ], [ -118.041667975939376, 33.862334444439369 ], [ -118.041884905794092, 33.862332720355347 ], [ -118.041879045435579, 33.861679208477895 ], [ -118.041878661410877, 33.861635133586446 ], [ -118.041877779312557, 33.861530668241585 ], [ -118.041877117333357, 33.861453668349675 ], [ -118.041875622573116, 33.86128871703405 ], [ -118.041874434390664, 33.861151243763409 ], [ -118.04187324622599, 33.86101379844164 ], [ -118.041872056970632, 33.860876325175354 ], [ -118.041870868813831, 33.86073887985755 ], [ -118.041869613384449, 33.860598713795902 ], [ -118.041868145114535, 33.860428321848957 ], [ -118.04186653720933, 33.860242294996745 ], [ -118.041865207827939, 33.860088170827417 ], [ -118.041854341147129, 33.858838905318855 ], [ -118.041854202456747, 33.8588251662961 ], [ -118.041853336146318, 33.858724067229424 ], [ -118.046188000416265, 33.858768000030139 ], [ -118.046186748924541, 33.858687270846296 ], [ -118.046200389259099, 33.858687186283355 ], [ -118.046186014574644, 33.857785576122218 ], [ -118.046163305133547, 33.856407842019244 ], [ -118.046152668322023, 33.855664249739483 ], [ -118.046110568906883, 33.853648342941831 ], [ -118.04611084525645, 33.853610518941778 ], [ -118.047386006877716, 33.853589266798537 ], [ -118.048728911992114, 33.853575817845297 ], [ -118.049101279351319, 33.853572084045524 ], [ -118.049609117085879, 33.853568105873244 ], [ -118.05041069369274, 33.85356182224956 ], [ -118.050410420346836, 33.853533108261765 ], [ -118.050405543181043, 33.853033914419463 ], [ -118.050399505365675, 33.852413871433946 ], [ -118.050398863336483, 33.852345210650313 ], [ -118.050398171596498, 33.852276536365281 ], [ -118.050395364025476, 33.851988181322085 ], [ -118.050394029188837, 33.851850845358634 ], [ -118.0503926949755, 33.851712741307736 ], [ -118.050392161744654, 33.85165789437027 ], [ -118.050391361261092, 33.851575460340229 ], [ -118.050390027518588, 33.85143812528397 ], [ -118.050388692733023, 33.851300845222546 ], [ -118.050387326600486, 33.851163537229304 ], [ -118.050386025351628, 33.851026311248653 ], [ -118.050383464434944, 33.850765297230296 ], [ -118.050382854871259, 33.850696677914939 ], [ -118.050382130718276, 33.850627962186074 ], [ -118.050379462200738, 33.850353264157327 ], [ -118.050375711015633, 33.849966976406435 ], [ -118.053892316950595, 33.849848893473471 ], [ -118.054516818610182, 33.849844709837626 ], [ -118.054590588300428, 33.849844214857512 ], [ -118.054722683312946, 33.849843325535495 ], [ -118.054722478592268, 33.849821017688754 ], [ -118.054723000454345, 33.849821000322997 ], [ -118.054716601109988, 33.84918063060708 ], [ -118.054705566290011, 33.84797815444341 ], [ -118.054700499743277, 33.847440996646093 ], [ -118.054689180780002, 33.846217950124199 ], [ -118.054776697011036, 33.846215943261306 ], [ -118.056046115878445, 33.846208952311493 ], [ -118.057043290604042, 33.846203779261714 ], [ -118.058278859805654, 33.846196339066665 ], [ -118.059040364775043, 33.846192198135391 ], [ -118.059040016006662, 33.846124967096777 ], [ -118.060671000051059, 33.846177999563118 ], [ -118.06338900026266, 33.84615300022368 ], [ -118.065990999985502, 33.846131999565429 ], [ -118.072090999789609, 33.846084000390604 ], [ -118.081980999696881, 33.84600600023699 ], [ -118.08202099972182, 33.849640999592488 ], [ -118.086370999820048, 33.84963300020425 ], [ -118.086368999500323, 33.845970999859297 ], [ -118.086803999550057, 33.845968999565606 ], [ -118.092398000044483, 33.845925000070416 ], [ -118.098939000208091, 33.845875000320532 ], [ -118.09921100033479, 33.845875999972094 ], [ -118.100211999558695, 33.848065999601282 ], [ -118.101733000020189, 33.853478000147867 ], [ -118.103054999461108, 33.858318000193101 ], [ -118.108316999981298, 33.858371000240467 ], [ -118.108428999611235, 33.865586999998889 ], [ -118.108536000018645, 33.872715000058548 ], [ -118.106910000099688, 33.872711000330419 ], [ -118.106974000434647, 33.872942999957047 ], [ -118.108003999515034, 33.876790000315744 ], [ -118.108546999473432, 33.87984299979373 ], [ -118.108563999545112, 33.886942999906346 ], [ -118.108417999623612, 33.886938999677412 ], [ -118.108160000123547, 33.886939999577628 ], [ -118.104370000310539, 33.886968000366373 ], [ -118.10425600018489, 33.887381999848436 ], [ -118.100572999781591, 33.887395000134291 ], [ -118.100547000184832, 33.886982999787215 ], [ -118.09988300024132, 33.886990000446659 ], [ -118.09988699995877, 33.88740200023738 ], [ -118.095532999746752, 33.887425999876328 ], [ -118.095537999774862, 33.88211299995568 ], [ -118.095466999498029, 33.880314000301986 ], [ -118.09541300051032, 33.87852799995575 ], [ -118.09380399970361, 33.87855300002056 ], [ -118.091064999993833, 33.878859999883623 ], [ -118.091085999524168, 33.88032599969636 ], [ -118.087806000080136, 33.880338000092316 ], [ -118.087776999582886, 33.876750000365199 ], [ -118.091033999660468, 33.876416000198674 ], [ -118.090991999619234, 33.8729809995612 ], [ -118.090990999805427, 33.865683999854205 ], [ -118.090901000460704, 33.861313000431181 ], [ -118.089982999574389, 33.861319000332337 ], [ -118.089973999821112, 33.860224999604107 ], [ -118.086482999908952, 33.860250000054762 ], [ -118.086474999522395, 33.85842399971353 ], [ -118.086450000287186, 33.856003999941251 ], [ -118.082092000279232, 33.856040000312333 ], [ -118.082110999618877, 33.860495000048402 ], [ -118.078810999737044, 33.85847399969186 ], [ -118.075151000444947, 33.856228000446528 ], [ -118.072288000163809, 33.856968999864691 ], [ -118.072240999730425, 33.854512000252328 ], [ -118.070459000360898, 33.853411000398474 ], [ -118.068915000458702, 33.853423000135727 ], [ -118.069006999624165, 33.858557000390903 ], [ -118.071223999523767, 33.858534999730935 ], [ -118.070178000376117, 33.860339000416801 ], [ -118.070294000094378, 33.865815999626136 ], [ -118.070313999561719, 33.869456999865655 ], [ -118.0724970001271, 33.869453999697591 ], [ -118.070334999534126, 33.869835999844774 ], [ -118.070384000066582, 33.873111000077408 ], [ -118.08004299960642, 33.873053999696083 ], [ -118.07964899968843, 33.876462000326832 ], [ -118.07927399950583, 33.87674000007636 ], [ -118.075086999544695, 33.8767670000233 ], [ -118.074840999957502, 33.876769000254562 ], [ -118.074895000371953, 33.880383000438925 ], [ -118.072708000101883, 33.880391999903772 ], [ -118.072825000397017, 33.885832999950722 ], [ -118.068447000489812, 33.885887999807679 ], [ -118.06846999965768, 33.887112000073593 ], [ -118.068475999850449, 33.887559000148578 ], [ -118.066323999719302, 33.887571000149549 ], [ -118.06528799964515, 33.887577000140304 ], [ -118.064333000067364, 33.887581999621858 ], [ -118.06408499971505, 33.887165000021376 ], [ -118.055376000176864, 33.887216000217663 ], [ -118.055382999695453, 33.887649999683752 ], [ -118.046538999840678, 33.887713000322073 ], [ -118.038572000150765, 33.88777300012908 ], [ -118.028887999836968, 33.882629000032836 ] ] ] ] } }
var cerritoPolygon = turf.polygon(cerrito.geometry.coordinates[0]) //turn cerrito coordinates into polygon
var cerritoFeatureCollection = turf.featureCollection(cerrito) //create a feature collection
var ptsWithin = turf.within(test, cerritoFeatureCollection); //see if test points are within the cerrito featureCollection
var pt = turf.point(thePoint);
var isInside = turf.inside(pt, cerritoPolygon);
console.log(ptsWithin)//returns a featureCollection with an empty features array
console.log(isInside)//returns true - thePoint is in the cerrito polygon

Related Links

turf.within() fails but turf.inside() is successful
Distance between two points over a path with turf.js
TurfJS Along Method not working as expected

Categories

HOME
windows
httparty
api
c++11
twig
cakephp-3.4
web-hosting
hugo
data-visualization
banner
jtextpane
title
little-proxy
google-chrome-app
reactive-programming
enthought
rtf
nancy
http-post
linear-algebra
standards
soci
sencha-touch
href
question2answer
aggregation
direct3d11
surveymonkey
syntax-highlighting
has-and-belongs-to-many
apktool
jaws
constexpr
record
database-comparison
hard-drive
sammy.js
login-script
hunspell
modalviewcontroller
engine.io
google-earth-engine
graphhopper
linq-to-objects
google-data-api
setup.py
facebook-social-plugins
jquery-ui-draggable
rserve
singleinstance
java-6
pdf-conversion
mouseleave
universal-analytics
reachability
autosar
hadoop-2.7.2
ziparchive
async.js
jquery-jscrollpane
firebase-security
appscale
refinerycms
jtwig
kendo-upload
toast
contentcontrol
opl
grgit
xenomai
sony-lifelog-api
wso2greg
mraid
node-serialport
addressing-mode
post-commit-hook
machine-instruction
xml-namespaces
verold
xml-dsig
ray
maven-scm
git-repo
c++builder-xe5
boost-signals
extconf.rb
jdb
unattended-processing
svk
cruisecontrol.rb
vs-android

Resources

Encrypt Message