Skip to content

Update Intersect for GeoJSON.Feature<any> inputs#479

Closed
DenisCarriere wants to merge 1 commit intoTurfjs:masterfrom
DenisCarriere:patch-11
Closed

Update Intersect for GeoJSON.Feature<any> inputs#479
DenisCarriere wants to merge 1 commit intoTurfjs:masterfrom
DenisCarriere:patch-11

Conversation

@DenisCarriere
Copy link
Copy Markdown
Contributor

Using intersection in jsts can be applied to any type of GeoJSON in any combinations.

Things can get pretty confusing depending in the parameters.

Example: intersect(poly, poly) returns Point | Line | Polygon

Here's a TypeScript definition that would best describe the functionality with overloaded methods.

intersect(
  feature1: GeoJSON.Feature<GeoJSON.Point>,
  feature2: GeoJSON.Feature<GeoJSON.Point>
): GeoJSON.Feature<GeoJSON.Point>;
intersect(
  feature1: GeoJSON.Feature<GeoJSON.LineString>,
  feature2: GeoJSON.Feature<GeoJSON.LineString>
): GeoJSON.Feature<GeoJSON.Point | GeoJSON.LineString>;
intersect(
  feature1: GeoJSON.Feature<GeoJSON.Polygon>,
  feature2: GeoJSON.Feature<GeoJSON.Polygon>
): GeoJSON.Feature<GeoJSON.Point | GeoJSON.LineString | GeoJSON.Polygon>;
intersect(
  feature1: GeoJSON.Feature<GeoJSON.MultiPoint>,
  feature2: GeoJSON.Feature<GeoJSON.MultiPoint>
): GeoJSON.Feature<GeoJSON.Point | GeoJSON.MultiPoint>;
intersect(
  feature1: GeoJSON.Feature<GeoJSON.MultiLineString>,
  feature2: GeoJSON.Feature<GeoJSON.MultiLineString>
): GeoJSON.Feature<GeoJSON.Point | GeoJSON.LineString | GeoJSON.MultiLineString>;
    intersect(
  feature1: GeoJSON.Feature<GeoJSON.MultiPolygon>,
  feature2: GeoJSON.Feature<GeoJSON.MultiPolygon>
): GeoJSON.Feature<GeoJSON.Point | GeoJSON.LineString | GeoJSON.Polygon | GeoJSON.MultiPolygon>;
intersect(
  feature1: GeoJSON.Feature<GeoJSON.Polygon | GeoJSON.Point>,
  feature2: GeoJSON.Feature<GeoJSON.Polygon | GeoJSON.Point>
): GeoJSON.Feature<GeoJSON.Point>;
intersect(
  feature1: GeoJSON.Feature<GeoJSON.Polygon | GeoJSON.LineString>,
  feature2: GeoJSON.Feature<GeoJSON.Polygon | GeoJSON.LineString>
): GeoJSON.Feature<GeoJSON.Point | GeoJSON.LineString>;
intersect(
  feature1: GeoJSON.Feature<GeoJSON.Polygon | GeoJSON.MultiLineString>,
  feature2: GeoJSON.Feature<GeoJSON.Polygon | GeoJSON.MultiLineString>
): GeoJSON.Feature<GeoJSON.Point | GeoJSON.LineString | GeoJSON.MultiLineString>;
intersect(
  feature1: GeoJSON.Feature<GeoJSON.Polygon | GeoJSON.MultiPolygon>,
  feature2: GeoJSON.Feature<GeoJSON.Polygon | GeoJSON.MultiPolygon>
): GeoJSON.Feature<GeoJSON.Point | GeoJSON.LineString | GeoJSON.Polygon | GeoJSON.MultiLineString | GeoJSON.MultiPolygon>;
intersect(
  feature1: GeoJSON.Feature<any>,
  feature2: GeoJSON.Feature<any>
): GeoJSON.Feature<any>;

Using `intersection` in `jsts` can be applied to any type of GeoJSON in any combinations.

Things can get pretty confusing depending in the parameters.

Example: **intersect(poly, poly)** returns `Point` | `Line` | `Polygon`

Here's a TypeScript definition that would best describe the functionality with overloaded methods.

```javascript
intersect(
  feature1: GeoJSON.Feature<GeoJSON.Point>,
  feature2: GeoJSON.Feature<GeoJSON.Point>
): GeoJSON.Feature<GeoJSON.Point>;
intersect(
  feature1: GeoJSON.Feature<GeoJSON.LineString>,
  feature2: GeoJSON.Feature<GeoJSON.LineString>
): GeoJSON.Feature<GeoJSON.Point | GeoJSON.LineString>;
intersect(
  feature1: GeoJSON.Feature<GeoJSON.Polygon>,
  feature2: GeoJSON.Feature<GeoJSON.Polygon>
): GeoJSON.Feature<GeoJSON.Point | GeoJSON.LineString | GeoJSON.Polygon>;
intersect(
  feature1: GeoJSON.Feature<GeoJSON.MultiPoint>,
  feature2: GeoJSON.Feature<GeoJSON.MultiPoint>
): GeoJSON.Feature<GeoJSON.Point | GeoJSON.MultiPoint>;
intersect(
  feature1: GeoJSON.Feature<GeoJSON.MultiLineString>,
  feature2: GeoJSON.Feature<GeoJSON.MultiLineString>
): GeoJSON.Feature<GeoJSON.Point | GeoJSON.LineString | GeoJSON.MultiLineString>;
    intersect(
  feature1: GeoJSON.Feature<GeoJSON.MultiPolygon>,
  feature2: GeoJSON.Feature<GeoJSON.MultiPolygon>
): GeoJSON.Feature<GeoJSON.Point | GeoJSON.LineString | GeoJSON.Polygon | GeoJSON.MultiPolygon>;
intersect(
  feature1: GeoJSON.Feature<GeoJSON.Polygon | GeoJSON.Point>,
  feature2: GeoJSON.Feature<GeoJSON.Polygon | GeoJSON.Point>
): GeoJSON.Feature<GeoJSON.Point>;
intersect(
  feature1: GeoJSON.Feature<GeoJSON.Polygon | GeoJSON.LineString>,
  feature2: GeoJSON.Feature<GeoJSON.Polygon | GeoJSON.LineString>
): GeoJSON.Feature<GeoJSON.Point | GeoJSON.LineString>;
intersect(
  feature1: GeoJSON.Feature<GeoJSON.Polygon | GeoJSON.MultiLineString>,
  feature2: GeoJSON.Feature<GeoJSON.Polygon | GeoJSON.MultiLineString>
): GeoJSON.Feature<GeoJSON.Point | GeoJSON.LineString | GeoJSON.MultiLineString>;
intersect(
  feature1: GeoJSON.Feature<GeoJSON.Polygon | GeoJSON.MultiPolygon>,
  feature2: GeoJSON.Feature<GeoJSON.Polygon | GeoJSON.MultiPolygon>
): GeoJSON.Feature<GeoJSON.Point | GeoJSON.LineString | GeoJSON.Polygon | GeoJSON.MultiLineString | GeoJSON.MultiPolygon>;
intersect(
  feature1: GeoJSON.Feature<any>,
  feature2: GeoJSON.Feature<any>
): GeoJSON.Feature<any>;
```
@morganherlocker
Copy link
Copy Markdown
Member

So far, I've restricted turf-intersect to only officially support poly,poly to keep things simple and scoped (falling short of actually throwing an exception). I can see a case to be made in opening this up, provided we can explain the input=>output combinations in a concise way. I see this as more of a "how do we explain this to humans" rather than a "how do we explain this to computers" type of problem.

@DenisCarriere
Copy link
Copy Markdown
Contributor Author

DenisCarriere commented Sep 14, 2016

@morganherlocker I totally agree, this would be a total nightmare to explain. You did the right move to restrict the support for only poly,poly.
I've reflected the same changes to the Typescript definition since Turf won't be officially supporting the other input > outputs (I don't blame you! it's a mess and very confusing)

DefinitelyTyped/DefinitelyTyped#11123

@DenisCarriere DenisCarriere deleted the patch-11 branch September 14, 2016 19:08
vvakame pushed a commit to DefinitelyTyped/DefinitelyTyped that referenced this pull request Sep 19, 2016
* Define Turf 3.5.2 definition
Update all methods with newest JSDocs & tests based on the latest TurfJS library.

AGGREGATION
- [x] collect
MEASUREMENT
- [ ] along
- [ ] area
- [ ] bboxPolygon
- [ ] bearing
- [ ] center
- [ ] centroid
- [ ] destination
- [ ] distance
- [ ] envelope
- [ ] lineDistance
- [ ] midpoint
- [ ] pointOnSurface
- [ ] square
TRANSFORMATION
- [ ] bezier
- [ ] buffer
- [ ] concave
- [ ] convex
- [ ] difference
- [ ] intersect
- [ ] simplify
- [ ] union
MISC
- [ ] combine
- [ ] explode
- [ ] flip
- [ ] kinks
- [ ] lineSlice
- [ ] pointOnLine
HELPER
- [x] featureCollection
- [x] feature
- [x] lineString
- [x] multiLineString
- [x] point
- [x] multiPoint
- [x] polygon
- [x] multiPolygon
- [x] geometryCollection
DATA
- [x] random
- [x] sample
INTERPOLATION
- [ ] isolines
- [ ] planepoint
- [ ] tin
JOINS
- [ ] inside
- [ ] tag
GRIDS
- [ ] hexGrid
- [ ] pointGrid
- [ ] squareGrid
- [ ] triangleGrid
- [ ] within
CLASSIFICATION
- [ ] nearest
META
- [ ] propEach
- [ ] coordEach
- [ ] coordReduce
- [ ] featureEach
- [ ] getCoord
ASSERTIONS
- [ ] featureOf
- [ ] collectionOf
- [ ] bbox
- [ ] circle
- [ ] geojsonType
- [ ] propReduce
- [ ] coordAll
- [ ] tesselate

* Added Turf Grids functions
- Added more variables to data initialisation.
- Remove excess feature points.
- Add URL in `@name` in function JSDocs

GRIDS
- [x] hexGrid
- [x] pointGrid
- [x] squareGrid
- [x] triangleGrid

* Use the latest Turf import
- Added in test case how to import individal functions
npm install in Node.js
```
npm install @turf/turf
```
https://github.com/Turfjs/turf

* Change Turf functions into interfaces

* Added Turf typeof units
`units` is an optional parameter for all Turf functions with the following options `'miles' | 'nauticalmiles' | 'degrees' | 'radians' | 'inches' | 'yards' | 'meters' | 'metres' | 'kilometers' | 'kilometres'`

* Update Turf `inside` & `tag`
Add JSDocs & validate both methods

* Add imports to Turf submodules

* Add Author to Turf
@vvakame followed the same syntax as Lodash

* Simplify Turf `intersect` interface
Turf only officially supports `poly,poly`, all other geometry input/outputs are valid, however can't control the outputs.
Turfjs/turf#479

* Comment Turf export default module
Next release of Turf will have this implemented

* Remove default export turf
Was meant to be a comment instead, removed it for now to be safe, it will become available next release

* Added Turf.bbox function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants