Select to view content in your preferred language

CORS error

6583
5
Jump to solution
07-22-2021 05:02 AM
ChitraKrishnan
Occasional Contributor

Hi,

I copied the sample code from https://developers.arcgis.com/javascript/latest/sample-code/sandbox/?sample=layers-featurelayer-shap... to my local and it works fine for drp_county_boundary.zip.

But when I try to upload tl_2020_39_tabblock20.zip which I downloaded from https://www.census.gov/geographies/mapping-files/time-series/geo/tiger-line-file.html  it throws below CORS error. 

Index:1 Access to fetch at 'https://www.arcgis.com/sharing/rest/content/features/generate?filetype=shapefile&publishParameters=%...' from origin 'http://localhost' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

1. Can't we directly work with the local copy of the downloaded shape files without adding to arcgisonline?

2. I did add to arcgisonline and getting the same CORS error - https://utility.arcgis.com/usrsvcs/servers/4b648ef9586c487b948f37e3ea4c5453/rest/services/tl_2020_39...

 

Thanks

Chitra

0 Kudos
3 Solutions

Accepted Solutions
Sage
by
Occasional Contributor

Hi Chitra,

I believe the shapefile you are trying to add has too many features and the CORS error you are seeing is a bit misleading.  I downloaded the shapefile and it has 276,428 individual features.  The sample in the params object has a maximum of 1000 features defined and is set to enforce maximum file sizes.

 

const params = {
     name: name,
     targetSR: view.spatialReference,
     maxRecordCount: 1000,
     enforceInputFileSizeLimit: true,
     enforceOutputJsonSizeLimit: true
};

 

 I'm not sure why the debugger is throwing a CORS error, but when I downloaded the tiger shapefile and exported just a handful of the features to a new shapefile, zipped up the result and added it from my local hard drive with the sample code it seemed to work as expected.

View solution in original post

0 Kudos
Sage
by
Occasional Contributor

Do you have access to ArcGIS Pro or ArcMap desktop software?  If so there are lots of different ways to go about it but probably the easiest would be to make an interactive selection, or selecting by attributes and then export the selected records as a new shapefile by right clicking on the original shapefile in the table of contents selecting 'Data' in the drop down and then export features.  Only the selected features will export.  To export to a shapefile select the folder you want to export to in the dialog and give it a name

https://pro.arcgis.com/en/pro-app/latest/help/mapping/navigation/select-features-interactively.htm

https://pro.arcgis.com/en/pro-app/latest/help/mapping/navigation/select-features-using-attributes.ht...

https://pro.arcgis.com/en/pro-app/latest/help/data/geodatabases/overview/export-data.htm

You could also clip the original shapefile if you have another a separate shapefile that represents your area of interest.

https://pro.arcgis.com/en/pro-app/latest/tool-reference/analysis/clip.htm

 

If you don't have access to ESRI's desktop software it won't be as easy but its still possible with python and and geopandas to do a clip.  

https://geopandas.org/gallery/plot_clip.html

 

There are lots of other ways as well like using QGIS or some other geospatial software, but the process should be similar.  Creating a selection and exporting or clipping.

 

View solution in original post

ChitraKrishnan
Occasional Contributor

Thank you!!! Let me try.

Thanks

Chitra

View solution in original post

0 Kudos
5 Replies
Sage
by
Occasional Contributor

Hi Chitra,

I believe the shapefile you are trying to add has too many features and the CORS error you are seeing is a bit misleading.  I downloaded the shapefile and it has 276,428 individual features.  The sample in the params object has a maximum of 1000 features defined and is set to enforce maximum file sizes.

 

const params = {
     name: name,
     targetSR: view.spatialReference,
     maxRecordCount: 1000,
     enforceInputFileSizeLimit: true,
     enforceOutputJsonSizeLimit: true
};

 

 I'm not sure why the debugger is throwing a CORS error, but when I downloaded the tiger shapefile and exported just a handful of the features to a new shapefile, zipped up the result and added it from my local hard drive with the sample code it seemed to work as expected.

0 Kudos
ChitraKrishnan
Occasional Contributor

Thank you very much for the reply.

I am actually new to Esri. how can I export only the required features to a new shapefile? Can you please share some link to understand this?

Thanks again

Chitra

0 Kudos
Sage
by
Occasional Contributor

Do you have access to ArcGIS Pro or ArcMap desktop software?  If so there are lots of different ways to go about it but probably the easiest would be to make an interactive selection, or selecting by attributes and then export the selected records as a new shapefile by right clicking on the original shapefile in the table of contents selecting 'Data' in the drop down and then export features.  Only the selected features will export.  To export to a shapefile select the folder you want to export to in the dialog and give it a name

https://pro.arcgis.com/en/pro-app/latest/help/mapping/navigation/select-features-interactively.htm

https://pro.arcgis.com/en/pro-app/latest/help/mapping/navigation/select-features-using-attributes.ht...

https://pro.arcgis.com/en/pro-app/latest/help/data/geodatabases/overview/export-data.htm

You could also clip the original shapefile if you have another a separate shapefile that represents your area of interest.

https://pro.arcgis.com/en/pro-app/latest/tool-reference/analysis/clip.htm

 

If you don't have access to ESRI's desktop software it won't be as easy but its still possible with python and and geopandas to do a clip.  

https://geopandas.org/gallery/plot_clip.html

 

There are lots of other ways as well like using QGIS or some other geospatial software, but the process should be similar.  Creating a selection and exporting or clipping.

 

ChitraKrishnan
Occasional Contributor

Thank you!!! Let me try.

Thanks

Chitra

0 Kudos
RachelGomez
Emerging Contributor

To get rid of a CORS error, you can download a browser extension like CORS Unblock. The extension appends Access-Control-Allow-Origin: * to every HTTP response when it is enabled. It can also add custom Access-Control-Allow-Origin and Access-Control-Allow-Methods headers to the responses.

 

Greeting,

Rachel Gomez

0 Kudos