Problem:
My fetch URL is too long. I have an array of over 100 coordinates I plug in. It will result in a 404. I am also not sure if the query can handle such long requests - it's not working great now, sometimes the server is fast and sometimes it's not. However, this will not work when the server is actually working, as my URL will contain over 2000 characters.
Result I need:
I need another way to call this API so I can insert hundreds of coordinates at a time. I could try POST, but I'm not sure of the syntax there in relation to me current GET request. I believe that will give me the same issue - correct me if I'm wrong.
Am I asking too much of the server? Is this impossible given the length of the URL and what I am trying to query? If a POST request is more appropriate, is it much different from a GET - can I ask more of it?
Here is some additional info:
Query in question: https://hazards.fema.gov/gis/nfhl/rest/services/public/NFHL/MapServer/28/query
Everything default except:
*Input Geometry:* {"points": *Insert array of coordinates here (bestArr)* }
*Geometry Type:* Multipoint
*Input Spatial Reference:* 4326
*Spatial Relationship:* Intersects
*Out Fields:* FLD_ZONE
*Return Geometry:* False
*Format:* JSON
I have variable bestArr which into my request URL to simulate a query. For readability, I didn't put the hundred other coordinate points into the array (which causes the issue) - so this one will end up working.
JS:
const bestArr = [
[-83.17381243, 40.22699651],
[-84.75011502, 39.31990622],
[-84.12588259, 39.68956496],
[-84.25222521, 39.05756839],
[-84.47963779, 39.23597312],
[-84.36351863, 39.23683882]
// The above, but with 100 more, I couldn't put them all here
];
let zoneArr = [];
let myString = JSON.stringify(bestArr);
console.log(myString);
let myBestString = myString.replace(/"/g,"").replace(/ /g, "").replace(/\[/g, "%5B").replace(/\]/g, "%5D").replace(/,/g, "%2C");
console.log(myBestString);
fetch('https://hazards.fema.gov/gis/nfhl/rest/services/public/NFHL/MapServer/28/query?where=1%3D1&text=&objectIds=&time=&geometry=%7B%22points%22%3A' + myBestString + '%7D&geometryType=esriGeometryMultipoint&inSR=4326&spatialRel=esriSpatialRelIntersects&distance=&units=esriSRUnit_Foot&relationParam=&outFields=FLD_ZONE%2C+ZONE_SUBTY&returnGeometry=false&returnTrueCurves=false&maxAllowableOffset=&geometryPrecision=&outSR=&havingClause=&returnIdsOnly=false&returnCountOnly=false&orderByFields=&groupByFieldsForStatistics=&outStatistics=&returnZ=false&returnM=false&gdbVersion=&historicMoment=&returnDistinctValues=false&resultOffset=&resultRecordCount=&returnExtentOnly=false&datumTransformation=¶meterValues=&rangeValues=&quantizationParameters=&featureEncoding=esriDefault&f=pjson')
.then(function (response) {
return response.json();
})
.then (function (data) {
appendData1(data);
})
.catch(function (err) {
console.log('error: ' + err);
});
function appendData1(data) {
for (let obj of data['features']) {
var zone = obj['attributes']['FLD_ZONE'];
zoneArr.push(zone);
}
console.log(zoneArr);
}