Giter Site home page Giter Site logo

terraformer-js / terraformer Goto Github PK

View Code? Open in Web Editor NEW
163.0 10.0 28.0 1.42 MB

A geographic toolkit for dealing with geometry, geography, formats, and building geodatabases

License: MIT License

JavaScript 96.51% Yacc 3.49%
data-management arcgis geojson javascript

terraformer's People

Contributors

barrynickel avatar dependabot[bot] avatar emafazillah avatar gavinr avatar jgravois avatar leviremi avatar mguida22 avatar rgwozdz avatar zakhmaster avatar zakjan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

terraformer's Issues

Allow for a possibility to override standard SRS warning

According to rfc7946

In general, GeoJSON
processing software is not expected to have access to coordinate
reference system databases or to have network access to coordinate
reference system transformation parameters. However, where all
involved parties have a prior arrangement, alternative coordinate
reference systems can be used without risk of data being
misinterpreted.

Therefore I think the warning is perhaps correct, but it should at least be possible to suppress it. Now I need to fake WGS84 and later restore the original crs on the ESRI geometry like this

        // Both sides agree on RD.
        // Note, geojson allows another crs when both parties agree by prior arrangement. See also https://datatracker.ietf.org/doc/html/rfc7946
        // Temporarily change geometry and set srs to wgs84 to suppress warning in argisToGeoJSON (not supported by geojson)
        const wkid = graphic.geometry.spatialReference.get( "wkid" );
        graphic.geometry.spatialReference.set( "wkid", 4326);
        orderItem.geometry = arcgisToGeoJSON( graphic.geometry.toJSON() );
        // Change spatial reference back to the original
        graphic.geometry.spatialReference.set( "wkid", wkid );

node_modules heavy/failing

looks like there's a few extremely heavy prerequisites:

~/w/s/terraformer-1   master  npm install

> [email protected] install /Users/jerry/work/sandbox/terraformer-1/node_modules/fsevents
> node install

[fsevents] Success: "/Users/jerry/work/sandbox/terraformer-1/node_modules/fsevents/lib/binding/Release/node-v57-darwin-x64/fse.node" already installed
Pass --update-binary to reinstall or --build-from-source to recompile

> [email protected] postinstall /Users/jerry/work/sandbox/terraformer-1/node_modules/electron
> node install.js

Downloading electron-v1.8.8-darwin-x64.zip
Error: read ECONNRESET
/Users/jerry/work/sandbox/terraformer-1/node_modules/electron/install.js:47
  throw err
  ^

Error: read ECONNRESET
    at _errnoException (util.js:1022:11)
    at TLSWrap.onread (net.js:615:25)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] postinstall: `node install.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/jerry/.npm/_logs/2019-01-21T21_18_42_614Z-debug.log

failing at electron install - if we're installing electron for something this simple, we're doing something really wrong.

Primitive.prototype.convexHull does not support GeometryCollection

from Esri/terraformer#313

I have geojson geometries that include GeometryCollections. The current implementation of convexHull in terraformer does not support "GeometryCollection" in convexHull.

I have made my own code that fixes convexHull. I'm attaching my code but it is in typescript.
You can use it as reference or easily addapt it to javascript.

Hopefully you can get this fixed in a future release.

public convexHull(): Polygon | null {
    function getCoordinates(shape: any) {
        let coordinates = [] as any;
        let i;
        let j;
        if (shape.type === 'Point') {
            if (shape.coordinates) {
                const returnArray = [];
                returnArray.push(shape.coordinates)
                return returnArray;
            } else {
                return null
            }
        } else if (shape.type === 'LineString' || shape.type === 'MultiPoint') {
            if (shape.coordinates) {
                return shape.coordinates;
            } else {
                return null;
            }
        } else if (shape.type === 'Polygon' || shape.type === 'MultiLineString') {
            if (shape.coordinates) {
                for (i = 0; i < shape.coordinates.length; i++) {
                    coordinates = coordinates.concat(shape.coordinates[i]);
                }
                if (coordinates) {
                    return coordinates;
                } else {
                    return null;
                }
            } else {
                return null;
            }
        } else if (shape.type === 'MultiPolygon') {
            if (shape.coordinates && shape.coordinates.length > 0) {
                for (i = 0; i < shape.coordinates.length; i++) {
                    for (j = 0; j < shape.coordinates[i].length; j++) {
                        coordinates = coordinates.concat(shape.coordinates[i][j]);
                    }
                }
                if (coordinates) {
                    return coordinates;
                } else {
                    return null;
                }
            } else {
                return null;
            }
        } else if (shape.type === 'GeometryCollection') {
            for (const index in shape.geometries) {
                if (index) {
                    const delta = getCoordinates(shape.geometries[index]);
                    if (delta) {
                        coordinates = coordinates.concat(delta);
                    } else {
                        return null;
                    }
                }
            }
            return coordinates;
        }
    }

    function pointsEqual(a: any, b: any) {
        for (let bb = 0; bb < a.length; bb++) {
            if (a[bb] !== b[bb]) {
                return false;
            }
        }
        return true;
    }

    function closedPolygon(coordinates2: any) {
        const outer = [];
        for (const coordinate of coordinates2) {
            const inner = coordinate.slice();
            if (pointsEqual(inner[0], inner[inner.length - 1]) === false) {
                inner.push(inner[0]);
            }
            outer.push(inner);
        }
        return outer;
    }

    let cords;
    if (this.type === "Feature") {
        cords = getCoordinates((this as any).geometry);
    } else {
        cords = getCoordinates(this);
    }

    if (cords && cords.length >= 3) {
        return new Terraformer.Polygon({
            coordinates: closedPolygon([Terraformer.Tools.convexHull(cords)]),
            type: 'Polygon'
        });
    } else {
        console.log("Invalid geometry. At least 3 coordinates are required to generate a convex hull.")
        return null
    }
}

Error with "intersects" method when using Feature Collections.

When attempting an intersects with multipolygon and polygon arguments, I get a fatal error:

const { intersects }= require("@terraformer/spatial")

const multipolygon = {"type":"FeatureCollection","features":[{"type":"Feature","properties":{},"geometry":{"type":"MultiPolygon","coordinates":[[[[-101.0,37.0],[-99.0,37.0],[-99.0,38.0],[-101.0,38.0],[-101.0,37.0]]],[[[-97.0,35.0],[-95.0,35.0],[-95.0,36.0],[-97.0,36.0],[-97.0,35.0]]]]}},{"type":"Feature","properties":{},"geometry":{"type":"Polygon","coordinates":[[[-104,33],[-100,33],[-100,34],[-104,34],[-104,33]]]}}]}

const geometryFilter = {"type":"FeatureCollection","features":[{"type":"Feature","properties":{},"geometry":{"type":"Polygon","coordinates":[[[-98.5,34.6],[-94,34.6],[-94,37],[-98.5,37],[-98.5,34.6]]]}}]}

intersects(multipolygon, geometryFilter)

Results:

Screen Shot 2022-07-05 at 1 14 23 PM

typescript typings

When I try to use

import { arcgisToGeoJSON } from "@terraformer/arcgis";

in a TypeScript project, I get the error:

semantic error TS7016: Could not find a declaration file for module '@terraformer/arcgis'.

How can we make these available? I think there was a previous version, perhaps we can use those?

polygonContainsPoint returns false for intersections. Is this intended?

I swapped out a pile of custom helpers in favour of your library (thankyou!). A couple of my unit tests expected points intersecting with polygon boundaries to be contained within said polygon.

I went looking through your unit tests but they do not cover this edge case. Were point intersections with polygon boundaries excluded from being within the polygon on purpose?

const coordinates = [
  [1, 1],
  [0, 2],
  [0, 0]
];

coordinatesContainPoint(coordinates, [1, 1]); //false
coordinatesContainPoint(coordinates, [0.5, 1.5]); //false
coordinatesContainPoint(coordinates, [0, 2]); //false
coordinatesContainPoint(coordinates, [0.5, 1]); //true

add JSDoc to public functions in @terraformer/spatial

like this:

/**
* @function
* Converts ArcGIS JSON into GeoJSON.
* @param {object} JSON - The input geometry, feature or feature collection.
* @param {string} idAttribute? - When converting an ArcGIS Feature its attributes will contain the ID of the feature. If something other than OBJECTID or FID stores the ID, you should pass through the fieldname explicitly.
* @return {object} GeoJSON.
*/
export const arcgisToGeoJSON = (arcgis, idAttribute) => {

using the info in http://terraformer.io/core/#terraformertools

Typescript typings for @terraformer/wkt

Similar to #46, there are no typings available for @terraformer/wkt.

npm ERR! 404 Not Found - GET https://registry.npmjs.org/@types%2fterraformer__wkt - Not found
npm ERR! 404
npm ERR! 404  '@types/terraformer__wkt@*' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it

Support Typescript

Hi,

Thanks for the great package, so handy and easy.

Is there any plan to release the module with supporting typescirpt?

intersects has unexpected result with multipolygon geometry

Hey again. I start with a multipolygon geometry (green) and a simple polygon (hash-fill). They look like this:

Screen Shot 2022-07-05 at 2 26 14 PM

When I do an intersects for these two geometries, I'm expecting a result of true. On an ArcGIS service, I do find that an intersect filter operation like this (with multipolygon as data set and simple polygon as filter) returns a result. Similarly in QGIS, a select operation on the multipolygon using an intersection of the simple polygon results in the multipolygon being selected.

But I find the terraformer intersects returns false:

const { intersects }= require("@terraformer/spatial")

const multipolygon = {"type":"MultiPolygon","coordinates":[[[[-101.0,37.0],[-99.0,37.0],[-99.0,38.0],[-101.0,38.0],[-101.0,37.0]]],[[[-97.0,35.0],[-95.0,35.0],[-95.0,36.0],[-97.0,36.0],[-97.0,35.0]]]]}

const geometryFilter = {"type":"Polygon","coordinates":[[[-98.5,34.6],[-94,34.6],[-94,37],[-98.5,37],[-98.5,34.6]]]}

intersects(multipolygon, geometryFilter) // false

So in the above example, terraformer result seems to diverge from similar operation in QGIS/ArcGIS. Not sure if this is intentional or just something that was missed. Can you advise?

Interestingly, if I adjust the filter polygon so that its boundary crosses one of the multipolygon's component polygons, the result is true.

const { intersects }= require("@terraformer/spatial")

const multipolygon = {"type":"MultiPolygon","coordinates":[[[[-101.0,37.0],[-99.0,37.0],[-99.0,38.0],[-101.0,38.0],[-101.0,37.0]]],[[[-97.0,35.0],[-95.0,35.0],[-95.0,36.0],[-97.0,36.0],[-97.0,35.0]]]]}

const geometryFilter = {"type":"Polygon","coordinates":[[[-100.5,34.6],[-94,34.6],[-94,37],[-100.5,37],[-100.5,34.6]]]}

intersects(multipolygon, geometryFilter) // true

evaluate test-harness tooling to confirm that the choices are appropriate

the tooling in this repo is basically just an update and monorepo port of what @patrickarlt used in https://github.com/Esri/arcgis-to-geojson-utils

(1) is there any reason not to use tape?

my impression is that we've tacked on jasmine and karma and everything else in other JS libraries i've contributed to mostly just to mock internet requests. i think tape is sufficient for the unit tests we need to run here, right?

(2) can/should the browserify dependency be removed?

at this point we could probably test the native ES modules directly in the browser. should we though?

(2a) are any of the other dependencies already 'stale' or out of fashion?

i've never cared much about popularity contests, but lots of the work i've done maintaining terraformer and other libraries over the last couple years has been trying to stay ahead of security vulnerabilities and keep things running in newer versions of Node.js as they've come out. in that sense, antiquated architecture is a pain.

lasso feedback/questions

intersects(polygon, point) returns true if point is inside polygon, but throws "Type Polygon to Point intersection is not supported by intersects" if it is not inside. Obviously it is an issue of not respecting false return value at the same line as above, but it is correct false in this case. This issue exists also in the original Terraformer, I just ignored it and forced to use contains with points (https://github.com/zakjan/leaflet-lasso/blob/master/src/calc.ts#L47-L49). Is there possibly another way of detecting that intersection is not supported? What specific combination of types is actually not supported?

createCircle still returns incorrrect radius and it is missing export. But I can stay with the other dependency.

new documentation site

JSDoc actually does a lot better with monorepos than i originally feared it would.

screenshot 2018-12-31 13 53 46

that said, we'll still need to clean things up quite a bit before i'd feel good hosting the new doc on http://terraformer.io and retiring the old page.

this.parseError is not a function

The function wktToGeoJSON of package @terraformer/wkt version 2.1.2 fails with error:
Unable to parse: TypeError: this.parseError is not a function
when the wkt is invalid.

To reproduce it just do
wkt.wktToGeoJSON("POINT(0,0)")

invalid type signature for arcgisToGeoJSON

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.

get *all* the tests running in Node.js

$ npm install && npm run bootstrap && npm run test:browser

Downloading SHASUMS256.txt
[============================================>] 100.0% of 5.74 kB (5.74 kB/s)
added 1134 packages from 499 contributors and audited 7100 packages in 59.925s
found 0 vulnerabilities
...
browserify packages/**/test/index.js -t [ babelify --presets [ @babel/preset-env ] ] --debug | tape-run | faucet
...
✓ should return false if a polygonContainsPoint is called and the point is outside the polygon.
# tests 101
# pass  101
✓ ok
$ npm run test:node

babel-node packages/**/test/index.js [ babelify --presets @babel/preset-env ] | faucet
...
# tests 66
# pass  66
✓ ok

this is because babel-node just transpiles the input and passes it down, and the Node.js CLI doesn't know about minimatch expressions.

i tried moving the appropriate command (and devDependencies) down into each package and calling lerna run test:node instead, but that doesn't work either.

obviously we could also do it like this, but yuck 😬😷

babel-node packages/arcgis/test/index.js [ babelify --presets @babel/preset-env ] | faucet &&
babel-node packages/wkt/test/index.js [ babelify --presets @babel/preset-env ] | faucet &&
babel-node packages/spatial/test/index.js [ babelify --presets @babel/preset-env ] | faucet &&
babel-node packages/common/test/index.js [ babelify --presets @babel/preset-env ] | faucet

wkt not support GEOMETRYCOLLECTION

Uncaught Error: Unable to parse: Error: Parse error on line 1:
GEOMETRYCOLLECTION(P
^
Expecting 'POINT', 'LINESTRING', 'POLYGON', 'MULTIPOINT', 'MULTILINESTRING', 'MULTIPOLYGON', got 'INVALID'

The type field of the Geometry class is missing in @terraformer/arcgis

Thank you very much for the conversion tool, but when I use it with ArcGIS JS, it has some problems. Specifically, the type field indicating the geometry type is missing.

In the Geometry document of ArcGIS JS, the type field exists. When switching from GeoJson to ArcGIS Json, the geometry type is lost.
In ArcGIS JS, when adding the features field to FeatureSet, the type field in Geometry must exist before it can be added.

Geometry JS document:
https://developers.arcgis.com/javascript/latest/api-reference/esri-geometry-Geometry.html#type

Graphic's JS document:
https://developers.arcgis.com/javascript/latest/api-reference/esri-Graphic.html

FeatureSet JS document:
https://developers.arcgis.com/javascript/latest/api-reference/esri-tasks-support-FeatureSet.html

Add support for Z values

At the moment Z values in a geojson point get stripped. it looks as though the issue us in the geojsonToArcGIS funciton in terraformer/packages/arcgis/src/geojson.js. Line 61 has:
result.y = geojson.coordinates[1];
There is no:
if (geojson.coordinates[2]) result.z = geojson.coordinates[2]
I'm not sure if there are other areas that also need updating.
Thanks!

`geojsonToArcGIS` has falsy checks for z-values

Checks for z-values are falsy, and as result they don't evaluate as we'd hope if the z-value has a zero-value.

Imagine a coordinate array [-170, 42, 0] flowing through the following code:

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

Since the z-coordinate is 0 the check evaluates to false and the result.z is never set.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.