-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Port Meta Tests and Functions #12
Comments
Hi @baparham, any updates? |
No 😳 it's been a rather busy year, but I can spend some time on this, I've been wanting to get back into flutter/dart development lately so your ping is timely. I'll block out some time this week to devote here. |
Nice! I'm also slowly starting to work on other parts of the library again, e.g. null-safety support which is more than overdue |
The most useful meta function to now work on will be edit: have implementation ready for propEach but depends on merging #13 first |
When implementing the functions, please let's keep in mind that my GeoJSON implementation follows a very strict class representation of the RFC standard. I would prefer to have stricter types for the functions, e.g.: - void geomEach(dynamic geoJSON, GeomEachCallback callback) {
+ void geomEach(GeoJSONObject geoJSON, GeomEachCallback callback) { also, see my comments here: #24 and here: #14 (comment) here you can see all the classes and their inheritance in a tree diagram: |
I agree @lukas-h that these should be typed stricter. Currently the GeoJSONObject doesn't include features, so perhaps that's the first step, is to bring that abstract class up to snuff? I can try and implement this in a new PR, I'll paste that in here if I get something that works |
It seems like I can use some runtime typechecking, and casting with e.g. this works: bool isFeatureCollection = instanceof(geoJSON, FeatureCollection);
bool isFeature = instanceof(geoJSON, Feature);
int stop = 1;
if (isFeatureCollection) {
stop = (geoJSON as FeatureCollection).features.length;
} but then further down we have things like this that do not work: for (var i = 0; i < stop; i++) {
geometryMaybeCollection = (isFeatureCollection
? geoJSON.features[i].geometry
: (isFeature ? geoJSON.geometry : geoJSON));
featureProperties = (isFeatureCollection
? geoJSON.features[i].properties
: (isFeature ? geoJSON.properties : {}));
featureBBox = (isFeatureCollection
? geoJSON.features[i].bbox
: (isFeature ? geoJSON.bbox : null));
featureId = (isFeatureCollection
? geoJSON.features[i].id
: (isFeature ? geoJSON.id : null));
isGeometryCollection = (geometryMaybeCollection != null)
? geometryMaybeCollection.type == GeoJSONObjectTypes.geometryCollection
: false;
... since I think I'll just go ahead and refactor this code to meet our intended purpose, be more readable, yet diverge from simple 1:1 implementation mapping from turf.js |
@baparham That's a little bit more difficult than that.. Not all subtypes of GeoJSONObject should have the same attributes following the RFC standard. Maybe we need to work more with type casting |
I think it works to simply trust the |
what about this method? #29 It's soooo ugly and needs to be refactored to use more focused helper functions I think, but to test the concept, I think it works. |
I see why the naming can be a little bit confusing. We should definitely think of a naming convention.
Background: the RFC standard defines different groups of GeoJSON object types:
|
Finally getting back to my original attempt of implementing |
I'll get started on |
I have a proposal: To have all the meta functions like as independent / standalone functions, seems to me very "non-OOP", not "Dart-like", but instead like a more common style for JavaScript. My idea is, to glue the meta functions (at for least those, that actually make sense) to the GeoJSON classes directly. For the user, the API could look like this: var featColl = FeatureCollection.fromJson(json);
featColl.geomEach(
// ...
); I started to implement this for the
You can see the changes in this commit: b02af15 It's not yet debugged, and there could still be some hurdles with the implementation, Please let me know what you think! |
I like the idea, the only things I could counter to this proposal are:
I don't think these reasons justify not doing it but I did want to provide that angle as input.
I would vote for an extension approach. In the past I had libraries that were dependent on the java geojson implementation but weren't allowed to pull in turf-java due to binary size constraints. Having them exposed as extension functions will give us the flexibility to pull out geojson into an independent library and have a separate extension function library to provide turf functionality. Are there any downsides to use extension functions? |
I agree with @tobrun that we don't want to arbitrarily pollute the namespace with stuff people may not care about, and your extensions approach seems to address this concern directly, that if one wants to use the syntactic sugar, they can import the extensions. I am not very familiar with extensions as a concept, but I do not immediately see downsides. Perhaps if someone is copying example code that takes advantage of the extensions, they may not do the extra import needed, and I don't know if their IDE would suggest such an import. |
I totally agree with both of you! Let’s keep the GeoJSON object representation in geojson.dart slim! But there’s one catch with the extension method approach: |
|
Is there a way to use the actual implementation via the extension method? import 'package:turf/src/meta.dart';
import 'package:turf/helpers.dart';
extension GeomEachGeoJSONObject on GeoJSONObject {
void geomEachImpl2(GeomEachCallback callback) {
geomEach(this, callback);
}
} |
I don't like that having the implementation in two places |
Totally agree. Tried to incorporate that in this commit: 3243325
I'm not sure, if your (@baparham) idea here using the
|
what about the other functions inside turf invariant? I guess @baparham you took the tasks from the README. In my opinion, most of the functions in turf invariant are not even needed in Dart, because of the better type system. |
Yeah those sound like type guards that aren't needed in a typed language, I
agree.
…On Sun, Dec 19, 2021, 5:55 PM Lukas Himsel ***@***.***> wrote:
- getCoord
- getCoords
- getGeom
- getType
what about the other functions inside turf invariant?
https://github.com/Turfjs/turf/tree/master/packages/turf-invariant
In my opinion, some of them are not even needed in Dart, because of the
better type system.
For example getGeom which just takes a Feature as a param and returns its
geometry.
—
Reply to this email directly, view it on GitHub
<#12 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAFFP3P3PRRFR2QTFWUHHC3URYE65ANCNFSM4UXYWOUQ>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Will close this, because we are done with this milestone 🎉 |
*each
*reduce
other
getType (@lukas-h)--getGeom (@lukas-h)--The text was updated successfully, but these errors were encountered: