I am attempting a Polygon Overlap (POST request) from: https://native-land.ca/resources/api-docs/
What I have below returns an empty list:
library(sf)
library(geojsonsf)
library(httr)
# Create a polygon
lon = c(-114.88984, -114.05445)
lat = c(48.99889,49.46062)
poly_df = data.frame(lon, lat)
poly <- poly_df %>%
st_as_sf(coords = c("lon", "lat"),
crs = 4326) %>%
st_bbox() %>%
st_as_sfc() %>%
st_as_sf
poly$id=1:length(poly)
# Convert sf into geoJSON
geo <- sf_geojson(poly)
# Set up POST request
body <- list(maps = "territories", polygon_geojson = geo)
url <- "https://native-land.ca/wp-json/nativeland/v1/api/index.php"
r <- POST(url, body = body)
# View request
content(r, "text")
I am not sure what I am missing here...
CodePudding user response:
Your JSON is not properly formed. Your body
is an R list. There's probably a better way to do this, but
body <- paste0('{"maps" : "territories", "polygon_geojson" :', geo, '}')
works.
CodePudding user response:
I have been able to get something out of the API with the following code :
library(sf)
library(geojsonsf)
library(httr)
# Set up POST request
body <- '{
"maps" : "territories",
"polygon_geojson" : {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
-105.556640625,
58.17070248348609
],
[
-107.09472656249999,
57.11238500793404
],
[
-104.853515625,
56.145549500679074
],
[
-98.6572265625,
56.70450561416937
],
[
-97.55859375,
57.89149735271034
],
[
-99.8876953125,
58.49369382056807
],
[
-103.7548828125,
58.768200159239576
],
[
-105.556640625,
58.17070248348609
]
]
]
}
}
]
}
}'
url <- "https://native-land.ca/wp-json/nativeland/v1/api/index.php"
r <- POST(url, body = body)
# View request
content(r, "text")
[1] "[{\"id\":\"d544aaffc99643ed5890d6ab4f54a680\",\"type\":\"Feature\",\"properties\":{\"Name\":\"Denendeh (D\\u00ebn\\u00ebs\\u0173\\u0142in\\u00eb\\u0301 N\\u00ebn\\u00e9)\",\"ID\":35980,\"Slug\":\"dene-chipewyan\",\"description\":\"https:\\/\\/native-land.ca\\/maps\\/territories\\/dene-chipewyan\\/\",\"color\":\"#436EC9\"},\"geometry\":{\"coordinates\":[[[-96.63408741077633,61.64147629881566],[-98.10883373826738,62.14926679661755],[-99.58358006572836,62.64868046813025],[-100.69057945540021,63.550057030861424],[-101.98549638569584,64.1512659405242],[-102.90298123096808,64.27738508558723],[-103.79956957639563,64.43031974514693],[-105.30212742812142,64.58482598184943],[-107.30708523193934,64.65971781808585],[-108.29168522758245,64.4251810535307],[-109.22015836584305,63.81194802913117],[-109.41647267903214,63.341804356252794],[-110.58567049859238,62.98899663049256],[-111.29184601986053,62.816448287931024],[-113.26702231819554,62.68657811581127],[-114.63308197403722,62.51291000825436],[-114.94516477475032,62.3390758004584],[-115.80528246536171,61.786166936948284],[-116.45282295998211,61.54583657799563],[-116.77237757017258,61.168338657243886],[-116.76954222003373,60.82919839319197],[-116.39186585911546,60.44020683170338],[-116.18329486811704,59.74407856677357],[-115.54877168969935,59.38181959909821],[-115.54877168969935,58.7504865990982],[-115.10931868969935,58.153769599098204],[-114.3071721085077,58.0334226278233],[-114.30078812993618,58.026404044666826],[-114.31695458978143,58.01155818774196],[-114.30329970480722,58.01559593012878],[-114.30355944715201,58.006213480810246],[-114.28521398495958,58.00015602732984],[-114.30154239276168,57.99986729621165],[-114.2324336932758,58.00006459437617],[-114.2179039083603,57.998413120418576],[-114.20072246415279,57.99409062411738],[-113.19129496507821,57.61934710781196],[-112.36931530008984,57.14816421936794],[-111.94719692187894,56.57541961316653],[-111.52507854366625,55.99386687776271],[-110.61573670470055,55.17775079007487],[-109.74103353557975,55.12608179838786],[-108.8118676470692,55.03294224232465],[-107.87372544301775,55.089318675779],[-107.09208238299203,55.301881069588205],[-106.58945071419558,55.64453901182378],[-105.5781968273977,56.09363608265079],[-103.00794204976752,56.67643153056056],[-102.75803074468901,56.94973818295181],[-102.78967126749963,57.33765640578148],[-102.60642142756039,57.78980163818225],[-102.03227156963517,58.14440773340992],[-101.6014734596441,58.2580590166059],[-100.74407819448587,58.37532601269617],[-99.28900568969935,58.613682599098205],[-97.44330268969935,58.613682599098205],[-95.59759968969935,58.613682599098205],[-94.90984344589211,58.67933094829942],[-94.71869368969935,58.841390599098204],[-94.71869368969935,59.337109599098206],[-94.71869368969935,60.0015845990982],[-94.44936488770298,60.29809720990376],[-94.29009709351574,60.565392354729724],[-94.21708049484194,60.66966191347518],[-94.39146079197296,60.79374335345621],[-94.30739850835715,60.86035134991189],[-94.55665658072905,60.98513335899635],[-94.97424155794928,61.105354222533805],[-95.61205007396443,61.14834865074215],[-96.63408741077633,61.64147629881566]]],\"type\":\"Polygon\"}},{\"id\":\"afe8efc325cec57f5c5e3ac105d39280\",\"type\":\"Feature\",\"properties\":{\"Name\":\"D\\u00ebn\\u00e9ndeh\",\"ID\":33550,\"Slug\":\"denendeh\",\"description\":\"https:\\/\\/native-land.ca\\/maps\\/territories\\/denendeh\\/\",\"color\":\"#DADB1C\"},\"geometry\":{\"coordinates\":[[[-119.73089394254217,54.403591293327366],[-119.57741436346332,54.46759894603795],[-118.53006365445373,55.05177082112249],[-117.02550104586881,55.530421068025305],[-116.18459019859705,56.01421205075701],[-115.9179439996436,56.44132290489213],[-115.45717561680154,56.95695870459926],[-114.98797568499734,57.479055792274664],[-114.59162941384342,57.93777529121064],[-114.13086103100083,58.183840577569015],[-113.27071609694876,58.34252065706295],[-112.72629151562514,58.38113130256929],[-112.23331207693487,58.29835548537716],[-111.58263728468424,58.03324615739575],[-111.30472097418988,57.73282238114464],[-110.71122223908684,57.395775587749654],[-110.32719364578215,57.15040821083471],[-109.97807674277657,56.80796284908649],[-109.62895983977457,56.09411328190373],[-109.24493124646989,55.54494826624341],[-109.03546110466797,55.06804525113094],[-108.54669744046231,54.78719780950195],[-107.4295233508509,54.92786662665725],[-106.87093630604701,55.48564873171486],[-105.8934089776357,55.95754822352461],[-105.02061672012891,56.55867844939203],[-104.38378004008051,57.02219596444519],[-103.33642933107095,57.51299738032699],[-102.6032838347643,57.848963387418024],[-102.07960848025954,57.94173544116097],[-101.52102143545206,57.94173544116097],[-100.82278762953086,57.904655348590865],[-98.90264466301092,57.99728381824326],[-97.78547057339594,58.10812252679395],[-96.73811986438638,58.32877004793593],[-95.06235872997105,58.60265517616378],[-94.32921323366435,58.765963951037605],[-94.11974309187252,59.01848215038933],[-93.98009633067598,59.65938627475029],[-93.98009633067598,60.25364640862702],[-94.04991971127424,60.58111080783223],[-94.57345889538489,60.914440211716055],[-95.55262026847646,61.159666113237705],[-96.24840300746665,61.29388983575345],[-97.15678780722304,61.62915252842086],[-98.03012474629685,61.9941142068877],[-98.48302352747582,62.302029176082556],[-99.00588185963544,62.49597088715407],[-99.84553264191572,62.95904903118395],[-100.40507287944352,63.78888027008628],[-101.20765745178078,64.23121816478266],[-102.22009647048768,64.41274983524366],[-104.69882648181512,64.77223957441402],[-106.37458761623046,64.95020978636344],[-108.25981889244768,65.00927177892342],[-109.41836980017133,65.05348273184569],[-110.81483741218649,65.47709477064379],[-112.06573897984536,65.77962612710172],[-114.2651754687653,66.19164421620508],[-116.49952364798796,66.62477298508315],[-117.8610795697003,66.68011604330783],[-119.50192901381995,66.91394640484046],[-120.68892648402951,67.19973591873367],[-121.9457473348445,67.64207517784234],[-123.14942896415255,67.86751482445246],[-124.96021048223346,68.01627150134195],[-126.31829662080132,68.18511544610271],[-128.1290781388821,68.12194398156893],[-130.44914195892258,67.88882417084099],[-132.31651039944433,67.76067523641959],[-135.88148651316496,67.63182148031439],[-137.9186157210037,67.58871304457571],[-141.09348553478125,67.78469965828387],[-144.86733337773666,68.39690474300798],[-149.46158292568296,68.96359533754588],[-151.43054701765996,68.90461811091762],[-154.0558324736272,68.5474286441947],[-156.59907775909826,67.56656084423835],[-158.1578409985798,66.51058393073421],[-158.89620253307038,65.47603743481963],[-158.79137471465853,64.63953700868288],[-157.90663360993443,63.236201175404005],[-157.07104478880692,62.17701369454292],[-156.03884683329295,60.67270371431664],[-155.33091015002697,59.83362929237316],[-155.33091015002697,59.65503391496844],[-154.94691641974225,59.2496936780351],[-154.26754289693076,59.05279246008797],[-152.82018191355135,59.189229326140094],[-151.49686629041585,59.19125298706177],[-150.39610313375397,59.6825363203242],[-149.88799328014267,60.029131501750044],[-148.96744010215954,60.464847950540985],[-148.5352104408367,60.76107434402792],[-148.37766275764614,61.0284080028413],[-148.06751397548948,61.279659822308844],[-147.53438393800104,61.41543888903928],[-146.5842530153185,61.54033209175728],[-146.06349313656122,61.511232326071536],[-145.7224598611764,61.45396321395566],[-145.2375310598851,61.18918277777422],[-145.26468329553506,60.8945881182554],[-145.57962658298007,60.65023745919163],[-146.02303849956485,60.456944589964735],[-145.4020174166872,60.10733198315006],[-144.78099633380134,59.77210442101142],[-144.05426340945516,59.670083799672284],[-142.69798755929583,59.64975272548094],[-141.3383543974564,59.61449406321972],[-140.643770894087,59.47657052840759],[-139.824219917484,59.279273362376244],[-138.27514815661206,58.63051676496778],[-137.44075041463685,58.206893935527916],[-136.90566198037635,57.618075104767684],[-135.86254788922602,56.61718917756349],[-135.3891678438427,56.25820121809312],[-134.92628954491067,55.918605163405545],[-134.57429534472126,55.54260581689357],[-134.08366117302245,55.311140115797144],[-133.75019439899353,55.21167086619192],[-133.60450300438828,55.233674404277224],[-133.45881160979724,55.33866320956122],[-133.1674288206119,55.417969304922906],[-132.57571498277392,55.64873420718814],[-132.43229961007503,55.68077389011026],[-132.36266438740955,55.68044607326232],[-132.32694770221752,55.64610525183514],[-132.28303322258287,55.59321016626208],[-132.11426780578554,55.49261219306064],[-131.9837952003495,55.32500466624202],[-131.87004891970048,55.17344838646508],[-131.78280474269621,55.10370440326008],[-131.7443381559019,55.09005693183417],[-131.69292373664803,55.09949054164116],[-131.65207246779454,55.18101911963021],[-131.5998631545261,55.28610551546589],[-131.57654062695158,55.29192310386699],[-131.49642787728996,55.278336491030785],[-131.42292069739082,55.23142249924632],[-131.34184148788555,55.19417921229504],[-131.192195060638,55.13730737769009],[-131.11322104639228,55.08693491416972],[-131.0472264737505,54.98065224835079],[-130.99655747708061,54.851206362705625],[-130.93587955805663,54.72512733964794],[-130.8348537571576,54.65172820480532],[-130.64546940453627,54.649832508449094],[-130.51796977074844,54.68359392648429],[-130.40112103602817,54.73112381532809],[-130.2364988330039,54.82529529558198],[-130.15751224801582,54.911908772879],[-130.13925852264822,54.98867293025427],[-130.1741037151141,55.06529054807018],[-130.12518411345363,55.16830698042841],[-130.05156600750536,55.23117106621217],[-129.99489097800702,55.267571007898056],[-129.97646325467724,55.298658654497046],[-130.00331612253456,55.325038419924056],[-130.03643977135025,55.38242263271289],[-130.04094080827025,55.45261666751978],[-130.08287422116433,55.49247140528411],[-130.1255768731385,55.555763969202815],[-130.124537412057,55.60536963468326],[-130.11834207252295,55.67890020662901],[-130.13940761254005,55.744838972841706],[-130.10732777648127,55.8150323521175],[-130.05577735338505,55.84343657948074],[-130.02526740782304,55.905434247254846],[-130.03605347209884,55.997339298687336],[-130.06577847239492,56.07317251371029],[-130.30990756334438,56.13134892331064],[-130.61394389797462,56.27172750761571],[-130.69506479089125,56.37634356445358],[-130.6630478060553,56.444637593581604],[-130.52648300332285,56.496327466059654],[-130.39451047574806,56.547234017798814],[-130.2466369068389,56.5801809398898],[-130.0999114067275,56.61667906823291],[-129.81728109913837,56.61238746951756],[-129.67596594534086,56.59772081847433],[-129.43456630750043,56.5379126072155],[-129.28389452457694,56.61352540730337],[-129.04109489637466,56.743210040425595],[-128.70199222451572,56.858295793756696],[-128.43196264654316,56.84248893326733],[-128.22891856326365,56.77164917458222],[-127.81035038169503,56.69262791700086],[-127.32488786571199,56.75502241449675],[-127.19343971893794,56.720955649623846],[-127.07085292336171,56.59363403584592],[-127.078628723452,56.36659423089125],[-127.08164113058946,56.09836241891168],[-126.91500868426361,55.73630138379741],[-127.00467878675963,55.50584561462534],[-127.15854725283113,55.2591994045201],[-127.36733769365485,55.08445360228458],[-127.58985862816274,54.7454311521887],[-127.72084293808919,54.371567026630316],[-127.88548618728313,54.17014753566005],[-127.9219781620601,53.93542446379206],[-127.88511816212817,53.79867997915366],[-127.78875935621848,53.63428221977452],[-127.52763462607582,53.46924134957021],[-127.37740360061429,53.34551409304038],[-127.18329047594275,53.234100349683246],[-126.9136193390687,53.15629150023463],[-126.7073328762707,53.04869760174944],[-126.51844857164679,52.897197882404726],[-126.36767141069177,52.82582110088876],[-125.93360789109917,52.69813680787337],[-126.04698501944972,52.604984249022095],[-126.17702355610996,52.52902285605995],[-126.30102419200061,52.43820934258528],[-126.28204320518611,52.373259907416866],[-126.1419379564406,52.20856680689218],[-126.03197457431384,52.11120200516572],[-126.00405988956834,51.96783896964604],[-125.97837238668465,51.89103626495796],[-125.93176135546814,51.90825680203213],[-125.80477201327946,52.055408269691895],[-125.7015026619871,52.058830859958704],[-125.60828059956403,51.97262075300094],[-125.47103673085974,51.932422822828954],[-125.31369828441171,51.80528646243698],[-125.17987259121836,51.6871996215535],[-125.04283596015706,51.618812710904706],[-124.88332881286775,51.57258817575706],[-124.81424726541407,51.46380846265669],[-124.8267935036061,51.31456259300134],[-124.80164953563214,51.27939735957969],[-124.69612725667952,51.344803050994955],[-124.53284593961256,51.36172885914584],[-124.4210634144583,51.2571496215632],[-124.05809866749753,51.01349820078457],[-123.61726338197103,50.9600366448893],[-123.57981390771036,50.87174488706816],[-123.59361684498391,50.80440951248033],[-123.62084811012119,50.70895316091432],[-123.35797851028198,50.689491992418056],[-122.99752588723643,50.6803307046502],[-122.29646920650832,50.636803053000534],[-121.98253449984017,50.60985672183983],[-121.78651261287392,50.63191861085866],[-121.43226917852569,50.90255854939903],[-121.16747684878182,51.079765402125474],[-121.27611501624736,51.070335605522075],[-121.42134681742215,51.05322581439637],[-121.57833137348865,51.09129810781721],[-121.73938188885482,51.15739732476072],[-121.89071262898099,51.23333902386605],[-122.0522082673649,51.21887148324589],[-122.11612088251998,51.19930404198374],[-122.2341449829961,51.29722462630238],[-122.22205838584532,51.364483250899895],[-122.23041286594389,51.43286494799983],[-122.2796495005416,51.50354267865899],[-122.35734785025437,51.67255550203444],[-122.40026298440662,51.79958852609681],[-122.3781227697651,51.881112421548636],[-122.3169608027572,51.89510898914219],[-122.26340414039137,51.92867392538423],[-122.2797174384976,52.019095218692286],[-122.27143533330735,52.09487072943028],[-122.2835411416708,52.195602564889356],[-122.27121263841084,52.33195558446525],[-122.18418504644805,52.36147662360236],[-121.93316156290392,52.405111571054505],[-121.52195516263907,52.453140603425425],[-121.39250445122462,52.46286023008213],[-120.96817155220168,52.49253354740253],[-120.53452512930265,52.54740388092529],[-120.34575091052626,52.58128063287961],[-120.10851300750703,52.62983995186647],[-119.96820247298315,52.71132256975221],[-119.7344822713741,52.821601214286204],[-119.5206948020616,52.96430359306862],[-119.24632772744275,53.18645923030837],[-119.41035590541671,53.66047585208591],[-119.82495344507447,54.12566724510785],[-119.73089394254217,54.403591293327366]]],\"type\":\"Polygon\"}}]"