-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create GeoJSON I/O project using new Sytem.Text.Json #44
Comments
I've been thinking about starting this for a while (pretty much ever since it was announced), I just never seem to have the time :-( |
Geometry converter is ready for review. Relates to #44
@FObermaier you're fast... var feature = new Feature(...);
feature.ToPoco(); Creating a POCO would allow any JSON serializer to simply serialize the POCO reducing the complexity of writing serializers, as most (or all) support serializing a simple object. I'm not sure if this should be a requirement to NTS or even JTS, but I think it can solve a lot of issues related to serialization. |
@FObermaier I noticed you've assigned this to yourself, have you gotten started on it yet? If not, I'd like to try my hand at doing this as sort-of a fresh start. |
This is how far I've gotten: |
Maybe I can find a simpler way of handling If nothing else, perhaps less allocation-heavy ( |
Perhaps you like 27485e0 better. |
I think what I'd ideally like to do is have it return
The idea being that if we see just Otherwise, we can still build |
So something like: object? coordData = null;
string? type = null;
/* ... */
switch (propertyName)
{
case "coordinates":
coordData = ReadCoordData(ref reader, /* and others */);
break;
case "type":
type = reader.GetString();
break;
/* ... */
}
/* ... */
return type switch
{
"Point" when coordData is Point pt => pt,
"LineString" when coordData is CoordinateSequence seq => _geometryFactory.CreateLineString(seq),
/* ... */
"MultiPolygon" when coordData is MultiPolygon mp => mp,
_ => throw new JsonException("type / coordinates mismatch"),
}; |
Some feedback I have from going through that code:
|
@airbreather, I have no objections. Instead of |
Is this still being worked on? I would love to be able to replace Newtonsoft with System.Text.Json! |
I am also waiting for the change! Great job!! |
This has been released and published to NuGet: https://www.nuget.org/packages/NetTopologySuite.IO.GeoJSON4STJ Release tag: https://github.com/NetTopologySuite/NetTopologySuite.IO.GeoJSON/releases/tag/stj-v2.0.3 Instructions on how to use it: https://github.com/NetTopologySuite/NetTopologySuite.IO.GeoJSON/wiki/Using-NTS.IO.GeoJSON4STJ-with-ASP.NET-Core-MVC Thanks to @FObermaier for getting the ball rolling on this one! |
This is super!!
Content of
Exception I get when running this test: Am I missing something obvious? |
It's got to be |
Yea, I just figured this out. :-/ |
The argument over [IFeature]/[IAttributesTable] can be found here: |
I've read the thread twice, I still don't understand how to structure my code.
But to our topic - I don't mind changing all my code that doesn't construct a I'd love to understand in order to build my code properly, changing a serialization layer (From Json.Net to STJ) should've made me change creation code in my personal opinion... |
There's a lot to unpack and respond to here, so I'm going to divide this into sections. Sorry about the long comment, but there's a lot to go through here, and if everything were simple, then we wouldn't have these significant API clarity issues to begin with.
During this exercise, certain other interfaces were also called out as not really doing anything for anyone, so they were removed too. I initially thought that
Each of the two activities has its own separate set of considerations. Serializing things out is relatively easy and straightforward, since we have all the information available on-demand, in any order we want it, and Deserializing is a bigger challenge, because we have to support (or at least somewhat consider) valid GeoJSON inputs from any application, with properties in any order, using any combination of features. The two biggest challenges for this (for me, anyway) were:
I hesitate to add support for deserializing into instances of
I wholeheartedly agree and sympathize with everything you say here. I raised up basically these same issues in the thread that @FObermaier linked. I felt that it's silly to implement this nonstandard From the standpoint of GeoJSON, it seemed better to just expose a However, there were examples of
Not to derail too much, but in my personal opinion, I think
|
Thanks for your detailed answer! I enjoyed reading it.
That's my 2 cents. I'd be happy to land a hand progressing this forward if need be. More than happy to test it when it's available on NuGet like I tried with STJ implementation and migration. |
Resolving #42 it seemed worthwhile to create a
NetTopologySuite.IO
project that does not depend onNewtonsoft.Json
but on the newSystem.Text.Json
package to improve performance and avoid/minimize unnecessary package references.The text was updated successfully, but these errors were encountered: