tannerjt / AGStoShapefile

Convert ArcGIS Server Dynamic Map Service to GeoJSON and Shapefile
MIT License
213 stars 47 forks source link

Crash when only one feature #30

Open scaddenp opened 7 years ago

scaddenp commented 7 years ago

(node:13548) DeprecationWarning: process.EventEmitter is deprecated. Use require ('events') instead. info: Number of features for service: 1 info: Getting chunks of 100 features... info: query -> 0 out of 1 C:\AGStoShapefile-master\AGStoSHP.js:71 objectIds.sort(); ^

TypeError: Cannot read property 'sort' of null at requestService (C:\AGStoShapefile-master\AGStoSHP.js:71:11) at Request._callback (C:\AGStoShapefile-master\AGStoSHP.js:64:4) at Request.self.callback (C:\AGStoShapefile-master\node_modules\request\requ est.js:188:22) at emitTwo (events.js:106:13) at Request.emit (events.js:191:7) at Request. (C:\AGStoShapefile-master\node_modules\request\reques t.js:1171:10) at emitOne (events.js:96:13) at Request.emit (events.js:188:7) at IncomingMessage. (C:\AGStoShapefile-master\node_modules\reques t\request.js:1091:12) at IncomingMessage.g (events.js:292:16)

C:\AGStoShapefile-master>node AGStoSHP.js services.txt W:/NZPM_Shapefiles

tannerjt commented 7 years ago

Interesting. Can you try logging the output out objectIds on line 71: console.log(objectIds). I guess I never accounted for what would happen with one feature. I am assuming ArcGIS Server is returning a single integer and not an array of integers. Since sort is not a method of a number, it is throwing an error.

tannerjt commented 7 years ago

The best thing to do is probably check to see if is an array

if(!Array.isArray(objectIds)) objectIds = [objectIds]

scaddenp commented 7 years ago

Having to work slowly through the service list to find which one is the issue - however, I find that unsurprizingly, it also crashes when service return empty (not uncommon in this instance - it is shapefile of permits and want weekly update as changes often and can none).

tannerjt commented 7 years ago

I really should have better logging and error handling. It's been on my todo list. It would save time if at the end it just said... https://.../1 failed but still processed the rest.

tannerjt commented 7 years ago

If it returns empty, does it return undefined or some standard? If it returned an empty array, or a boolean value we could easily detect.

scaddenp commented 7 years ago

I am getting it on an odd one: Added console.log(serverUrl) so I can see which service fails and you can see the service I am using.

(node:6308) DeprecationWarning: process.EventEmitter is deprecated. Use require( 'events') instead. http://data.nzpam.govt.nz/arcgis/rest/services/EXTERNAL/Petroleum/MapServer/9 [ 3702, 8112, 9317 ] info: Number of features for service: 3 info: Getting chunks of 100 features... info: query -> 0 out of 3 http://data.nzpam.govt.nz/arcgis/rest/services/EXTERNAL/Petroleum/MapServer/3 null C:\AGStoShapefile-master\AGStoSHP.js:73 objectIds.sort(); ^

TypeError: Cannot read property 'sort' of null at requestService (C:\AGStoShapefile-master\AGStoSHP.js:73:11) at Request._callback (C:\AGStoShapefile-master\AGStoSHP.js:64:4) at Request.self.callback (C:\AGStoShapefile-master\node_modules\request\requ est.js:188:22) at emitTwo (events.js:106:13) at Request.emit (events.js:191:7) at Request. (C:\AGStoShapefile-master\node_modules\request\reques t.js:1171:10) at emitOne (events.js:96:13) at Request.emit (events.js:188:7) at IncomingMessage. (C:\AGStoShapefile-master\node_modules\reques t\request.js:1091:12) at IncomingMessage.g (events.js:292:16)

scaddenp commented 7 years ago

objectId is null.

tannerjt commented 7 years ago
if(objectIds == null) return

if(!Array.isArray(objectIds)) objectIds = [objectIds]

I wonder if that would take care of these two (line 71)

scaddenp commented 7 years ago

Yup. That works well. Now I get: http://data.nzpam.govt.nz/arcgis/rest/services/EXTERNAL/Minerals/MapServer/2 [ 779, 128023, 134421, 193261, 193264, 197296, 197696, 200912, 203327, 203329, 204932, 205333, 205742 ] info: Number of features for service: 13 info: Getting chunks of 100 features... info: query -> 0 out of 13 info: code=400, message=Invalid or missing input parameters., details=[]

scaddenp commented 7 years ago

(My services file is large so giving this a good workout).

tannerjt commented 7 years ago

Hopefully the script is helping with some of the other services. It's not perfect, but it will usually get the job done with some minor adjustments 😄

yipcma commented 7 years ago

ya i'm getting code=400 as well... anyone got a fix?

yipcma commented 7 years ago

ok, the issue with code=400 with me is on there being sublayers....

tannerjt commented 7 years ago

It should be straightforward to define sublayers under the root REST endpoint, and I'll look into that for future improvements. For now, all sublayers need to be defined explicitly in the services.txt file:

https://tmservices1.esri.com/arcgis/rest/services/LiveFeeds/NDFD_Precipitation/MapServer/2|Percipitation
https://tmservices1.esri.com/arcgis/rest/services/LiveFeeds/Wildfire_Activity/MapServer/0|WildFire
yipcma commented 7 years ago

i solved it by using just sublayers, not anything above (which caused the 400s)