terraformer-js / terraformer

A geographic toolkit for dealing with geometry, geography, formats, and building geodatabases
MIT License
182 stars 28 forks source link

invalid type signature for arcgisToGeoJSON #98

Open tomwayson opened 1 year ago

tomwayson commented 1 year ago

Seems like this line

export function arcgisToGeoJSON(arcgis: ArcGIS.Geometry, idAttribute?: string): GeoJSON.GeometryObject;

Should be:

export function arcgisToGeoJSON(arcgis: ArcGIS.Geometry | ArcGIS.Feature | ArcGIS.FeatureSet, idAttribute?: string): GeoJSON.GeometryObject;

Based on the description:

Param Type Description
JSON object The input ArcGIS geometry, feature or feature collection.
jgravois commented 1 year ago

greetings old friend. 👋

a PR (to DefinitelyTyped) would most certainly be welcome.

tomwayson commented 1 year ago

greetings indeed.

I did start on that, but the above change didn't solve the problem in my environment, likely due to mismatches between the "arcgis-rest-api" types and the corresponding types from @arcgis/core and I just ended up sprinkling as any through my code.

This made me wonder if the types for this library should be using the actual types from @arcgis/core, but that feels like a bigger issue.

jgravois commented 1 year ago

i don't have any firm opinions about better Typescript support. this library is pretty mature/stable at this point so i'm not opposed to (someone else) tackling a full-blown revamp. i wouldn't expect it to be yeoman's work.

i'd also be fine with moving the typings here if it'd make maintenance easier. ❤️

webmapLee commented 1 year ago

Except for type errors,The code for this function geojsonToArcGIS needs to be optimized ` var geojsonToArcGIS = function geojsonToArcGIS(geojson, idAttribute) { idAttribute = idAttribute || 'OBJECTID'; var spatialReference = { wkid: 4326 }; var result = {}; var i;

switch (geojson.type) { case 'Point': result.x = geojson.coordinates[0]; result.y = geojson.coordinates[1];

  if (geojson.coordinates[2] != null) {
    result.z = geojson.coordinates[2];
  }

  result.spatialReference = spatialReference;
  break;

case 'MultiPoint':
  result.points = geojson.coordinates.slice(0);

  if (geojson.coordinates[0][2] != null) {
    result.hasZ = true;
  }

  result.spatialReference = spatialReference;
  break;

case 'LineString':
  result.paths = [geojson.coordinates.slice(0)];

  if (geojson.coordinates[0][2] != null) {
    result.hasZ = true;
  }

  result.spatialReference = spatialReference;
  break;

case 'MultiLineString':
  result.paths = geojson.coordinates.slice(0);

  if (geojson.coordinates[0][0][2] != null) {
    result.hasZ = true;
  }

  result.spatialReference = spatialReference;
  break;

case 'Polygon':
  result.rings = orientRings(geojson.coordinates.slice(0));

  if (geojson.coordinates[0][0][2] != null) {
    result.hasZ = true;
  }

  result.spatialReference = spatialReference;
  break;

case 'MultiPolygon':
  result.rings = flattenMultiPolygonRings(geojson.coordinates.slice(0));

  if (geojson.coordinates[0][0][0][2] != null) {
    result.hasZ = true;
  }

  result.spatialReference = spatialReference;
  break;

case 'Feature':
  if (geojson.geometry) {
    result.geometry = geojsonToArcGIS(geojson.geometry, idAttribute);
  }

  result.attributes = geojson.properties ? shallowClone(geojson.properties) : {};

  if (geojson.id) {
    result.attributes[idAttribute] = geojson.id;
  }

  break;

case 'FeatureCollection':
  result = [];

  for (i = 0; i < geojson.features.length; i++) {
    result.push(geojsonToArcGIS(geojson.features[i], idAttribute));
  }

  break;

case 'GeometryCollection':
  result = [];

  for (i = 0; i < geojson.geometries.length; i++) {
    result.push(geojsonToArcGIS(geojson.geometries[i], idAttribute));
  }

  break;

}

return result; };

`

the result should be an array or an object , so 'var result = {}' this code is error ,