terraformer-js / terraformer Goto Github PK
View Code? Open in Web Editor NEWA geographic toolkit for dealing with geometry, geography, formats, and building geodatabases
License: MIT License
A geographic toolkit for dealing with geometry, geography, formats, and building geodatabases
License: MIT License
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 );
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.
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
}
}
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:
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?
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
like this:
terraformer/packages/arcgis/index.js
Lines 201 to 208 in f0857d6
using the info in http://terraformer.io/core/#terraformertools
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
Is there any replacement for Terraformer Code and Geostore in this repository?
https://github.com/Esri/terraformer/blob/master/docs/core.md
https://github.com/Esri/terraformer-geostore
Hi,
Thanks for the great package, so handy and easy.
Is there any plan to release the module with supporting typescirpt?
Hey again. I start with a multipolygon geometry (green) and a simple polygon (hash-fill). They look like this:
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
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
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?
at this point we could probably test the native ES modules directly in the browser. should we though?
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.
How do I use the applyConverter tool with the latest release?
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.
JSDoc actually does a lot better with monorepos than i originally feared it would.
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.
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)")
from #34 (comment)
the generated docs is missing a few functions: positionToMercator, toGeographic, isConvex, even though they are documented. Also, exported constants MercatorCRS, GeographicCRS. I couldn't figure out yet why, maybe you have an idea?
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. |
$ 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
Hi! I created a PR to add wkt types into DefinitelyTyped, where typescript fetches type definitions: DefinitelyTyped/DefinitelyTyped#59985
May I get some reviews? Thanks!
Uncaught Error: Unable to parse: Error: Parse error on line 1:
GEOMETRYCOLLECTION(P
^
Expecting 'POINT', 'LINESTRING', 'POLYGON', 'MULTIPOINT', 'MULTILINESTRING', 'MULTIPOLYGON', got 'INVALID'
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
inspiration - zakjan/leaflet-lasso#10
export createCircle()
maybe
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!
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.