question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

GeoJSON typing for the feature service package

See original GitHub issue

Since 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:closed
  • Created 5 years ago
  • Comments:10 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
itrewcommented, Nov 9, 2018

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.

0reactions
davetapleycommented, Feb 19, 2021

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found