GeoJSON typing for the feature service package
See original GitHub issueSince GeoJSON is a valid output for FeatureLayer/query
endpoints, I was thinking it may be helpful to add that as an alternative response type for the getFeature
, queryFeatures
, and queryRelated
methods. Maybe a Typescript generic for those three methods?
The reason I bring this up is that I am working on a library that needs to grab data from a service before processing it. The utility I will be using for processing desires GeoJSON, so my goal was to just overwrite the request options with the output format of ‘geojson’. Right now, I have to assert the response to the GeoJSON type as follows.
import * as fetch from 'isomorphic-fetch'
import * as FormData from 'form-data'
import { queryFeatures, IQueryFeaturesRequestOptions } from '@esri/arcgis-rest-feature-service'
export async function fetchESRIGeoJSON(
options: IQueryFeaturesRequestOptions
): Promise<GeoJSON.GeoJSON> {
// Overwrite the output format parameter.
options.params = {
...options.params,
...{ f: "geojson" }
}
// Requires the assertion of the queryFeatures response as a GeoJSON.
const features: GeoJSON.GeoJSON = await queryFeatures(options) as GeoJSON.GeoJSON
return features
}
It works fine for now, but just a thought for the future.
Issue Analytics
- State:
- Created 5 years ago
- Comments:10 (10 by maintainers)
Top Results From Across the Web
GeoJSON—ArcGIS Online Help | Documentation
GeoJSON is an open standard geospatial data interchange format that represents simple geographic features and their nonspatial attributes.
Read more >Solved: overwriting GeoJSON-based hosted feature service?
It will create duplicate items with the same name, but one is type "Feature Layer (hosted)" in the web interface (which is callled...
Read more >GeoJSON
GeoJSON is a format for encoding a variety of geographic data structures. { "type": ... Geometric objects with additional properties are Feature objects....
Read more >Feature (services-geojson API) - Mapbox docs
Gson TYPE adapter for parsing Gson to this class. Methods inherited from class java.lang.Object. clone, finalize, getClass, notify, notifyAll, wait, wait, ...
Read more >RFC 7946: The GeoJSON Format
Features in GeoJSON contain a Geometry object and additional properties, ... is no particular service model or Feature type ontology implied in the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Personally I am in favor of using overloads in scenarios like this. To me would be nicer to let the function (queryFeature, queryFeatures, etc.) determine the response type based on the input rather than worry about asserting the output. Since this is a TS library, it would be nice to be able to provide TS features where possible.
I’d be happy to take another crack at it after I closed #346.
Hello, I just ran in to this 👋🏻
I’m just doing an
as GeoJSONObject
to workaround it, but if there’s more interesting I’d be happy to 👀 at a fix.